Skip to content

Commit

Permalink
json_reference_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 18, 2024
1 parent 8baf629 commit 1e2ca93
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 84 deletions.
186 changes: 115 additions & 71 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ namespace jsoncons {

static const basic_json& null()
{
static const basic_json a_null = basic_json(null_type(), semantic_tag::none);
static const basic_json a_null = basic_json(null_arg, semantic_tag::none);
return a_null;
}

Expand Down Expand Up @@ -2582,6 +2582,8 @@ namespace jsoncons {
}
break;
}
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value()[key];
default:
JSONCONS_THROW(not_an_object(key.data(),key.length()));
break;
Expand Down Expand Up @@ -2609,6 +2611,10 @@ namespace jsoncons {
}
break;
}
case json_storage_kind::json_const_pointer:
return *(cast<json_const_pointer_storage>().value())[key];
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value()[key];
default:
JSONCONS_THROW(not_an_object(key.data(),key.length()));
break;
Expand Down Expand Up @@ -2873,21 +2879,15 @@ namespace jsoncons {
switch (storage_kind())
{
case json_storage_kind::long_str:
{
return cast<long_string_storage>().get_allocator();
}
case json_storage_kind::byte_str:
{
return cast<byte_string_storage>().get_allocator();
}
case json_storage_kind::array:
{
return cast<array_storage>().get_allocator();
}
case json_storage_kind::object:
{
return cast<object_storage>().get_allocator();
}
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value().get_allocator();
default:
return get_default_allocator(typename std::allocator_traits<U>::is_always_equal());
}
Expand Down Expand Up @@ -3222,15 +3222,14 @@ namespace jsoncons {
cast<array_storage>().value().reserve(n);
break;
case json_storage_kind::empty_object:
{
create_object_implicitly();
cast<object_storage>().value().reserve(n);
}
break;
break;
case json_storage_kind::object:
{
cast<object_storage>().value().reserve(n);
}
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().reserve(n);
break;
default:
break;
Expand All @@ -3245,6 +3244,9 @@ namespace jsoncons {
case json_storage_kind::array:
cast<array_storage>().value().resize(n);
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().resize(n);
break;
default:
break;
}
Expand All @@ -3258,6 +3260,9 @@ namespace jsoncons {
case json_storage_kind::array:
cast<array_storage>().value().resize(n, val);
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().resize(n, val);
break;
default:
break;
}
Expand Down Expand Up @@ -3653,17 +3658,19 @@ namespace jsoncons {
}
}

object_iterator find(const string_view_type& name)
object_iterator find(const string_view_type& key)
{
switch (storage_kind())
{
case json_storage_kind::empty_object:
return object_range().end();
case json_storage_kind::object:
return object_iterator(cast<object_storage>().value().find(name));
return object_iterator(cast<object_storage>().value().find(key));
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value().find(key);
default:
{
JSONCONS_THROW(not_an_object(name.data(),name.length()));
JSONCONS_THROW(not_an_object(key.data(),key.length()));
}
}
}
Expand Down Expand Up @@ -3935,7 +3942,7 @@ namespace jsoncons {
cast<object_storage>().value().merge(source.cast<object_storage>().value());
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().merge(source.cast<object_storage>().value());
merge(source.cast<json_reference_storage>().value());
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
Expand All @@ -3962,12 +3969,15 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge(std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::json_reference:
merge(std::move(source.cast<json_reference_storage>().value()));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
}
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
}
}

