senf::console::ArgumentTraits< Type > Struct Template Reference

Customize argument parsing. More...

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

Public Types

typedef Type type
 

Static Public Member Functions

static void parse (ParseCommandInfo::TokensRange const &tokens, Type &out)
 Parse token range into value. More...
 
static std::string description ()
 String description of type. More...
 
static std::string str (Type const &value)
 Stringify value. More...
 

Static Public Attributes

static bool const singleToken
 

Related Functions

(Note that these are not member functions.)

template<class Type >
bool senf_console_parse_argument (ParseCommandInfo::TokensRange const &tokens, Type &out)
 Argument parser. More...
 

Detailed Description

template<class Type>
struct senf::console::ArgumentTraits< Type >

Customize argument parsing.

ArgumentTraits provides argument parsing, Additionally, this class provides a way to get a string-description of a type and to convert a value back into it's string representation used to display default values.

The default implementation provided here

  • will use senf_console_parse_argument() to parse a value. This functions default implementation uses boost::lexical_cast and thereby iostreams to convert an argument consisting of a single input token into the required type.
  • will name types by returning the last component of the fully scoped name (e.g. "string" for std::string).
  • Will format values (for default value display) by forwarding the value to the ReturnValueTraits of that type.

To customize just the argument parsing, just provide an implementation of senf_console_parse_argument(). Alternatively or to customize type naming or default value formatting, specialize ArgumentTraits for the type.

Definition at line 201 of file Parse.hh.

Member Typedef Documentation

◆ type

template<class Type >
typedef Type senf::console::ArgumentTraits< Type >::type

Definition at line 54 of file Traits.hh.

Member Function Documentation

◆ description()

template<class Type >
static std::string senf::console::ArgumentTraits< Type >::description ( )
static

String description of type.

Returns the string description of Type. Used to generate online help.

◆ parse()

template<class Type >
static void senf::console::ArgumentTraits< Type >::parse ( ParseCommandInfo::TokensRange const &  tokens,
Type &  out 
)
static

Parse token range into value.

This function needs to parse tokens and write the parsed value into out. This function needs to parse the complete list of tokens, additional tokens must be considered as syntax error.

Exceptions
SyntaxErrorException
Parameters
[in]tokenstokens to parse
[out]outparsed value

◆ str()

template<class Type >
static std::string senf::console::ArgumentTraits< Type >::str ( Type const &  value)
static

Stringify value.

To show default values in the online help, this function converts a value back into a one-line string representation. The default implementation uses the ReturnValueTraits for this conversion.

Friends And Related Function Documentation

◆ senf_console_parse_argument()

template<class Type >
bool senf_console_parse_argument ( ParseCommandInfo::TokensRange const &  tokens,
Type &  out 
)
related

Argument parser.

See also
ArgumentTraits

Member Data Documentation

◆ singleToken

template<class Type >
bool const senf::console::ArgumentTraits< Type >::singleToken
static
Initial value:
=
boost::is_same< decltype(senf_console_parse_argument(
*static_cast<ParseCommandInfo::TokensRange const *>(0),
*static_cast<Type*>(0))),
bool >::value

Definition at line 56 of file Traits.hh.


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