args-parser 6.3.3
Loading...
Searching...
No Matches
Args::Arg Class Reference

Argument with one value that can be present only once in the command line. More...

#include <arg.hpp>

+ Inheritance diagram for Args::Arg:
+ Collaboration diagram for Args::Arg:

Public Member Functions

template<typename T >
 Arg (Char flag, T &&name, bool isWithValue=false, bool isRequired=false)
 Construct argument with flag and name.
 
 Arg (Char flag, bool isWithValue=false, bool isRequired=false)
 Construct argument only with flag, without name.
 
template<typename T >
 Arg (T &&name, bool isWithValue=false, bool isRequired=false)
 Construct argument only with name, without flag.
 
virtual ~Arg ()
 
ArgType type () const override
 
String name () const override
 
bool isWithValue () const override
 
void setWithValue (bool on=true)
 Set is this argument with value.
 
bool isRequired () const override
 
void setRequired (bool on=true)
 Set required.
 
bool isDefined () const override
 
void setDefined (bool on=true)
 Set defined.
 
virtual const Stringvalue () const
 
virtual void setValue (const String &v)
 Set value.
 
const Stringflag () const override
 
void setFlag (Char f)
 Set flag.
 
const StringargumentName () const override
 
void setArgumentName (const String &name)
 Set argument name.
 
const StringvalueSpecifier () const override
 
void setValueSpecifier (const String &vs)
 Set value specifier.
 
const Stringdescription () const override
 
void setDescription (const String &desc)
 Set description.
 
const StringlongDescription () const override
 
void setLongDescription (const String &desc)
 Set long description.
 
virtual const StringdefaultValue () const
 
virtual void setDefaultValue (const String &v)
 Set default value.
 
bool isMisspelledName (const String &name, StringList &possibleNames) const override
 
void clear () override
 Clear state of the argument.
 
- Public Member Functions inherited from Args::ArgIface
 ArgIface ()
 
virtual ~ArgIface ()
 
CmdLinecmdLine () const
 

Protected Member Functions

ArgIfacefindArgument (const String &name) override
 
void process (Context &context) override
 Process argument's staff, for example take values from context.
 
void checkCorrectnessBeforeParsing (StringList &flags, StringList &names) const override
 Check correctness of the argument before parsing.
 
void checkCorrectnessAfterParsing () const override
 Check correctness of the argument after parsing.
 
- Protected Member Functions inherited from Args::ArgIface
virtual void setCmdLine (CmdLine *cmdLine)
 Set command line parser.
 

Detailed Description

Argument with one value that can be present only once in the command line.

Definition at line 56 of file arg.hpp.

Constructor & Destructor Documentation

◆ Arg() [1/3]

template<typename T >
Args::Arg::Arg ( Char  flag,
T &&  name,
bool  isWithValue = false,
bool  isRequired = false 
)

Construct argument with flag and name.

Parameters
flagFlag for this argument.
nameName for this argument.
isWithValueIs this argument with value?
isRequiredIs this argument required?

Definition at line 272 of file arg.hpp.

◆ Arg() [2/3]

Args::Arg::Arg ( Char  flag,
bool  isWithValue = false,
bool  isRequired = false 
)
inlineexplicit

Construct argument only with flag, without name.

Parameters
flagFlag for this argument.
isWithValueIs this argument with value?
isRequiredIs this argument required?

Definition at line 284 of file arg.hpp.

◆ Arg() [3/3]

template<typename T >
Args::Arg::Arg ( T &&  name,
bool  isWithValue = false,
bool  isRequired = false 
)
explicit

Construct argument only with name, without flag.

Parameters
nameName for this argument.
isWithValueIs this argument with value?
isRequiredIs this argument required?

Definition at line 295 of file arg.hpp.

◆ ~Arg()

Args::Arg::~Arg ( )
inlinevirtual

Definition at line 306 of file arg.hpp.

Member Function Documentation

◆ argumentName()

const String & Args::Arg::argumentName ( ) const
inlineoverridevirtual
Returns
Argument name.

Implements Args::ArgIface.

Definition at line 460 of file arg.hpp.

◆ checkCorrectnessAfterParsing()

void Args::Arg::checkCorrectnessAfterParsing ( ) const
inlineoverrideprotectedvirtual

Check correctness of the argument after parsing.

Implements Args::ArgIface.

Definition at line 389 of file arg.hpp.

◆ checkCorrectnessBeforeParsing()

void Args::Arg::checkCorrectnessBeforeParsing ( StringList flags,
StringList names 
) const
inlineoverrideprotectedvirtual

Check correctness of the argument before parsing.

Implementation of this method must add his flag and name to the flags and names.

Parameters
flagsAll known flags.
namesAll known names.

Implements Args::ArgIface.

Definition at line 342 of file arg.hpp.

◆ clear()

void Args::Arg::clear ( )
inlineoverridevirtual

Clear state of the argument.

Implements Args::ArgIface.

Reimplemented in Args::MultiArg.

Definition at line 186 of file arg.hpp.

◆ defaultValue()

