|
| property_set ()=default |
| Default constructor. More...
|
|
| property_set (datatools::properties const &ps) |
| Construct from an existing datatools::properties. More...
|
|
bool | is_empty () const |
| Returns true if no key-value pairs are held. More...
|
|
std::vector< std::string > | get_names () const |
| Returns a vector of all keys in the property_set. More...
|
|
bool | has_key (std::string const &key) const |
| Returns true if the property_set stores a pair with the supplied key. More...
|
|
bool | is_key_to_property (std::string const &key) const |
| Returns true if the key's value is a property/atom. More...
|
|
bool | is_key_to_sequence (std::string const &key) const |
| Returns true if the keys's value is sequence. More...
|
|
bool | is_key_to_property_set (std::string const &key) const |
| Returns true if the key's value is a property_set. More...
|
|
std::string | to_string () const |
| Returns a string representation of the property_set. More...
|
|
template<typename T > |
T | get (std::string const &key) const |
| Return the value of type T held at supplied key. More...
|
|
template<typename T > |
T | get (std::string const &key, T const &default_value) const |
|
| operator datatools::properties () const |
| Convert back to datatools::properties. More...
|
|
template<typename T > |
void | put (std::string const &key, T const &value) |
| Insert key-value pair in property_set. More...
|
|
template<typename T > |
void | put_or_replace (std::string const &key, T const &value) |
| Insert key-value pair in property_set, replacing value if key exists. More...
|
|
bool | erase (std::string const &key) |
| Erase the name-value pair stored at key. More...
|
|
template<> |
property_set | get (std::string const &key) const |
|
template<> |
property_set | get (std::string const &key, property_set const &default_value) const |
|
template<> |
void | put (std::string const &key, property_set const &value) |
|
template<> |
void | put_or_replace (std::string const &key, property_set const &value) |
|
template<> |
void | put_impl_ (std::string const &key, falaise::config::path const &value) |
| Private specialization of put_impl_ for path. More...
|
|
template<> |
void | put_impl_ (std::string const &key, falaise::config::quantity const &value) |
| Private specialization of put_impl_ for quantity. More...
|
|
template<> |
void | get_impl_ (std::string const &key, falaise::config::path &result) const |
|
template<> |
void | get_impl_ (std::string const &key, falaise::config::quantity &result) const |
|
Class holding a set of key-value properties.
Provides a convenient adaptor interface over datatools::properties, targeted at developers of modules for Falaise needing key-value storage and validation of input parameters. It may be used directly as
falaise::property_set ps{};
ps.put("a",2);
int x = ps.get<int>("a");
ps.put("a",3.14);
std::string s = ps.get<std::string>("b", "hello");
std::cout << s << std::endl;
or it can be constructed from an existing instance of datatools::properties
falaise::property_set ps{x};
}
or from a datatools::properties file
void example(std::string const& file) {
falaise::property_set ps{};
}
Storage and retrieval of parameters is typesafe in the sense that:
- You can only put values that are of type
- You can only get values of the above types, and a wrong_type_error will be thrown if you try to retrieve a value with a different type, e.g
ps.put("a", 2);
double x = ps.get<double>("a");
Support for path and quantity_t is provided to support validation of input configuration scripts. These types model the path
and dimension
decorators for properties parameters:
# this is a true filesystem path
foo : string as path = "${HOME}/something"
# this is a true physical quantity with dimension "length"
bar : real as length = 3.14 m
When extracting parameters, you can ensure that that you have a true path or physical quantity of the right dimension:
Support for put and get of property_set values is provided to support datatools::properties constructs of the form:
plain : string = "A plain property"
table.foo : string = "A string property in a 'table'"
table.bar : int = 42
The foo
and bar
properties an be extracted either by their full keys:
auto foo = ps.get<std::string>("table.foo");
auto bar = ps.get<int>("table.bar);
or by getting the table
key as a property_set, then its properties which will be stored using their subkey names:
auto foo = ps.
get<std::string>(
"foo");
auto bar = ps.get<int>("bar);
This can be extended to further levels of nesting if required. However, note that datatools::properties configuration of the form:
table : string = "Not a valid table"
table.x : int = 11
table.y : int = 22
are not considered get-able as property_set
s. This is due to the ambiguity of the table
key which property_set regards as an atomic property of type std::string
. Here, the table.x
and table.y` keys can be extracted only via their fully qualified keys. It is therefore strongly recommended that you structure your configuration in the "pure table" form above for clarity and ease of use.
The default value form of get can be used to implement optional configuration, for example
auto requiredParam = ps.get<int>("foo");
auto optionalParam = ps.get<int>("answer",42);
...
}
Combined, these various ways of using property_set allow simple and reliable usage for configuration and configuration validation in Falaise modules.
- See also
- path
-
quantity
-
datatools::properties
-
datatools::units