forked from bblanchon/ArduinoJson
Merged JsonArrayNode and JsonObjectNode into a single template
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
// Copyright Benoit Blanchon 2014
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonVariant.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
struct JsonArrayNode {
|
||||
JsonArrayNode() : next(NULL) {}
|
||||
|
||||
JsonVariant content;
|
||||
JsonArrayNode* next;
|
||||
};
|
||||
}
|
||||
}
|
@ -6,16 +6,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../JsonPair.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
struct JsonObjectNode {
|
||||
JsonObjectNode() : next(NULL) {}
|
||||
template <typename T>
|
||||
struct Node {
|
||||
Node() : next(NULL) {}
|
||||
|
||||
JsonPair content;
|
||||
JsonObjectNode* next;
|
||||
T content;
|
||||
Node<T>* next;
|
||||
};
|
||||
}
|
||||
}
|
@ -6,13 +6,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Internals/JsonArrayNode.hpp"
|
||||
#include "Internals/JsonIterator.hpp"
|
||||
#include "Internals/JsonPrintable.hpp"
|
||||
#include "Internals/Node.hpp"
|
||||
#include "Internals/ReferenceType.hpp"
|
||||
#include "JsonVariant.hpp"
|
||||
|
||||
#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
|
||||
(sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(Internals::JsonArrayNode))
|
||||
(sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(JsonArray::node_type))
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
@ -25,10 +26,9 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
|
||||
|
||||
public:
|
||||
typedef JsonVariant value_type;
|
||||
typedef Internals::JsonIterator<Internals::JsonArrayNode, JsonVariant>
|
||||
iterator;
|
||||
typedef Internals::JsonIterator<Internals::JsonArrayNode, const JsonVariant>
|
||||
const_iterator;
|
||||
typedef Internals::Node<JsonVariant> node_type;
|
||||
typedef Internals::JsonIterator<node_type, JsonVariant> iterator;
|
||||
typedef Internals::JsonIterator<node_type, const JsonVariant> const_iterator;
|
||||
|
||||
int size() const;
|
||||
|
||||
@ -65,11 +65,11 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
|
||||
// constructor is private: instance must be created via a JsonBuffer
|
||||
JsonArray(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
Internals::JsonArrayNode *createNode();
|
||||
inline void addNode(Internals::JsonArrayNode *node);
|
||||
node_type *createNode();
|
||||
inline void addNode(node_type *node);
|
||||
|
||||
JsonBuffer *_buffer;
|
||||
Internals::JsonArrayNode *_firstNode;
|
||||
node_type *_firstNode;
|
||||
static JsonArray _invalid;
|
||||
};
|
||||
}
|
||||
|
@ -7,13 +7,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Internals/JsonIterator.hpp"
|
||||
#include "Internals/JsonObjectNode.hpp"
|
||||
#include "Internals/JsonPrintable.hpp"
|
||||
#include "Internals/Node.hpp"
|
||||
#include "Internals/ReferenceType.hpp"
|
||||
#include "JsonPair.hpp"
|
||||
|
||||
#define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \
|
||||
(sizeof(JsonObject) + \
|
||||
(NUMBER_OF_ELEMENTS) * sizeof(Internals::JsonObjectNode))
|
||||
(sizeof(JsonObject) + (NUMBER_OF_ELEMENTS) * sizeof(JsonObject::node_type))
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
@ -27,9 +27,9 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
|
||||
public:
|
||||
typedef const char *key_type;
|
||||
typedef JsonPair value_type;
|
||||
typedef Internals::JsonIterator<Internals::JsonObjectNode, JsonPair> iterator;
|
||||
typedef Internals::JsonIterator<Internals::JsonObjectNode, const JsonPair>
|
||||
const_iterator;
|
||||
typedef Internals::Node<JsonPair> node_type;
|
||||
typedef Internals::JsonIterator<node_type, JsonPair> iterator;
|
||||
typedef Internals::JsonIterator<node_type, const JsonPair> const_iterator;
|
||||
|
||||
bool success() const { return _buffer != NULL; }
|
||||
int size() const;
|
||||
@ -67,15 +67,15 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
|
||||
JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
JsonVariant &add(key_type key) { return (*this)[key]; }
|
||||
Internals::JsonObjectNode *createNode();
|
||||
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
||||
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
||||
node_type *createNode();
|
||||
void addNode(node_type *nodeToAdd);
|
||||
void removeNode(node_type *nodeToRemove);
|
||||
|
||||
Internals::JsonObjectNode *getNodeAt(key_type key) const;
|
||||
Internals::JsonObjectNode *getOrCreateNodeAt(key_type key);
|
||||
node_type *getNodeAt(key_type key) const;
|
||||
node_type *getOrCreateNodeAt(key_type key);
|
||||
|
||||
JsonBuffer *_buffer;
|
||||
Internals::JsonObjectNode *_firstNode;
|
||||
node_type *_firstNode;
|
||||
static JsonObject _invalid;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user