Simple argument class. More...
#include <Argument.hpp>
Public Member Functions | |
Argument (std::string description) | |
Create an argument with flag and/or name set by description. More... | |
Argument (std::string description, char flag) | |
Create an argument that is identified by a flag. More... | |
Argument (std::string description, std::string name) | |
Create an argument that is identified by a name. More... | |
Argument (std::string description, char flag, std::string name) | |
Create an argument that is identified by both a name and flag. More... | |
Argument (const Argument &)=default | |
Argument copy constructor. | |
Argument (Argument &&)=default | |
Argument move constructor. | |
virtual | ~Argument () |
Argument destructor. | |
Argument & | operator= (const Argument &other)=default |
Argument assignment operator. | |
Argument & | operator= (Argument &&other)=default |
Argument move assignment operator. | |
Argument & | alias (char flag) |
An a flag alias for the argument. More... | |
Argument & | alias (std::string name) |
An a name alias for the argument. More... | |
Argument & | alias (char flag, std::string name) |
An both a flag and name alias for the argument. More... | |
const std::string & | description () const |
Returns the description of this argument. More... | |
virtual Argument & | check (ArgumentCheckFunc checkFunc) |
Set the check function to use. More... | |
bool | matches () const |
Returns a pointer to this argument if it matches as a positional argument, otherwise a null-pointer. More... | |
bool | matches (char flag) const |
Returns a pointer to this argument if it matches the given flag with any alias, otherwise a null-pointer. More... | |
bool | matches (const std::string &name) const |
Returns a pointer to this argument if it matches the given name with any alias, otherwise a null-pointer. More... | |
void | find_all_arguments (std::vector< const Argument * > &collector) const override |
See BaseArgument::find_all_arguments() | |
Argument & | many (bool many=true) |
Allow the argument to occur multiple times or not. More... | |
Argument & | min (unsigned int min) |
Set the minimum number of required occurrences if set. More... | |
unsigned int | min () const |
Returns the minimum number of occurrences of this argument for it to be satisfied if set. More... | |
Argument & | max (unsigned int max) |
Set the maximum number of required occurrences. More... | |
unsigned int | max () const |
Returns the maximum number of occurrences of this argument. More... | |
unsigned int | count () const override |
See BaseArgument::count() | |
bool | can_set () const |
Returns whether this argument is still allowed to occur on the command line. More... | |
virtual void | set () const |
Set the argument (mark as occurred). | |
virtual bool | takes_value () const |
Returns whether or not this argument requires a value when it occurs (see also set()). More... | |
void | check_valid () const override |
See BaseArgument::check_valid() | |
std::string | usage () const override |
See BaseArgument::usage() | |
virtual std::string | ident () const |
Print a string representation of this argument to the given stream. More... | |
std::unique_ptr< BaseArgument > | clone () const &override |
See BaseArgument::clone(). | |
std::unique_ptr< BaseArgument > | clone ()&&override |
See BaseArgument::clone(). | |
![]() | |
BaseArgument () | |
Base constructor. | |
BaseArgument (const BaseArgument &)=default | |
BaseArgument copy constructor. | |
BaseArgument (BaseArgument &&)=default | |
BaseArgument move constructor. | |
virtual | ~BaseArgument () |
BaseArgument destructor. | |
BaseArgument & | operator= (const BaseArgument &)=default |
BaseArgument assignment operator. | |
BaseArgument & | operator= (BaseArgument &&)=default |
BaseArgument move assignment operator. | |
operator bool () const | |
Boolean conversion operator (so you can do things like if (arg) { ... More... | |
BaseArgument & | set_required (bool required=true) |
Mark the argument as required or not. More... | |
bool | required () const |
Returns whether the argument is required. More... | |
Protected Member Functions | |
virtual void | check () const |
Executes the associated check function. More... | |
Protected Attributes | |
std::string | m_flags |
Flags this arguments matches. | |
std::vector< std::string > | m_names |
Names this argument matches. | |
bool | m_isPositional |
True if used as positional argument. | |
std::string | m_description |
Description or help text of argument. | |
unsigned int | m_min = 1 |
Minimum number of occurrences if argument is set. | |
unsigned int | m_max = 1 |
Maximum number of occurrences. More... | |
std::shared_ptr< unsigned int > | m_count |
Actual counted number of occurrences. | |
ArgumentCheckFunc | m_checkFunc = nullptr |
Callback for check. | |
![]() | |
bool | m_required = false |
True if the argument has to be set. | |
Private Member Functions | |
void | parse_description () |
When TAP_AUTOFLAG is defined, this function finds flag and/or name markers in the description of the argument, and uses these to set aliases. More... | |
Simple argument class.
Arguments are identified by a flag ('-a') or name ('–alpha'), or can be positional (only if they accept a value, see ValuedArgument). An Argument by default is optional (as they normally should be for most applications, makes them easier to use), but has functions to mark it required. By default an argument is allowed to occur only once, but can be set to occur an arbitrary amount of times.
|
inline |
Create an argument with flag and/or name set by description.
Using this constructing with a description without a flag or name is invalid.
description | Description of the argument, requires a flag or name to be defined |
|
inline |
Create an argument that is identified by a flag.
description | Description of the argument (used in help text) |
flag | Flag identifier of this argument |
|
inline |
Create an argument that is identified by a name.
description | Description of the argument (used in help text) |
name | Name identifier of this argument |
|
inline |
Create an argument that is identified by both a name and flag.
description | Description of the argument (used in help text) |
flag | Flag identifier of this argument |
name | Name identifier of this argument |
|
inline |
An a flag alias for the argument.
flag | Flag alias of Argument |
|
inline |
An a name alias for the argument.
name | Name alias of Argument |
|
inline |
|
inline |
Returns whether this argument is still allowed to occur on the command line.
|
inlinevirtual |
Set the check function to use.
checkFunc | Check function to use (see ArgumentCheckFunc) |
|
inlineprotectedvirtual |
Executes the associated check function.
Reimplemented in TAP::TypedArgument< T, multi >, TAP::TypedArgument< bool, false >, TAP::TypedArgument< T, false >, TAP::TypedArgument< T, multi >, TAP::TypedArgument< bool, false >, and TAP::TypedArgument< T, false >.
|
inline |
|
virtual |
Print a string representation of this argument to the given stream.
This is usually represented in the first column of help text.
Reimplemented in TAP::VariableArgument< T, multi >.
|
inline |
Allow the argument to occur multiple times or not.
See also max()
many | If true, set the maximum number of occurrences to infinite, otherwise the current limit or 1. |
|
inline |
Returns a pointer to this argument if it matches as a positional argument, otherwise a null-pointer.
|
inline |
Returns a pointer to this argument if it matches the given flag with any alias, otherwise a null-pointer.
flag | Flag to check |
|
inline |
Returns a pointer to this argument if it matches the given name with any alias, otherwise a null-pointer.
name | Name to check |
|
inline |
Set the maximum number of required occurrences.
This value may be 0 to indicate unbounded.
max | Maximum number of occurrences |
|
inline |
Returns the maximum number of occurrences of this argument.
|
inline |
Set the minimum number of required occurrences if set.
If this value is higher than the current maximum, the maximum is set to the same value.
min | Minimum number of occurrences, must be >0 |
|
inline |
Returns the minimum number of occurrences of this argument for it to be satisfied if set.
|
inlineprivate |
When TAP_AUTOFLAG is defined, this function finds flag and/or name markers in the description of the argument, and uses these to set aliases.
Names are delimited by word boundaries, which is any non-alphanumeric character. Empty names are ignored. Markers:
For example, the description "Show this &help text" will set a flag 'h' and a name "help".
|
inlinevirtual |
Returns whether or not this argument requires a value when it occurs (see also set()).
Reimplemented in TAP::SwitchArgument, TAP::ConstArgument< T >, TAP::VariableArgument< T, multi >, TAP::TypedArgument< T, multi >, TAP::TypedArgument< bool, false >, and TAP::TypedArgument< T, false >.
|
protected |
Maximum number of occurrences.
0 means no limit