diff --git a/srcs/JsonObject.cpp b/srcs/JsonObject.cpp new file mode 100644 index 00000000..230586ea --- /dev/null +++ b/srcs/JsonObject.cpp @@ -0,0 +1,38 @@ +//#include "JsonBuffer.h" +#include "JsonObject.h" +#include "JsonValue.h" +//#include "JsonNode.h" + + +//JsonValue& JsonObject::operator[](char const* key) +//{ +// addNodeAt(key, innerObject._node); +// return innerObject; +//} +// +//void JsonObject::addNodeAt(const char* key, JsonNode& node) +//{ +// JsonNode& keyNode = _buffer.createNode(); +// keyNode.becomeKey(key, node); +// appendChild(keyNode); +//} +// +//void JsonObject::appendChild(JsonNode& newChild) +//{ +// JsonNode* lastChild = _node.asObjectNode.child; +// while (lastChild->next) +// { +// lastChild = lastChild->next; +// } +// +// if (lastChild) +// lastChild->next = &newChild; +// else +// _node.asObjectNode.child = &newChild; +//} + +JsonValue JsonObject::operator[](char const* key) +{ + _size++; + return JsonValue(); +} \ No newline at end of file diff --git a/srcs/JsonObject.h b/srcs/JsonObject.h index e0f53715..5ad8d7a6 100644 --- a/srcs/JsonObject.h +++ b/srcs/JsonObject.h @@ -1,42 +1,52 @@ #pragma once class JsonBuffer; -struct JsonNode; class JsonValue; +struct JsonNode; class JsonObject { -// friend class JsonValue; -// -//public: -// JsonObject(JsonBuffer& buffer, JsonNode& node) -// : _buffer(buffer), _node(node) -// { -// } -// -// JsonObject createObject(const char* key) -// { -// JsonObject innerObject = _buffer.createObject(); -// addNodeAt(key, innerObject._node); -// return innerObject; -// } -// -// JsonValue& operator[](const char* key); + // friend class JsonValue; + // + //public: + // JsonObject(JsonBuffer& buffer, JsonNode& node) + // : _buffer(buffer), _node(node) + // { + // } + // + // JsonObject createObject(const char* key) + // { + // JsonObject innerObject = _buffer.createObject(); + // addNodeAt(key, innerObject._node); + // return innerObject; + // } + // public: - int size() + + explicit JsonObject() + : _size(0) { - return 0; } -//private: -// JsonBuffer& _buffer; -// JsonNode& _node; -// -// void addNodeAt(char const* key, JsonNode& node); -// JsonNode& getNodeAt(const char* key); -// -// // TODO: pull up -// void appendChild(JsonNode& newChild); + int size() + { + return _size; + } + + JsonValue operator[](const char* key); + +private: + + int _size; + + // JsonBuffer& _buffer; + // JsonNode& _node; + // + // void addNodeAt(char const* key, JsonNode& node); + // JsonNode& getNodeAt(const char* key); + // + // // TODO: pull up + // void appendChild(JsonNode& newChild); }; \ No newline at end of file diff --git a/srcs/JsonValue.h b/srcs/JsonValue.h new file mode 100644 index 00000000..cf3e9f85 --- /dev/null +++ b/srcs/JsonValue.h @@ -0,0 +1,26 @@ +#pragma once + +//class JsonBuffer; +//class JsonNode; +//class JsonObject; + +class JsonValue +{ +//public: +// +// JsonValue(JsonBuffer& buffer, JsonNode& node) +// : _buffer(buffer), _node(node) +// { +// } +// +// void operator=(const JsonObject& object); +// void operator=(int); +// +// operator JsonObject(); +// operator int(); +// +//private: +// JsonBuffer& _buffer; +// JsonNode& _node; +}; + diff --git a/srcs/srcs.vcxproj b/srcs/srcs.vcxproj index 4f9e2e09..335e3cc1 100644 --- a/srcs/srcs.vcxproj +++ b/srcs/srcs.vcxproj @@ -66,8 +66,12 @@ + + + + diff --git a/srcs/srcs.vcxproj.filters b/srcs/srcs.vcxproj.filters index a4b4b6a1..eac2a79c 100644 --- a/srcs/srcs.vcxproj.filters +++ b/srcs/srcs.vcxproj.filters @@ -21,5 +21,13 @@ Header Files + + Header Files + + + + + Source Files + \ No newline at end of file diff --git a/tests/JsonObjectTests.cpp b/tests/JsonObjectTests.cpp new file mode 100644 index 00000000..d0c2c84f --- /dev/null +++ b/tests/JsonObjectTests.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne) +{ + StaticJsonBuffer<42> json; + + JsonObject object = json.createObject(); + + object["hello"]; + EXPECT_EQ(1, object.size()); + + object["world"]; + EXPECT_EQ(2, object.size()); +} \ No newline at end of file diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj index 99223c99..a278b7ee 100644 --- a/tests/tests.vcxproj +++ b/tests/tests.vcxproj @@ -85,6 +85,7 @@ + diff --git a/tests/tests.vcxproj.filters b/tests/tests.vcxproj.filters index 383683cb..592f014f 100644 --- a/tests/tests.vcxproj.filters +++ b/tests/tests.vcxproj.filters @@ -27,5 +27,8 @@ Source Files + + Source Files + \ No newline at end of file