Seastar
High performance C++ framework for concurrent servers
|
A group of options.
option_group is the basis for organizing options. It can hold a number of basic_value objects. These are typically also its members:
struct my_option_group : public option_group { value<> opt1; value<bool> opt2; ... my_option_group() : option_group(nullptr, "My option group") , opt1(this, "opt1", ... , opt2(this, "opt2", ... , ... { } };
Option groups can also be nested and using this property one can build a tree of option groups and values. This tree then can be visited using the two visitor methods exposed by option_group:
Using these two visitors one can easily implement glue code to expose an entire options tree to the command line. Use describe() to build the command-line level description of the objects (using e.g. boost::program_options) and after parsing the provided command-line options use mutate() to propagate the extracted values back into the options tree. How this is done is entirely up to the visitors, the above methods only offer an API to visit each group and value in the tree, they don't make any assumption about how the visitor works and what its purpose is.
#include <seastar/util/program-options.hh>
Public Types | |
using | value_list_type = boost::intrusive::list< basic_value, boost::intrusive::base_hook< list_base_hook >, boost::intrusive::constant_time_size< false > > |
using | option_group_list_type = boost::intrusive::list< option_group, boost::intrusive::base_hook< list_base_hook >, boost::intrusive::constant_time_size< false > > |
Public Member Functions | |
option_group (option_group *parent, std::string name) | |
option_group (option_group *parent, std::string name, unused) | |
option_group (option_group &&) | |
option_group (const option_group &)=delete | |
option_group & | operator= (option_group &&)=delete |
option_group & | operator= (const option_group &)=delete |
operator bool () const | |
Does the option group has any values contained in it? | |
bool | used () const |
const std::string & | name () const |
const value_list_type & | values () const |
value_list_type & | values () |
void | describe (options_descriptor &descriptor) const |
void | mutate (options_mutator &mutator) |
|
explicit |
Construct an option group.
parent | - the parent option-group, this option group will become a sub option group of the parent group |
name | - the name of the option group |
|
explicit |
Construct an unused option group.
parent | - the parent option-group, this option group will become a sub option group of the parent group |
name | - the name of the option group |
void seastar::program_options::option_group::describe | ( | options_descriptor & | descriptor | ) | const |
Describe the content of this option group to the visitor.
The content is visited in a depth-first manner:
false
the entire content of the group, including all its subgroups and values are skipped and options_descriptor::visit_group_end() is called immediately. Otherwise visiting the content of the group proceeds.false
the value is skipped, otherwise visiting the value proceeds.void seastar::program_options::option_group::mutate | ( | options_mutator & | mutator | ) |
Mutate the content of this option group by the visitor.
The visiting algorithm is identical to that of describe(), with the following differences:
true
if it did so and false
otherwise.