From 888fdc1d547367923b4e38c30a421a591a4d86ad Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 23 Oct 2014 18:56:04 +0200 Subject: [PATCH] Improved JsonObjectIterator --- include/ArduinoJson/JsonObjectIterator.hpp | 63 +++++++++++----------- include/ArduinoJson/JsonObjectKeyValue.hpp | 60 ++++++++++----------- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/include/ArduinoJson/JsonObjectIterator.hpp b/include/ArduinoJson/JsonObjectIterator.hpp index f70bc113..eb0dfaff 100644 --- a/include/ArduinoJson/JsonObjectIterator.hpp +++ b/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; - } + { + return &_objectKeyValue; + } - bool operator==(const JsonObjectIterator& other) const - { - return _objectKeyValue == other._objectKeyValue; - } + bool operator==(const JsonObjectIterator& other) const + { + return _objectKeyValue == other._objectKeyValue; + } - bool operator!=(const JsonObjectIterator& other) const - { - return _objectKeyValue != other._objectKeyValue; - } + bool operator!=(const JsonObjectIterator& other) const + { + return _objectKeyValue != other._objectKeyValue; + } - private: - JsonObjectKeyValue _objectKeyValue; - }; + private: + JsonObjectKeyValue _objectKeyValue; + }; } \ No newline at end of file diff --git a/include/ArduinoJson/JsonObjectKeyValue.hpp b/include/ArduinoJson/JsonObjectKeyValue.hpp index 27ca0133..d4b67e1c 100644 --- a/include/ArduinoJson/JsonObjectKeyValue.hpp +++ b/include/ArduinoJson/JsonObjectKeyValue.hpp @@ -4,40 +4,40 @@ namespace ArduinoJson { - class JsonObjectKeyValue - { - public: - explicit JsonObjectKeyValue(Internals::JsonNode* node) - : _node(node) - { - } + class JsonObjectKeyValue + { + public: + explicit JsonObjectKeyValue(Internals::JsonNode* node) + : _node(node) + { + } - const char* key() const - { - return _node->getAsObjectKey(); - } + const char* key() const + { + return _node->getAsObjectKey(); + } - JsonValue value() - { - return JsonValue(_node->getAsObjectValue()); - } + 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; - } + 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; - }; + private: + Internals::JsonNode* _node; + }; } \ No newline at end of file