forked from bblanchon/ArduinoJson
Replaced JsonArrayIterator and JsonArrayConstIterator by a template
This commit is contained in:
37
include/ArduinoJson/Internals/JsonIterator.hpp
Normal file
37
include/ArduinoJson/Internals/JsonIterator.hpp
Normal file
@ -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 <typename TNode, typename TValue>
|
||||||
|
class JsonIterator {
|
||||||
|
public:
|
||||||
|
explicit JsonIterator(TNode *node) : _node(node) {}
|
||||||
|
|
||||||
|
TValue &operator*() const { return _node->value; }
|
||||||
|
TValue *operator->() { return &_node->value; }
|
||||||
|
|
||||||
|
bool operator==(const JsonIterator<TNode, TValue> &other) const {
|
||||||
|
return _node == other._node;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const JsonIterator<TNode, TValue> &other) const {
|
||||||
|
return _node != other._node;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonIterator<TNode, TValue> &operator++() {
|
||||||
|
if (_node) _node = _node->next;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TNode *_node;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Internals/JsonArrayNode.hpp"
|
||||||
|
#include "Internals/JsonIterator.hpp"
|
||||||
#include "Internals/JsonPrintable.hpp"
|
#include "Internals/JsonPrintable.hpp"
|
||||||
#include "Internals/ReferenceType.hpp"
|
#include "Internals/ReferenceType.hpp"
|
||||||
#include "JsonArrayConstIterator.hpp"
|
|
||||||
#include "JsonArrayIterator.hpp"
|
|
||||||
|
|
||||||
#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
|
#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
|
||||||
(sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(Internals::JsonArrayNode))
|
(sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(Internals::JsonArrayNode))
|
||||||
@ -25,8 +25,10 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
typedef JsonVariant value_type;
|
typedef JsonVariant value_type;
|
||||||
typedef JsonArrayIterator iterator;
|
typedef Internals::JsonIterator<Internals::JsonArrayNode, JsonVariant>
|
||||||
typedef JsonArrayConstIterator const_iterator;
|
iterator;
|
||||||
|
typedef Internals::JsonIterator<Internals::JsonArrayNode, const JsonVariant>
|
||||||
|
const_iterator;
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Internals/JsonArrayNode.hpp"
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
|
||||||
|
|
||||||
class JsonArrayConstIterator {
|
|
||||||
public:
|
|
||||||
explicit JsonArrayConstIterator(Internals::JsonArrayNode *node)
|
|
||||||
: _node(node) {}
|
|
||||||
|
|
||||||
const JsonVariant &operator*() const { return _node->value; }
|
|
||||||
const JsonVariant *operator->() { return &_node->value; }
|
|
||||||
|
|
||||||
bool operator==(const JsonArrayConstIterator &other) const {
|
|
||||||
return _node == other._node;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const JsonArrayConstIterator &other) const {
|
|
||||||
return _node != other._node;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArrayConstIterator &operator++() {
|
|
||||||
if (_node) _node = _node->next;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Internals::JsonArrayNode *_node;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
// Copyright Benoit Blanchon 2014
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Arduino JSON library
|
|
||||||
// https://github.com/bblanchon/ArduinoJson
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Internals/JsonArrayNode.hpp"
|
|
||||||
|
|
||||||
namespace ArduinoJson {
|
|
||||||
|
|
||||||
class JsonArrayIterator {
|
|
||||||
public:
|
|
||||||
explicit JsonArrayIterator(Internals::JsonArrayNode *node) : _node(node) {}
|
|
||||||
|
|
||||||
JsonVariant &operator*() const { return _node->value; }
|
|
||||||
JsonVariant *operator->() { return &_node->value; }
|
|
||||||
|
|
||||||
bool operator==(const JsonArrayIterator &other) const {
|
|
||||||
return _node == other._node;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const JsonArrayIterator &other) const {
|
|
||||||
return _node != other._node;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonArrayIterator &operator++() {
|
|
||||||
if (_node) _node = _node->next;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Internals::JsonArrayNode *_node;
|
|
||||||
};
|
|
||||||
}
|
|
Reference in New Issue
Block a user