libmoost
|
binder is a helper class that aids synchronized binding/setting/getting of nested configurations. More...
#include <binder.h>
Public Member Functions | |
binder () | |
Constructs a binder. | |
virtual | ~binder () |
Destroys binder. | |
void | read (std::istream &source) |
read properties from source, and set defaults where properties omitted | |
void | write (std::ostream &dest, int indent=0) const |
write properties to dest | |
void | set (const std::string &key, const std::string &value) |
set a particular binding to value | |
void | get (const std::string &key, std::string &value) const |
get the value of a particular binding and store it in value | |
void | list (std::vector< std::pair< std::string, std::string > > &items) |
list all bindings and their values | |
void | set_default () |
set default values to all bindings | |
Protected Member Functions | |
void | child (const std::string &key, persistable &value) |
add persistable as subcomponent with name key | |
template<typename T > | |
void | bind (const std::string &key, T &value) |
add reference to field with name key | |
template<typename T > | |
void | bind (const std::string &key, T &value, const T &default_value) |
add reference to field with name key with a default value | |
Private Types | |
typedef std::map< std::string, persistable * > | route_map |
Private Attributes | |
route_map | m_routes |
std::vector< persistable * > | m_bindings |
binder is a helper class that aids synchronized binding/setting/getting of nested configurations.
Inherit from binder to obtain property getting/setting superpowers. Define your bindings in your ctor using the helper functions child and bind (see the tests for examples).
typedef std::map<std::string, persistable * > moost::configurable::binder::route_map [private] |
moost::configurable::binder::binder | ( | ) | [inline] |
binder::~binder | ( | ) | [virtual] |
Destroys binder.
Definition at line 37 of file binder.cpp.
void moost::configurable::binder::bind | ( | const std::string & | key, |
T & | value | ||
) | [protected] |
void moost::configurable::binder::bind | ( | const std::string & | key, |
T & | value, | ||
const T & | default_value | ||
) | [protected] |
void binder::child | ( | const std::string & | key, |
persistable & | value | ||
) | [protected] |
add persistable as subcomponent with name key
Definition at line 43 of file binder.cpp.
void binder::get | ( | const std::string & | key, |
std::string & | value | ||
) | const [virtual] |
get the value of a particular binding and store it in value
set one key/value pair
Implements moost::configurable::configurable.
Definition at line 160 of file binder.cpp.
void binder::list | ( | std::vector< std::pair< std::string, std::string > > & | items | ) | [virtual] |
list all bindings and their values
Implements moost::configurable::configurable.
Definition at line 188 of file binder.cpp.
void binder::read | ( | std::istream & | source | ) | [virtual] |
read properties from source, and set defaults where properties omitted
set all key/value pairs
Implements moost::configurable::persistable.
Definition at line 49 of file binder.cpp.
void binder::set | ( | const std::string & | key, |
const std::string & | value | ||
) | [virtual] |
set a particular binding to value
get one key/value pair
Implements moost::configurable::configurable.
Definition at line 132 of file binder.cpp.
void binder::set_default | ( | ) | [virtual] |
set default values to all bindings
Implements moost::configurable::persistable.
Definition at line 209 of file binder.cpp.
void binder::write | ( | std::ostream & | dest, |
int | indent = 0 |
||
) | const [virtual] |
write properties to dest
get all key/value pairs
Implements moost::configurable::persistable.
Definition at line 108 of file binder.cpp.
std::vector< persistable * > moost::configurable::binder::m_bindings [private] |