Просмотр исходного кода

Replaced JsonObjectIterator and JsonObjectConstIterator by a template

Benoit Blanchon 11 лет назад
Родитель
Сommit
8ac4346fd5

+ 5 - 4
include/ArduinoJson/JsonObject.hpp

@@ -6,10 +6,10 @@
 
 #pragma once
 
+#include "Internals/JsonIterator.hpp"
+#include "Internals/JsonObjectNode.hpp"
 #include "Internals/JsonPrintable.hpp"
 #include "Internals/ReferenceType.hpp"
-#include "JsonObjectConstIterator.hpp"
-#include "JsonObjectIterator.hpp"
 
 #define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \
   (sizeof(JsonObject) +                      \
@@ -27,8 +27,9 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
  public:
   typedef const char *key_type;
   typedef JsonPair value_type;
-  typedef JsonObjectIterator iterator;
-  typedef JsonObjectConstIterator const_iterator;
+  typedef Internals::JsonIterator<Internals::JsonObjectNode, JsonPair> iterator;
+  typedef Internals::JsonIterator<Internals::JsonObjectNode, const JsonPair>
+      const_iterator;
 
   bool success() const { return _buffer != NULL; }
   int size() const;

+ 0 - 37
include/ArduinoJson/JsonObjectConstIterator.hpp

@@ -1,37 +0,0 @@
-// Copyright Benoit Blanchon 2014
-// MIT License
-//
-// Arduino JSON library
-// https://github.com/bblanchon/ArduinoJson
-
-#pragma once
-
-#include "Internals/JsonObjectNode.hpp"
-
-namespace ArduinoJson {
-
-class JsonObjectConstIterator {
- public:
-  explicit JsonObjectConstIterator(Internals::JsonObjectNode *node)
-      : _node(node) {}
-
-  const JsonPair &operator*() { return _node->content; }
-  const JsonPair *operator->() { return &_node->content; }
-
-  bool operator==(const JsonObjectConstIterator &other) const {
-    return _node == other._node;
-  }
-
-  bool operator!=(const JsonObjectConstIterator &other) const {
-    return _node != other._node;
-  }
-
-  JsonObjectConstIterator &operator++() {
-    if (_node) _node = _node->next;
-    return *this;
-  }
-
- private:
-  Internals::JsonObjectNode *_node;
-};
-}

+ 0 - 36
include/ArduinoJson/JsonObjectIterator.hpp

@@ -1,36 +0,0 @@
-// Copyright Benoit Blanchon 2014
-// MIT License
-//
-// Arduino JSON library
-// https://github.com/bblanchon/ArduinoJson
-
-#pragma once
-
-#include "Internals/JsonObjectNode.hpp"
-
-namespace ArduinoJson {
-
-class JsonObjectIterator {
- public:
-  explicit JsonObjectIterator(Internals::JsonObjectNode *node) : _node(node) {}
-
-  JsonPair &operator*() { return _node->content; }
-  JsonPair *operator->() { return &_node->content; }
-
-  bool operator==(const JsonObjectIterator &other) const {
-    return _node == other._node;
-  }
-
-  bool operator!=(const JsonObjectIterator &other) const {
-    return _node != other._node;
-  }
-
-  JsonObjectIterator &operator++() {
-    if (_node) _node = _node->next;
-    return *this;
-  }
-
- private:
-  Internals::JsonObjectNode *_node;
-};
-}