RSC
0.17.1
|
Properties objects are basically glorified map<string, boost::any>
objects.
More...
#include <Properties.h>
Public Member Functions | |
Properties & | operator<<= (const Properties &other) |
Merge with other. More... | |
bool | operator== (const Properties &other) const |
Compare to other. More... | |
bool | has (const std::string &name) const throw () |
template<typename T > | |
T | get (const std::string &name) const |
template<typename T > | |
T | get (const std::string &name, const T &default_) const |
template<typename T > | |
T | getAs (const std::string &name) const |
Parse the value of the property name as type T and return the parsed value. More... | |
template<typename T > | |
T | getAs (const std::string &name, const T &default_) const |
Parse the value of the property name as type T and return the parsed value. More... | |
template<typename Target , typename T > | |
bool | set (const std::string &name, const T &value) throw () |
Sets a new property in the map. More... | |
Friends | |
RSC_EXPORT Properties | operator<< (const Properties &properties1, const Properties &properties2) |
Merge left and right. More... | |
template<typename Ch , typename Tr > | |
std::basic_ostream< Ch, Tr > & | operator<< (std::basic_ostream< Ch, Tr > &stream, const Properties &properties) |
Properties objects are basically glorified map<string, boost::any>
objects.
In addition to the implied semantics, Properties objects support basic stream output and merging and provide some convenience functions for setting and retrieving values.
Definition at line 57 of file Properties.h.
T rsc::runtime::Properties::get | ( | const std::string & | name | ) | const |
NoSuchObject | |
boost::bad_any_cast |
Definition at line 182 of file Properties.h.
References rsc::runtime::typeName().
T rsc::runtime::Properties::get | ( | const std::string & | name, |
const T & | default_ | ||
) | const |
boost::bad_any_cast |
Definition at line 202 of file Properties.h.
References rsc::runtime::typeName().
T rsc::runtime::Properties::getAs | ( | const std::string & | name | ) | const |
Parse the value of the property name as type T and return the parsed value.
This assumes that the stored value is of type std::string.
T | Desired target type of the conversion. |
name | Name of the property. |
NoSuchObject | If there is no propery named name. |
std::bad_cast | If the string value of the property cannot be converted to the desired target type. |
Definition at line 219 of file Properties.h.
T rsc::runtime::Properties::getAs | ( | const std::string & | name, |
const T & | default_ | ||
) | const |
Parse the value of the property name as type T and return the parsed value.
This assumes that the stored value is of type std::string.
T | Desired target type of the conversion. |
name | Name of the property. |
default_ | A fallback value which is returned when there is no property named name. |
std::bad_cast | If the string value of the property cannot be converted to the desired target type. |
Definition at line 234 of file Properties.h.
bool rsc::runtime::Properties::has | ( | const std::string & | name | ) | const |
throw | ( | ||||
) |
Definition at line 92 of file Properties.cpp.
Properties & rsc::runtime::Properties::operator<<= | ( | const Properties & | other | ) |
Merge with other.
Values from other replace values with identical keys.
other | New Properties which should take precedence over already present values. |
Definition at line 82 of file Properties.cpp.
bool rsc::runtime::Properties::operator== | ( | const Properties & | other | ) | const |
Compare to other.
All keys and values are checked for equality. Values can only be checked if they are of type std::string, bool, int, unsigned int or double.
other | The Properties object to which this one should be compared. |
std::runtime_error | If any value is of a type for which comparison has not been explicitly implemented. |
Definition at line 39 of file Properties.cpp.
References rsc::runtime::typeName().
bool rsc::runtime::Properties::set | ( | const std::string & | name, |
const T & | value | ||
) | |||
throw | ( | ||
) |
Sets a new property in the map.
If a property with this name exits, the new one will not be inserted. The old property has to be removed first. The property will be stored with type Target
.
name | name of the property to set |
value | value to set |
true
if the property was inserted, false
if a property with the given name existed and nothing was changedusage: props.set<unsigned int>("port", 22);
Definition at line 243 of file Properties.h.
References rsc::patterns::detail::make_pair().
|
friend |
Merge left and right.
Values in right take precedence over values with identical keys in left.
left | Properties with lower precedence. |
right | Properties with higher precedence. |
Definition at line 98 of file Properties.cpp.
|
friend |
Definition at line 252 of file Properties.h.