forked from bblanchon/ArduinoJson
Huge refactoring in progress...
This commit is contained in:
@ -14,16 +14,16 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
class JsonArray : public JsonPrintable {
|
||||
friend class JsonBuffer;
|
||||
|
||||
public:
|
||||
typedef JsonValue value_type;
|
||||
typedef JsonArrayIterator iterator;
|
||||
typedef JsonArrayConstIterator const_iterator;
|
||||
|
||||
JsonArray(JsonBuffer *buffer = NULL) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
int size() const;
|
||||
|
||||
bool success() {return _buffer != NULL;}
|
||||
bool success() { return _buffer != NULL; }
|
||||
|
||||
value_type &operator[](int index) const;
|
||||
value_type &add();
|
||||
@ -33,13 +33,9 @@ class JsonArray : public JsonPrintable {
|
||||
add().set(value);
|
||||
}
|
||||
|
||||
void add(JsonArray &nestedArray) {
|
||||
add().set(nestedArray);
|
||||
}
|
||||
|
||||
void add(JsonObject&nestedObject){
|
||||
add().set(nestedObject);
|
||||
}
|
||||
void add(double value, int decimals) { add().set(value, decimals); }
|
||||
void add(JsonArray &nestedArray) { add().set(nestedArray); }
|
||||
void add(JsonObject &nestedObject) { add().set(nestedObject); }
|
||||
|
||||
JsonArray &createNestedArray();
|
||||
JsonObject &createNestedObject();
|
||||
@ -55,8 +51,12 @@ class JsonArray : public JsonPrintable {
|
||||
virtual void writeTo(Internals::JsonWriter &writer) const;
|
||||
|
||||
private:
|
||||
JsonArray(const JsonArray&); // copy is forbidden, use a reference instead
|
||||
JsonArray& operator=(const JsonArray&); // copy is forbidden, use a reference instead
|
||||
// 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
|
||||
|
||||
inline void addNode(Internals::JsonArrayNode *node);
|
||||
|
||||
|
@ -14,14 +14,14 @@
|
||||
|
||||
namespace ArduinoJson {
|
||||
class JsonObject : public JsonPrintable {
|
||||
friend class JsonBuffer;
|
||||
|
||||
public:
|
||||
typedef const char *key_type;
|
||||
typedef JsonPair value_type;
|
||||
typedef JsonObjectIterator iterator;
|
||||
typedef JsonObjectConstIterator const_iterator;
|
||||
|
||||
JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
int size() const;
|
||||
|
||||
JsonValue &operator[](key_type key);
|
||||
@ -29,16 +29,11 @@ class JsonObject : public JsonPrintable {
|
||||
|
||||
template <typename T>
|
||||
void add(key_type key, T value) {
|
||||
(*this)[key] = value;
|
||||
add(key).set(value);
|
||||
}
|
||||
|
||||
void add(key_type key, JsonArray &nestedArray) {
|
||||
(*this)[key] = nestedArray;
|
||||
}
|
||||
|
||||
void add(key_type key, JsonObject &nestedObject) {
|
||||
(*this)[key] = nestedObject;
|
||||
}
|
||||
void add(key_type key, JsonArray &array) { add(key).set(array); }
|
||||
void add(key_type key, JsonObject &object) { add(key).set(object); }
|
||||
|
||||
JsonArray &createNestedArray(key_type key);
|
||||
JsonObject &createNestedObject(key_type key);
|
||||
@ -54,9 +49,14 @@ class JsonObject : public JsonPrintable {
|
||||
virtual void writeTo(Internals::JsonWriter &writer) const;
|
||||
|
||||
private:
|
||||
JsonObject(const JsonObject&); // copy is forbidden, use a reference instead
|
||||
JsonObject& operator=(const JsonObject&); // copy is forbidden, use a reference instead
|
||||
// constructor is private, instance must be created via JsonBuffer
|
||||
JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
|
||||
|
||||
JsonObject(const JsonObject &); // copy is forbidden, use a reference instead
|
||||
JsonObject &operator=(
|
||||
const JsonObject &); // copy is forbidden, use a reference instead
|
||||
|
||||
JsonValue &add(key_type key) { return (*this)[key]; }
|
||||
void addNode(Internals::JsonObjectNode *nodeToAdd);
|
||||
void removeNode(Internals::JsonObjectNode *nodeToRemove);
|
||||
|
||||
|
@ -32,25 +32,30 @@ class JsonValue {
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonValue &operator=(JsonArray& array) {
|
||||
JsonValue &operator=(JsonArray &array) {
|
||||
set(array);
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonValue &operator=(JsonObject& object) {
|
||||
JsonValue &operator=(JsonObject &object) {
|
||||
set(object);
|
||||
return *this;
|
||||
}
|
||||
|
||||
JsonArray &asArray();
|
||||
JsonObject &asObject();
|
||||
bool asBool() const;
|
||||
const char *asString() const;
|
||||
double asDouble() const;
|
||||
long asLong() const;
|
||||
operator bool() const;
|
||||
operator const char *() const;
|
||||
operator double() const;
|
||||
operator long() const;
|
||||
operator JsonArray &() const;
|
||||
operator JsonObject &() const;
|
||||
|
||||
JsonArray &asArray() { return static_cast<JsonArray &>(*this); };
|
||||
JsonObject &asObject() { return static_cast<JsonObject &>(*this); };
|
||||
|
||||
template <typename T>
|
||||
T as(){}
|
||||
T as() {
|
||||
return static_cast<T>(*this);
|
||||
}
|
||||
|
||||
static JsonValue &invalid() { return _invalid; }
|
||||
|
||||
@ -63,8 +68,3 @@ class JsonValue {
|
||||
Internals::JsonValueContent _content;
|
||||
static JsonValue _invalid;
|
||||
};
|
||||
|
||||
template <>
|
||||
int JsonValue::as<int>() { return asLong(); }
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user