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:
[legend]
Collaboration diagram for TCLAP::CmdLine:
[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...
void | add (Arg &a)
| Adds an argument to the list of arguments to be parsed. More...
void | add (Arg *a)
| An alternative add. More...
void | xorAdd (Arg &a, Arg &b)
| Add two Args that will be xor'd. More...
void | xorAdd (const std::vector< Arg * > &xors)
| Add a list of Args that will be xor'd. More...
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...
CmdLineOutput * | getOutput ()
| Returns the CmdLineOutput object. More...
void | setOutput (CmdLineOutput *co)
std::string & | getVersion ()
| Returns the version string. More...
std::string & | getProgramName ()
| Returns the program name string. More...
std::list< Arg * > & | getArgList ()
| Returns the argList. More...
XorHandler & | getXorHandler ()
| Returns the XorHandler. More...
char | getDelimiter ()
| Returns the delimiter string. More...
std::string & | getMessage ()
| Returns the message string. More...
bool | hasHelpAndVersion ()
| 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 | getExceptionHandling () 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...
Public Member Functions inherited from TCLAP::CmdLineInterface
virtual | ~CmdLineInterface ()
| Destructor. More...
void | parse (std::vector< std::string > &args)
| Parses the command line. More...

## Protected Member Functions

void | missingArgsException ()
| 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...
void | deleteOnExit (Arg *ptr)
| Perform a delete ptr; operation on ptr when this object is deleted. More...
void | deleteOnExit (Visitor *ptr)
| Perform a delete ptr; operation on ptr when this object is deleted. More...

## Protected Attributes

std::list< Arg * > | _argList
| The list of arguments that will be tested against the command line. 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...
XorHandler | _xorHandler
| The handler that manages xoring lists of args. More...
std::list< Arg * > | _argDeleteOnExitList
| A list of Args to be explicitly deleted when the destructor is called. More...
std::list< Visitor * > | _visitorDeleteOnExitList
| A list of Visitors to be explicitly deleted when the destructor is called. 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 70 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 335 of file CmdLine.h.

## ~CmdLine()

TCLAP::CmdLine::~CmdLine | ( |  | ) |

inlinevirtual

Deletes any resources allocated by a CmdLine object.

Definition at line 358 of file CmdLine.h.

References _argDeleteOnExitList, _output, _visitorDeleteOnExitList, and TCLAP::ClearContainer().

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 530 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/2]

void TCLAP::CmdLine::add | ( | Arg & | a | ) |

inlinevirtual

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

Parameters

  a | - Argument to be added.

Implements TCLAP::CmdLineInterface.

Definition at line 426 of file CmdLine.h.

Referenced by xorAdd().

## add() [2/2]

void TCLAP::CmdLine::add | ( | Arg * | a | ) |

inlinevirtual

An alternative add.

Functionally identical.

Parameters

  a | - Argument to be added.

Implements TCLAP::CmdLineInterface.

Definition at line 431 of file CmdLine.h.

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

Here is the call graph for this function:

## deleteOnExit() [1/2]

void TCLAP::CmdLine::deleteOnExit | ( | Arg * | ptr | ) |

inlineprotected

Perform a delete ptr; operation on ptr when this object is deleted.

Definition at line 569 of file CmdLine.h.

References _argDeleteOnExitList.

## deleteOnExit() [2/2]

void TCLAP::CmdLine::deleteOnExit | ( | Visitor * | ptr | ) |

inlineprotected

Perform a delete ptr; operation on ptr when this object is deleted.

Definition at line 574 of file CmdLine.h.

References _visitorDeleteOnExitList.

## getArgList()

std::list< Arg * > & TCLAP::CmdLine::getArgList | ( |  | ) |

inlinevirtual

Returns the argList.

Implements TCLAP::CmdLineInterface.

Definition at line 602 of file CmdLine.h.

References _argList.

## getDelimiter()

char TCLAP::CmdLine::getDelimiter | ( |  | ) |

inlinevirtual

Returns the delimiter string.

Implements TCLAP::CmdLineInterface.

Definition at line 612 of file CmdLine.h.

References _delimiter.

## getExceptionHandling()

bool TCLAP::CmdLine::getExceptionHandling | ( |  | ) | const

inline

Returns the current state of the internal exception handling.

Return values

  true | Parsing exceptions are handled internally.
  false | Parsing exceptions are propagated to the caller.

Definition at line 632 of file CmdLine.h.

References _handleExceptions.

## getMessage()

std::string & TCLAP::CmdLine::getMessage | ( |  | ) |

inlinevirtual

Returns the message string.

Implements TCLAP::CmdLineInterface.

Definition at line 617 of file CmdLine.h.

References _message.

## getOutput()

CmdLineOutput * TCLAP::CmdLine::getOutput | ( |  | ) |

inlinevirtual

Returns the CmdLineOutput object.

Implements TCLAP::CmdLineInterface.

Definition at line 579 of file CmdLine.h.

