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 T,
size_t N>
95 YAML::Node YAML::convert<std::array<T, N>>::encode(
const std::array<T, N>& rhs)
97 Node node(NodeType::Sequence);
98 for (
auto it = rhs.cbegin(); it != rhs.cend(); ++it)
105 template <
class T,
size_t N>
106 bool YAML::convert<std::array<T, N>>::decode(
const Node& node, std::array<T, N>& rhs)
108 if (!node.IsSequence() || node.size() != N)
114 auto rhsit = rhs.begin();
115 for (YAML::const_iterator it = node.begin(); it != node.end(); ++it, ++rhsit)
119 (*rhsit) = it->as<T>();
121 catch (YAML::RepresentationException)
125 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
131 template <
class Key,
class T>
132 YAML::Node YAML::convert<std::unordered_map<Key, T>>::encode(
const std::unordered_map<Key, T>& rhs)
134 Node node(NodeType::Map);
135 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
137 node[it->first] = it->second;
142 template <
class Key,
class T>
143 bool YAML::convert<std::unordered_map<Key, T>>::decode(
const Node& node, std::unordered_map<Key, T>& rhs)
151 for (
auto it = node.begin(); it != node.end(); ++it)
155 rhs[it->first.as<Key>()] = it->second.as<T>();
157 catch (YAML::RepresentationException)
161 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
167 template <
class Value>
168 YAML::Node YAML::convert<std::unordered_set<Value>>::encode(
const std::unordered_set<Value>& rhs)
170 Node node(NodeType::Sequence);
171 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
178 template <
class Value>
179 bool YAML::convert<std::unordered_set<Value>>::decode(
const Node& node, std::unordered_set<Value>& rhs)
181 if (!node.IsSequence())
187 for (
auto it = node.begin(); it != node.end(); ++it)
191 rhs.insert(it->as<Value>());
193 catch (YAML::RepresentationException)
197 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
203 #endif // SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H Definition: CompoundShapeToGraphics.cpp:29
void invalidate()
Mark this object as invalid.
Definition: OptionalValue.h:62
Container class that can indicate whether the object has been assigned a value.
Definition: OptionalValue.h:29
The convenience header that provides the entirety of the logging API.
static std::shared_ptr< Logger > getLogger(const std::string &name)
Get a logger by name from Logger Manager.
Definition: Logger.h:109
#define SURGSIM_LOG(logger, level)
Logs a message to the specified logger with the short level name.
Definition: LogMacros.h:60
const std::string hasValueName
Definition: DataStructuresConvert-inl.h:30
bool hasValue() const
Query if this object has been assigned a value.
Definition: OptionalValue.h:56
void setValue(const T &val)
Set the value of this object, and mark it as valid.
Definition: OptionalValue.h:69
const std::string valueName
Definition: DataStructuresConvert-inl.h:31
const std::string serializeLogger
Definition: DataStructuresConvert-inl.h:29
const T & getValue() const
Gets the value.
Definition: OptionalValue.h:78