RSC  0.17.1
rsc::runtime::Properties Class Reference

Properties objects are basically glorified map<string, boost::any> objects. More...

#include <Properties.h>

Inheritance diagram for rsc::runtime::Properties:
Inheritance graph
Collaboration diagram for rsc::runtime::Properties:
Collaboration graph

Public Member Functions

Propertiesoperator<<= (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 >
get (const std::string &name) const
 
template<typename T >
get (const std::string &name, const T &default_) const
 
template<typename 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 >
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)
 

Detailed Description

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.

Author
Jan Moringen jmori.nosp@m.nge@.nosp@m.techf.nosp@m.ak.u.nosp@m.ni-bi.nosp@m.elef.nosp@m.eld.d.nosp@m.e

Definition at line 57 of file Properties.h.

Member Function Documentation

template<typename T >
T rsc::runtime::Properties::get ( const std::string &  name) const
Exceptions
NoSuchObject
boost::bad_any_cast

Definition at line 182 of file Properties.h.

References rsc::runtime::typeName().

Here is the call graph for this function:

template<typename T >
T rsc::runtime::Properties::get ( const std::string &  name,
const T &  default_ 
) const
Exceptions
boost::bad_any_cast

Definition at line 202 of file Properties.h.

References rsc::runtime::typeName().

Here is the call graph for this function:

template<typename T >
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.

Template Parameters
TDesired target type of the conversion.
Parameters
nameName of the property.
Exceptions
NoSuchObjectIf there is no propery named name.
std::bad_castIf the string value of the property cannot be converted to the desired target type.

Definition at line 219 of file Properties.h.

template<typename T >
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.

Template Parameters
TDesired target type of the conversion.
Parameters
nameName of the property.
default_A fallback value which is returned when there is no property named name.
Exceptions
std::bad_castIf 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.

Parameters
otherNew Properties which should take precedence over already present values.
Returns
The modified Properties object.

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.

Parameters
otherThe Properties object to which this one should be compared.
Exceptions
std::runtime_errorIf 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().

Here is the call graph for this function:

template<typename Target , typename T >
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.

Parameters
namename of the property to set
valuevalue to set
Returns
true if the property was inserted, false if a property with the given name existed and nothing was changed

usage: props.set<unsigned int>("port", 22);

Definition at line 243 of file Properties.h.

References rsc::patterns::detail::make_pair().

Here is the call graph for this function:

Friends And Related Function Documentation

RSC_EXPORT Properties operator<< ( const Properties properties1,
const Properties properties2 
)
friend

Merge left and right.

Values in right take precedence over values with identical keys in left.

Parameters
leftProperties with lower precedence.
rightProperties with higher precedence.
Returns
A new Properties object which contains the result of the merge.

Definition at line 98 of file Properties.cpp.

template<typename Ch , typename Tr >
std::basic_ostream<Ch, Tr>& operator<< ( std::basic_ostream< Ch, Tr > &  stream,
const Properties properties 
)
friend

Definition at line 252 of file Properties.h.


The documentation for this class was generated from the following files: