29 #include <yaml-cpp/yaml.h>
54 if (node.Tag() ==
"!include")
58 throw std::runtime_error(
"!include tag must be a scalar containing the file path");
61 auto included_file = node.as<std::string>();
63 if (resource ==
nullptr)
64 throw std::runtime_error(
"Unable to locate resource: " + included_file);
72 YAML::Node processed_map = YAML::Node(YAML::NodeType::Map);
73 for (
auto it = node.begin(); it != node.end(); ++it)
79 if (node.IsSequence())
82 YAML::Node processed_sequence = YAML::Node(YAML::NodeType::Sequence);
83 for (
const auto& child : node)
86 return processed_sequence;
96 YAML::Node root = YAML::LoadFile(resource->getFilePath());
102 YAML::Node root = YAML::Load(yaml_string);
112 throw std::runtime_error(
"Failed to serialize YAML node: " + std::string(out.GetLastError()));
114 std::ofstream file(file_path);
116 throw std::runtime_error(
"Failed to open file: " + file_path);
125 throw std::runtime_error(
"checkForUnknownKeys, node should be a map");
127 for (YAML::const_iterator it = node.begin(); it != node.end(); ++it)
129 auto key = it->first.as<std::string>();
130 if (expected_keys.find(key) == expected_keys.end())
131 throw std::runtime_error(
"checkForUnknownKeys, unknown key: " + key);
137 std::stringstream stream;
142 YAML::Node
fromYAMLString(
const std::string&
string) {
return YAML::Load(
string); }
144 bool compareYAML(
const YAML::Node& node1,
const YAML::Node& node2)
149 if (node1.Type() != node2.Type())
152 switch (node1.Type())
154 case YAML::NodeType::Scalar:
158 auto v1 = node1.as<
bool>();
159 auto v2 = node2.as<
bool>();
162 catch (YAML::TypedBadConversion<bool>& )
166 auto v1 = node1.as<
int>();
167 auto v2 = node2.as<
int>();
170 catch (YAML::TypedBadConversion<int>& )
174 auto v1 = node1.as<
double>();
175 auto v2 = node2.as<
double>();
178 catch (YAML::TypedBadConversion<double>& )
182 auto v1 = node1.as<std::string>();
183 auto v2 = node2.as<std::string>();
186 catch (YAML::TypedBadConversion<std::string>& )
194 case YAML::NodeType::Null:
196 case YAML::NodeType::Undefined:
198 case YAML::NodeType::Map:
199 case YAML::NodeType::Sequence:
200 if (node1.size() != node2.size())
207 for (YAML::const_iterator it1 = node1.begin(), it2; it1 != node1.end() && result; ++it1)
209 for (it2 = node2.begin(); it2 != node2.end(); ++it2)
214 if (it2 == node2.end())
222 return std::equal(node1.begin(), node1.end(), node2.begin(),
compareYAML);