senf::console::CheckedArgumentIteratorWrapper Class Reference

Wrapper checking argument iterator access for validity. More...

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

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

List of all members.


Detailed Description

Wrapper checking argument iterator access for validity.

CheckedArgumentIteratorWrapper is a wrapper around a range of arguments parsed using the ParseCommandInfo::ArgumentIterator. It is used to parse arguments either in a command (registered with manual argument parsing) or when defining a custom parser.

void fn(std::ostream & out, senf::console::ParseCommandInfo command)
{
    std:;string arg1;
    unsigned arg2 (0);

    {
        senf::console::CheckedArgumentIteratorWrapper arg (command.arguments());
        senf::console::parse( *(arg++), arg1 );
        senf::console::parse( *(arg++), arg2 );
    }

    // ...
}

To use the wrapper, you must ensure that:

  • You increment the iterator past all arguments you parse. The iterator must point to the end of the range when parsing is complete.
  • The iterator wrapper is destroyed after parsing but before executing the command itself begins.
Accessing a non-existent argument or failing to parse all arguments will raise a senf::console::SyntaxErrorException.
See also:
Example customer parser

Definition at line 493 of file Parse.hh.


Public Member Functions

  CheckedArgumentIteratorWrapper (ParseCommandInfo::ArgumentsRange const &range, std::string const &msg="invalid number of arguments")
  Make wrapper from ArgumentsRange.
  CheckedArgumentIteratorWrapper (ParseCommandInfo::TokensRange const &range, std::string const &msg="invalid number of arguments")
  Make wrapper from TokensRange.
  ~CheckedArgumentIteratorWrapper ()
  Check, if all arguments are parsed.
  operator ParseCommandInfo::ArgumentIterator ()
  Use wrapper as ParseCommandInfo::ArgumentIterator.
bool  boolean_test () const
  true, if more arguments are available
bool  done () const
  true, if all arguments are parsed
void  clear ()
  Set range empty.
bool  operator== (ParseCommandInfo::ArgumentIterator const &other) const
  Compare wrapper against ArgumentIterator.
bool  operator!= (ParseCommandInfo::ArgumentIterator const &other) const
  Compare wrapper against ArgumentIterator.
ParseCommandInfo::ArgumentIterator  operator++ (int)

Constructor & Destructor Documentation

senf::console::CheckedArgumentIteratorWrapper::
CheckedArgumentIteratorWrapper ( ParseCommandInfo::ArgumentsRange const &  range,
std::string const &  msg = "invalid number of arguments" )

Make wrapper from ArgumentsRange.

This constructs a wrapper from a ParseCommandInfo::ArgumentsRange.

Parameters:
[in]  range  Range of arguments to parse
[in]  msg  Error message

Definition at line 250 of file Parse.cci.

senf::console::CheckedArgumentIteratorWrapper::
CheckedArgumentIteratorWrapper ( ParseCommandInfo::TokensRange const &  range,
std::string const &  msg = "invalid number of arguments" )

Make wrapper from TokensRange.

This constructs a wrapper from a ParseCommandInfo::TokensRange. The TokensRange is first converted into an ParseCommandInfo::ArgumentsRange which is then wrapped.

Parameters:
[in]  range  Range of tokens to parse
[in]  msg  Error message

Definition at line 256 of file Parse.cci.

senf::console::CheckedArgumentIteratorWrapper::
~CheckedArgumentIteratorWrapper ()

Check, if all arguments are parsed.

The destructor validates, that all arguments are parsed correctly when leaving the scope, in which the wrapper is instantiated normally (not by an exception).

Warning:
This destructor will throw a SyntaxErrorException, if not all arguments are parsed and when no other exception is in progress.

Definition at line 261 of file Parse.cci.


Member Function Documentation

bool senf::console::CheckedArgumentIteratorWrapper::
boolean_test ()

true, if more arguments are available

Definition at line 272 of file Parse.cci.

void senf::console::CheckedArgumentIteratorWrapper::
clear ()

Set range empty.

This call will point the current iterator to the end of the tokens range.

Postcondition:
done() == true;

Definition at line 284 of file Parse.cci.

bool senf::console::CheckedArgumentIteratorWrapper::
done ()

true, if all arguments are parsed

Definition at line 278 of file Parse.cci.

senf::console::CheckedArgumentIteratorWrapper::operator ParseCommandInfo::
ArgumentIterator ()

Use wrapper as ParseCommandInfo::ArgumentIterator.

Definition at line 267 of file Parse.cci.

bool senf::console::CheckedArgumentIteratorWrapper::
operator!= ( ParseCommandInfo::ArgumentIterator const &  other )

Compare wrapper against ArgumentIterator.

Definition at line 313 of file Parse.cci.

senf::console::ParseCommandInfo::ArgumentIterator senf::console::CheckedArgumentIteratorWrapper::
operator++ ( int  )

Definition at line 320 of file Parse.cci.

bool senf::console::CheckedArgumentIteratorWrapper::
operator== ( ParseCommandInfo::ArgumentIterator const &  other )

Compare wrapper against ArgumentIterator.

Definition at line 306 of file Parse.cci.


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