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

Customize argument parsing. More...

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

List of all members.


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 63 of file Traits.hh.


Public Types

typedef Type  type

Static Public Member Functions

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

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.

Member Typedef Documentation

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

Reimplemented in senf::console::detail::CharArgumentTraits< CharT >.

Definition at line 65 of file Traits.hh.


Member Function Documentation

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

String description of type.

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

Reimplemented in senf::console::detail::CharArgumentTraits< CharT >.

Definition at line 62 of file Traits.cci.

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

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]  tokens  tokens to parse
[out]  out  parsed value

Definition at line 57 of file Traits.cti.

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

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.

Definition at line 87 of file Traits.cti.


Friends And Related Function Documentation

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

Argument parser.

See also:
ArgumentTraits

Member Data Documentation

template<class Type>
bool const senf::console::ArgumentTraits< Type >::singleToken
[static]

Initial value:

            boost::is_same< typeof(senf_console_parse_argument(
                                       *static_cast<ParseCommandInfo::TokensRange const *>(0),
                                       *static_cast<Type*>(0))),
                            bool >::value

Definition at line 67 of file Traits.hh.


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