senf::console::ParsedCommandOverloadBase Class Reference
[Supported command types]

CommandOverload implementation with automatic argument parsing. More...

#include <senf/Utils/Console/ParsedCommand.hh>

Inheritance diagram for senf::console::ParsedCommandOverloadBase:
Inheritance graph
[legend]

List of all members.


Detailed Description

CommandOverload implementation with automatic argument parsing.

ParsedCommandOverloadBase implements a CommandOverload implementation supporting automatic parsing of arguments. This is not a node, it's a CommandOverload which is then added to an OverloadedCommandNode instance.

Automatic argument parsing and return value processing consists of several components:

Adding argument parsing callbacks to the tree

To add overloads to the tree, use the senf::console::factory::Command factory:
namespace fty = senf::console::factory;

std::string taskStatus(int id);

senf::console::root().add("taskStatus", fty::Command(&taskStatus));

There are quite a number of additional parameters available to be set. These parameters are documented in ParsedArgumentAttributor. Parameters are set by adding them as additional calls after adding the node:

senf::console::root().add("taskStatus", fty::Command(&taskStatus)
    .doc("Query the current task status")
    .arg( name = "id",
          description = "numeric id of task to check, -1 for the current task."
          default_value = -1 ) );

You may also add an additional std::ostream & Argument as first argument to the callback. If this argument is present, the stream connected to the console which issued the command will be passed there. This allows writing arbitrary messages to the console.

Additionally, overloading is supported by registering multiple commands under the same name. So, elaborating on above example:

std::string taskStatus(int id);
std::string taskStatus(std::string const & name);

senf::console::root()
    .add("taskStatus", fty::Command(static_cast<std::string (*)(int)>(
                                        &taskStatus))
    .doc("Query the current task status")
    .overloadDoc("Query status by id")
    .arg( name = "id",
          description = "numeric id of task to check, -1 for the current task."
          default_value = -1 ) );
senf::console::root()
    .add("taskStatus", fty::Command(static_cast<std::string (*)(std::string const &)>(
                                         &taskStatus))
    .overloadDoc("Query status by name")
    .arg( name = "name",
          description = "name of task to check" ) );

We can see here, that taking the address of an overloaded function requires a cast. If you can give unique names to each of the C++ overloads (not the overloads in the console), you should do so to make the unwieldy casts unnecessary.

Custom parameter parsers

By default, parameters are parsed using boost::lexical_cast and therefore using iostreams. This means, that any type which can be read from a stream can automatically be used as argument type.

However, argument parsing can be configured by specializing senf::console::ArgumentTraits. See that class for more information.

Custom return-value formatters

By default, return values are streamed to an ostream. This automatically allows any streamable type to be used as return value. To add new types or customize the formating, the senf::console::ReturnValueTraits template needs to be specialized for that type. See that class for more information.

Definition at line 136 of file ParsedCommand.hh.


Public Types

typedef boost::intrusive_ptr
< ParsedCommandOverloadBase
ptr

Public Member Functions

detail::ArgumentInfoBase arg (unsigned n) const
void  doc (std::string const &d)

Protected Member Functions

  ParsedCommandOverloadBase ()
template<class Type >
void  addParameter ()

Member Typedef Documentation

typedef boost::intrusive_ptr<ParsedCommandOverloadBase> senf::console::ParsedCommandOverloadBase::
ptr

Constructor & Destructor Documentation

senf::console::ParsedCommandOverloadBase::
ParsedCommandOverloadBase ()

Definition at line 44 of file ParsedCommand.cci.


Member Function Documentation

template<class Type >
void senf::console::ParsedCommandOverloadBase::
addParameter ()

Definition at line 64 of file ParsedCommand.cti.

senf::console::detail::ArgumentInfoBase & senf::console::ParsedCommandOverloadBase::
arg ( unsigned  n )

Definition at line 48 of file ParsedCommand.cci.

void senf::console::ParsedCommandOverloadBase::
doc ( std::string const &  d )

Definition at line 55 of file ParsedCommand.cci.


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