Просмотр исходного кода

Unified JsonArrayNode and JsonObjectNode

Benoit Blanchon 11 лет назад
Родитель
Сommit
bafec6f1a3

+ 1 - 1
include/ArduinoJson/Internals/JsonArrayNode.hpp

@@ -14,8 +14,8 @@ namespace Internals {
 struct JsonArrayNode {
   JsonArrayNode() : next(NULL) {}
 
+  JsonVariant content;
   JsonArrayNode* next;
-  JsonVariant value;
 };
 }
 }

+ 2 - 2
include/ArduinoJson/Internals/JsonIterator.hpp

@@ -14,8 +14,8 @@ class JsonIterator {
  public:
   explicit JsonIterator(TNode *node) : _node(node) {}
 
-  TValue &operator*() const { return _node->value; }
-  TValue *operator->() { return &_node->value; }
+  TValue &operator*() const { return _node->content; }
+  TValue *operator->() { return &_node->content; }
 
   bool operator==(const JsonIterator<TNode, TValue> &other) const {
     return _node == other._node;

+ 2 - 2
include/ArduinoJson/Internals/JsonObjectNode.hpp

@@ -12,9 +12,9 @@ namespace ArduinoJson {
 namespace Internals {
 
 struct JsonObjectNode {
-  JsonObjectNode(const char* k) : pair(k), next(NULL) {}
+  JsonObjectNode(const char* key) : content(key), next(NULL) {}
 
-  JsonPair pair;
+  JsonPair content;
   JsonObjectNode* next;
 };
 }

+ 2 - 2
include/ArduinoJson/JsonObjectConstIterator.hpp

@@ -15,8 +15,8 @@ class JsonObjectConstIterator {
   explicit JsonObjectConstIterator(Internals::JsonObjectNode *node)
       : _node(node) {}
 
-  const JsonPair &operator*() { return _node->pair; }
-  const JsonPair *operator->() { return &_node->pair; }
+  const JsonPair &operator*() { return _node->content; }
+  const JsonPair *operator->() { return &_node->content; }
 
   bool operator==(const JsonObjectConstIterator &other) const {
     return _node == other._node;

+ 2 - 2
include/ArduinoJson/JsonObjectIterator.hpp

@@ -14,8 +14,8 @@ class JsonObjectIterator {
  public:
   explicit JsonObjectIterator(Internals::JsonObjectNode *node) : _node(node) {}
 
-  JsonPair &operator*() { return _node->pair; }
-  JsonPair *operator->() { return &_node->pair; }
+  JsonPair &operator*() { return _node->content; }
+  JsonPair *operator->() { return &_node->content; }
 
   bool operator==(const JsonObjectIterator &other) const {
     return _node == other._node;

+ 3 - 3
src/JsonArray.cpp

@@ -25,7 +25,7 @@ int JsonArray::size() const {
 JsonVariant &JsonArray::at(int index) const {
   JsonArrayNode *node = _firstNode;
   while (node && index--) node = node->next;
-  return node ? node->value : JsonVariant::invalid();
+  return node ? node->content : JsonVariant::invalid();
 }
 
 JsonVariant &JsonArray::add() {
@@ -34,7 +34,7 @@ JsonVariant &JsonArray::add() {
 
   addNode(node);
 
-  return node->value;
+  return node->content;
 }
 
 JsonArrayNode *JsonArray::createNode() {
@@ -75,7 +75,7 @@ void JsonArray::writeTo(T &writer) const {
     writer.beginArray();
 
     for (;;) {
-      child->value.writeTo(writer);
+      child->content.writeTo(writer);
 
       child = child->next;
       if (!child) break;

+ 6 - 6
src/JsonObject.cpp

@@ -27,17 +27,17 @@ int JsonObject::size() const {
 
 JsonVariant &JsonObject::at(const char *key) {
   JsonObjectNode *node = getNodeAt(key);
-  return node ? node->pair.value : JsonVariant::invalid();
+  return node ? node->content.value : JsonVariant::invalid();
 }
 
 const JsonVariant &JsonObject::at(const char *key) const {
   JsonObjectNode *node = getNodeAt(key);
-  return node ? node->pair.value : JsonVariant::invalid();
+  return node ? node->content.value : JsonVariant::invalid();
 }
 
 JsonVariant &JsonObject::operator[](const char *key) {
   JsonObjectNode *node = getOrCreateNodeAt(key);
-  return node ? node->pair.value : JsonVariant::invalid();
+  return node ? node->content.value : JsonVariant::invalid();
 }
 
 void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); }
@@ -58,7 +58,7 @@ JsonObject &JsonObject::createNestedObject(const char *key) {
 
 JsonObjectNode *JsonObject::getNodeAt(const char *key) const {
   for (JsonObjectNode *node = _firstNode; node; node = node->next) {
-    if (!strcmp(node->pair.key, key)) return node;
+    if (!strcmp(node->content.key, key)) return node;
   }
   return NULL;
 }
@@ -108,9 +108,9 @@ void JsonObject::writeTo(T &writer) const {
     writer.beginObject();
 
     for (;;) {
-      writer.writeString(node->pair.key);
+      writer.writeString(node->content.key);
       writer.writeColon();
-      node->pair.value.writeTo(writer);
+      node->content.value.writeTo(writer);
 
       node = node->next;
       if (!node) break;