List of options. More...
#include <wipal/tool/options.hh>
Inherits std::map< name, value >.
Public Types | |
typedef std::map< name, value > | super_type |
Public Member Functions | |
list () | |
list (const internals::pair &defaults) | |
template<class D > | |
list (const internals::defaults_list< D > &defaults) | |
value & | operator[] (const name &n) |
const value & | operator[] (const name &n) const |
void | add (const list &l) |
void | add (const name &n, const value &v) |
list & | add (const name &n, const list &l) |
void | populate (list &other) const |
std::ostream & | print (std::ostream &o, unsigned depth=0) const |
List of options.
A list of options is a dynamic map that associates values of arbitrary types to std::string keys. Once a list of options is constructed and filled with various options, one access a specific item with operator[]():
opt::list l; l.add("int", int (42)); l.add("float", float (42)); int i = l["int"].get<int>(); // Both methods float f = opt::get<float>(l["float"]); // are valid.
Instead of using add() it is possible to initialize a list as follows:
opt::list l ((opt::name ("int") -= 42, opt::name ("sublist") -= opt::list (( opt::name ("bool") -= true )) ));
You can access sub-list items as follows:
bool b = l["sublist"]["bool"].get<bool>();
Looking for an option that does not exist or trying a conversion to an invalid type with raise an exception.
Add another option list l
as a new option with name n
.
If an option with name n
already exists and is already an option list, the options from l
are *added* to this list, i.e. the previous options are not deleted in the sub-list.