Преглед изворни кода

Improved JsonObjectIterator

Benoit Blanchon пре 11 година
родитељ
комит
888fdc1d54
2 измењених фајлова са 71 додато и 70 уклоњено
  1. 35 34
      include/ArduinoJson/JsonObjectIterator.hpp
  2. 36 36
      include/ArduinoJson/JsonObjectKeyValue.hpp

+ 35 - 34
include/ArduinoJson/JsonObjectIterator.hpp

@@ -4,44 +4,45 @@
 
 namespace ArduinoJson
 {
-	class JsonObject;
+    class JsonObject;
 
-	class JsonObjectIterator
-	{
-		friend class JsonObject;
+    class JsonObjectIterator
+    {
+        friend class JsonObject;
 
-	public:
-		explicit JsonObjectIterator(Internals::JsonNode* node)
-			: _objectKeyValue(node)
-		{
-		}
+    public:
+        explicit JsonObjectIterator(Internals::JsonNode* node)
+            : _objectKeyValue(node)
+        {
+        }
 
-		void operator++()
-		{
-			++_objectKeyValue;
-		}
+        JsonObjectIterator& operator++()
+        {
+            _objectKeyValue = JsonObjectKeyValue(_objectKeyValue.next());
+            return *this;
+        }
 
-		JsonObjectKeyValue operator*() const
-		{
-			return _objectKeyValue;
-		}
+        JsonObjectKeyValue operator*() const
+        {
+            return _objectKeyValue;
+        }
 
         JsonObjectKeyValue* operator->()
-		{
-			return &_objectKeyValue;
-		}
-
-		bool operator==(const JsonObjectIterator& other) const
-		{
-			return _objectKeyValue == other._objectKeyValue;
-		}
-
-		bool operator!=(const JsonObjectIterator& other) const
-		{
-			return _objectKeyValue != other._objectKeyValue;
-		}
-
-	private:
-		JsonObjectKeyValue _objectKeyValue;
-	};
+        {
+            return &_objectKeyValue;
+        }
+
+        bool operator==(const JsonObjectIterator& other) const
+        {
+            return _objectKeyValue == other._objectKeyValue;
+        }
+
+        bool operator!=(const JsonObjectIterator& other) const
+        {
+            return _objectKeyValue != other._objectKeyValue;
+        }
+
+    private:
+        JsonObjectKeyValue _objectKeyValue;
+    };
 }

+ 36 - 36
include/ArduinoJson/JsonObjectKeyValue.hpp

@@ -4,40 +4,40 @@
 
 namespace ArduinoJson
 {
-	class JsonObjectKeyValue
-	{
-	public:
-		explicit JsonObjectKeyValue(Internals::JsonNode* node)
-			: _node(node)
-		{			
-		}
-
-		const char* key() const
-		{
-			return _node->getAsObjectKey();
-		}
-
-		JsonValue value()
-		{
-			return JsonValue(_node->getAsObjectValue());
-		}
-
-		void operator++()
-		{
-			_node = _node->next;
-		}
-
-		bool operator==(const JsonObjectKeyValue& other) const
-		{
-			return _node == other._node;
-		}
-
-		bool operator!=(const JsonObjectKeyValue& other) const
-		{
-			return _node != other._node;
-		}		
-
-	private:
-		Internals::JsonNode* _node;
-	};
+    class JsonObjectKeyValue
+    {
+    public:
+        explicit JsonObjectKeyValue(Internals::JsonNode* node)
+            : _node(node)
+        {
+        }
+
+        const char* key() const
+        {
+            return _node->getAsObjectKey();
+        }
+
+        JsonValue value()
+        {
+            return JsonValue(_node->getAsObjectValue());
+        }
+
+        bool operator==(const JsonObjectKeyValue& other) const
+        {
+            return _node == other._node;
+        }
+
+        bool operator!=(const JsonObjectKeyValue& other) const
+        {
+            return _node != other._node;
+        }
+
+        Internals::JsonNode* next()
+        {
+            return _node->next;
+        }
+
+    private:
+        Internals::JsonNode* _node;
+    };
 }