forked from bblanchon/ArduinoJson
Simplified JsonArray
This commit is contained in:
@ -24,12 +24,14 @@ class JsonArray : public JsonContainer {
|
|||||||
|
|
||||||
JsonValue operator[](int index) const;
|
JsonValue operator[](int index) const;
|
||||||
|
|
||||||
void add(bool value);
|
template <typename T>
|
||||||
void add(const char *value);
|
void add(T value) {
|
||||||
void add(double value, int decimals = 2);
|
addNewValue() = value;
|
||||||
void add(int value) { add(static_cast<long>(value)); }
|
}
|
||||||
void add(long value);
|
|
||||||
void add(JsonContainer nestedArray); // TODO: should allow JsonValue too
|
void add(double value, int decimals = 2) {
|
||||||
|
addNewValue().set(value, decimals);
|
||||||
|
}
|
||||||
|
|
||||||
JsonArray createNestedArray();
|
JsonArray createNestedArray();
|
||||||
JsonObject createNestedObject();
|
JsonObject createNestedObject();
|
||||||
@ -41,5 +43,8 @@ class JsonArray : public JsonContainer {
|
|||||||
|
|
||||||
const_iterator begin() const { return const_iterator(firstChild()); }
|
const_iterator begin() const { return const_iterator(firstChild()); }
|
||||||
const_iterator end() const { return const_iterator(0); }
|
const_iterator end() const { return const_iterator(0); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
JsonValue addNewValue();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Arduino/Printable.hpp"
|
#include "Arduino/Printable.hpp"
|
||||||
#include "ForwardDeclarations.hpp"
|
|
||||||
#include "Internals/JsonNodeIterator.hpp"
|
#include "Internals/JsonNodeIterator.hpp"
|
||||||
#include "Internals/JsonNodeWrapper.hpp"
|
#include "Internals/JsonNodeWrapper.hpp"
|
||||||
|
|
||||||
namespace ArduinoJson {
|
namespace ArduinoJson {
|
||||||
|
|
||||||
class JsonContainer : public Printable, public Internals::JsonNodeWrapper {
|
class JsonContainer : public Printable, public Internals::JsonNodeWrapper {
|
||||||
friend class JsonArray;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JsonContainer() {}
|
JsonContainer() {}
|
||||||
|
|
||||||
|
@ -20,45 +20,10 @@ JsonValue JsonArray::operator[](int index) const {
|
|||||||
return JsonValue();
|
return JsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonArray::add(bool value) {
|
JsonValue JsonArray::addNewValue() {
|
||||||
JsonNode *node = createNode();
|
JsonNode *node = createNode();
|
||||||
if (!node) return;
|
if (node) addChild(node);
|
||||||
|
return JsonValueInternal(node);
|
||||||
node->setAsBoolean(value);
|
|
||||||
addChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JsonArray::add(char const *value) {
|
|
||||||
JsonNode *node = createNode();
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
node->setAsString(value);
|
|
||||||
addChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JsonArray::add(double value, int decimals) {
|
|
||||||
JsonNode *node = createNode();
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
node->setAsDouble(value, decimals);
|
|
||||||
addChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JsonArray::add(long value) {
|
|
||||||
JsonNode *node = createNode();
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
node->setAsLong(value);
|
|
||||||
addChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: we should have the same issue as in JsonValue
|
|
||||||
void JsonArray::add(JsonContainer nestedContainer) {
|
|
||||||
JsonNode *node = createNode();
|
|
||||||
if (!node) return;
|
|
||||||
|
|
||||||
node->duplicate(nestedContainer._node);
|
|
||||||
addChild(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonArray JsonArray::createNestedArray() {
|
JsonArray JsonArray::createNestedArray() {
|
||||||
|
Reference in New Issue
Block a user