BRE12
YamlUtils.h
1 #pragma once
2 
3 #include <string>
4 #pragma warning( push )
5 #pragma warning( disable : 4127)
6 #include <yaml-cpp/yaml.h>
7 #pragma warning( pop )
8 
9 #include <Utils\DebugUtils.h>
10 
11 namespace BRE {
12 class YamlUtils {
13 public:
14  YamlUtils() = delete;
15  ~YamlUtils() = delete;
16  YamlUtils(const YamlUtils&) = delete;
17  const YamlUtils& operator=(const YamlUtils&) = delete;
18  YamlUtils(YamlUtils&&) = delete;
19  YamlUtils& operator=(YamlUtils&&) = delete;
20 
21  static bool IsDefined(const YAML::Node& node,
22  const char* key);
23 
24  template<typename T>
25  static T GetScalar(const YAML::Node& node,
26  const char* key)
27  {
28  BRE_ASSERT(key != nullptr);
29  YAML::Node attr = node[key];
30  BRE_ASSERT(attr.IsDefined());
31  BRE_ASSERT(attr.IsScalar());
32  return std::to_string(attr.as<std::string>());
33  }
34 
35  template<>
36  static std::string GetScalar(const YAML::Node& node,
37  const char* key)
38  {
39  BRE_ASSERT(key != nullptr);
40  YAML::Node attr = node[key];
41  BRE_ASSERT(attr.IsDefined());
42  BRE_ASSERT(attr.IsScalar());
43  return attr.as<std::string>();
44  }
45 
46  template<typename T>
47  static void GetSequence(const YAML::Node& node,
48  T* const sequenceOutput,
49  const size_t numElems)
50  {
51  BRE_ASSERT(sequenceOutput != nullptr);
52  BRE_ASSERT(node.IsDefined());
53  BRE_ASSERT(node.IsSequence());
54  size_t currentNumElems = 0;
55  for (const YAML::Node& seqNode : node) {
56  BRE_ASSERT(seqNode.IsScalar());
57  BRE_ASSERT(currentNumElems < numElems);
58  sequenceOutput[currentNumElems] = seqNode.as<T>();
59  ++currentNumElems;
60  }
61  BRE_ASSERT(currentNumElems == numElems);
62  }
63 };
64 
65 }
66 
Definition: Camera.cpp:8
Definition: YamlUtils.h:12
Definition: node.h:29