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(
64 catch (YAML::RepresentationException)
78 template <
class T,
size_t N>
79 YAML::Node YAML::convert<std::array<T, N>>::encode(
const std::array<T, N>& rhs)
81 Node node(NodeType::Sequence);
82 for (
auto it = rhs.cbegin(); it != rhs.cend(); ++it)
89 template <
class T,
size_t N>
90 bool YAML::convert<std::array<T, N>>::decode(
const Node& node, std::array<T, N>& rhs)
92 if (!node.IsSequence() || node.size() != N)
98 auto rhsit = rhs.begin();
99 for (YAML::const_iterator it = node.begin(); it != node.end(); ++it, ++rhsit)
103 (*rhsit) = it->as<T>();
105 catch (YAML::RepresentationException)
109 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
115 template <
class Key,
class T>
116 YAML::Node YAML::convert<std::unordered_map<Key, T>>::encode(
const std::unordered_map<Key, T>& rhs)
118 Node node(NodeType::Map);
119 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
121 node[it->first] = it->second;
126 template <
class Key,
class T>
127 bool YAML::convert<std::unordered_map<Key, T>>::decode(
const Node& node, std::unordered_map<Key, T>& rhs)
135 for (
auto it = node.begin(); it != node.end(); ++it)
139 rhs[it->first.as<Key>()] = it->second.as<T>();
141 catch (YAML::RepresentationException)
145 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
151 template <
class Value>
152 YAML::Node YAML::convert<std::unordered_set<Value>>::encode(
const std::unordered_set<Value>& rhs)
154 Node node(NodeType::Sequence);
155 for (
auto it = std::begin(rhs); it != std::end(rhs); ++it)
162 template <
class Value>
163 bool YAML::convert<std::unordered_set<Value>>::decode(
const Node& node, std::unordered_set<Value>& rhs)
165 if (!node.IsSequence())
171 for (
auto it = node.begin(); it != node.end(); ++it)
175 rhs.insert(it->as<Value>());
177 catch (YAML::RepresentationException)
181 SURGSIM_LOG(logger, WARNING) << __FUNCTION__ <<
": Bad conversion";
187 #endif // SURGSIM_DATASTRUCTURES_DATASTRUCTURESCONVERT_INL_H Definition: DriveElementFromInputBehavior.cpp:27
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.
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
bool hasValue() const
Query if this object has been assigned a value.
Definition: OptionalValue.h:56
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
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