Moved JsonObject._buffer into the JsonNode's content

This commit is contained in:
Benoit Blanchon
2014-09-27 15:34:34 +02:00
parent a7ff04db0e
commit bcc8cece24
5 changed files with 20 additions and 13 deletions

View File

@ -7,7 +7,11 @@
JsonObject JsonBuffer::createObject()
{
JsonNode* node = createNode(JSON_OBJECT);
return JsonObject(this, node);
if (node)
node->content.asObject.buffer = this;
return JsonObject(node);
}
JsonNode* JsonBuffer::createNode(JsonNodeType type)

View File

@ -1,5 +1,7 @@
#pragma once
class JsonBuffer;
enum JsonNodeType
{
JSON_UNDEFINED,
@ -37,7 +39,8 @@ struct JsonNode
struct
{
JsonNode* child;
} asObjectNode;
JsonBuffer* buffer;
} asObject;
} content;
};

View File

@ -33,7 +33,7 @@
size_t JsonObject::size()
{
JsonNode* firstChild = _node->content.asObjectNode.child;
JsonNode* firstChild = _node->content.asObject.child;
int size = 0;
@ -55,7 +55,7 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
{
if (!_node || _node->type != JSON_OBJECT) return 0;
JsonNode* firstChild = _node->content.asObjectNode.child;
JsonNode* firstChild = _node->content.asObject.child;
JsonNode* lastChild = 0;
for (JsonNode* child = firstChild; child; child = child->next)
@ -68,16 +68,18 @@ JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
lastChild = child;
}
JsonNode* newValueNode = _buffer->createNode(JSON_UNDEFINED);
JsonBuffer* buffer = _node->content.asObject.buffer;
JsonNode* newKeyNode = _buffer->createNode(JSON_KEY);
JsonNode* newValueNode = buffer->createNode(JSON_UNDEFINED);
JsonNode* newKeyNode = buffer->createNode(JSON_KEY);
newKeyNode->content.asKey.key = key;
newKeyNode->content.asKey.value = newValueNode;
if (lastChild)
lastChild->next = newKeyNode;
else
_node->content.asObjectNode.child = newKeyNode;
_node->content.asObject.child = newKeyNode;
return newValueNode;
}

View File

@ -1,6 +1,5 @@
#pragma once
class JsonBuffer;
class JsonValue;
struct JsonNode;
@ -12,8 +11,8 @@ public:
{
}
JsonObject(JsonBuffer* buffer, JsonNode* node)
: _buffer(buffer), _node(node)
JsonObject(JsonNode* node)
: _node(node)
{
}
@ -22,7 +21,7 @@ public:
JsonValue operator[](const char* key);
private:
JsonBuffer* _buffer;
JsonNode* _node;
JsonNode* getOrCreateNodeAt(char const* key);
};

View File

@ -1,8 +1,7 @@
#pragma once
struct JsonNode;
//class JsonBuffer;
//class JsonNode;
//class JsonObject;
class JsonValue
{