TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ destroy()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::destroy ( value_t  t)
inlineprivate

Definition at line 18815 of file json.hpp.

18816 {
18817 if (t == value_t::array || t == value_t::object)
18818 {
18819 // flatten the current json_value to a heap-allocated stack
18820 std::vector<basic_json> stack;
18821
18822 // move the top-level items to stack
18823 if (t == value_t::array)
18824 {
18825 stack.reserve(array->size());
18826 std::move(array->begin(), array->end(), std::back_inserter(stack));
18827 }
18828
18829 else
18830 {
18831 stack.reserve(object->size());
18832
18833 for (auto &&it : *object)
18834 {
18835 stack.push_back(std::move(it.second));
18836 }
18837 }
18838
18839 while (!stack.empty())
18840 {
18841 // move the last item to local variable to be processed
18842 basic_json current_item(std::move(stack.back()));
18843 stack.pop_back();
18844
18845 // if current_item is array/object, move
18846 // its children to the stack to be processed later
18847 if (current_item.is_array())
18848 {
18849 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
18850 current_item.m_value.array->clear();
18851 }
18852
18853 else if (current_item.is_object())
18854 {
18855 for (auto &&it : *current_item.m_value.object)
18856 {
18857 stack.push_back(std::move(it.second));
18858 }
18859
18860 current_item.m_value.object->clear();
18861 }
18862
18863 // it's now safe that current_item get destructed
18864 // since it doesn't have any children
18865 }
18866 }
18867
18868 switch (t)
18869 {
18870 case value_t::object:
18871 {
18872 AllocatorType<object_t> alloc;
18873 std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
18874 std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
18875 break;
18876 }
18877
18878 case value_t::array:
18879 {
18880 AllocatorType<array_t> alloc;
18881 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
18882 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
18883 break;
18884 }
18885
18886 case value_t::string:
18887 {
18888 AllocatorType<string_t> alloc;
18889 std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
18890 std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
18891 break;
18892 }
18893
18894 case value_t::binary:
18895 {
18896 AllocatorType<binary_t> alloc;
18897 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
18898 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18899 break;
18900 }
18901
18902 case value_t::null:
18903 case value_t::boolean:
18907 case value_t::discarded:
18908 default:
18909 {
18910 break;
18911 }
18912 }
18913 }
basic_json(const value_t v)
create an empty value with a given type
Definition: json.hpp:19164
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:22912
binary_t * binary
binary (stored with pointer to save storage)
Definition: json.hpp:18661
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.hpp:19662
array_t * array
array (stored with pointer to save storage)
Definition: json.hpp:18657
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)