16 #ifndef SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H
17 #define SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H
25 namespace DataStructures
37 YAML::Node YAML::convert<SurgSim::DataStructures::OptionalValue<T>>::encode(
54 bool YAML::convert<SurgSim::DataStructures::OptionalValue<T>>::decode(
66 catch (YAML::RepresentationException)
78 else if (node.IsScalar())
84 catch (YAML::RepresentationException)
94 template <
class Key,
class T>
95 YAML::Node YAML::convert<std::unordered_map<Key, T>>::encode(
const std::unordered_map<Key, T>& rhs)
97 Node node(NodeType::Map);
98 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
100 node[it->first] = it->second;
105 template <
class Key,
class T>
106 bool YAML::convert<std::unordered_map<Key, T>>::decode(
const Node& node, std::unordered_map<Key, T>& rhs)
114 for (
auto it = node.begin(); it != node.end(); ++it)
118 rhs[it->first.as<Key>()] = it->second.as<T>();
120 catch (YAML::RepresentationException)
124 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
130 template <
class Value>
131 YAML::Node YAML::convert<std::unordered_set<Value>>::encode(
const std::unordered_set<Value>& rhs)
133 Node node(NodeType::Sequence);
134 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
141 template <
class Value>
142 bool YAML::convert<std::unordered_set<Value>>::decode(
const Node& node, std::unordered_set<Value>& rhs)
144 if (!node.IsSequence())
150 for (
auto it = node.begin(); it != node.end(); ++it)
154 rhs.insert(it->as<Value>());
156 catch (YAML::RepresentationException)
160 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
166 #endif // SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H