|
Utopia 2
Framework for studying models of complex & adaptive systems.
|
Allows reading configuration entries from YAML files. More...

Typedefs | |
| using | Utopia::DataIO::Config = YAML::Node |
| Type of a variadic dictionary-like data structure used throughout Utopia. | |
Functions | |
| template<typename ReturnType > | |
| ReturnType | Utopia::get_as (const std::string &key, const DataIO::Config &node) |
| This function is a wrapper around the yaml-cpp YAML::Node::as function. | |
| template<typename ReturnType > | |
| ReturnType | Utopia::get_as (const std::string &key, const DataIO::Config &node, ReturnType fallback) |
| Like Utopia::get_as, but instead of KeyError, returns a fallback value. | |
| template<DimType dim> | |
| SpaceVecType< dim > | Utopia::get_as_SpaceVec (const std::string &key, const DataIO::Config &node) |
| Special case of Utopia::get_as to retrieve an entry as SpaceVec. | |
| template<DimType dim> | |
| MultiIndexType< dim > | Utopia::get_as_MultiIndex (const std::string &key, const DataIO::Config &node) |
| Special case of Utopia::get_as to retrieve an entry as MultiIndex. | |
Allows reading configuration entries from YAML files.
This module implements functions which allow for improved access to yaml-cpp processed yaml-files. The primary focus lies on improved exceptions and usability, mainly through the Utopia::get_as function.
Utopia relies heavily on the use of YAML configuration files. These files and substructures of it are available as so called "config nodes", Utopia::DataIO::Config objects, which are hierarchically nested maps, sequences, and scalars.
When retrieving values from these nodes, a type cast becomes necessary. While the library used for YAML reading provides such a function, we found it more convenient to define some thin wrappers around them, which supply more information when something goes wrong.
To remember the order of arguments, this sentence can be employed: get_as a double: the entry named my_double from this cfg node. Of course, YAML has no types associated with each entry; the Utopia::get_as function tries to do this conversion and, if it fails, throws an exception.
The core of this module consists of the get_as function, which i conjunction with improve_yaml_exception works to improve error messages and simplifies the syntax of converting yaml nodes to c++ types. Additionally, specializations for non-standard types are provided, e.g. for working with types from the Armadillo linear algebra package.
| using Utopia::DataIO::Config = typedef YAML::Node |
Type of a variadic dictionary-like data structure used throughout Utopia.
| ReturnType Utopia::get_as | ( | const std::string & | key, |
| const DataIO::Config & | node | ||
| ) |
This function is a wrapper around the yaml-cpp YAML::Node::as function.
It enhances the error messages that can occur in a read operation.
Example:
| ReturnType | The type to evaluate from the YAML::Node |
| key | The key that is to be read |
| node | The node to read the entry with the given key from |
| Utopia::KeyError | On missing key |
| YAML::Exception | On bad conversions or other YAML-related errors |
| ReturnType Utopia::get_as | ( | const std::string & | key, |
| const DataIO::Config & | node, | ||
| ReturnType | fallback | ||
| ) |
Like Utopia::get_as, but instead of KeyError, returns a fallback value.
| MultiIndexType< dim > Utopia::get_as_MultiIndex | ( | const std::string & | key, |
| const DataIO::Config & | node | ||
| ) |
Special case of Utopia::get_as to retrieve an entry as MultiIndex.
| dim | The dimensionality of the returned Utopia::MultiIndexType |
| SpaceVecType< dim > Utopia::get_as_SpaceVec | ( | const std::string & | key, |
| const DataIO::Config & | node | ||
| ) |
Special case of Utopia::get_as to retrieve an entry as SpaceVec.
| dim | The dimensionality of the returned Utopia::SpaceVecType |