Replaced JsonObjectIterator and JsonObjectConstIterator by a template

This commit is contained in:
Benoit Blanchon
2014-11-05 09:27:03 +01:00
parent bafec6f1a3
commit 8ac4346fd5
3 changed files with 5 additions and 77 deletions

View File

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

View File

@ -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;
};
}

View File

@ -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;
};
}