args-parser 6.3.6
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
ArgsetWithValue (bool on=true)
 Set is this argument with value.
bool isRequired () const override
ArgsetRequired (bool on=true)
 Set required.
bool isDefined () const override
ArgsetDefined (bool on=true)
 Set defined.
virtual const Stringvalue () const
virtual ArgsetValue (const String &v)
 Set value.
const Stringflag () const override
ArgsetFlag (Char f)
 Set flag.
const StringargumentName () const override
ArgsetArgumentName (const String &name)
 Set argument name.
const StringvalueSpecifier () const override
ArgsetValueSpecifier (const String &vs)
 Set value specifier.
const Stringdescription () const override
ArgsetDescription (const String &desc)
 Set description.
const StringlongDescription () const override
ArgsetLongDescription (const String &desc)
 Set long description.
const StringdefaultValue () const override
virtual ArgsetDefaultValue (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 32 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 245 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 259 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 272 of file arg.hpp.

◆ ~Arg()

Args::Arg::~Arg ( )
inlinevirtual

Definition at line 283 of file arg.hpp.

Member Function Documentation

◆ argumentName()

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

Implements Args::ArgIface.

Definition at line 427 of file arg.hpp.

◆ checkCorrectnessAfterParsing()

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

Check correctness of the argument after parsing.

Implements Args::ArgIface.

Definition at line 361 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 313 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 159 of file arg.hpp.

◆ defaultValue()

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

Reimplemented from Args::ArgIface.

Reimplemented in Args::MultiArg.

Definition at line 128 of file arg.hpp.

◆ description()

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

Implements Args::ArgIface.

Definition at line 449 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 175 of file arg.hpp.

◆ flag()

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

Implements Args::ArgIface.

Definition at line 416 of file arg.hpp.

◆ isDefined()

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

Implements Args::ArgIface.

Definition at line 390 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 141 of file arg.hpp.

◆ isRequired()

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

Implements Args::ArgIface.

Definition at line 379 of file arg.hpp.

◆ isWithValue()

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

Implements Args::ArgIface.

Definition at line 368 of file arg.hpp.

◆ longDescription()

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

Implements Args::ArgIface.

Definition at line 460 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 304 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 287 of file arg.hpp.

◆ setArgumentName()

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

Set argument name.

Definition at line 432 of file arg.hpp.

◆ setDefaultValue()

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

Set default value.

Reimplemented in Args::MultiArg.

Definition at line 134 of file arg.hpp.

◆ setDefined()

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

Set defined.

Definition at line 395 of file arg.hpp.

◆ setDescription()

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

Set description.

Definition at line 454 of file arg.hpp.

◆ setFlag()

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

Set flag.

Definition at line 421 of file arg.hpp.

◆ setLongDescription()

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

Set long description.

Definition at line 469 of file arg.hpp.

◆ setRequired()

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

Set required.

Definition at line 384 of file arg.hpp.

◆ setValue()

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

Set value.

Reimplemented in Args::MultiArg.

Definition at line 410 of file arg.hpp.

◆ setValueSpecifier()

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

Set value specifier.

Definition at line 443 of file arg.hpp.

◆ setWithValue()

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

Set is this argument with value.

Definition at line 373 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 69 of file arg.hpp.

◆ value()

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

Reimplemented in Args::MultiArg.

Definition at line 401 of file arg.hpp.

◆ valueSpecifier()

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

Implements Args::ArgIface.

Definition at line 438 of file arg.hpp.


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