From fadf87c0d2ad63ec18fcf7d52206260052970575 Mon Sep 17 00:00:00 2001 From: Andreev Gregory Date: Tue, 27 Aug 2024 13:54:35 +0300 Subject: [PATCH] Khem khem --- .gitignore | 2 +- building/main.cpp | 2 +- src/library/jsonincpp/jsonobj.h | 5 +++++ src/library/jsonincpp/quality_of_life.cpp | 16 ++++++++++++++++ src/tests/test0.cpp | 15 ++++++++++----- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index fc8ccb4..1650dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ building/*.png building/*.svg .idea/ - +local.sh diff --git a/building/main.cpp b/building/main.cpp index ffac90b..af9a7b3 100644 --- a/building/main.cpp +++ b/building/main.cpp @@ -69,7 +69,7 @@ struct TestWebsiteBuildScript { }; for (std::string& u: T.exported_headers) u = "jsonincpp/" + u; - T.installation_dir = ""; + T.installation_dir = "json"; my_targets.push_back(T); } if (make_tests) { CTarget T{"libjsonincpp_test0", "executable"}; diff --git a/src/library/jsonincpp/jsonobj.h b/src/library/jsonincpp/jsonobj.h index 673910b..0017b88 100644 --- a/src/library/jsonincpp/jsonobj.h +++ b/src/library/jsonincpp/jsonobj.h @@ -29,6 +29,11 @@ namespace json { struct JSON_reference; struct JSON_reference_const; + struct JSON; + + typedef std::vector jarr; + typedef std::map jdict; + struct JSON { void* value = NULL; json_t type = null_symbol; diff --git a/src/library/jsonincpp/quality_of_life.cpp b/src/library/jsonincpp/quality_of_life.cpp index 966613b..1c83000 100644 --- a/src/library/jsonincpp/quality_of_life.cpp +++ b/src/library/jsonincpp/quality_of_life.cpp @@ -83,18 +83,34 @@ namespace json { } Integer & JSON::asInteger() { + if (isNull()) { + value = new Integer(); + type = integer; + } return const_cast(const_cast(this)->asInteger()); } std::string &JSON::asString() { + if (isNull()) { + value = new std::string(); + type = string; + } return const_cast(const_cast(this)->asString()); } std::vector &JSON::asArray() { + if (isNull()) { + value = new ArrayData(); + type = array; + } return const_cast&>(const_cast(this)->asArray()); } std::map &JSON::asDictionary() { + if (isNull()) { + value = new DictionaryData(); + type = dictionary; + } return const_cast&>(const_cast(this)->asDictionary()); } diff --git a/src/tests/test0.cpp b/src/tests/test0.cpp index 004c110..f635e73 100644 --- a/src/tests/test0.cpp +++ b/src/tests/test0.cpp @@ -34,12 +34,17 @@ void test_obvious(const JSON& A) { test(*big[0], *big[1], true); } -int main() { - json::JSON cba; - cba["boba"] = json::JSON("<>"); - printf("%s\n", generate_str(cba["boba"].g(), print_compact).c_str()); - // return 0; +void ftest(int i) { + JSON A; + JSON B; + A["aaa"][(size_t)i]["bbb"].g().asArray().push_back(JSON(jarr{JSON(""), JSON("")})); + // B.asDictionary(). +} +int main() { + for (int i = 0; i < 1000; i++) { + ftest(i); + } test_obvious(parse_str_flawless("{ \"aaa\": true, \"2\":[true]}")); test_obvious(parse_str_flawless("{ \"aa\": true, \"tttt\": [true, false]}")); test_obvious(parse_str_flawless("[[[]]]"));