MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / push_back

Function push_back

Source/Utils/json.hpp:21712–21731  ·  view source on GitHub ↗

! @brief add an object to an array Appends the given element @a val to the end of the JSON value. If the function is called on a JSON null value, an empty array is created before appending @a val. @param[in] val the value to add to the JSON array @throw type_error.308 when called on a type other than JSON array or null; example: `"cannot u

Source from the content-addressed store, hash-verified

21710 @since version 1.0.0
21711 */
21712 void push_back(basic_json&& val)
21713 {
21714 // push_back only works for null objects or arrays
21715 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
21716 {
21717 JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name())));
21718 }
21719
21720 // transform null object into an array
21721 if (is_null())
21722 {
21723 m_type = value_t::array;
21724 m_value = value_t::array;
21725 assert_invariant();
21726 }
21727
21728 // add element to array (move semantics)
21729 m_value.array->push_back(std::move(val));
21730 // if val is moved from, basic_json move constructor marks it null so we do not call the destructor
21731 }
21732
21733 /*!
21734 @brief add an object to an array

Callers 3

json_pointerClass · 0.85
insertMethod · 0.85
operator+=Function · 0.85

Calls 12

is_nullFunction · 0.85
is_arrayFunction · 0.85
createFunction · 0.85
type_nameFunction · 0.85
assert_invariantFunction · 0.85
is_objectFunction · 0.85
insertMethod · 0.80
moved_or_copiedMethod · 0.80
basic_jsonFunction · 0.70
push_backMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected