senf::console::factory::Variable Class Reference

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...
 

Detailed Description

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.

int var;
ScopedDirectory<> dir;
dir.add("var", fty::Variable(var));
    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.
dir.add("const_var", fty::Variable(boost::cref(var)));
    \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.

Member Typedef Documentation

◆ Formatter

Definition at line 111 of file Variables.hh.

◆ OnChangeHandler

Definition at line 109 of file Variables.hh.

◆ Parser

typedef detail::ArgumentInfo<typename SetOverload::arg1_type>::Parser senf::console::factory::Variable::Parser

Definition at line 108 of file Variables.hh.

◆ QueryOverload

Definition at line 112 of file Variables.hh.

◆ SetOverload

typedef detail::SetVariable<Variable>::Traits::Overload senf::console::factory::Variable::SetOverload

Definition at line 107 of file Variables.hh.

Member Function Documentation

◆ doc()

VariableFactory senf::console::factory::Variable::doc ( std::string const &  doc)

Set documentation of the variable.

◆ formatter()

VariableFactory senf::console::factory::Variable::formatter ( Formatter  formatter)

Set formatter.

The formatter must be a callable with a signature compatible with

void formatter(Variable const & value, std::ostream & os);

The formatter takes the return value of the call value and writes it properly formatted to os.

◆ onChange()

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

void handler(Variable const & oldValue);

◆ parser()

VariableFactory senf::console::factory::Variable::parser ( Parser  parser)

Set argument parser.

The parser is an arbitrary callable object with the signature

void parser(senf::console::ParseCommandInfo::TokensRange const & tokens, value_type & out);
                                         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.  

◆ shortdoc()

VariableFactory senf::console::factory::Variable::shortdoc ( std::string const &  doc)

Set short documentation.

◆ typeName()

VariableFactory senf::console::factory::Variable::typeName ( std::string const &  name)

Set name of the variable type.

◆ VariableFactory()

senf::console::factory::Variable::VariableFactory ( Variable var)
explicit

Create Variable node.


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