FLAME  devel
 All Classes Functions Variables Typedefs Enumerations Pages
Public Types | Public Member Functions | List of all members
Config Class Reference

Associative configuration container. More...

#include <config.h>

Public Types

typedef boost::variant< double,
std::vector< double >
, std::string, std::vector
< Config > > 
value_t
 An individual value (double, double[], string, or Config[])
 
typedef std::vector< Configvector_t
 
typedef std::map< std::string,
value_t
values_t
 
typedef values_t::iterator iterator
 iterator
 
typedef values_t::const_iterator const_iterator
 const_iterator
 

Public Member Functions

 Config ()
 New empty config.
 
 Config (const Config &)
 
Configoperator= (const Config &)
 Assignment.
 
bool tryGetAny (const std::string &name, value_t &ret) const
 
const value_tgetAny (const std::string &name) const
 
void setAny (const std::string &name, const value_t &val)
 
void swapAny (const std::string &name, value_t &val)
 Exchange a single parameter untyped.
 
template<typename T >
detail::RT< T >::type get (const std::string &name) const
 
template<typename T >
detail::RT< T >::type get (const std::string &name, typename boost::call_traits< T >::param_type def) const
 
template<typename T >
bool tryGet (const std::string &name, T &val) const
 
template<typename T >
void set (const std::string &name, typename boost::call_traits< typename detail::is_config_value< T >::type >::param_type val)
 
template<typename T >
void swap (const std::string &name, typename boost::call_traits< typename detail::is_config_value< T >::type >::reference val)
 
void swap (Config &c)
 Exchange entire Config.
 
void show (std::ostream &, unsigned indent=0) const
 Print listing of inner scope.
 
const_iterator begin () const
 The first element.
 
const_iterator end () const
 one after the last element
 
void reserve (size_t)
 
Config new_scope () const
 Create a new inner scope.
 
void push_scope ()
 
void flatten ()
 

Detailed Description

Associative configuration container.

Typed key/value storage. Value types must be:

double,

std::vector<double>,

std::string, or

std::vector<Config>

Most common usage is get<>() and set<>() to fetch and store typed values. Generic code might also use getAny() or setAny().

Also has the notion

Definition at line 66 of file config.h.

Constructor & Destructor Documentation

Config::Config ( const Config O)

Build config from a single std::map (single scope) Copy ctor

Definition at line 15 of file config.cpp.

Member Function Documentation

template<typename T >
detail::RT<T>::type Config::get ( const std::string &  name) const
inline

lookup typed.

Exceptions
key_errorif name doesn't refer to an existing parameter, or the parameter has other than the requested type.
double v = X.get<double>("param"); // throws since "param" is not set

Definition at line 123 of file config.h.

template<typename T >
detail::RT<T>::type Config::get ( const std::string &  name,
typename boost::call_traits< T >::param_type  def 
) const
inline

lookup typed with default. If 'name' doesn't refer to a parameter, or it has the wrong type, then 'def' is returned instead.

double v = X.get<double>("param", 0.0); // returns 0.0 since "param" is not set

Definition at line 141 of file config.h.

const Config::value_t & Config::getAny ( const std::string &  name) const

lookup untyped.

Exceptions
key_errorif name doesn't refer to an existing parameter

Definition at line 58 of file config.cpp.

template<typename T >
void Config::set ( const std::string &  name,
typename boost::call_traits< typename detail::is_config_value< T >::type >::param_type  val 
)
inline

add/replace with a new value

X.set<double>("param", 42.0);

Definition at line 175 of file config.h.

void Config::setAny ( const std::string &  name,
const value_t val 
)

add/replace with a new value, untyped

Definition at line 69 of file config.cpp.

template<typename T >
void Config::swap ( const std::string &  name,
typename boost::call_traits< typename detail::is_config_value< T >::type >::reference  val 
)
inline

Exchange a single parameter typed

X.set<double>("param", 42.0);
double v = 43.0;
X.swap<double>("param", v);
assert(v==42.0);

Definition at line 192 of file config.h.

template<typename T >
bool Config::tryGet ( const std::string &  name,
T &  val 
) const
inline

lookup where missing parameters returns false

Returns
true if val is updated, false otherwise

Definition at line 156 of file config.h.

bool Config::tryGetAny ( const std::string &  name,
value_t ret 
) const

lookup untyped.

Returns
true if 'ret' updates, and false if no parameter with 'name'.

Definition at line 40 of file config.cpp.


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