From 0dce0022d3e79c11e6aea1a1ea4451767744a675 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 9 Oct 2014 14:31:25 +0200 Subject: [PATCH] Made JsonNodeType private --- srcs/Internals/JsonNode.h | 88 +++++++++++++++++++-------------------- srcs/JsonObject.cpp | 10 ----- srcs/JsonObject.h | 1 - 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/srcs/Internals/JsonNode.h b/srcs/Internals/JsonNode.h index b521b812..d680653e 100644 --- a/srcs/Internals/JsonNode.h +++ b/srcs/Internals/JsonNode.h @@ -1,23 +1,6 @@ #pragma once class JsonBuffer; - -enum JsonNodeType -{ - JSON_UNDEFINED, - JSON_NULL, - JSON_ARRAY, - JSON_OBJECT, - JSON_KEY_VALUE, - JSON_BOOLEAN, - JSON_STRING, - JSON_LONG, - JSON_DOUBLE_0_DECIMALS, - JSON_DOUBLE_1_DECIMAL, - JSON_DOUBLE_2_DECIMALS, - // etc. -}; - class JsonWriter; class JsonNodeIterator; @@ -25,6 +8,48 @@ class JsonNode { friend class JsonNodeIterator; + enum JsonNodeType + { + JSON_UNDEFINED, + JSON_NULL, + JSON_ARRAY, + JSON_OBJECT, + JSON_KEY_VALUE, + JSON_BOOLEAN, + JSON_STRING, + JSON_LONG, + JSON_DOUBLE_0_DECIMALS, + JSON_DOUBLE_1_DECIMAL, + JSON_DOUBLE_2_DECIMALS, + // etc. + }; + + union JsonNodeContent + { + bool asBoolean; + double asDouble; + long asInteger; + const char* asString; + + struct + { + const char* key; + JsonNode* value; + } asKey; + + struct + { + JsonNode* child; + JsonBuffer* buffer; + } asContainer; + + struct + { + JsonNode* target; + } asProxy; + + }; + public: JsonNode() : type(JSON_UNDEFINED), next(0) @@ -124,35 +149,10 @@ public: void removeChildFromContainer(JsonNode* childToRemove); private: - JsonNodeType type; // <- TODO: hide JsonNode* next; + JsonNodeContent content; + JsonNodeType type; inline void writeArrayTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer inline void writeObjectTo(JsonWriter&);// TODO: <- move in JsonNodeSerializer - - union - { - bool asBoolean; - double asDouble; - long asInteger; - const char* asString; - - struct - { - const char* key; - JsonNode* value; - } asKey; - - struct - { - JsonNode* child; - JsonBuffer* buffer; - } asContainer; - - struct - { - JsonNode* target; - } asProxy; - - } content; }; \ No newline at end of file diff --git a/srcs/JsonObject.cpp b/srcs/JsonObject.cpp index de82ed1b..f02c366d 100644 --- a/srcs/JsonObject.cpp +++ b/srcs/JsonObject.cpp @@ -70,14 +70,4 @@ JsonNode* JsonObject::getOrCreateNodeAt(const char* key) addChild(newKeyNode); return newValueNode; -} - -JsonNode* JsonObject::createContainerNodeAt(char const* key, JsonNodeType type) -{ - JsonNode* node = getOrCreateNodeAt(key); - if (!node) return 0; - - node->setAsArray(_node->getContainerBuffer()); - - return node; } \ No newline at end of file diff --git a/srcs/JsonObject.h b/srcs/JsonObject.h index dfe0a9f4..da8bad8d 100644 --- a/srcs/JsonObject.h +++ b/srcs/JsonObject.h @@ -23,5 +23,4 @@ public: private: JsonNode* getOrCreateNodeAt(const char* key); - JsonNode* createContainerNodeAt(const char* key, JsonNodeType type); }; \ No newline at end of file