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(); return g();
} }
JSON & JSON_reference::g() { JSON& patch_up(JSON_reference& ref) {
if (!isDefined()) JSON* cur_last_real = &ref.last_real;
throw misuse("dereferencing json reference with non-empty imaginary part"); for (const auto& ck: ref.imaginary_chain) {
return last_real;
}
void JSON_reference::operator=(const JSON &obj) {
JSON* cur_last_real = &last_real;
for (const auto& ck: imaginary_chain) {
if (ck.type == undefined_array_element) { if (ck.type == undefined_array_element) {
if (cur_last_real->type == null_symbol) if (cur_last_real->type == null_symbol)
*cur_last_real = JSON(array); *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 = &(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) { JSON_reference JSON_reference::operator[](size_t index) {