Expand All @@ -3987,6 +3997,9 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge(hint, source.cast<object_storage>().value());
break;
case json_storage_kind::json_reference:
merge(hint, source.cast<json_reference_storage>().value());
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
}
Expand All @@ -4012,6 +4025,9 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge(hint, std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::json_reference:
merge(hint, std::move(source.cast<json_reference_storage>().value()));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge a value that is not an object"));
}
Expand Down Expand Up @@ -4039,6 +4055,9 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge_or_update(source.cast<object_storage>().value());
break;
case json_storage_kind::json_reference:
merge_or_update(source.cast<json_reference_storage>().value());
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge or update a value that is not an object"));
}
Expand All @@ -4057,15 +4076,18 @@ namespace jsoncons {
case json_storage_kind::object:
switch (storage_kind())
{
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().merge_or_update(std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::object:
cast<object_storage>().value().merge_or_update(std::move(source.cast<object_storage>().value()));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge or update a value that is not an object"));
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().merge_or_update(std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::object:
cast<object_storage>().value().merge_or_update(std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::json_reference:
merge_or_update(std::move(source.cast<json_reference_storage>().value()));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge or update a value that is not an object"));
}
break;
default:
Expand All @@ -4089,6 +4111,9 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge_or_update(hint, source.cast<object_storage>().value());
break;
case json_storage_kind::json_reference:
merge_or_update(hint, source.cast<json_reference_storage>().value());
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge or update a value that is not an object"));
}
Expand All @@ -4114,6 +4139,9 @@ namespace jsoncons {
case json_storage_kind::object:
cast<object_storage>().value().merge_or_update(hint, std::move(source.cast<object_storage>().value()));
break;
case json_storage_kind::json_reference:
merge_or_update(hint, std::move(source.cast<json_reference_storage>().value()));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to merge or update a value that is not an object"));
}
Expand All @@ -4128,13 +4156,15 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::empty_object:
create_object_implicitly();
return object_iterator(cast<object_storage>().value().insert_or_assign(hint, name, std::forward<T>(val)));
case json_storage_kind::object:
return object_iterator(cast<object_storage>().value().insert_or_assign(hint, name, std::forward<T>(val)));
default:
JSONCONS_THROW(not_an_object(name.data(),name.length()));
case json_storage_kind::empty_object:
create_object_implicitly();
return object_iterator(cast<object_storage>().value().insert_or_assign(hint, name, std::forward<T>(val)));
case json_storage_kind::object:
return object_iterator(cast<object_storage>().value().insert_or_assign(hint, name, std::forward<T>(val)));
case json_storage_kind::json_reference:
return object_iterator(cast<json_reference_storage>().value().insert_or_assign(hint, name, std::forward<T>(val)));
default:
JSONCONS_THROW(not_an_object(name.data(),name.length()));
}
}

Expand All @@ -4143,13 +4173,15 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::empty_object:
create_object_implicitly();
return object_iterator(cast<object_storage>().value().try_emplace(hint, name, std::forward<Args>(args)...));
case json_storage_kind::object:
return object_iterator(cast<object_storage>().value().try_emplace(hint, name, std::forward<Args>(args)...));
default:
JSONCONS_THROW(not_an_object(name.data(),name.length()));
case json_storage_kind::empty_object:
create_object_implicitly();
return object_iterator(cast<object_storage>().value().try_emplace(hint, name, std::forward<Args>(args)...));
case json_storage_kind::object:
return object_iterator(cast<object_storage>().value().try_emplace(hint, name, std::forward<Args>(args)...));
case json_storage_kind::json_reference:
return object_iterator(cast<json_reference_storage>().value().try_emplace(hint, name, std::forward<Args>(args)...));
default:
JSONCONS_THROW(not_an_object(name.data(),name.length()));
}
}

Expand All @@ -4158,11 +4190,14 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::array:
return cast<array_storage>().value().insert(pos, std::forward<T>(val));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an array"));
case json_storage_kind::array:
return cast<array_storage>().value().insert(pos, std::forward<T>(val));
break;
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value().insert(pos, std::forward<T>(val));
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an array"));
}
}

Expand All @@ -4171,11 +4206,14 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::array:
return cast<array_storage>().value().insert(pos, first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an array"));
case json_storage_kind::array:
return cast<array_storage>().value().insert(pos, first, last);
break;
case json_storage_kind::json_reference:
return cast<json_reference_storage>().value().insert(pos, first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an array"));
}
}

Expand All @@ -4184,15 +4222,18 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().insert(first, last);
break;
case json_storage_kind::object:
cast<object_storage>().value().insert(first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an object"));
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().insert(first, last);
break;
case json_storage_kind::object:
cast<object_storage>().value().insert(first, last);
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().insert(first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an object"));
}
}

Expand All @@ -4201,15 +4242,18 @@ namespace jsoncons {
{
switch (storage_kind())
{
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().insert(tag, first, last);
break;
case json_storage_kind::object:
cast<object_storage>().value().insert(tag, first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an object"));
case json_storage_kind::empty_object:
create_object_implicitly();
cast<object_storage>().value().insert(tag, first, last);
break;
case json_storage_kind::object:
cast<object_storage>().value().insert(tag, first, last);
break;
case json_storage_kind::json_reference:
cast<json_reference_storage>().value().insert(tag, first, last);
break;
default:
JSONCONS_THROW(json_runtime_error<std::domain_error>("Attempting to insert into a value that is not an object"));
}
}

Expand Down
2 changes: 2 additions & 0 deletions include/jsoncons/tag_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct null_type
explicit null_type() = default;
};

constexpr null_type null_arg{};

struct temp_allocator_arg_t
{
explicit temp_allocator_arg_t() = default;
Expand Down
Loading

0 comments on commit 1e2ca93

Please sign in to comment.