forked from bblanchon/ArduinoJson
Huge refactoring in progress...
This commit is contained in:
@ -6,8 +6,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// TODO: cleanup
|
||||
|
||||
namespace ArduinoJson {
|
||||
class JsonArray;
|
||||
class JsonArrayConstIterator;
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class CompactJsonWriter : public JsonWriter {
|
||||
public:
|
||||
explicit CompactJsonWriter(Print *sink) : JsonWriter(sink) {}
|
||||
|
@ -14,16 +14,10 @@ namespace Internals {
|
||||
|
||||
class JsonArrayNode {
|
||||
public:
|
||||
static JsonArrayNode* createFrom(JsonBuffer* buffer) {
|
||||
void* ptr = buffer->alloc(sizeof(JsonArrayNode));
|
||||
return ptr ? new (ptr) JsonArrayNode() : NULL;
|
||||
}
|
||||
JsonArrayNode() : next(0) {}
|
||||
|
||||
JsonArrayNode* next;
|
||||
JsonValue value;
|
||||
|
||||
private:
|
||||
JsonArrayNode() : next(0) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,10 @@ namespace Internals {
|
||||
|
||||
class JsonObjectNode {
|
||||
public:
|
||||
static JsonObjectNode* createFrom(JsonBuffer* buffer, const char* key) {
|
||||
void* ptr = buffer->alloc(sizeof(JsonObjectNode));
|
||||
return ptr ? new (ptr) JsonObjectNode(key) : NULL;
|
||||
}
|
||||
JsonObjectNode(const char* k) : pair(k), next(NULL) {}
|
||||
|
||||
JsonPair pair;
|
||||
JsonObjectNode* next;
|
||||
|
||||
private:
|
||||
JsonObjectNode(const char* k) : pair(k), next(NULL) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,4 @@ class JsonSerializer {
|
||||
JsonWriter &_writer;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class JsonWriter {
|
||||
public:
|
||||
explicit JsonWriter(Print *sink) : _sink(sink), _length(0) {}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class PrettyJsonWriter : public JsonWriter {
|
||||
public:
|
||||
explicit PrettyJsonWriter(IndentedPrint *sink)
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
namespace Internals {
|
||||
|
||||
class QuotedString {
|
||||
public:
|
||||
static size_t printTo(const char *, Print *);
|
||||
|
||||
static char *extractFrom(char *input, char **end);
|
||||
};
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "JsonObject.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
class JsonArray : public JsonPrintable {
|
||||
friend class JsonBuffer;
|
||||
|
||||
@ -25,14 +26,15 @@ class JsonArray : public JsonPrintable {
|
||||
|
||||
bool success() { return _buffer != NULL; }
|
||||
|
||||
value_type &operator[](int index) const;
|
||||
value_type &add();
|
||||
value_type &operator[](int index) const { return at(index); }
|
||||
value_type &at(int index) const;
|
||||
|
||||
template <typename T>
|
||||
void add(T value) {
|
||||
add().set(value);
|
||||
}
|
||||
|
||||
value_type &add();
|
||||
void add(double value, int decimals) { add().set(value, decimals); }
|
||||
void add(JsonArray &nestedArray) { add().set(nestedArray); }
|
||||
void add(JsonObject &nestedObject) { add().set(nestedObject); }
|
||||
@ -54,14 +56,21 @@ class JsonArray : public JsonPrintable {
|
||||
// constructor is private: instance must be created via a JsonBuffer
|
||||
JsonArray(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
JsonArray(const JsonArray &); // copy is forbidden, use a reference instead
|
||||
JsonArray &operator=(
|
||||
const JsonArray &); // copy is forbidden, use a reference instead
|
||||
// copy is forbidden, use a reference instead
|
||||
JsonArray(const JsonArray &);
|
||||
JsonArray &operator=(const JsonArray &);
|
||||
|
||||
Internals::JsonArrayNode *createNode();
|
||||
inline void addNode(Internals::JsonArrayNode *node);
|
||||
|
||||
JsonBuffer *_buffer;
|
||||
Internals::JsonArrayNode *_firstNode;
|
||||
static JsonArray _invalid;
|
||||
};
|
||||
|
||||
bool operator==(const JsonArray &left, const JsonArray &right) {
|
||||
// two JsonArray are equal if they are the same instance
|
||||
// (we don't compare the content)
|
||||
return &left == &right;
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,4 @@ class JsonArrayConstIterator {
|
||||
private:
|
||||
Internals::JsonArrayNode *_node;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "ForwardDeclarations.hpp"
|
||||
#include "JsonValue.hpp"
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "JsonArray.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
class JsonObject : public JsonPrintable {
|
||||
friend class JsonBuffer;
|
||||
|
||||
@ -22,16 +23,18 @@ class JsonObject : public JsonPrintable {
|
||||
typedef JsonObjectIterator iterator;
|
||||
typedef JsonObjectConstIterator const_iterator;
|
||||
|
||||
bool success() const { return _buffer != NULL; }
|
||||
int size() const;
|
||||
|
||||
JsonValue &operator[](key_type key);
|
||||
JsonValue &at(key_type key);
|
||||
JsonValue &operator[](key_type key) { return at(key); }
|
||||
|
||||
void remove(key_type key);
|
||||
|
||||
template <typename T>
|
||||
void add(key_type key, T value) {
|
||||
add(key).set(value);
|
||||
}
|
||||
|
||||
void add(key_type key, JsonArray &array) { add(key).set(array); }
|
||||
void add(key_type key, JsonObject &object) { add(key).set(object); }
|
||||
|
||||
@ -57,6 +60,7 @@ class JsonObject : public JsonPrintable {
|
||||
const JsonObject &); // copy is forbidden, use a reference instead
|
||||
|
||||
JsonValue &add(key_type key) { return (*this)[key]; }
|
||||
Internals::JsonObjectNode *createNode(key_type key);
|
||||
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
||||
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
||||
|
||||
@ -67,4 +71,10 @@ class JsonObject : public JsonPrintable {
|
||||
Internals::JsonObjectNode *_firstNode;
|
||||
static JsonObject _invalid;
|
||||
};
|
||||
|
||||
bool operator==(const JsonObject &left, const JsonObject &right) {
|
||||
// two JsonObject are equal if they are the same instance
|
||||
// (we don't compare the content)
|
||||
return &left == &right;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Internals/JsonObjectNode.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
struct JsonPair {
|
||||
JsonPair(const char* k) : key(k) {}
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "Internals/JsonValueType.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
class JsonValue {
|
||||
public:
|
||||
JsonValue() : _type(Internals::JSON_UNDEFINED) {}
|
||||
@ -64,7 +63,10 @@ class JsonValue {
|
||||
void writeTo(Internals::JsonWriter &writer) const;
|
||||
|
||||
private:
|
||||
JsonValue(Internals::JsonValueType type) : _type(type) {}
|
||||
|
||||
Internals::JsonValueType _type;
|
||||
Internals::JsonValueContent _content;
|
||||
static JsonValue _invalid;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user