Huge refactoring in progress...

This commit is contained in:
Benoit Blanchon
2014-10-29 21:18:27 +01:00
parent ba2b142c8a
commit 5cf744dbac
6 changed files with 58 additions and 16 deletions

View File

@ -10,6 +10,7 @@
#include "JsonArrayIterator.hpp"
#include "JsonArrayConstIterator.hpp"
#include "JsonPrintable.hpp"
#include "JsonObject.hpp"
namespace ArduinoJson {
class JsonArray : public JsonPrintable {
@ -22,6 +23,8 @@ class JsonArray : public JsonPrintable {
int size() const;
bool success() {return _buffer != NULL;}
value_type &operator[](int index) const;
value_type &add();
@ -30,6 +33,14 @@ class JsonArray : public JsonPrintable {
add().set(value);
}
void add(JsonArray &nestedArray) {
add().set(nestedArray);
}
void add(JsonObject&nestedObject){
add().set(nestedObject);
}
JsonArray &createNestedArray();
JsonObject &createNestedObject();
@ -44,6 +55,9 @@ 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
inline void addNode(Internals::JsonArrayNode *node);
JsonBuffer *_buffer;

View File

@ -10,6 +10,7 @@
#include "JsonObjectIterator.hpp"
#include "JsonPrintable.hpp"
#include "Internals/JsonObjectNode.hpp"
#include "JsonArray.hpp"
namespace ArduinoJson {
class JsonObject : public JsonPrintable {
@ -31,6 +32,14 @@ class JsonObject : public JsonPrintable {
(*this)[key] = value;
}
void add(key_type key, JsonArray &nestedArray) {
(*this)[key] = nestedArray;
}
void add(key_type key, JsonObject &nestedObject) {
(*this)[key] = nestedObject;
}
JsonArray &createNestedArray(key_type key);
JsonObject &createNestedObject(key_type key);
@ -45,6 +54,9 @@ 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
void addNode(Internals::JsonObjectNode *nodeToAdd);
void removeNode(Internals::JsonObjectNode *nodeToRemove);

View File

@ -26,6 +26,22 @@ class JsonValue {
void set(JsonArray &array);
void set(JsonObject &object);
template <typename T>
JsonValue &operator=(T value) {
set(value);
return *this;
}
JsonValue &operator=(JsonArray& array) {
set(array);
return *this;
}
JsonValue &operator=(JsonObject& object) {
set(object);
return *this;
}
JsonArray &asArray();
JsonObject &asObject();
bool asBool() const;
@ -34,10 +50,7 @@ class JsonValue {
long asLong() const;
template <typename T>
JsonValue &operator=(T value) {
set(value);
return *this;
}
T as(){}
static JsonValue &invalid() { return _invalid; }
@ -50,4 +63,8 @@ class JsonValue {
Internals::JsonValueContent _content;
static JsonValue _invalid;
};
template <>
int JsonValue::as<int>() { return asLong(); }
}