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

Function erase

Source/Utils/json.hpp:20515–20576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20513 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type
20514 = 0 >
20515 IteratorType erase(IteratorType pos)
20516 {
20517 // make sure iterator fits the current value
20518 if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
20519 {
20520 JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value"));
20521 }
20522
20523 IteratorType result = end();
20524
20525 switch (m_type)
20526 {
20527 case value_t::boolean:
20528 case value_t::number_float:
20529 case value_t::number_integer:
20530 case value_t::number_unsigned:
20531 case value_t::string:
20532 case value_t::binary:
20533 {
20534 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
20535 {
20536 JSON_THROW(invalid_iterator::create(205, "iterator out of range"));
20537 }
20538
20539 if (is_string())
20540 {
20541 AllocatorType<string_t> alloc;
20542 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
20543 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
20544 m_value.string = nullptr;
20545 }
20546 else if (is_binary())
20547 {
20548 AllocatorType<binary_t> alloc;
20549 std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
20550 std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
20551 m_value.binary = nullptr;
20552 }
20553
20554 m_type = value_t::null;
20555 assert_invariant();
20556 break;
20557 }
20558
20559 case value_t::object:
20560 {
20561 result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
20562 break;
20563 }
20564
20565 case value_t::array:
20566 {
20567 result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
20568 break;
20569 }
20570
20571 default:
20572 JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name())));

Callers 1

merge_patchFunction · 0.85

Calls 14

createFunction · 0.85
is_stringFunction · 0.85
destroyFunction · 0.85
is_binaryFunction · 0.85
assert_invariantFunction · 0.85
type_nameFunction · 0.85
is_objectFunction · 0.85
is_arrayFunction · 0.85
sizeFunction · 0.85
is_beginMethod · 0.80
eraseMethod · 0.80
is_endMethod · 0.80

Tested by

no test coverage detected