MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / dump

Method dump

include/behaviortree_cpp/contrib/json.hpp:18115–18382  ·  view source on GitHub ↗

! @brief internal implementation of the serialization function This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively. - strings and object keys are escaped using `escape_string()` - integer numb

Source from the content-addressed store, hash-verified

18113 @param[in] current_indent the current indent level (only used internally)
18114 */
18115 void dump(const BasicJsonType& val,
18116 const bool pretty_print,
18117 const bool ensure_ascii,
18118 const unsigned int indent_step,
18119 const unsigned int current_indent = 0)
18120 {
18121 switch (val.m_data.m_type)
18122 {
18123 case value_t::object:
18124 {
18125 if (val.m_data.m_value.object->empty())
18126 {
18127 o->write_characters("{}", 2);
18128 return;
18129 }
18130
18131 if (pretty_print)
18132 {
18133 o->write_characters("{\n", 2);
18134
18135 // variable to hold indentation for recursive calls
18136 const auto new_indent = current_indent + indent_step;
18137 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18138 {
18139 indent_string.resize(indent_string.size() * 2, ' ');
18140 }
18141
18142 // first n-1 elements
18143 auto i = val.m_data.m_value.object->cbegin();
18144 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18145 {
18146 o->write_characters(indent_string.c_str(), new_indent);
18147 o->write_character('\"');
18148 dump_escaped(i->first, ensure_ascii);
18149 o->write_characters("\": ", 3);
18150 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18151 o->write_characters(",\n", 2);
18152 }
18153
18154 // last element
18155 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18156 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18157 o->write_characters(indent_string.c_str(), new_indent);
18158 o->write_character('\"');
18159 dump_escaped(i->first, ensure_ascii);
18160 o->write_characters("\": ", 3);
18161 dump(i->second, true, ensure_ascii, indent_step, new_indent);
18162
18163 o->write_character('\n');
18164 o->write_characters(indent_string.c_str(), current_indent);
18165 o->write_character('}');
18166 }
18167 else
18168 {
18169 o->write_character('{');
18170
18171 // first n-1 elements
18172 auto i = val.m_data.m_value.object->cbegin();

Callers 10

toJsonStringFunction · 0.80
serverLoopMethod · 0.80
TEST_FFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
json.hppFile · 0.80
patch_inplaceFunction · 0.80
string to_stringMethod · 0.80
fuzzJsonOperationsMethod · 0.80

Calls 7

dump_integerFunction · 0.85
dump_floatFunction · 0.85
cbeginMethod · 0.80
cendMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
write_characterMethod · 0.45

Tested by 1

TEST_FFunction · 0.64