MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / update

Function update

3rd/nlohmann_json/include/nlohmann/json.hpp:6000–6026  ·  view source on GitHub ↗

! @brief updates a JSON object from another object, overwriting existing keys Inserts all values from JSON object @a j and overwrites existing keys. @param[in] j JSON object to read values from @throw type_error.312 if called on JSON values other than objects; example: `"cannot use update() with string"` @complexity O(N*log(size() + N)), where N is the number of elemen

Source from the content-addressed store, hash-verified

5998 @since version 3.0.0
5999 */
6000 void update(const_reference j)
6001 {
6002 // implicitly convert null value to an empty object
6003 if (is_null())
6004 {
6005 m_type = value_t::object;
6006 m_value.object = create<object_t>();
6007 assert_invariant();
6008 }
6009
6010 if (JSON_HEDLEY_UNLIKELY(!is_object()))
6011 {
6012 JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
6013 }
6014 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
6015 {
6016 JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this));
6017 }
6018
6019 for (auto it = j.cbegin(); it != j.cend(); ++it)
6020 {
6021 m_value.object->operator[](it.key()) = it.value();
6022#if JSON_DIAGNOSTICS
6023 m_value.object->operator[](it.key()).m_parent = this;
6024#endif
6025 }
6026 }
6027
6028 /*!
6029 @brief updates a JSON object from another object, overwriting existing keys

Callers

nothing calls this directly

Calls 10

stringFunction · 0.85
is_nullFunction · 0.70
is_objectFunction · 0.70
createFunction · 0.70
type_nameFunction · 0.70
cbeginMethod · 0.45
cendMethod · 0.45
operator[]Method · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected