MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / update

Function update

lesson6-Segmentation/json.hpp:22257–22280  ·  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

22255 @since version 3.0.0
22256 */
22257 void update(const_reference j)
22258 {
22259 // implicitly convert null value to an empty object
22260 if (is_null())
22261 {
22262 m_type = value_t::object;
22263 m_value.object = create<object_t>();
22264 assert_invariant();
22265 }
22266
22267 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22268 {
22269 JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name())));
22270 }
22271 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22272 {
22273 JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name())));
22274 }
22275
22276 for (auto it = j.cbegin(); it != j.cend(); ++it)
22277 {
22278 m_value.object->operator[](it.key()) = it.value();
22279 }
22280 }
22281
22282 /*!
22283 @brief updates a JSON object from another object, overwriting existing keys

Callers

nothing calls this directly

Calls 8

is_nullFunction · 0.85
assert_invariantFunction · 0.85
is_objectFunction · 0.85
createFunction · 0.85
type_nameFunction · 0.85
operator[]Method · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected