tclap 1.4.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
TCLAP::Arg Class Referenceabstract

A virtual base class that defines the essential data for all arguments. More...

#include <Arg.h>

Inheritance diagram for TCLAP::Arg:
Inheritance graph
[legend]
Collaboration diagram for TCLAP::Arg:
Collaboration graph
[legend]

Public Member Functions

Arg & addAlias (const std::string &flag, const std::string &name="")
 Add equivalent spellings before registration.
 
const std::vector< ArgAlias > & aliases () const
 Alias spellings in insertion order; no prefixes are stored.
 
virtual ~Arg ()
 Destructor.
 
virtual void addToList (std::list< Arg * > &argList) const
 Adds this to the specified list of Args.
 
char getDelimiter () const
 Returns this argument's parser delimiter, or the legacy default.
 
virtual bool processArg (int *i, std::vector< std::string > &args)=0
 Pure virtual method meant to handle the parsing and value assignment of the string on the command line.
 
virtual bool operator== (const Arg &a) const
 Operator ==.
 
bool conflictsWith (const Arg &a) const
 Checks declared registration conflicts: the same object, the same name, or the same nonempty short flag, including aliases.
 
const std::string & getFlag () const
 Returns the argument flag.
 
const std::string & getName () const
 Returns the argument name.
 
std::string getDescription () const
 Returns the argument description.
 
virtual void setDescription (const std::string &desc)
 Updates the argument description.
 
std::string getDescription (bool required) const
 Returns the argument description.
 
virtual bool isRequired () const
 Indicates whether the argument is required.
 
bool isValueRequired () const
 Indicates whether a value must be specified for argument.
 
bool isSet () const
 Indicates whether the argument has already been set.
 
const std::string & setBy () const
 Returns the value specified to set this flag (like -a or –all).
 
bool isIgnoreable () const
 Indicates whether the argument can be ignored, if desired.
 
virtual bool argMatches (const std::string &s) const
 A method that tests whether a string matches this argument.
 
virtual std::string toString () const
 Returns a simple string representation of the argument.
 
virtual std::string shortID (const std::string &valueId="val") const
 Returns a short ID for the usage.
 
virtual std::string longID (const std::string &valueId="val") const
 Returns a long ID for the usage.
 
virtual void trimFlag (std::string &flag, std::string &value) const
 Trims a value off of the flag.
 
bool _hasBlanks (const std::string &s) const
 Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
 
virtual bool allowMore ()
 Used for MultiArgs to determine whether args can still be set.
 
virtual bool acceptsMultipleValues ()
 Use by output classes to determine whether an Arg accepts multiple values.
 
virtual void reset ()
 Clears the Arg object and allows it to be reused by new command lines.
 
