MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / destroy

Function destroy

extern/json/json.hpp:19772–19868  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19770 json_value(binary_t&& value) : binary(create<binary_t>(std::move(value))) {}
19771
19772 void destroy(value_t t)
19773 {
19774 if (t == value_t::array || t == value_t::object)
19775 {
19776 // flatten the current json_value to a heap-allocated stack
19777 std::vector<basic_json> stack;
19778
19779 // move the top-level items to stack
19780 if (t == value_t::array)
19781 {
19782 stack.reserve(array->size());
19783 std::move(array->begin(), array->end(), std::back_inserter(stack));
19784 }
19785 else
19786 {
19787 stack.reserve(object->size());
19788 for (auto&& it : *object)
19789 {
19790 stack.push_back(std::move(it.second));
19791 }
19792 }
19793
19794 while (!stack.empty())
19795 {
19796 // move the last item to local variable to be processed
19797 basic_json current_item(std::move(stack.back()));
19798 stack.pop_back();
19799
19800 // if current_item is array/object, move
19801 // its children to the stack to be processed later
19802 if (current_item.is_array())
19803 {
19804 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
19805
19806 current_item.m_value.array->clear();
19807 }
19808 else if (current_item.is_object())
19809 {
19810 for (auto&& it : *current_item.m_value.object)
19811 {
19812 stack.push_back(std::move(it.second));
19813 }
19814
19815 current_item.m_value.object->clear();
19816 }
19817
19818 // it's now safe that current_item get destructed
19819 // since it doesn't have any children
19820 }
19821 }
19822
19823 switch (t)
19824 {
19825 case value_t::object:
19826 {
19827 AllocatorType<object_t> alloc;
19828 std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
19829 std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);

Callers 3

eraseFunction · 0.85
mainLoopMethod · 0.85
~ShaderMethod · 0.85

Calls 8

moveFunction · 0.85
reserveMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected