Property Map for storing settings and statistical information. More...
Public Types | |
typedef std::map< std::string, boost::any > | storage_type |
Internal storage type used with the internal property map. | |
typedef boost::associative_property_map < storage_type > | property_map_type |
Internal property map type which makes use of the storage type. | |
typedef boost::property_traits < property_map_type > ::value_type | value_type |
Value type of the property map, i.e. std::string . | |
typedef boost::property_traits < property_map_type > ::key_type | key_type |
Key type of the property map, i.e. boost::any . | |
typedef boost::shared_ptr < properties > | ptr |
Smart Pointer version of this class. | |
Public Member Functions | |
properties () | |
Standard constructor. | |
value_type & | operator[] (const key_type &k) const |
Direct access to the value type. | |
template<typename T > | |
T | get (const key_type &k) const |
Casted access to an existing element. | |
template<typename T > | |
T | get (const key_type &k, const T &default_value) const |
Casted access to an existing element with fall-back option. | |
void | set (const key_type &k, const value_type &value) |
Adds or modifies a value in the property map. | |
unsigned | size () const |
Number of properties. |
Property Map for storing settings and statistical information.
In this data structure settings and statistical data can be stored. The key to access data is always of type std::string
and the value can be of any type. To be type-safe, the getter corresponding get functions have to be provided with a type.
typedef boost::property_traits<property_map_type>::key_type key_type |
Key type of the property map, i.e. boost::any
.
There are pre-defined getter methods, which can be called with a type identifier for explicit casting.
typedef boost::associative_property_map<storage_type> property_map_type |
Internal property map type which makes use of the storage type.
typedef boost::shared_ptr<properties> ptr |
Smart Pointer version of this class.
Inside the framework, always the Smart Pointer version is used. To have an easy access, there are special functions provided which take the smart pointer as parameter and check as well if it can be dereferenced.
typedef std::map<std::string, boost::any> storage_type |
Internal storage type used with the internal property map.
typedef boost::property_traits<property_map_type>::value_type value_type |
Value type of the property map, i.e. std::string
.
properties | ( | ) |
Standard constructor.
Creates the property map on base of the storage map
T get | ( | const key_type & | k, | |
const T & | default_value | |||
) | const [inline] |
Casted access to an existing element with fall-back option.
The same as get(const key_type& k), but if k
does not exist, a default value is returned, which has to be of type T
.
k | Key to access the property map. May not exist. | |
default_value | If k does not exist, this value is returned. |
k
casted to its original type T
. If the key k
does not exist, default_value
is returned.T get | ( | const key_type & | k | ) | const [inline] |
Casted access to an existing element.
With T
you can specify the type of the element. Note, that it has to be the original used type, e.g. there is a difference even between int
and unsigned
.
The type is determined automatically using the set method.
k | Key to access the property map. Must exist. |
k
casted to its original type T
.value_type& operator[] | ( | const key_type & | k | ) | const |
Direct access to the value type.
Since the value_type
is of type boost::any
, it is not recommended to use this operator, but rather get and set.
k | Key to access the property map. Must exist. |
k
.void set | ( | const key_type & | k, | |
const value_type & | value | |||
) |
Adds or modifies a value in the property map.
This methods sets the value located at key k
to value
. If the key does not exist, it will be created. Be careful which type was used, especially with typed constants:
properties p; p.set( "a unsigned number", 5u ); p.get<unsigned>( "a unsigned number" ); // OK! p.get<int>( "a unsigned number" ); // FAIL! p.set( "a signed number", 5 ); p.get<unsigned>( "a signed number" ); // FAIL! p.get<int>( "a signed number" ); // OK!
k | Key of the property | |
value | The new value of k . If k already existed, the type of value must not change. |
unsigned size | ( | ) | const |
Number of properties.