virtual const String & Args::Arg::defaultValue ( ) const
inlinevirtual
Returns
Default value.

Reimplemented in Args::MultiArg.

Definition at line 153 of file arg.hpp.

◆ description()

const String & Args::Arg::description ( ) const
inlineoverridevirtual
Returns
Description of the argument.

Implements Args::ArgIface.

Definition at line 484 of file arg.hpp.

◆ findArgument()

ArgIface * Args::Arg::findArgument ( const String name)
inlineoverrideprotectedvirtual
Returns
Argument for the given name.
Return values
Pointerto the ArgIface if this argument handles argument with the given name.
nullptrif this argument doesn't know about argument with name.
Parameters
nameName of the argument. Can be for example "-t" or "--timeout".

Implements Args::ArgIface.

Definition at line 202 of file arg.hpp.

◆ flag()

const String & Args::Arg::flag ( ) const
inlineoverridevirtual
Returns
Flag.

Implements Args::ArgIface.

Definition at line 448 of file arg.hpp.

◆ isDefined()

bool Args::Arg::isDefined ( ) const
inlineoverridevirtual
Returns
Is this argument defined?

Implements Args::ArgIface.

Definition at line 421 of file arg.hpp.

◆ isMisspelledName()

bool Args::Arg::isMisspelledName ( const String name,
StringList possibleNames 
) const
inlineoverridevirtual
Returns
Is given name a misspelled name of the argument.
Parameters
nameName to check (misspelled).
possibleNamesList of possible names for the given misspelled name.

Implements Args::ArgIface.

Definition at line 165 of file arg.hpp.

◆ isRequired()

bool Args::Arg::isRequired ( ) const
inlineoverridevirtual
Returns
Is this argument required?

Implements Args::ArgIface.

Definition at line 409 of file arg.hpp.

◆ isWithValue()

bool Args::Arg::isWithValue ( ) const
inlineoverridevirtual
Returns
Is this argument with value?

Implements Args::ArgIface.

Definition at line 397 of file arg.hpp.

◆ longDescription()

const String & Args::Arg::longDescription ( ) const
inlineoverridevirtual
Returns
Long description of the argument.

Implements Args::ArgIface.

Definition at line 496 of file arg.hpp.

◆ name()

String Args::Arg::name ( ) const
inlineoverridevirtual
Returns
Name of the argument.

If name is empty returned value should be a flag. I.e. for example "-t" or "--timeout"

Implements Args::ArgIface.

Definition at line 333 of file arg.hpp.

◆ process()

void Args::Arg::process ( Context context)
inlineoverrideprotectedvirtual

Process argument's staff, for example take values from context.

This method invokes exactly at that moment when parser has found this argument.

Parameters
contextContext of the command line.

Implements Args::ArgIface.

Reimplemented in Args::Help, and Args::MultiArg.

Definition at line 311 of file arg.hpp.

◆ setArgumentName()

void Args::Arg::setArgumentName ( const String name)
inline

Set argument name.

Definition at line 466 of file arg.hpp.

◆ setDefaultValue()

virtual void Args::Arg::setDefaultValue ( const String v)
inlinevirtual

Set default value.

Reimplemented in Args::MultiArg.

Definition at line 159 of file arg.hpp.

◆ setDefined()

void Args::Arg::setDefined ( bool  on = true)
inline

Set defined.

Definition at line 427 of file arg.hpp.

◆ setDescription()

void Args::Arg::setDescription ( const String desc)
inline

Set description.

Definition at line 490 of file arg.hpp.

◆ setFlag()

void Args::Arg::setFlag ( Char  f)
inline

Set flag.

Definition at line 454 of file arg.hpp.

◆ setLongDescription()

void Args::Arg::setLongDescription ( const String desc)
inline

Set long description.

Definition at line 505 of file arg.hpp.

◆ setRequired()

void Args::Arg::setRequired ( bool  on = true)
inline

Set required.

Definition at line 415 of file arg.hpp.

◆ setValue()

void Args::Arg::setValue ( const String v)
inlinevirtual

Set value.

Reimplemented in Args::MultiArg.

Definition at line 442 of file arg.hpp.

◆ setValueSpecifier()

void Args::Arg::setValueSpecifier ( const String vs)
inline

Set value specifier.

Definition at line 478 of file arg.hpp.

◆ setWithValue()

void Args::Arg::setWithValue ( bool  on = true)
inline

Set is this argument with value.

Definition at line 403 of file arg.hpp.

◆ type()

ArgType Args::Arg::type ( ) const
inlineoverridevirtual
Returns
Type of the argument.

Implements Args::ArgIface.

Reimplemented in Args::MultiArg.

Definition at line 94 of file arg.hpp.

◆ value()

const String & Args::Arg::value ( ) const
inlinevirtual
Returns
Value of this argument.

Reimplemented in Args::MultiArg.

Definition at line 433 of file arg.hpp.

◆ valueSpecifier()

const String & Args::Arg::valueSpecifier ( ) const
inlineoverridevirtual
Returns
Value specifier.

Implements Args::ArgIface.

Definition at line 472 of file arg.hpp.


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