Khem khem

This commit is contained in:
Андреев Григорий 2024-08-27 13:54:35 +03:00
parent d4c48ea269
commit fadf87c0d2
5 changed files with 33 additions and 7 deletions

2
.gitignore vendored
View File

@ -9,4 +9,4 @@ building/*.png
building/*.svg
.idea/
local.sh

View File

@ -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"};

View File

@ -29,6 +29,11 @@ namespace json {
struct JSON_reference;
struct JSON_reference_const;
struct JSON;
typedef std::vector<JSON> jarr;
typedef std::map<std::string, JSON> jdict;
struct JSON {
void* value = NULL;
json_t type = null_symbol;

View File

@ -83,18 +83,34 @@ namespace json {
}
Integer & JSON::asInteger() {
if (isNull()) {
value = new Integer();
type = integer;
}
return const_cast<Integer&>(const_cast<const JSON*>(this)->asInteger());
}
std::string &JSON::asString() {
if (isNull()) {
value = new std::string();
type = string;
}
return const_cast<std::string&>(const_cast<const JSON*>(this)->asString());
}
std::vector<JSON> &JSON::asArray() {
if (isNull()) {
value = new ArrayData();
type = array;
}
return const_cast<std::vector<JSON>&>(const_cast<const JSON*>(this)->asArray());
}
std::map<std::string, JSON> &JSON::asDictionary() {
if (isNull()) {
value = new DictionaryData();
type = dictionary;
}
return const_cast<std::map<std::string, JSON>&>(const_cast<const JSON*>(this)->asDictionary());
}

View File

@ -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("[[[]]]"));