virtual void hideFromHelp (bool hide=true)
 Hide this argument from the help output (e.g., when specifying the –help flag or on error.
 
virtual bool visibleInHelp () const
 Returns true if this Arg is visible in the help output.
 
virtual bool hasLabel () const
 

Static Public Member Functions

static char delimiter ()
 The delimiter that separates an argument flag/name from the value.
 
static char blankChar ()
 The char used as a place holder when SwitchArgs are combined.
 
static char flagStartChar ()
 
static const std::string flagStartString ()
 
static const std::string nameStartString ()
 
static const std::string ignoreNameString ()
 The name used to identify the ignore rest argument.
 
static void setDelimiter (char c)
 Sets the legacy delimiter for unregistered arguments and static callers.
 

Protected Member Functions

bool matchesShortFlag (const std::string &flag) const
 
bool matchesLongName (const std::string &name) const
 
void _checkWithVisitor () const
 Performs the special handling described by the Visitor.
 
 Arg (const std::string &flag, const std::string &name, const std::string &desc, bool req, bool valreq, Visitor *v=NULL)
 Primary constructor.
 

Protected Attributes

std::string _flag
 The single char flag used to identify the argument.
 
std::string _name
 A single word namd identifying the argument.
 
std::string _description
 Description of the argument.
 
const bool _required
 Indicating whether the argument is required.
 
std::string _requireLabel
 Label to be used in usage description.
 
bool _valueRequired
 Indicates whether a value is required for the argument.
 
bool _alreadySet
 Indicates whether the argument has been set.
 
std::string _setBy
 Indicates the value specified to set this flag (like -a or –all).
 
Visitor * _visitor
 A pointer to a visitor object.
 
bool _ignoreable
 Whether this argument can be ignored, if desired.
 
bool _acceptsMultipleValues
 
bool _visibleInHelp
 Indicates if the argument is visible in the help output (e.g., when specifying –help).
 

Friends

class CmdLine
 

Detailed Description

A virtual base class that defines the essential data for all arguments.

This class, or one of its existing children, must be subclassed to do anything.

Definition at line 66 of file Arg.h.

Constructor & Destructor Documentation

◆ Arg()

TCLAP::Arg::Arg ( const std::string &  flag,
const std::string &  name,
const std::string &  desc,
bool  req,
bool  valreq,
Visitor *  v = NULL 
)
inlineprotected

Primary constructor.

YOU (yes you) should NEVER construct an Arg directly, this is a base class that is extended by various children that are meant to be used. Use SwitchArg, ValueArg, MultiArg, UnlabeledValueArg, or UnlabeledMultiArg instead.

Parameters
flag- The flag identifying the argument.
name- The name identifying the argument.
desc- The description of the argument, used in the usage.
req- Whether the argument is required.
valreq- Whether the a value is required for the argument.
v- The visitor checked by the argument. Defaults to NULL.

Definition at line 527 of file Arg.h.

References _flag, _name, flagStartString(), ignoreNameString(), nameStartString(), and toString().

Here is the call graph for this function:

◆ ~Arg()

TCLAP::Arg::~Arg ( )
inlinevirtual

Destructor.

Definition at line 566 of file Arg.h.

Member Function Documentation

◆ _checkWithVisitor()

void TCLAP::Arg::_checkWithVisitor ( ) const
inlineprotected

Performs the special handling described by the Visitor.

Definition at line 775 of file Arg.h.

References _visitor, and TCLAP::Visitor::visit().

Referenced by TCLAP::MultiSwitchArg::processArg().

Here is the call graph for this function:

◆ _hasBlanks()

bool TCLAP::Arg::_hasBlanks ( const std::string &  s) const
inline

Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.

Implementation of _hasBlanks.

If so, return true, otherwise return false.

Parameters
s- string to be checked.

Definition at line 799 of file Arg.h.

References blankChar().

Here is the call graph for this function:

◆ acceptsMultipleValues()

bool TCLAP::Arg::acceptsMultipleValues ( )
inlinevirtual

Use by output classes to determine whether an Arg accepts multiple values.

Definition at line 815 of file Arg.h.

References _acceptsMultipleValues.

Referenced by TCLAP::DocBookOutput::printShortArg().

◆ addAlias()

Arg & TCLAP::Arg::addAlias ( const std::string &  flag,
const std::string &  name = "" 
)
inline

Add equivalent spellings before registration.

Either may be blank, but not both. Positional arguments cannot have aliases. Registration freezes aliases; reset() retains them. Values, callbacks and group membership are shared with the canonical argument. For self-registering constructors, use a non-registering constructor instead, add aliases, then call parser.add(arg).

Definition at line 699 of file Arg.h.

References hasLabel(), matchesLongName(), matchesShortFlag(), and toString().

Here is the call graph for this function:

◆ addToList()

void TCLAP::Arg::addToList ( std::list< Arg * > &  argList) const
inlinevirtual

Adds this to the specified list of Args.

Overridden by Args that need to added to the end of the list.

Parameters
argList- The list to add this to.

Reimplemented in TCLAP::UnlabeledMultiArg< T >, and TCLAP::UnlabeledValueArg< T >.

Definition at line 809 of file Arg.h.

Referenced by TCLAP::CmdLine::Registration::add().

◆ aliases()

const std::vector< ArgAlias > & TCLAP::Arg::aliases ( ) const
inline

Alias spellings in insertion order; no prefixes are stored.

Definition at line 217 of file Arg.h.

◆ allowMore()

bool TCLAP::Arg::allowMore ( )
inlinevirtual

Used for MultiArgs to determine whether args can still be set.

Reimplemented in TCLAP::MultiArg< T >.

Definition at line 813 of file Arg.h.

◆ argMatches()

bool TCLAP::Arg::argMatches ( const std::string &  s) const
inlinevirtual

A method that tests whether a string matches this argument.

This is generally called by the processArg() method. This method could be re-implemented by a child to change how arguments are specified on the command line.

Parameters
s- The string to be compared to the flag/name to determine whether the arg matches.

Definition at line 755 of file Arg.h.

References _name, flagStartString(), matchesLongName(), matchesShortFlag(), and nameStartString().

Referenced by TCLAP::MultiSwitchArg::processArg(), and TCLAP::SwitchArg::processArg().

Here is the call graph for this function:

◆ blankChar()

static char TCLAP::Arg::blankChar ( )
inlinestatic

The char used as a place holder when SwitchArgs are combined.

Currently set to the bell char (ASCII 7).

Definition at line 247 of file Arg.h.

Referenced by TCLAP::CmdLine::_emptyCombined(), _hasBlanks(), and TCLAP::SwitchArg::combinedSwitchesMatch().

◆ conflictsWith()

bool TCLAP::Arg::conflictsWith ( const Arg &  a) const
inline

Checks declared registration conflicts: the same object, the same name, or the same nonempty short flag, including aliases.

Descriptions do not conflict. This nonvirtual rule also applies to custom arguments; additional tokens recognized by processArg() are not inferred.

Parameters
a- The Arg to compare with this argument.

Definition at line 730 of file Arg.h.

References _flag, _name, matchesLongName(), and matchesShortFlag().

Referenced by TCLAP::ArgGroup::add(), and TCLAP::StandaloneArgs::add().

Here is the call graph for this function:

◆ delimiter()

static char TCLAP::Arg::delimiter ( )
inlinestatic

The delimiter that separates an argument flag/name from the value.

Definition at line 234 of file Arg.h.

Referenced by getDelimiter().

◆ flagStartChar()

static char TCLAP::Arg::flagStartChar ( )
inlinestatic

Definition at line 256 of file Arg.h.

References TCLAP_FLAGSTARTCHAR.

Referenced by TCLAP::CmdLine::_emptyCombined(), and TCLAP::DocBookOutput::printShortArg().

◆ flagStartString()

static const std::string TCLAP::Arg::flagStartString ( )
inlinestatic

◆ getDelimiter()

char TCLAP::Arg::getDelimiter ( ) const
inline

Returns this argument's parser delimiter, or the legacy default.

Custom arguments should use this instead of the static delimiter().

Definition at line 239 of file Arg.h.

References delimiter().

Referenced by longID(), shortID(), and trimFlag().

Here is the call graph for this function:

◆ getDescription() [1/2]

std::string TCLAP::Arg::getDescription ( ) const
inline

Returns the argument description.

Definition at line 328 of file Arg.h.

References _required, and getDescription().

Referenced by getDescription(), TCLAP::UnlabeledMultiArg< T >::operator==(), and TCLAP::UnlabeledValueArg< T >::operator==().

Here is the call graph for this function:

◆ getDescription() [2/2]

std::string TCLAP::Arg::getDescription ( bool  required) const
inline

Returns the argument description.

Parameters
requiredif the argument should be treated as required when described.

Definition at line 341 of file Arg.h.

References _description, and _requireLabel.

◆ getFlag()

const std::string & TCLAP::Arg::getFlag ( ) const
inline

Returns the argument flag.

Definition at line 743 of file Arg.h.

References _flag.

Referenced by TCLAP::DocBookOutput::printShortArg(), and TCLAP::DocBookOutput::valueLabel().

◆ getName()

const std::string & TCLAP::Arg::getName ( ) const
inline

◆ hasLabel()

virtual bool TCLAP::Arg::hasLabel ( ) const
inlinevirtual

◆ hideFromHelp()

virtual void TCLAP::Arg::hideFromHelp ( bool  hide = true)
inlinevirtual

Hide this argument from the help output (e.g., when specifying the –help flag or on error.

Definition at line 438 of file Arg.h.

References _visibleInHelp.

◆ ignoreNameString()

static const std::string TCLAP::Arg::ignoreNameString ( )
inlinestatic

The name used to identify the ignore rest argument.

Definition at line 280 of file Arg.h.

Referenced by Arg().

◆ isIgnoreable()

bool TCLAP::Arg::isIgnoreable ( ) const
inline

Indicates whether the argument can be ignored, if desired.

Definition at line 753 of file Arg.h.

References _ignoreable.

◆ isRequired()

bool TCLAP::Arg::isRequired ( ) const
inlinevirtual

Indicates whether the argument is required.

Definition at line 747 of file Arg.h.

References _required.

Referenced by TCLAP::CmdLine::Registration::add(), TCLAP::ExclusiveArgGroup::add(), and TCLAP::DocBookOutput::printShortGroup().

◆ isSet()

bool TCLAP::Arg::isSet ( ) const
inline

Indicates whether the argument has already been set.

Only true if the arg has been matched on the command line.

Definition at line 751 of file Arg.h.

References _alreadySet.

◆ isValueRequired()

bool TCLAP::Arg::isValueRequired ( ) const
inline

Indicates whether a value must be specified for argument.

Definition at line 749 of file Arg.h.

References _valueRequired.

Referenced by TCLAP::DocBookOutput::printShortArg().

◆ longID()

std::string TCLAP::Arg::longID ( const std::string &  valueId = "val") const
inlinevirtual

◆ matchesLongName()

bool TCLAP::Arg::matchesLongName ( const std::string &  name) const
inlineprotected

Definition at line 690 of file Arg.h.

References _name.

Referenced by addAlias(), argMatches(), and conflictsWith().

◆ matchesShortFlag()

bool TCLAP::Arg::matchesShortFlag ( const std::string &  flag) const
inlineprotected

Definition at line 681 of file Arg.h.

References _flag.

Referenced by addAlias(), argMatches(), TCLAP::SwitchArg::combinedSwitchesMatch(), and conflictsWith().

◆ nameStartString()

static const std::string TCLAP::Arg::nameStartString ( )
inlinestatic

◆ operator==()

bool TCLAP::Arg::operator== ( const Arg &  a) const
inlinevirtual

Operator ==.

Legacy equality operator, retained for source compatibility. Registration uses conflictsWith(), not this virtual comparison.

Parameters
a- The Arg to be compared to this.

Reimplemented in TCLAP::UnlabeledMultiArg< T >, and TCLAP::UnlabeledValueArg< T >.

Definition at line 739 of file Arg.h.

References _flag, and _name.

◆ processArg()

virtual bool TCLAP::Arg::processArg ( int *  i,
std::vector< std::string > &  args 
)
pure virtual

Pure virtual method meant to handle the parsing and value assignment of the string on the command line.

Parameters
i- Pointer the the current argument in the list.
args- Mutable list of strings. What is passed in from main.

Implemented in TCLAP::MultiArg< T >, TCLAP::MultiSwitchArg, TCLAP::SwitchArg, TCLAP::UnlabeledMultiArg< T >, TCLAP::UnlabeledValueArg< T >, and TCLAP::ValueArg< T >.

◆ reset()

void TCLAP::Arg::reset ( )
inlinevirtual

Clears the Arg object and allows it to be reused by new command lines.

Reimplemented in TCLAP::MultiArg< T >, TCLAP::MultiSwitchArg, TCLAP::SwitchArg, and TCLAP::ValueArg< T >.

Definition at line 817 of file Arg.h.

References _alreadySet.

Referenced by TCLAP::MultiArg< T >::reset(), TCLAP::MultiSwitchArg::reset(), TCLAP::SwitchArg::reset(), and TCLAP::ValueArg< T >::reset().

◆ setBy()

const std::string & TCLAP::Arg::setBy ( ) const
inline

Returns the value specified to set this flag (like -a or –all).

Definition at line 364 of file Arg.h.

References _setBy.

Referenced by TCLAP::ExclusiveArgGroup::validate().

◆ setDelimiter()

static void TCLAP::Arg::setDelimiter ( char  c)
inlinestatic

Sets the legacy delimiter for unregistered arguments and static callers.

Registered built-in arguments use their owning parser delimiter.

Parameters
c- The character that delimits flags/names from values.

Definition at line 287 of file Arg.h.

◆ setDescription()

virtual void TCLAP::Arg::setDescription ( const std::string &  desc)
inlinevirtual

Updates the argument description.

Definition at line 333 of file Arg.h.

References _description.

◆ shortID()

std::string TCLAP::Arg::shortID ( const std::string &  valueId = "val") const
inlinevirtual

Returns a short ID for the usage.

Parameters
valueId- The value used in the id.

Reimplemented in TCLAP::UnlabeledMultiArg< T >, TCLAP::UnlabeledValueArg< T >, TCLAP::MultiSwitchArg, TCLAP::MultiArg< T >, and TCLAP::ValueArg< T >.

Definition at line 568 of file Arg.h.

References _flag, _name, _valueRequired, flagStartString(), getDelimiter(), and nameStartString().

Referenced by TCLAP::MultiSwitchArg::shortID(), TCLAP::MultiArg< T >::shortID(), TCLAP::ValueArg< T >::shortID(), and TCLAP::DocBookOutput::valueLabel().

Here is the call graph for this function:

◆ toString()

std::string TCLAP::Arg::toString ( ) const
inlinevirtual

Returns a simple string representation of the argument.

Primarily for debugging.

Definition at line 765 of file Arg.h.

References _flag, _name, flagStartString(), and nameStartString().

Referenced by addAlias(), Arg(), and TCLAP::SwitchArg::processArg().

Here is the call graph for this function:

◆ trimFlag()

void TCLAP::Arg::trimFlag ( std::string &  flag,
std::string &  value 
) const
inlinevirtual

Trims a value off of the flag.

Implementation of trimFlag.

Parameters
flag- The string from which the flag and value will be trimmed. Contains the flag once the value has been trimmed.
value- Where the value trimmed from the string will be stored.

Definition at line 782 of file Arg.h.

References getDelimiter().

Here is the call graph for this function:

◆ visibleInHelp()

virtual bool TCLAP::Arg::visibleInHelp ( ) const
inlinevirtual

Returns true if this Arg is visible in the help output.

Definition at line 443 of file Arg.h.

References _visibleInHelp.

Referenced by TCLAP::DocBookOutput::printLongArg(), and TCLAP::DocBookOutput::printShortGroup().

Friends And Related Symbol Documentation

◆ CmdLine

friend class CmdLine
friend

Definition at line 67 of file Arg.h.

Member Data Documentation

◆ _acceptsMultipleValues

bool TCLAP::Arg::_acceptsMultipleValues
protected

◆ _alreadySet

bool TCLAP::Arg::_alreadySet
protected

Indicates whether the argument has been set.

Indicates that a value on the command line has matched the name/flag of this argument and the values have been set accordingly.

Definition at line 158 of file Arg.h.

Referenced by isSet(), TCLAP::MultiSwitchArg::processArg(), and reset().

◆ _description

std::string TCLAP::Arg::_description
protected

Description of the argument.

Definition at line 133 of file Arg.h.

Referenced by getDescription(), and setDescription().

◆ _flag

std::string TCLAP::Arg::_flag
protected

The single char flag used to identify the argument.

This value (preceded by a dash {-}), can be used to identify an argument on the command line. The _flag can be blank, in fact this is how unlabeled args work. Unlabeled args must override appropriate functions to get correct handling. Note that the _flag does NOT include the dash as part of the flag.

Definition at line 119 of file Arg.h.

Referenced by Arg(), conflictsWith(), getFlag(), longID(), matchesShortFlag(), operator==(), shortID(), and toString().

◆ _ignoreable

bool TCLAP::Arg::_ignoreable
protected

◆ _name

std::string TCLAP::Arg::_name
protected

A single word namd identifying the argument.

This value (preceded by two dashed {–}) can also be used to identify an argument on the command line. Note that the _name does NOT include the two dashes as part of the _name. The _name cannot be blank.

Definition at line 128 of file Arg.h.

Referenced by Arg(), argMatches(), conflictsWith(), getName(), longID(), matchesLongName(), operator==(), shortID(), and toString().

◆ _required

const bool TCLAP::Arg::_required
protected

Indicating whether the argument is required.

Definition at line 138 of file Arg.h.

Referenced by getDescription(), and isRequired().

◆ _requireLabel

std::string TCLAP::Arg::_requireLabel
protected

Label to be used in usage description.

Normally set to "required", but can be changed when necessary.

Definition at line 144 of file Arg.h.

Referenced by getDescription().

◆ _setBy

std::string TCLAP::Arg::_setBy
protected

Indicates the value specified to set this flag (like -a or –all).

Definition at line 162 of file Arg.h.

Referenced by TCLAP::SwitchArg::combinedSwitchesMatch(), TCLAP::MultiSwitchArg::processArg(), TCLAP::SwitchArg::processArg(), and setBy().

◆ _valueRequired

bool TCLAP::Arg::_valueRequired
protected

Indicates whether a value is required for the argument.

Note that the value may be required but the argument/value combination may not be, as specified by _required.

Definition at line 151 of file Arg.h.

Referenced by isValueRequired(), longID(), and shortID().

◆ _visibleInHelp

bool TCLAP::Arg::_visibleInHelp
protected

Indicates if the argument is visible in the help output (e.g., when specifying –help).

Definition at line 183 of file Arg.h.

Referenced by hideFromHelp(), and visibleInHelp().

◆ _visitor

Visitor* TCLAP::Arg::_visitor
protected

A pointer to a visitor object.

The visitor allows special handling to occur as soon as the argument is matched. This defaults to NULL and should not be used unless absolutely necessary.

Definition at line 170 of file Arg.h.

Referenced by _checkWithVisitor().


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