TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ get_and_create()

template<typename BasicJsonType >
BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_and_create ( BasicJsonType &  j) const
inlineprivate

create and return a reference to the pointed to value

@complexity Linear in the number of reference tokens.

Exceptions
parse_error.109if array index is not a number
type_error.313if value cannot be unflattened

Definition at line 12943 of file json.hpp.

12944 {
12945 auto *result = &j;
12946
12947 // in case no reference tokens exist, return a reference to the JSON value
12948 // j which will be overwritten by a primitive value
12949 for (const auto &reference_token : reference_tokens)
12950 {
12951 switch (result->type())
12952 {
12954 {
12955 if (reference_token == "0")
12956 {
12957 // start a new array if reference token is 0
12958 result = &result->operator[](0);
12959 }
12960
12961 else
12962 {
12963 // start a new object otherwise
12964 result = &result->operator[](reference_token);
12965 }
12966
12967 break;
12968 }
12969
12971 {
12972 // create an entry in the object
12973 result = &result->operator[](reference_token);
12974 break;
12975 }
12976
12978 {
12979 // create an entry in the array
12980 result = &result->operator[](array_index(reference_token));
12981 break;
12982 }
12983
12984 /*
12985 The following code is only reached if there exists a reference
12986 token _and_ the current value is primitive. In this case, we have
12987 an error situation, because primitive values may only occur as
12988 single value; that is, with an empty list of reference tokens.
12989 */
12997 default:
12998 JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
12999 }
13000 }
13001
13002 return *result;
13003 }
static BasicJsonType::size_type array_index(const std::string &s)
Definition: json.hpp:12878
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)