senf::console::CheckedArgumentIteratorWrapper Class Reference

Wrapper checking argument iterator access for validityOutput ParseCommandInfo instance. More...

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

Inheritance diagram for senf::console::CheckedArgumentIteratorWrapper:

Public Member Functions

 CheckedArgumentIteratorWrapper (ParseCommandInfo::ArgumentsRange const &range, std::string const &msg="invalid number of arguments")
 Make wrapper from ArgumentsRange. More...
 
 CheckedArgumentIteratorWrapper (ParseCommandInfo::TokensRange const &range, std::string const &msg="invalid number of arguments")
 Make wrapper from TokensRange. More...
 
 ~CheckedArgumentIteratorWrapper () noexcept(false)
 Check, if all arguments are parsed. More...
 
 operator ParseCommandInfo::ArgumentIterator ()
 Use wrapper as ParseCommandInfo::ArgumentIterator. More...
 
bool boolean_test () const
 true, if more arguments are available More...
 
bool done () const
 true, if all arguments are parsed More...
 
void clear ()
 Set range empty. More...
 
bool operator== (ParseCommandInfo::ArgumentIterator const &other) const
 Compare wrapper against ArgumentIterator. More...
 
bool operator!= (ParseCommandInfo::ArgumentIterator const &other) const
 Compare wrapper against ArgumentIterator. More...
 
ParseCommandInfo::ArgumentIterator operator++ (int)
 
- Public Member Functions inherited from senf::comparable_safe_bool< class >
 operator bool_type () const
 
bool operator! () const
 

Additional Inherited Members

- Protected Types inherited from senf::safe_bool_base
typedef void(safe_bool_base::* bool_type) () const
 
- Protected Member Functions inherited from senf::comparable_safe_bool< class >
 ~comparable_safe_bool ()
 
- Protected Member Functions inherited from senf::safe_bool_base
void this_type_does_not_support_comparisons () const
 
 safe_bool_base ()
 
 safe_bool_base (const safe_bool_base &)
 
safe_bool_baseoperator= (const safe_bool_base &)
 
 ~safe_bool_base ()
 

Detailed Description

Wrapper checking argument iterator access for validityOutput ParseCommandInfo instance.

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::parse( *(arg++), arg1 );
senf::console::parse( *(arg++), arg2 );
}
// ...
}
    To use the wrapper, you must ensure that:
    \li You increment the iterator \e past all arguments you parse. The iterator must point to
        the end of the range when parsing is complete.
    \li 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 \ref console_args_custom "Example customer parser"

Definition at line 508 of file Parse.hh.

Constructor & Destructor Documentation

◆ CheckedArgumentIteratorWrapper() [1/2]

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

Make wrapper from ArgumentsRange.

This constructs a wrapper from a ParseCommandInfo::ArgumentsRange.

Parameters
[in]rangeRange of arguments to parse
[in]msgError message

◆ CheckedArgumentIteratorWrapper() [2/2]

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

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]rangeRange of tokens to parse
[in]msgError message

◆ ~CheckedArgumentIteratorWrapper()

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

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.

Member Function Documentation

◆ boolean_test()

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

true, if more arguments are available

◆ clear()

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;

◆ done()

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

true, if all arguments are parsed

◆ operator ParseCommandInfo::ArgumentIterator()

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

◆ operator!=()

Compare wrapper against ArgumentIterator.

◆ operator++()

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

◆ operator==()

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

Compare wrapper against ArgumentIterator.


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