forked from bblanchon/ArduinoJson
Removed all friends of JsonValue
This commit is contained in:
@ -8,14 +8,14 @@
|
||||
|
||||
#include <new>
|
||||
|
||||
#include "ArduinoJson/JsonValue.hpp"
|
||||
#include "ArduinoJson/Internals/JsonValueInternal.hpp"
|
||||
#include "ArduinoJson/Internals/JsonParser.hpp"
|
||||
#include "ArduinoJson/Internals/JsonNode.hpp"
|
||||
|
||||
using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonBuffer::createValue() { return JsonValue(createNode()); }
|
||||
JsonValue JsonBuffer::createValue() { return JsonValueInternal(createNode()); }
|
||||
|
||||
JsonNode *JsonBuffer::createNode() {
|
||||
void *node = allocateNode();
|
||||
@ -36,7 +36,7 @@ JsonObject JsonBuffer::parseObject(char *json) {
|
||||
|
||||
JsonValue JsonBuffer::parseValue(char *json) {
|
||||
JsonParser parser(this, json);
|
||||
return JsonValue(parser.parseAnything());
|
||||
return JsonValueInternal(parser.parseAnything());
|
||||
}
|
||||
|
||||
JsonNode *JsonBuffer::createArrayNode() {
|
||||
|
@ -17,20 +17,17 @@ using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonObject::operator[](char const *key) {
|
||||
JsonNode *node = getOrCreateNodeAt(key);
|
||||
return JsonValue(node);
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
return JsonValueInternal(node);
|
||||
}
|
||||
|
||||
void JsonObject::remove(char const *key) {
|
||||
for (iterator it = begin(); it != end(); ++it) {
|
||||
if (!strcmp(it->key(), key)) {
|
||||
removeChild(it->_node);
|
||||
}
|
||||
}
|
||||
JsonNode *nodeToRemove = getPairAt(key);
|
||||
if (nodeToRemove) removeChild(nodeToRemove);
|
||||
}
|
||||
|
||||
JsonArray JsonObject::createNestedArray(char const *key) {
|
||||
JsonNode *node = getOrCreateNodeAt(key);
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
|
||||
if (node) node->setAsArray(_node->getContainerBuffer());
|
||||
|
||||
@ -38,17 +35,23 @@ JsonArray JsonObject::createNestedArray(char const *key) {
|
||||
}
|
||||
|
||||
JsonObject JsonObject::createNestedObject(char const *key) {
|
||||
JsonNode *node = getOrCreateNodeAt(key);
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
|
||||
if (node) node->setAsObject(_node->getContainerBuffer());
|
||||
|
||||
return JsonObject(node);
|
||||
}
|
||||
|
||||
JsonNode *JsonObject::getOrCreateNodeAt(const char *key) {
|
||||
for (iterator it = begin(); it != end(); ++it) {
|
||||
if (!strcmp(it->key(), key)) return it->value()._node;
|
||||
JsonNode *JsonObject::getPairAt(const char *key) {
|
||||
for (JsonNode *node = firstChild(); node; node = node->next) {
|
||||
if (!strcmp(node->getAsObjectKey(), key)) return node;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JsonNode *JsonObject::getOrCreateValueAt(const char *key) {
|
||||
JsonNode *existingNode = getPairAt(key);
|
||||
if (existingNode) return existingNode->getAsObjectValue();
|
||||
|
||||
JsonNode *newValueNode = createNode();
|
||||
if (!newValueNode) return 0;
|
||||
|
Reference in New Issue
Block a user