Now dereferencing json_ref with imaginary chain will "fix" the JSON to make dereferenciation possible

This commit is contained in:
Андреев Григорий 2024-08-13 15:07:35 +03:00
parent 149a363947
commit bf7d8e987d

View File

@ -9,15 +9,9 @@ namespace json {
return g();
}
JSON & JSON_reference::g() {
if (!isDefined())
throw misuse("dereferencing json reference with non-empty imaginary part");
return last_real;
}
void JSON_reference::operator=(const JSON &obj) {
JSON* cur_last_real = &last_real;
for (const auto& ck: imaginary_chain) {
JSON& patch_up(JSON_reference& ref) {
JSON* cur_last_real = &ref.last_real;
for (const auto& ck: ref.imaginary_chain) {
if (ck.type == undefined_array_element) {
if (cur_last_real->type == null_symbol)
*cur_last_real = JSON(array);
@ -33,7 +27,15 @@ namespace json {
cur_last_real = &(cur_last_real->asDictionary()[ck.when_dictionary_key]);
}
}
*cur_last_real = obj;
return *cur_last_real;
}
JSON & JSON_reference::g() {
return patch_up(*this);
}
void JSON_reference::operator=(const JSON &obj) {
patch_up(*this) = obj;
}
JSON_reference JSON_reference::operator[](size_t index) {