diff --git a/include/ArduinoJson/Internals/JsonIterator.hpp b/include/ArduinoJson/Internals/JsonIterator.hpp deleted file mode 100644 index cffeb622..00000000 --- a/include/ArduinoJson/Internals/JsonIterator.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Benoit Blanchon 2014 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -template -class JsonIterator { - public: - explicit JsonIterator(TNode *node) : _node(node) {} - - TValue &operator*() const { return _node->content; } - TValue *operator->() { return &_node->content; } - - bool operator==(const JsonIterator &other) const { - return _node == other._node; - } - - bool operator!=(const JsonIterator &other) const { - return _node != other._node; - } - - JsonIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - private: - TNode *_node; -}; -} -} diff --git a/include/ArduinoJson/Internals/Node.hpp b/include/ArduinoJson/Internals/Node.hpp index ca80a48d..0b81d367 100644 --- a/include/ArduinoJson/Internals/Node.hpp +++ b/include/ArduinoJson/Internals/Node.hpp @@ -6,6 +6,8 @@ #pragma once +#include // for NULL + namespace ArduinoJson { namespace Internals { diff --git a/include/ArduinoJson/Internals/NodeConstIterator.hpp b/include/ArduinoJson/Internals/NodeConstIterator.hpp new file mode 100644 index 00000000..4dd9ac1a --- /dev/null +++ b/include/ArduinoJson/Internals/NodeConstIterator.hpp @@ -0,0 +1,37 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#pragma once + +namespace ArduinoJson { +namespace Internals { + +template +class NodeConstIterator { + public: + explicit NodeConstIterator(const Node *node) : _node(node) {} + + const T &operator*() const { return _node->content; } + const T *operator->() { return &_node->content; } + + bool operator==(const NodeConstIterator &other) const { + return _node == other._node; + } + + bool operator!=(const NodeConstIterator &other) const { + return _node != other._node; + } + + NodeConstIterator &operator++() { + if (_node) _node = _node->next; + return *this; + } + + private: + const Node *_node; +}; +} +} diff --git a/include/ArduinoJson/Internals/NodeIterator.hpp b/include/ArduinoJson/Internals/NodeIterator.hpp new file mode 100644 index 00000000..100962e6 --- /dev/null +++ b/include/ArduinoJson/Internals/NodeIterator.hpp @@ -0,0 +1,39 @@ +// Copyright Benoit Blanchon 2014 +// MIT License +// +// Arduino JSON library +// https://github.com/bblanchon/ArduinoJson + +#pragma once + +#include "Node.hpp" + +namespace ArduinoJson { +namespace Internals { + +template +class NodeIterator { + public: + explicit NodeIterator(Node *node) : _node(node) {} + + T &operator*() const { return _node->content; } + T *operator->() { return &_node->content; } + + bool operator==(const NodeIterator &other) const { + return _node == other._node; + } + + bool operator!=(const NodeIterator &other) const { + return _node != other._node; + } + + NodeIterator &operator++() { + if (_node) _node = _node->next; + return *this; + } + + private: + Node *_node; +}; +} +} diff --git a/include/ArduinoJson/JsonArray.hpp b/include/ArduinoJson/JsonArray.hpp index 9e3114ad..4c72ca83 100644 --- a/include/ArduinoJson/JsonArray.hpp +++ b/include/ArduinoJson/JsonArray.hpp @@ -6,9 +6,10 @@ #pragma once -#include "Internals/JsonIterator.hpp" #include "Internals/JsonPrintable.hpp" #include "Internals/Node.hpp" +#include "Internals/NodeConstIterator.hpp" +#include "Internals/NodeIterator.hpp" #include "Internals/ReferenceType.hpp" #include "JsonVariant.hpp" @@ -27,8 +28,8 @@ class JsonArray : public Internals::JsonPrintable, public: typedef JsonVariant value_type; typedef Internals::Node node_type; - typedef Internals::JsonIterator iterator; - typedef Internals::JsonIterator const_iterator; + typedef Internals::NodeIterator iterator; + typedef Internals::NodeConstIterator const_iterator; int size() const; diff --git a/include/ArduinoJson/JsonObject.hpp b/include/ArduinoJson/JsonObject.hpp index a1155232..1a806b97 100644 --- a/include/ArduinoJson/JsonObject.hpp +++ b/include/ArduinoJson/JsonObject.hpp @@ -6,7 +6,8 @@ #pragma once -#include "Internals/JsonIterator.hpp" +#include "Internals/NodeIterator.hpp" +#include "Internals/NodeConstIterator.hpp" #include "Internals/JsonPrintable.hpp" #include "Internals/Node.hpp" #include "Internals/ReferenceType.hpp" @@ -28,8 +29,8 @@ class JsonObject : public Internals::JsonPrintable, typedef const char *key_type; typedef JsonPair value_type; typedef Internals::Node node_type; - typedef Internals::JsonIterator iterator; - typedef Internals::JsonIterator const_iterator; + typedef Internals::NodeIterator iterator; + typedef Internals::NodeConstIterator const_iterator; bool success() const { return _buffer != NULL; } int size() const;