Variable node factory. More...
#include <senf/Utils/Console/Variables.hh>
Public Types | |
typedef detail::SetVariable< Variable >::Traits::Overload | SetOverload |
typedef detail::ArgumentInfo< typename SetOverload::arg1_type >::Parser | Parser |
typedef detail::SetVariable< Variable >::OnChangeHandler | OnChangeHandler |
typedef ConstVariableFactory< Variable >::Formatter | Formatter |
typedef ConstVariableFactory< Variable >::QueryOverload | QueryOverload |
Public Member Functions | |
VariableFactory | doc (std::string const &doc) |
Set documentation of the variable. More... | |
VariableFactory | shortdoc (std::string const &doc) |
Set short documentation. More... | |
VariableFactory | formatter (Formatter formatter) |
Set formatter. More... | |
VariableFactory | parser (Parser parser) |
Set argument parser. More... | |
VariableFactory | typeName (std::string const &name) |
Set name of the variable type. More... | |
VariableFactory | onChange (OnChangeHandler handler) |
Set change callback. More... | |
VariableFactory (Variable &var) | |
Create Variable node. More... | |
Variable node factory.
Variable commands allow to register any arbitrary variable as a command node. The variable will be registered as two command overloads: One which takes a single argument of the variables type to set the variable and another one taking no arguments and just querying the current variable value.
Variables should be registered only with a ScopedDirectory declared in the same scope (e.g. as a class member for member variables). This ensures, that the variable node is removed from the tree when the scope is destroyed. Since a variable command is added as a combination of two ordinary overloads, it is possible to register additional overloads with the same name before or after registering the variable. It is also possible, to register a variable read-only. To achieve this, just wrap it with \c boost::cref(). Such a variable only queried. Therefore, it does not have the parser() and typeName() attributes.
\note Even though the interface is documented as a class, in reality it is implemented using factory functions returning instances of an internal factory class. \see \ref console_variables
Definition at line 99 of file Variables.hh.
typedef ConstVariableFactory<Variable>::Formatter senf::console::factory::Variable::Formatter |
Definition at line 111 of file Variables.hh.
typedef detail::SetVariable<Variable>::OnChangeHandler senf::console::factory::Variable::OnChangeHandler |
Definition at line 109 of file Variables.hh.
typedef detail::ArgumentInfo<typename SetOverload::arg1_type>::Parser senf::console::factory::Variable::Parser |
Definition at line 108 of file Variables.hh.
typedef ConstVariableFactory<Variable>::QueryOverload senf::console::factory::Variable::QueryOverload |
Definition at line 112 of file Variables.hh.
typedef detail::SetVariable<Variable>::Traits::Overload senf::console::factory::Variable::SetOverload |
Definition at line 107 of file Variables.hh.
VariableFactory senf::console::factory::Variable::doc | ( | std::string const & | doc | ) |
Set documentation of the variable.
VariableFactory senf::console::factory::Variable::formatter | ( | Formatter | formatter | ) |
Set formatter.
The formatter must be a callable with a signature compatible with
The formatter takes the return value of the call value and writes it properly formatted to os.
VariableFactory senf::console::factory::Variable::onChange | ( | OnChangeHandler | handler | ) |
Set change callback.
The handler callback is called, whenever the value of the variable is changed. The new value has already been set, when the callback is called, the old value is passed to the callback. The callback must have a signature compatible to
VariableFactory senf::console::factory::Variable::parser | ( | Parser | parser | ) |
Set argument parser.
The parser is an arbitrary callable object with the signature
where \c value_type is the type of the overload parameter. The parser must read and parse the complete \a tokens range and return the parsed value in \a out. If the parser fails, it must raise a senf::console::SyntaxErrorException.
VariableFactory senf::console::factory::Variable::shortdoc | ( | std::string const & | doc | ) |
Set short documentation.
VariableFactory senf::console::factory::Variable::typeName | ( | std::string const & | name | ) |
Set name of the variable type.