7#include <yaml-cpp/yaml.h>
38 YAML::Node root(YAML::NodeType::Sequence);
40 for (
const auto &poly : polygons) {
41 YAML::Node poly_node(YAML::NodeType::Sequence);
42 for (
const auto &v : poly) {
46 poly_node.push_back(vtx);
48 root.push_back(poly_node);
51 YAML::Emitter emitter;
53 return {emitter.c_str(),
static_cast<std::size_t
>(emitter.size())};
78 void load(
const std::string& file_name);
95 T
get_path(
const std::string& dotted_key,
const T& default_value = T())
const;
107 T
get(
const T& default_value = T())
const;
119 void set(
const std::string& key,
const T& value);
144 std::vector<std::pair<std::string, Configuration>>
children()
const;
148 mutable YAML::Node resolved_cache_;
149 mutable bool cache_valid_;
156 static YAML::Node resolve_hierarchical_default(
const YAML::Node& n);
161 const YAML::Node& get_resolved()
const;
170typename std::enable_if<std::is_arithmetic<T>::value, T>::type
174 typedef typename std::conditional<
175 std::is_integral<T>::value, double,
long double>::type tmp_t;
177 tmp_t tmp = n.as<tmp_t>();
178 return static_cast<T
>(tmp);
179 }
catch (
const YAML::Exception&) {
180 return default_value;
186typename std::enable_if<!std::is_arithmetic<T>::value, T>::type
188 return default_value;
196 return default_value;
200 const YAML::Node& target_ref = get_resolved();
201 YAML::Node target = target_ref;
204 if (target.IsMap()) {
205 YAML::Node opt = target[
"default_option"];
206 if (opt) { target = opt; }
211 return target.as<T>();
212 }
catch (
const YAML::Exception&) {
221 if (!node_ || !node_.IsMap()) {
222 node_ = YAML::Node(YAML::NodeType::Map);
229 return at_path(dotted_key).
get<T>(default_value);
Configuration at_path(const std::string &dotted_key) const
Access a nested sub-configuration via a dotted path (supports '.' to escape dots).
Definition configuration.cpp:65
T get(const T &default_value=T()) const
Retrieves the configuration value cast to type T.
Definition configuration.h:194
std::string summary() const
Provides a summary of the configuration.
Definition configuration.cpp:39
T get_path(const std::string &dotted_key, const T &default_value=T()) const
Read a value at a dotted path with a default (convenience wrapper around at_path(....
Definition configuration.h:228
Configuration()
Default constructor creates an empty configuration.
Definition configuration.cpp:5
void set(const std::string &key, const T &value)
Sets the configuration entry for the given key.
Definition configuration.h:219
bool exists() const
Checks if the current node is defined.
Definition configuration.cpp:35
void load(const std::string &file_name)
Loads configuration parameters from a YAML file.
Definition configuration.cpp:17
Configuration operator[](const std::string &key) const
Access a sub-configuration.
Definition configuration.cpp:25
std::vector< std::pair< std::string, Configuration > > children() const
Returns the children (sub-entries) of the current node.
Definition configuration.cpp:45
std::string polygons_to_yaml(const arena_polygons_t &polygons)
Convert an arena_polygons_t structure into a compact YAML string.
Definition configuration.h:37
std::vector< std::vector< b2Vec2 > > arena_polygons_t
Definition geometry.h:13
Definition configuration.h:166
std::enable_if< std::is_arithmetic< T >::value, T >::type numeric_fallback(const YAML::Node &n, const T &default_value)
compile-time branch for arithmetic targets
Definition configuration.h:171