|
| Options ()=default |
| Constructs an empty instance. More...
|
|
| Options (Options const &rhs) |
|
Options & | operator= (Options const &rhs) |
|
| Options (Options &&)=default |
|
Options & | operator= (Options &&)=default |
|
template<typename T > |
Options & | set (ValueTypeT< T > v) |
| Sets option T to the value v and returns a reference to *this . More...
|
|
template<typename T > |
bool | has () const |
| Returns true IFF an option with type T exists. More...
|
|
template<typename T > |
void | unset () |
| Erases the option specified by the type T . More...
|
|
template<typename T > |
ValueTypeT< T > const & | get () const |
| Returns a reference to the value for T , or a value-initialized default if T was not set. More...
|
|
template<typename T > |
ValueTypeT< T > & | lookup (ValueTypeT< T > value={}) |
| Returns a reference to the value for option T , setting the value to init_value if necessary. More...
|
|
A class that holds option structs indexed by their type.
An "Option" is any struct that has a public Type
member typedef. By convention they are named like "FooOption". Each library (e.g., spanner, storage) may define their own set of options. Additionally, there are common options defined that many libraries may use. All these options may be set in a single Options
instance, and each library will look at the options that it needs.
Here's an overview of this class's interface, but see the method documentation below for details.
.set<T>(x)
– Sets the option T
to value x
.has<T>()
– Returns true iff option T
is set
.unset<T>()
– Removes the option T
.get<T>()
– Gets a const-ref to the value of option T
.lookup<T>(x)
– Gets a non-const-ref to option T
's value, initializing it to x
if it was not set (x
is optional).
- Example:
struct FooOption {
using Type = int;
};
struct BarOption {
using Type = std::set<std::string>;
};
...
Options opts;
assert(opts.get<FooOption>() == 0);
opts.set<FooOption>(42);
assert(opts.get<FooOption>() == 42);
opts.lookup<BarOption>().insert("hello");
opts.lookup<BarOption>().insert("world");
std::set<std::string> const& bar = opts.get<BarOption>();
assert(bar == std::set<std::string>{"hello", "world"});
Definition at line 91 of file options.h.