From 8baf6294ff5231e4db141f8da25301ffc7ca0e8b Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Mon, 18 Nov 2024 15:26:49 -0500 Subject: [PATCH] json_pointer_arg -> json_reference_arg --- include/jsoncons/basic_json.hpp | 335 +++++++++--------- include/jsoncons/json_type.hpp | 8 +- include/jsoncons/tag_type.hpp | 6 +- test/CMakeLists.txt | 2 +- ...tests.cpp => json_reference_arg_tests.cpp} | 44 +-- test/corelib/src/json_storage_tests.cpp | 4 +- 6 files changed, 199 insertions(+), 200 deletions(-) rename test/corelib/src/{json_pointer_arg_tests.cpp => json_reference_arg_tests.cpp} (74%) diff --git a/include/jsoncons/basic_json.hpp b/include/jsoncons/basic_json.hpp index 8df3b1040..dffe31ddd 100644 --- a/include/jsoncons/basic_json.hpp +++ b/include/jsoncons/basic_json.hpp @@ -827,27 +827,27 @@ namespace jsoncons { } }; - struct json_pointer_storage + struct json_reference_storage { uint8_t storage_kind_:4; uint8_t short_str_length_:4; semantic_tag tag_; - basic_json* p_; + std::reference_wrapper ref_; - json_pointer_storage(basic_json* p) - : storage_kind_(static_cast(json_storage_kind::json_pointer)), short_str_length_(0), tag_(p->tag()), - p_(p) + json_reference_storage(basic_json& ref) + : storage_kind_(static_cast(json_storage_kind::json_reference)), short_str_length_(0), tag_(ref.tag()), + ref_(ref) { } - basic_json* value() + basic_json& value() { - return p_; + return ref_.get(); } - const basic_json* value() const + const basic_json& value() const { - return p_; + return ref_.get(); } }; @@ -867,7 +867,7 @@ namespace jsoncons { object_storage object_; empty_object_storage empty_object_; json_const_pointer_storage json_const_pointer_; - json_pointer_storage json_pointer_; + json_reference_storage json_ref_; }; void destroy() @@ -1112,9 +1112,9 @@ namespace jsoncons { return json_const_pointer_; } - json_pointer_storage& cast(identity) + json_reference_storage& cast(identity) { - return json_pointer_; + return json_ref_; } const json_const_pointer_storage& cast(identity) const @@ -1122,9 +1122,9 @@ namespace jsoncons { return json_const_pointer_; } - const json_pointer_storage& cast(identity) const + const json_reference_storage& cast(identity) const { - return json_pointer_; + return json_ref_; } template @@ -1159,7 +1159,7 @@ namespace jsoncons { case json_storage_kind::array : swap_l_r(other); break; case json_storage_kind::object : swap_l_r(other); break; case json_storage_kind::json_const_pointer : swap_l_r(other); break; - case json_storage_kind::json_pointer : swap_l_r(other); break; + case json_storage_kind::json_reference : swap_l_r(other); break; default: JSONCONS_UNREACHABLE(); break; @@ -1453,8 +1453,8 @@ namespace jsoncons { return json_type::object_value; case json_storage_kind::json_const_pointer: return cast().value()->type(); - case json_storage_kind::json_pointer: - return cast().value()->type(); + case json_storage_kind::json_reference: + return cast().value().type(); default: JSONCONS_UNREACHABLE(); break; @@ -1471,8 +1471,8 @@ namespace jsoncons { { case json_storage_kind::json_const_pointer: return cast().value()->tag(); - case json_storage_kind::json_pointer: - return cast().value()->tag(); + case json_storage_kind::json_reference: + return cast().value().tag(); default: return common_.tag_; } @@ -1490,8 +1490,8 @@ namespace jsoncons { return cast().value().size(); case json_storage_kind::json_const_pointer: return cast().value()->size(); - case json_storage_kind::json_pointer: - return cast().value()->size(); + case json_storage_kind::json_reference: + return cast().value().size(); default: return 0; } @@ -1507,8 +1507,8 @@ namespace jsoncons { return string_view_type(cast().data(),cast().length()); case json_storage_kind::json_const_pointer: return cast().value()->as_string_view(); - case json_storage_kind::json_pointer: - return cast().value()->as_string_view(); + case json_storage_kind::json_reference: + return cast().value().as_string_view(); default: JSONCONS_THROW(json_runtime_error("Not a string")); } @@ -1537,8 +1537,8 @@ namespace jsoncons { return basic_byte_string(cast().data(),cast().length()); case json_storage_kind::json_const_pointer: return cast().value()->as_byte_string(); - case json_storage_kind::json_pointer: - return cast().value()->as_byte_string(); + case json_storage_kind::json_reference: + return cast().value().as_byte_string(); default: JSONCONS_THROW(json_runtime_error("Not a byte string")); } @@ -1552,8 +1552,8 @@ namespace jsoncons { return byte_string_view(cast().data(),cast().length()); case json_storage_kind::json_const_pointer: return cast().value()->as_byte_string_view(); - case json_storage_kind::json_pointer: - return cast().value()->as_byte_string_view(); + case json_storage_kind::json_reference: + return cast().value().as_byte_string_view(); default: JSONCONS_THROW(json_runtime_error("Not a byte string")); } @@ -1571,18 +1571,18 @@ namespace jsoncons { switch (rhs.storage_kind()) { case json_storage_kind::json_const_pointer: - return (cast().value())->compare(*(rhs.cast().value())); + return cast().value()->compare(*(rhs.cast().value())); default: - return (cast().value())->compare(rhs); + return cast().value()->compare(rhs); } break; - case json_storage_kind::json_pointer: + case json_storage_kind::json_reference: switch (rhs.storage_kind()) { - case json_storage_kind::json_pointer: - return (cast().value())->compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return cast().value().compare(rhs.cast().value()); default: - return (cast().value())->compare(rhs); + return cast().value().compare(rhs); } break; case json_storage_kind::null: @@ -1596,8 +1596,8 @@ namespace jsoncons { return rhs.empty() ? 0 : -1; case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1609,8 +1609,8 @@ namespace jsoncons { return static_cast(cast().value()) - static_cast(rhs.cast().value()); case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1638,8 +1638,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1666,8 +1666,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1692,8 +1692,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: if (is_string_storage(rhs.storage_kind())) { @@ -1732,8 +1732,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: if (is_string_storage(rhs.storage_kind())) { @@ -1758,8 +1758,8 @@ namespace jsoncons { return as_string_view().compare(rhs.as_string_view()); case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1774,8 +1774,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1792,8 +1792,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1812,8 +1812,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return compare(*(rhs.cast().value())); - case json_storage_kind::json_pointer: - return compare(*(rhs.cast().value())); + case json_storage_kind::json_reference: + return compare(rhs.cast().value()); default: return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); } @@ -1854,7 +1854,7 @@ namespace jsoncons { case json_storage_kind::array: swap_l(other); break; case json_storage_kind::object: swap_l(other); break; case json_storage_kind::json_const_pointer: swap_l(other); break; - case json_storage_kind::json_pointer: swap_l(other); break; + case json_storage_kind::json_reference: swap_l(other); break; default: JSONCONS_UNREACHABLE(); break; @@ -2294,16 +2294,9 @@ namespace jsoncons { } } - basic_json(json_pointer_arg_t, basic_json* p) noexcept + basic_json(json_reference_arg_t, basic_json& ref) noexcept { - if (p == nullptr) - { - construct(semantic_tag::none); - } - else - { - construct(p); - } + construct(ref); } basic_json(const array& val, semantic_tag tag = semantic_tag::none) @@ -2857,8 +2850,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_null(); - case json_storage_kind::json_pointer: - return cast().value()->is_null(); + case json_storage_kind::json_reference: + return cast().value().is_null(); default: return false; } @@ -2910,8 +2903,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->ext_tag(); - case json_storage_kind::json_pointer: - return cast().value()->ext_tag(); + case json_storage_kind::json_reference: + return cast().value().ext_tag(); default: return 0; } @@ -2928,8 +2921,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->contains(key); - case json_storage_kind::json_pointer: - return cast().value()->contains(key); + case json_storage_kind::json_reference: + return cast().value().contains(key); default: return false; } @@ -2956,8 +2949,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->count(key); - case json_storage_kind::json_pointer: - return cast().value()->count(key); + case json_storage_kind::json_reference: + return cast().value().count(key); default: return 0; } @@ -2978,8 +2971,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_string(); - case json_storage_kind::json_pointer: - return cast().value()->is_string(); + case json_storage_kind::json_reference: + return cast().value().is_string(); default: return false; } @@ -2998,8 +2991,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_byte_string(); - case json_storage_kind::json_pointer: - return cast().value()->is_byte_string(); + case json_storage_kind::json_reference: + return cast().value().is_byte_string(); default: return false; } @@ -3020,8 +3013,8 @@ namespace jsoncons { case json_storage_kind::int64: case json_storage_kind::uint64: return true; - case json_storage_kind::json_pointer: - return cast().value()->is_bignum(); + case json_storage_kind::json_reference: + return cast().value().is_bignum(); default: return false; } @@ -3035,8 +3028,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_bool(); - case json_storage_kind::json_pointer: - return cast().value()->is_bool(); + case json_storage_kind::json_reference: + return cast().value().is_bool(); default: return false; } @@ -3051,8 +3044,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_object(); - case json_storage_kind::json_pointer: - return cast().value()->is_object(); + case json_storage_kind::json_reference: + return cast().value().is_object(); default: return false; } @@ -3066,8 +3059,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_array(); - case json_storage_kind::json_pointer: - return cast().value()->is_array(); + case json_storage_kind::json_reference: + return cast().value().is_array(); default: return false; } @@ -3083,8 +3076,8 @@ namespace jsoncons { return as_integer() <= static_cast((std::numeric_limits::max)()); case json_storage_kind::json_const_pointer: return cast().value()->is_int64(); - case json_storage_kind::json_pointer: - return cast().value()->is_int64(); + case json_storage_kind::json_reference: + return cast().value().is_int64(); default: return false; } @@ -3100,8 +3093,8 @@ namespace jsoncons { return as_integer() >= 0; case json_storage_kind::json_const_pointer: return cast().value()->is_uint64(); - case json_storage_kind::json_pointer: - return cast().value()->is_uint64(); + case json_storage_kind::json_reference: + return cast().value().is_uint64(); default: return false; } @@ -3115,8 +3108,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_half(); - case json_storage_kind::json_pointer: - return cast().value()->is_half(); + case json_storage_kind::json_reference: + return cast().value().is_half(); default: return false; } @@ -3130,8 +3123,8 @@ namespace jsoncons { return true; case json_storage_kind::json_const_pointer: return cast().value()->is_double(); - case json_storage_kind::json_pointer: - return cast().value()->is_double(); + case json_storage_kind::json_reference: + return cast().value().is_double(); default: return false; } @@ -3153,8 +3146,8 @@ namespace jsoncons { tag() == semantic_tag::bigfloat; case json_storage_kind::json_const_pointer: return cast().value()->is_number(); - case json_storage_kind::json_pointer: - return cast().value()->is_number(); + case json_storage_kind::json_reference: + return cast().value().is_number(); default: return false; } @@ -3179,8 +3172,8 @@ namespace jsoncons { return cast().value().empty(); case json_storage_kind::json_const_pointer: return cast().value()->empty(); - case json_storage_kind::json_pointer: - return cast().value()->empty(); + case json_storage_kind::json_reference: + return cast().value().empty(); default: return false; } @@ -3196,8 +3189,8 @@ namespace jsoncons { return cast().value().capacity(); case json_storage_kind::json_const_pointer: return cast().value()->capacity(); - case json_storage_kind::json_pointer: - return cast().value()->capacity(); + case json_storage_kind::json_reference: + return cast().value().capacity(); default: return 0; } @@ -3322,8 +3315,8 @@ namespace jsoncons { return T(as_byte_string_view().begin(), as_byte_string_view().end()); case json_storage_kind::json_const_pointer: return cast().value()->template as(byte_string_arg, hint); - case json_storage_kind::json_pointer: - return cast().value()->template as(byte_string_arg, hint); + case json_storage_kind::json_reference: + return cast().value().template as(byte_string_arg, hint); default: JSONCONS_THROW(json_runtime_error("Not a byte string")); } @@ -3341,8 +3334,8 @@ namespace jsoncons { return cast().value() != 0; case json_storage_kind::json_const_pointer: return cast().value()->as_bool(); - case json_storage_kind::json_pointer: - return cast().value()->as_bool(); + case json_storage_kind::json_reference: + return cast().value().as_bool(); default: JSONCONS_THROW(json_runtime_error("Not a bool")); } @@ -3376,8 +3369,8 @@ namespace jsoncons { return static_cast(cast().value() ? 1 : 0); case json_storage_kind::json_const_pointer: return cast().value()->template as_integer(); - case json_storage_kind::json_pointer: - return cast().value()->template as_integer(); + case json_storage_kind::json_reference: + return cast().value().template as_integer(); default: JSONCONS_THROW(json_runtime_error("Not an integer")); } @@ -3395,8 +3388,8 @@ namespace jsoncons { return as_integer() <= static_cast((extension_traits::integer_limits::max)()); case json_storage_kind::json_const_pointer: return cast().value()->template is_integer(); - case json_storage_kind::json_pointer: - return cast().value()->template is_integer(); + case json_storage_kind::json_reference: + return cast().value().template is_integer(); default: return false; } @@ -3421,8 +3414,8 @@ namespace jsoncons { return as_integer() <= static_cast((extension_traits::integer_limits::max)()); case json_storage_kind::json_const_pointer: return cast().value()->template is_integer(); - case json_storage_kind::json_pointer: - return cast().value()->template is_integer(); + case json_storage_kind::json_reference: + return cast().value().template is_integer(); default: return false; } @@ -3440,8 +3433,8 @@ namespace jsoncons { return as_integer() <= (extension_traits::integer_limits::max)(); case json_storage_kind::json_const_pointer: return cast().value()->template is_integer(); - case json_storage_kind::json_pointer: - return cast().value()->template is_integer(); + case json_storage_kind::json_reference: + return cast().value().template is_integer(); default: return false; } @@ -3466,8 +3459,8 @@ namespace jsoncons { return as_integer() <= (extension_traits::integer_limits::max)(); case json_storage_kind::json_const_pointer: return cast().value()->template is_integer(); - case json_storage_kind::json_pointer: - return cast().value()->template is_integer(); + case json_storage_kind::json_reference: + return cast().value().template is_integer(); default: return false; } @@ -3494,8 +3487,8 @@ namespace jsoncons { return static_cast(cast().value()); case json_storage_kind::json_const_pointer: return cast().value()->as_double(); - case json_storage_kind::json_pointer: - return cast().value()->as_double(); + case json_storage_kind::json_reference: + return cast().value().as_double(); default: JSONCONS_THROW(json_runtime_error("Not a double")); } @@ -3541,8 +3534,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->as_string(alloc); - case json_storage_kind::json_pointer: - return cast().value()->as_string(alloc); + case json_storage_kind::json_reference: + return cast().value().as_string(alloc); default: { string_type2 s(alloc); @@ -3563,8 +3556,8 @@ namespace jsoncons { return cast().c_str(); case json_storage_kind::json_const_pointer: return cast().value()->as_cstring(); - case json_storage_kind::json_pointer: - return cast().value()->as_cstring(); + case json_storage_kind::json_reference: + return cast().value().as_cstring(); default: JSONCONS_THROW(json_runtime_error("Not a cstring")); } @@ -3585,8 +3578,8 @@ namespace jsoncons { } return it->value(); } - case json_storage_kind::json_pointer: - return cast().value()->at(key); + case json_storage_kind::json_reference: + return cast().value().at(key); default: { JSONCONS_THROW(not_an_object(key.data(),key.length())); @@ -3611,8 +3604,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->at(key); - case json_storage_kind::json_pointer: - return cast().value()->at(key); + case json_storage_kind::json_reference: + return cast().value().at(key); default: { JSONCONS_THROW(not_an_object(key.data(),key.length())); @@ -3632,8 +3625,8 @@ namespace jsoncons { return cast().value().operator[](i); case json_storage_kind::object: return cast().value().at(i); - case json_storage_kind::json_pointer: - return cast().value()->at(i); + case json_storage_kind::json_reference: + return cast().value().at(i); default: JSONCONS_THROW(json_runtime_error("Index on non-array value not supported")); } @@ -3653,8 +3646,8 @@ namespace jsoncons { return cast().value().at(i); case json_storage_kind::json_const_pointer: return cast().value()->at(i); - case json_storage_kind::json_pointer: - return cast().value()->at(i); + case json_storage_kind::json_reference: + return cast().value().at(i); default: JSONCONS_THROW(json_runtime_error("Index on non-array value not supported")); } @@ -3685,8 +3678,8 @@ namespace jsoncons { return const_object_iterator(cast().value().find(key)); case json_storage_kind::json_const_pointer: return cast().value()->find(key); - case json_storage_kind::json_pointer: - return cast().value()->find(key); + case json_storage_kind::json_reference: + return cast().value().find(key); default: { JSONCONS_THROW(not_an_object(key.data(),key.length())); @@ -3717,8 +3710,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->at_or_null(key); - case json_storage_kind::json_pointer: - return cast().value()->at_or_null(key); + case json_storage_kind::json_reference: + return cast().value().at_or_null(key); default: { JSONCONS_THROW(not_an_object(key.data(),key.length())); @@ -3752,8 +3745,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->template get_value_or(key,std::forward(default_value)); - case json_storage_kind::json_pointer: - return cast().value()->template get_value_or(key,std::forward(default_value)); + case json_storage_kind::json_reference: + return cast().value().template get_value_or(key,std::forward(default_value)); default: { JSONCONS_THROW(not_an_object(key.data(),key.length())); @@ -3773,8 +3766,8 @@ namespace jsoncons { case json_storage_kind::object: cast().value().shrink_to_fit(); break; - case json_storage_kind::json_pointer: - cast().value()->shrink_to_fit(); + case json_storage_kind::json_reference: + cast().value().shrink_to_fit(); break; default: break; @@ -3791,8 +3784,8 @@ namespace jsoncons { case json_storage_kind::object: cast().value().clear(); break; - case json_storage_kind::json_pointer: - cast().value()->clear(); + case json_storage_kind::json_reference: + cast().value().clear(); break; default: break; @@ -3807,8 +3800,8 @@ namespace jsoncons { return object_range().end(); case json_storage_kind::object: return object_iterator(cast().value().erase(pos)); - case json_storage_kind::json_pointer: - return cast().value()->erase(pos); + case json_storage_kind::json_reference: + return cast().value().erase(pos); default: JSONCONS_THROW(json_runtime_error("Not an object")); break; @@ -3823,8 +3816,8 @@ namespace jsoncons { return object_range().end(); case json_storage_kind::object: return object_iterator(cast().value().erase(first, last)); - case json_storage_kind::json_pointer: - return cast().value()->erase(first, last); + case json_storage_kind::json_reference: + return cast().value().erase(first, last); default: JSONCONS_THROW(json_runtime_error("Not an object")); break; @@ -3837,8 +3830,8 @@ namespace jsoncons { { case json_storage_kind::array: return cast().value().erase(pos); - case json_storage_kind::json_pointer: - return cast().value()->erase(pos); + case json_storage_kind::json_reference: + return cast().value().erase(pos); default: JSONCONS_THROW(json_runtime_error("Not an array")); } @@ -3850,8 +3843,8 @@ namespace jsoncons { { case json_storage_kind::array: return cast().value().erase(first, last); - case json_storage_kind::json_pointer: - return cast().value()->erase(first, last); + case json_storage_kind::json_reference: + return cast().value().erase(first, last); default: JSONCONS_THROW(json_runtime_error("Not an array")); break; @@ -3869,8 +3862,8 @@ namespace jsoncons { case json_storage_kind::object: cast().value().erase(key); break; - case json_storage_kind::json_pointer: - return cast().value()->erase(key); + case json_storage_kind::json_reference: + return cast().value().erase(key); default: JSONCONS_THROW(not_an_object(key.data(),key.length())); break; @@ -3893,8 +3886,8 @@ namespace jsoncons { auto result = cast().value().insert_or_assign(key, std::forward(val)); return std::make_pair(object_iterator(result.first), result.second); } - case json_storage_kind::json_pointer: - return cast().value()->insert_or_assign(key, std::forward(val)); + case json_storage_kind::json_reference: + return cast().value().insert_or_assign(key, std::forward(val)); default: JSONCONS_THROW(not_an_object(key.data(),key.length())); } @@ -3916,8 +3909,8 @@ namespace jsoncons { auto result = cast().value().try_emplace(key, std::forward(args)...); return std::make_pair(object_iterator(result.first),result.second); } - case json_storage_kind::json_pointer: - return cast().value()->try_emplace(key, std::forward(args)...); + case json_storage_kind::json_reference: + return cast().value().try_emplace(key, std::forward(args)...); default: JSONCONS_THROW(not_an_object(key.data(),key.length())); } @@ -3941,8 +3934,8 @@ namespace jsoncons { case json_storage_kind::object: cast().value().merge(source.cast().value()); break; - case json_storage_kind::json_pointer: - cast().value()->merge(source.cast().value()); + case json_storage_kind::json_reference: + cast().value().merge(source.cast().value()); break; default: JSONCONS_THROW(json_runtime_error("Attempting to merge a value that is not an object")); @@ -4228,8 +4221,8 @@ namespace jsoncons { case json_storage_kind::array: return cast().value().emplace(pos, std::forward(args)...); break; - case json_storage_kind::json_pointer: - return cast().value()->emplace(pos, std::forward(args)...); + case json_storage_kind::json_reference: + return cast().value().emplace(pos, std::forward(args)...); default: JSONCONS_THROW(json_runtime_error("Attempting to insert into a value that is not an array")); } @@ -4242,8 +4235,8 @@ namespace jsoncons { { case json_storage_kind::array: return cast().value().emplace_back(std::forward(args)...); - case json_storage_kind::json_pointer: - return cast().value()->emplace_back(std::forward(args)...); + case json_storage_kind::json_reference: + return cast().value().emplace_back(std::forward(args)...); default: JSONCONS_THROW(json_runtime_error("Attempting to insert into a value that is not an array")); } @@ -4262,8 +4255,8 @@ namespace jsoncons { case json_storage_kind::array: cast().value().push_back(std::forward(val)); break; - case json_storage_kind::json_pointer: - cast().value()->push_back(std::forward(val)); + case json_storage_kind::json_reference: + cast().value().push_back(std::forward(val)); break; default: JSONCONS_THROW(json_runtime_error("Attempting to insert into a value that is not an array")); @@ -4277,8 +4270,8 @@ namespace jsoncons { case json_storage_kind::array: cast().value().push_back(std::move(val)); break; - case json_storage_kind::json_pointer: - cast().value()->push_back(std::move(val)); + case json_storage_kind::json_reference: + cast().value().push_back(std::move(val)); break; default: JSONCONS_THROW(json_runtime_error("Attempting to insert into a value that is not an array")); @@ -4309,8 +4302,8 @@ namespace jsoncons { case json_storage_kind::object: return object_range_type(object_iterator(cast().value().begin()), object_iterator(cast().value().end())); - case json_storage_kind::json_pointer: - return cast().value()->object_range(); + case json_storage_kind::json_reference: + return cast().value().object_range(); default: JSONCONS_THROW(json_runtime_error("Not an object")); } @@ -4327,8 +4320,8 @@ namespace jsoncons { const_object_iterator(cast().value().end())); case json_storage_kind::json_const_pointer: return cast().value()->object_range(); - case json_storage_kind::json_pointer: - return cast().value()->object_range(); + case json_storage_kind::json_reference: + return cast().value().object_range(); default: JSONCONS_THROW(json_runtime_error("Not an object")); } @@ -4341,8 +4334,8 @@ namespace jsoncons { case json_storage_kind::array: return array_range_type(cast().value().begin(), cast().value().end()); - case json_storage_kind::json_pointer: - return cast().value()->array_range(); + case json_storage_kind::json_reference: + return cast().value().array_range(); default: JSONCONS_THROW(json_runtime_error("Not an array")); } @@ -4357,8 +4350,8 @@ namespace jsoncons { cast().value().end()); case json_storage_kind::json_const_pointer: return cast().value()->array_range(); - case json_storage_kind::json_pointer: - return cast().value()->array_range(); + case json_storage_kind::json_reference: + return cast().value().array_range(); default: JSONCONS_THROW(json_runtime_error("Not an array")); } @@ -4439,8 +4432,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return cast().value()->dump_noflush(visitor, ec); - case json_storage_kind::json_pointer: - return cast().value()->dump_noflush(visitor, ec); + case json_storage_kind::json_reference: + return cast().value().dump_noflush(visitor, ec); default: break; } @@ -4494,8 +4487,8 @@ namespace jsoncons { } case json_storage_kind::json_const_pointer: return deep_copy(*(other.cast().value())); - case json_storage_kind::json_pointer: - return deep_copy(*(other.cast().value())); + case json_storage_kind::json_reference: + return deep_copy(other.cast().value()); default: return other; } diff --git a/include/jsoncons/json_type.hpp b/include/jsoncons/json_type.hpp index 237553201..b3c901251 100644 --- a/include/jsoncons/json_type.hpp +++ b/include/jsoncons/json_type.hpp @@ -107,7 +107,7 @@ namespace jsoncons { half_float = 6, // 0110 short_str = 7, // 0111 json_const_pointer = 8, // 1000 - json_pointer = 9, // 1001 + json_reference = 9, // 1001 byte_str = 12, // 1100 object = 13, // 1101 array = 14, // 1110 @@ -143,6 +143,7 @@ namespace jsoncons { static constexpr const CharT* empty_object_value = JSONCONS_CSTRING_CONSTANT(CharT, "empty_object"); static constexpr const CharT* object_value = JSONCONS_CSTRING_CONSTANT(CharT, "object"); static constexpr const CharT* json_const_pointer = JSONCONS_CSTRING_CONSTANT(CharT, "json_const_pointer"); + static constexpr const CharT* json_reference = JSONCONS_CSTRING_CONSTANT(CharT, "json_reference"); switch (storage) { @@ -211,6 +212,11 @@ namespace jsoncons { os << json_const_pointer; break; } + case json_storage_kind::json_reference: + { + os << json_reference; + break; + } } return os; } diff --git a/include/jsoncons/tag_type.hpp b/include/jsoncons/tag_type.hpp index 0e4233e08..94b319416 100644 --- a/include/jsoncons/tag_type.hpp +++ b/include/jsoncons/tag_type.hpp @@ -59,12 +59,12 @@ struct json_const_pointer_arg_t constexpr json_const_pointer_arg_t json_const_pointer_arg{}; -struct json_pointer_arg_t +struct json_reference_arg_t { - explicit json_pointer_arg_t() = default; + explicit json_reference_arg_t() = default; }; -constexpr json_pointer_arg_t json_pointer_arg{}; +constexpr json_reference_arg_t json_reference_arg{}; enum class semantic_tag : uint8_t { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7ac22d442..9b1519342 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -140,7 +140,7 @@ add_executable(unit_tests corelib/src/json_checker_tests.cpp corelib/src/json_comparator_tests.cpp corelib/src/json_const_pointer_arg_tests.cpp - corelib/src/json_pointer_arg_tests.cpp + corelib/src/json_reference_arg_tests.cpp corelib/src/json_assignment_tests.cpp corelib/src/json_constructor_tests.cpp corelib/src/json_cursor_tests.cpp diff --git a/test/corelib/src/json_pointer_arg_tests.cpp b/test/corelib/src/json_reference_arg_tests.cpp similarity index 74% rename from test/corelib/src/json_pointer_arg_tests.cpp rename to test/corelib/src/json_reference_arg_tests.cpp index 81335d56e..b2904aa5d 100644 --- a/test/corelib/src/json_pointer_arg_tests.cpp +++ b/test/corelib/src/json_reference_arg_tests.cpp @@ -19,40 +19,40 @@ TEST_CASE("json_pointer array tests") SECTION("size()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_array()); CHECK(v.size() == 3); CHECK_FALSE(v.empty()); } SECTION("at()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_array()); REQUIRE_NOTHROW(v.at(1)); } SECTION("copy") { - json v(json_pointer_arg, &j); - CHECK(v.storage_kind() == json_storage_kind::json_pointer); + json v(json_reference_arg, j); + CHECK(v.storage_kind() == json_storage_kind::json_reference); json j2(v); - CHECK(j2.storage_kind() == json_storage_kind::json_pointer); + CHECK(j2.storage_kind() == json_storage_kind::json_reference); } SECTION("assignment") { - json v(json_pointer_arg, &j); - CHECK(v.storage_kind() == json_storage_kind::json_pointer); + json v(json_reference_arg, j); + CHECK(v.storage_kind() == json_storage_kind::json_reference); json j2; j2 = v; - CHECK(j2.storage_kind() == json_storage_kind::json_pointer); + CHECK(j2.storage_kind() == json_storage_kind::json_reference); } SECTION("push_back") { json expected = json::parse(R"( ["one", "two", "three", "four"] )"); - json v(json_pointer_arg, &j); - CHECK(v.storage_kind() == json_storage_kind::json_pointer); + json v(json_reference_arg, j); + CHECK(v.storage_kind() == json_storage_kind::json_reference); j.push_back("four"); CHECK(expected == v); @@ -61,8 +61,8 @@ TEST_CASE("json_pointer array tests") { json expected = json::parse(R"( ["one", "two", "three", "four"] )"); - json v(json_pointer_arg, &j); - CHECK(v.storage_kind() == json_storage_kind::json_pointer); + json v(json_reference_arg, j); + CHECK(v.storage_kind() == json_storage_kind::json_reference); j.emplace_back("four"); CHECK(expected == v); @@ -75,14 +75,14 @@ TEST_CASE("json_pointer object tests") SECTION("size()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_object()); CHECK(v.size() == 3); CHECK_FALSE(v.empty()); } SECTION("at()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_object()); REQUIRE_NOTHROW(v.at("two")); CHECK(v.contains("two")); @@ -99,7 +99,7 @@ TEST_CASE("json_pointer string tests") SECTION("is_string()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_string()); REQUIRE(v.is_string_view()); @@ -114,7 +114,7 @@ TEST_CASE("json_pointer byte_string tests") SECTION("is_byte_string()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_byte_string()); REQUIRE(v.is_byte_string_view()); } @@ -127,13 +127,13 @@ TEST_CASE("json_pointer bool tests") SECTION("true") { - json v(json_pointer_arg, &tru); + json v(json_reference_arg, tru); REQUIRE(v.is_bool()); CHECK(v.as_bool()); } SECTION("false") { - json v(json_pointer_arg, &fal); + json v(json_reference_arg, fal); REQUIRE(v.is_bool()); CHECK_FALSE(v.as_bool()); } @@ -145,7 +145,7 @@ TEST_CASE("json_pointer int64 tests") SECTION("is_int64()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_int64()); CHECK(v.as() == -100); } @@ -157,7 +157,7 @@ TEST_CASE("json_pointer uint64 tests") SECTION("is_uint64()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_uint64()); CHECK(v.as() == 100); } @@ -169,7 +169,7 @@ TEST_CASE("json_pointer half tests") SECTION("is_half()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_half()); CHECK(v.as() == 100); } @@ -181,7 +181,7 @@ TEST_CASE("json_pointer double tests") SECTION("is_double()") { - json v(json_pointer_arg, &j); + json v(json_reference_arg, j); REQUIRE(v.is_double()); CHECK(v.as_double() == 123.456); diff --git a/test/corelib/src/json_storage_tests.cpp b/test/corelib/src/json_storage_tests.cpp index 9c6a4b37f..6bbdb0b42 100644 --- a/test/corelib/src/json_storage_tests.cpp +++ b/test/corelib/src/json_storage_tests.cpp @@ -21,7 +21,7 @@ TEST_CASE("test json_storage_kind") CHECK(is_trivial_storage(json_storage_kind::short_str)); CHECK(is_trivial_storage(json_storage_kind::empty_object)); CHECK(is_trivial_storage(json_storage_kind::json_const_pointer)); - CHECK(is_trivial_storage(json_storage_kind::json_pointer)); + CHECK(is_trivial_storage(json_storage_kind::json_reference)); CHECK_FALSE(is_trivial_storage(json_storage_kind::long_str)); CHECK_FALSE(is_trivial_storage(json_storage_kind::byte_str)); CHECK_FALSE(is_trivial_storage(json_storage_kind::array)); @@ -37,7 +37,7 @@ TEST_CASE("test json_storage_kind") CHECK(is_string_storage(json_storage_kind::short_str)); CHECK_FALSE(is_string_storage(json_storage_kind::empty_object)); CHECK_FALSE(is_string_storage(json_storage_kind::json_const_pointer)); - CHECK_FALSE(is_string_storage(json_storage_kind::json_pointer)); + CHECK_FALSE(is_string_storage(json_storage_kind::json_reference)); CHECK(is_string_storage(json_storage_kind::long_str)); CHECK_FALSE(is_string_storage(json_storage_kind::byte_str)); CHECK_FALSE(is_string_storage(json_storage_kind::array));