tclap  1.4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TCLAP::CmdLine Class Reference

The base class that manages the command line definition and passes along the parsing to the appropriate Arg classes. More...

#include <CmdLine.h>

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

Public Member Functions

 CmdLine (const std::string &message, const char delimiter=' ', const std::string &version="none", bool helpAndVersion=true)
 Command line constructor. More...
 
virtual ~CmdLine ()
 Deletes any resources allocated by a CmdLine object. More...
 
ArgContaineradd (Arg &a)
 Adds an argument to the list of arguments to be parsed. More...
 
ArgContaineradd (Arg *a)
 An alternative add. More...
 
ArgContaineradd (ArgGroup &args)
 Adds an argument group to the list of arguments to be parsed. More...
 
void addToArgList (Arg *a)
 
void xorAdd (Arg &a, Arg &b)
 
void xorAdd (const std::vector< Arg *> &xors)
 
void parse (int argc, const char *const *argv)
 Parses the command line. More...
 
void parse (std::vector< std::string > &args)
 Parses the command line. More...
 
void setOutput (CmdLineOutput *co)
 
std::string getVersion () const
 Returns the version string. More...
 
std::string getProgramName () const
 Returns the program name string. More...
 
std::list< Arg * > getArgList () const
 
std::list< ArgGroup * > getArgGroups ()
 Returns the list of ArgGroups. More...
 
char getDelimiter () const
 Returns the delimiter string. More...
 
std::string getMessage () const
 Returns the message string. More...
 
bool hasHelpAndVersion () const
 Indicates whether or not the help and version switches were created automatically. More...
 
void setExceptionHandling (const bool state)
 Disables or enables CmdLine's internal parsing exception handling. More...
 
bool hasExceptionHandling () const
 Returns the current state of the internal exception handling. More...
 
void reset ()
 Allows the CmdLine object to be reused. More...
 
void ignoreUnmatched (const bool ignore)
 Allows unmatched args to be ignored. More...
 
void beginIgnoring ()
 Begin ignoring arguments since the "--" argument was specified. More...
 
bool ignoreRest ()
 Whether to ignore the rest. More...
 
- Public Member Functions inherited from TCLAP::CmdLineInterface
virtual ~CmdLineInterface ()
 Destructor. More...
 
void parse (std::vector< std::string > &args)
 Parses the command line. More...
 
- Public Member Functions inherited from TCLAP::ArgContainer
virtual ~ArgContainer ()
 

Protected Member Functions

void missingArgsException (const std::list< ArgGroup *> &missing)
 Throws an exception listing the missing args. More...
 
bool _emptyCombined (const std::string &s)
 Checks whether a name/flag string matches entirely matches the Arg::blankChar. More...
 

Protected Attributes

std::list< Arg * > _argList
 The list of arguments that will be tested against the command line. More...
 
StandaloneArgs _standaloneArgs
 
StandaloneArgs _autoArgs
 
std::list< ArgGroup * > _argGroups
 Some args have set constraints on them (i.e., exactly or at most one must be specified. More...
 
std::string _progName
 The name of the program. More...
 
std::string _message
 A message used to describe the program. More...
 
std::string _version
 The version to be displayed with the –version switch. More...
 
int _numRequired
 The number of arguments that are required to be present on the command line. More...
 
char _delimiter
 The character that is used to separate the argument flag/name from the value. More...
 
DeferDelete _deleteOnExit
 Add pointers that should be deleted as part of cleanup when this object is destroyed. More...
 
StdOutput _defaultOutput
 Default output handler if nothing is specified. More...
 
CmdLineOutput_output
 Object that handles all output for the CmdLine. More...
 
bool _handleExceptions
 Should CmdLine handle parsing exceptions internally? More...
 

Detailed Description

The base class that manages the command line definition and passes along the parsing to the appropriate Arg classes.

Definition at line 82 of file CmdLine.h.

Constructor & Destructor Documentation

◆ CmdLine()

TCLAP::CmdLine::CmdLine ( const std::string &  message,
const char  delimiter = ' ',
const std::string &  version = "none",
bool  helpAndVersion = true 
)
inline

Command line constructor.

Defines how the arguments will be parsed.

Parameters
message- The message to be used in the usage output.
delimiter- The character that is used to separate the argument flag/name from the value. Defaults to ' ' (space).
version- The version number to be used in the –version switch.
helpAndVersion- Whether or not to create the Help and Version switches. Defaults to true.

Definition at line 320 of file CmdLine.h.

References _autoArgs, _deleteOnExit, _delimiter, _output, _standaloneArgs, TCLAP::StandaloneArgs::add(), add(), addToArgList(), TCLAP::Arg::flagStartString(), TCLAP::Arg::ignoreNameString(), TCLAP::Arg::setDelimiter(), and TCLAP::ArgGroup::setParser().

Here is the call graph for this function:

◆ ~CmdLine()

virtual TCLAP::CmdLine::~CmdLine ( )
inlinevirtual

Deletes any resources allocated by a CmdLine object.

Definition at line 209 of file CmdLine.h.

References TCLAP::StandaloneArgs::add().

Here is the call graph for this function:

Member Function Documentation

◆ _emptyCombined()

bool TCLAP::CmdLine::_emptyCombined ( const std::string &  s)
inlineprotected

Checks whether a name/flag string matches entirely matches the Arg::blankChar.

Used when multiple switches are combined into a single argument.

Parameters
s- The message to be used in the usage.

Definition at line 545 of file CmdLine.h.

References TCLAP::Arg::blankChar(), and TCLAP::Arg::flagStartChar().

Referenced by parse().

Here is the call graph for this function:

◆ add() [1/3]

ArgContainer & TCLAP::CmdLine::add ( Arg a)
inlinevirtual

Adds an argument to the list of arguments to be parsed.

Parameters
a- Argument to be added.
Return values
Areference to this so that add calls can be chained

Implements TCLAP::CmdLineInterface.

Definition at line 405 of file CmdLine.h.

Referenced by CmdLine().

◆ add() [2/3]

ArgContainer & TCLAP::CmdLine::add ( Arg a)
inlinevirtual

An alternative add.

Functionally identical.

Parameters
a- Argument to be added.
Return values
Areference to this so that add calls can be chained

Implements TCLAP::CmdLineInterface.

Definition at line 420 of file CmdLine.h.

References _standaloneArgs, TCLAP::StandaloneArgs::add(), and addToArgList().

Here is the call graph for this function:

◆ add() [3/3]

ArgContainer & TCLAP::CmdLine::add ( ArgGroup args)
inlinevirtual

Adds an argument group to the list of arguments to be parsed.

All arguments in the group are added and the ArgGroup object will validate that the input matches its constraints.

Parameters
args- Argument group to be added.
Return values
Areference to this so that add calls can be chained

Implements TCLAP::CmdLineInterface.

Definition at line 398 of file CmdLine.h.

References _argGroups, and TCLAP::ArgGroup::setParser().

Here is the call graph for this function:

◆ addToArgList()

void TCLAP::CmdLine::addToArgList ( Arg a)
inlinevirtual

Implements TCLAP::CmdLineInterface.

Definition at line 409 of file CmdLine.h.

References _argList, _numRequired, TCLAP::Arg::addToList(), TCLAP::Arg::isRequired(), and TCLAP::Arg::longID().

Referenced by add(), and CmdLine().

Here is the call graph for this function:

◆ beginIgnoring()

void TCLAP::CmdLine::beginIgnoring ( )
inlinevirtual

Begin ignoring arguments since the "--" argument was specified.

Implements TCLAP::CmdLineInterface.

Definition at line 312 of file CmdLine.h.

◆ getArgGroups()

std::list<ArgGroup *> TCLAP::CmdLine::getArgGroups ( )
inlinevirtual

Returns the list of ArgGroups.

Implements TCLAP::CmdLineInterface.

Definition at line 274 of file CmdLine.h.

◆ getArgList()

std::list<Arg *> TCLAP::CmdLine::getArgList ( ) const
inlinevirtual

Implements TCLAP::CmdLineInterface.

Definition at line 273 of file CmdLine.h.

◆ getDelimiter()

char TCLAP::CmdLine::getDelimiter ( ) const
inlinevirtual

Returns the delimiter string.

Implements TCLAP::CmdLineInterface.

Definition at line 280 of file CmdLine.h.

◆ getMessage()

std::string TCLAP::CmdLine::getMessage ( ) const
inlinevirtual

Returns the message string.

Implements TCLAP::CmdLineInterface.

Definition at line 281 of file CmdLine.h.

◆ getProgramName()

std::string TCLAP::CmdLine::getProgramName ( ) const
inlinevirtual

Returns the program name string.

Implements TCLAP::CmdLineInterface.

Definition at line 270 of file CmdLine.h.

◆ getVersion()

std::string TCLAP::CmdLine::getVersion ( ) const
inlinevirtual

Returns the version string.

Implements TCLAP::CmdLineInterface.

Definition at line 268 of file CmdLine.h.

◆ hasExceptionHandling()

bool TCLAP::CmdLine::hasExceptionHandling ( ) const
inline

Returns the current state of the internal exception handling.

Return values
trueParsing exceptions are handled internally.
falseParsing exceptions are propagated to the caller.

Definition at line 297 of file CmdLine.h.

◆ hasHelpAndVersion()

bool TCLAP::CmdLine::hasHelpAndVersion ( ) const
inlinevirtual

Indicates whether or not the help and version switches were created automatically.

Implements TCLAP::CmdLineInterface.

Definition at line 282 of file CmdLine.h.

◆ ignoreRest()

bool TCLAP::CmdLine::ignoreRest ( )
inlinevirtual

Whether to ignore the rest.

Implements TCLAP::CmdLineInterface.

Definition at line 313 of file CmdLine.h.

Referenced by parse().

◆ ignoreUnmatched()

void TCLAP::CmdLine::ignoreUnmatched ( const bool  ignore)
inline

Allows unmatched args to be ignored.

By default false.

Parameters
ignoreIf true the cmdline will ignore any unmatched args and if false it will behave as normal.

Definition at line 601 of file CmdLine.h.

◆ missingArgsException()

void TCLAP::CmdLine::missingArgsException ( const std::list< ArgGroup *> &  missing)
inlineprotected

Throws an exception listing the missing args.

Definition at line 554 of file CmdLine.h.

References _argList.

Referenced by parse().

◆ parse() [1/2]

void TCLAP::CmdLine::parse ( int  argc,
const char *const *  argv 
)
inlinevirtual

Parses the command line.

Parameters
argc- Number of arguments.
argv- Array of arguments.

Implements TCLAP::CmdLineInterface.

Definition at line 427 of file CmdLine.h.

◆ parse() [2/2]

void TCLAP::CmdLine::parse ( std::vector< std::string > &  args)
inline

Parses the command line.

Parameters
args- A vector of strings representing the args. args[0] is still the program name.

Definition at line 436 of file CmdLine.h.

References _argGroups, _argList, _emptyCombined(), _handleExceptions, _numRequired, _output, _progName, TCLAP::basename(), TCLAP::CmdLineOutput::failure(), TCLAP::ExitException::getExitStatus(), ignoreRest(), TCLAP::Arg::isIgnoreable(), TCLAP::Arg::isRequired(), TCLAP::Arg::isSet(), missingArgsException(), and TCLAP::Arg::processArg().

Here is the call graph for this function:

◆ reset()

void TCLAP::CmdLine::reset ( )
inlinevirtual

Allows the CmdLine object to be reused.

Implements TCLAP::CmdLineInterface.

Definition at line 593 of file CmdLine.h.

References _argList, and _progName.

◆ setExceptionHandling()

void TCLAP::CmdLine::setExceptionHandling ( const bool  state)
inline

Disables or enables CmdLine's internal parsing exception handling.

Parameters
stateShould CmdLine handle parsing exceptions internally?

Definition at line 589 of file CmdLine.h.

References _handleExceptions.

◆ setOutput()

void TCLAP::CmdLine::setOutput ( CmdLineOutput co)
inlinevirtual
Parameters
co- CmdLineOutput object that we want to use instead.

Implements TCLAP::CmdLineInterface.

Definition at line 587 of file CmdLine.h.

References _output.

◆ xorAdd() [1/2]

void TCLAP::CmdLine::xorAdd ( Arg a,
Arg b 
)
inlinevirtual
Deprecated:
Use OneOf instead.

Implements TCLAP::CmdLineInterface.

Definition at line 391 of file CmdLine.h.

◆ xorAdd() [2/2]

void TCLAP::CmdLine::xorAdd ( const std::vector< Arg *> &  xors)
inlinevirtual
Deprecated:
Use OneOf instead.

Implements TCLAP::CmdLineInterface.

Definition at line 381 of file CmdLine.h.

References _deleteOnExit, and TCLAP::ExclusiveArgGroup::add().

Here is the call graph for this function:

Member Data Documentation

◆ _argGroups

std::list<ArgGroup *> TCLAP::CmdLine::_argGroups
protected

Some args have set constraints on them (i.e., exactly or at most one must be specified.

Definition at line 97 of file CmdLine.h.

Referenced by add(), and parse().

◆ _argList

std::list<Arg *> TCLAP::CmdLine::_argList
protected

The list of arguments that will be tested against the command line.

Definition at line 88 of file CmdLine.h.

Referenced by addToArgList(), missingArgsException(), parse(), and reset().

◆ _autoArgs

StandaloneArgs TCLAP::CmdLine::_autoArgs
protected

Definition at line 91 of file CmdLine.h.

Referenced by CmdLine().

◆ _defaultOutput

StdOutput TCLAP::CmdLine::_defaultOutput
protected

Default output handler if nothing is specified.

Definition at line 137 of file CmdLine.h.

◆ _deleteOnExit

DeferDelete TCLAP::CmdLine::_deleteOnExit
protected

Add pointers that should be deleted as part of cleanup when this object is destroyed.

Definition at line 132 of file CmdLine.h.

Referenced by CmdLine(), and xorAdd().

◆ _delimiter

char TCLAP::CmdLine::_delimiter
protected

The character that is used to separate the argument flag/name from the value.

Defaults to ' ' (space).

Definition at line 125 of file CmdLine.h.

Referenced by CmdLine().

◆ _handleExceptions

bool TCLAP::CmdLine::_handleExceptions
protected

Should CmdLine handle parsing exceptions internally?

Definition at line 147 of file CmdLine.h.

Referenced by parse(), and setExceptionHandling().

◆ _message

std::string TCLAP::CmdLine::_message
protected

A message used to describe the program.

Used in the usage output.

Definition at line 107 of file CmdLine.h.

◆ _numRequired

int TCLAP::CmdLine::_numRequired
protected

The number of arguments that are required to be present on the command line.

This is set dynamically, based on the Args added to the CmdLine object.

Definition at line 119 of file CmdLine.h.

Referenced by addToArgList(), and parse().

◆ _output

CmdLineOutput* TCLAP::CmdLine::_output
protected

Object that handles all output for the CmdLine.

Definition at line 142 of file CmdLine.h.

Referenced by CmdLine(), parse(), and setOutput().

◆ _progName

std::string TCLAP::CmdLine::_progName
protected

The name of the program.

Set to argv[0].

Definition at line 102 of file CmdLine.h.

Referenced by parse(), and reset().

◆ _standaloneArgs

StandaloneArgs TCLAP::CmdLine::_standaloneArgs
protected

Definition at line 90 of file CmdLine.h.

Referenced by add(), and CmdLine().

◆ _version

std::string TCLAP::CmdLine::_version
protected

The version to be displayed with the –version switch.

Definition at line 112 of file CmdLine.h.


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