References _output.

## getProgramName()

std::string & TCLAP::CmdLine::getProgramName | ( |  | ) |

inlinevirtual

Returns the program name string.

Implements TCLAP::CmdLineInterface.

Definition at line 597 of file CmdLine.h.

References _progName.

## getVersion()

std::string & TCLAP::CmdLine::getVersion | ( |  | ) |

inlinevirtual

Returns the version string.

Implements TCLAP::CmdLineInterface.

Definition at line 592 of file CmdLine.h.

References _version.

## getXorHandler()

XorHandler & TCLAP::CmdLine::getXorHandler | ( |  | ) |

inlinevirtual

Returns the XorHandler.

Implements TCLAP::CmdLineInterface.

Definition at line 607 of file CmdLine.h.

References _xorHandler.

## hasHelpAndVersion()

bool TCLAP::CmdLine::hasHelpAndVersion | ( |  | ) |

inlinevirtual

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

Implements TCLAP::CmdLineInterface.

Definition at line 622 of file CmdLine.h.

## ignoreUnmatched()

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

inline

Allows unmatched args to be ignored.

By default false.

Parameters

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

Definition at line 645 of file CmdLine.h.

## missingArgsException()

void TCLAP::CmdLine::missingArgsException | ( |  | ) |

inlineprotected

Throws an exception listing the missing args.

Definition at line 542 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 446 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 457 of file CmdLine.h.

References _argList, _emptyCombined(), _handleExceptions, _numRequired, _output, _progName, _xorHandler, TCLAP::XorHandler::check(), TCLAP::CmdLineOutput::failure(), TCLAP::ExitException::getExitStatus(), TCLAP::Arg::ignoreRest(), and missingArgsException().

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 637 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

  state | Should CmdLine handle parsing exceptions internally?

Definition at line 627 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 584 of file CmdLine.h.

References _output.

## xorAdd() [1/2]

void TCLAP::CmdLine::xorAdd | ( | Arg & | a,
|  | Arg & | b
| ) |  |

inlinevirtual

Add two Args that will be xor'd.

If this method is used, add does not need to be called.

Parameters

  a | - Argument to be added and xor'd.
  b | - Argument to be added and xor'd.

Implements TCLAP::CmdLineInterface.

Definition at line 418 of file CmdLine.h.

## xorAdd() [2/2]

void TCLAP::CmdLine::xorAdd | ( | const std::vector< Arg * > & | xors | ) |

inlinevirtual

Add a list of Args that will be xor'd.

If this method is used, add does not need to be called.

Parameters

  xors | - List of Args to be added and xor'd.

Implements TCLAP::CmdLineInterface.

Definition at line 406 of file CmdLine.h.

References _xorHandler, add(), and TCLAP::XorHandler::add().

Here is the call graph for this function:

## Member Data Documentation

## _argDeleteOnExitList

std::list<Arg*> TCLAP::CmdLine::_argDeleteOnExitList

protected

A list of Args to be explicitly deleted when the destructor is called.

At the moment, this only includes the three default Args.

Definition at line 118 of file CmdLine.h.

Referenced by deleteOnExit(), and ~CmdLine().

## _argList

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

protected

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

Definition at line 78 of file CmdLine.h.

Referenced by add(), getArgList(), missingArgsException(), parse(), and reset().

## _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 106 of file CmdLine.h.

Referenced by getDelimiter().

## _handleExceptions

bool TCLAP::CmdLine::_handleExceptions

protected

Should CmdLine handle parsing exceptions internally?

Definition at line 135 of file CmdLine.h.

Referenced by getExceptionHandling(), 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 88 of file CmdLine.h.

Referenced by getMessage().

## _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 100 of file CmdLine.h.

Referenced by add(), and parse().

## _output

CmdLineOutput* TCLAP::CmdLine::_output

protected

Object that handles all output for the CmdLine.

Definition at line 130 of file CmdLine.h.

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

## _progName

std::string TCLAP::CmdLine::_progName

protected

The name of the program.

Set to argv[0].

Definition at line 83 of file CmdLine.h.

Referenced by getProgramName(), parse(), and reset().

## _version

std::string TCLAP::CmdLine::_version

protected

The version to be displayed with the –version switch.

Definition at line 93 of file CmdLine.h.

Referenced by getVersion().

## _visitorDeleteOnExitList

std::list<Visitor*> TCLAP::CmdLine::_visitorDeleteOnExitList

protected

A list of Visitors to be explicitly deleted when the destructor is called.

At the moment, these are the Visitors created for the default Args.

Definition at line 125 of file CmdLine.h.

Referenced by deleteOnExit(), and ~CmdLine().

## _xorHandler

XorHandler TCLAP::CmdLine::_xorHandler

protected

The handler that manages xoring lists of args.

Definition at line 111 of file CmdLine.h.

Referenced by getXorHandler(), parse(), and xorAdd().

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

- CmdLine.h