From bf7d8e987dc960d02e8d7b86ed888970ac4a9b5c Mon Sep 17 00:00:00 2001 From: Andreev Gregory Date: Tue, 13 Aug 2024 15:07:35 +0300 Subject: [PATCH] Now dereferencing json_ref with imaginary chain will "fix" the JSON to make dereferenciation possible --- src/library/jsonincpp/quality_of_life_2.cpp | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/library/jsonincpp/quality_of_life_2.cpp b/src/library/jsonincpp/quality_of_life_2.cpp index 3593fce..7e4034d 100644 --- a/src/library/jsonincpp/quality_of_life_2.cpp +++ b/src/library/jsonincpp/quality_of_life_2.cpp @@ -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) {