MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / serialize_node

Function serialize_node

example/cacheHierarchy/fkYAML/node.hpp:10878–11037  ·  view source on GitHub ↗

@brief Recursively serialize each Node object. @param node A Node object to be serialized. @param cur_indent The current indent width @param str A string to hold serialization result.

Source from the content-addressed store, hash-verified

10876 /// @param cur_indent The current indent width
10877 /// @param str A string to hold serialization result.
10878 void serialize_node(const BasicNodeType& node, const uint32_t cur_indent, std::string& str) {
10879 switch (node.get_type()) {
10880 case node_type::SEQUENCE:
10881 if (node.size() == 0) {
10882 str += "[]\n";
10883 return;
10884 }
10885 for (const auto& seq_item : node) {
10886 insert_indentation(cur_indent, str);
10887 str += "-";
10888
10889 const bool is_appended = try_append_alias(seq_item, true, str);
10890 if (is_appended) {
10891 str += "\n";
10892 continue;
10893 }
10894
10895 try_append_anchor(seq_item, true, str);
10896 try_append_tag(seq_item, true, str);
10897
10898 const bool is_scalar = seq_item.is_scalar();
10899 if (is_scalar) {
10900 str += " ";
10901 serialize_node(seq_item, cur_indent, str);
10902 str += "\n";
10903 continue;
10904 }
10905
10906 const bool is_empty = seq_item.empty();
10907 if (!is_empty) {
10908 str += "\n";
10909 serialize_node(seq_item, cur_indent + 2, str);
10910 continue;
10911 }
10912
10913 // an empty sequence or mapping
10914 if (seq_item.is_sequence()) {
10915 str += " []\n";
10916 }
10917 else /*seq_item.is_mapping()*/ {
10918 str += " {}\n";
10919 }
10920 }
10921 break;
10922 case node_type::MAPPING:
10923 if (node.size() == 0) {
10924 str += "{}\n";
10925 return;
10926 }
10927 for (auto itr : node.map_items()) {
10928 insert_indentation(cur_indent, str);
10929
10930 // serialize a mapping key node.
10931 const auto& key_node = itr.key();
10932
10933 bool is_appended = try_append_alias(key_node, false, str);
10934 if (is_appended) {
10935 // The trailing white space is necessary since anchor names can contain a colon (:) at its end.

Callers 1

node.hppFile · 0.85

Calls 10

insert_indentationFunction · 0.85
try_append_aliasFunction · 0.85
try_append_anchorFunction · 0.85
try_append_tagFunction · 0.85
get_cur_indentFunction · 0.85
to_stringFunction · 0.85
get_string_node_valueFunction · 0.85
valueMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected