24 #ifndef TCLAP_CMDLINE_H 25 #define TCLAP_CMDLINE_H 53 template<
typename T>
void DelPtr(T ptr)
60 typedef typename C::value_type value_type;
61 std::for_each(c.begin(), c.end(), DelPtr<value_type>);
184 bool _helpAndVersion;
189 bool _ignoreUnmatched;
205 CmdLine(
const std::string& message,
206 const char delimiter =
' ',
207 const std::string& version =
"none",
208 bool helpAndVersion =
true);
240 void xorAdd(
const std::vector<Arg*>& xors );
247 void parse(
int argc,
const char *
const * argv);
254 void parse(std::vector<std::string>& args);
335 inline CmdLine::CmdLine(
const std::string& m,
337 const std::string& v,
351 _userSetOutput(false),
352 _helpAndVersion(help),
353 _ignoreUnmatched(false)
363 if ( !_userSetOutput ) {
369 inline void CmdLine::_constructor()
377 if ( _helpAndVersion )
381 "Displays usage information and exits.",
389 "Displays version information and exits.",
399 "Ignores the rest of the labeled arguments following this flag.",
412 (*it)->forceRequired();
413 (*it)->setRequireLabel(
"OR required" );
420 std::vector<Arg*> ors;
436 "Argument with same flag/name already exists!",
450 std::vector<std::string> args;
451 for (
int i = 0; i < argc; i++)
452 args.push_back(argv[i]);
459 bool shouldExit =
false;
465 "the first entry should contain the " 470 args.erase(args.begin());
472 int requiredCount = 0;
474 for (
int i = 0;
static_cast<unsigned int>(i) < args.size(); i++)
476 bool matched =
false;
479 if ( (*it)->processArg( &i, args ) )
535 for (
int i = 1;
static_cast<unsigned int>(i) < s.length(); i++ )
546 std::string missingArgList;
549 if ( (*it)->isRequired() && !(*it)->isSet() )
551 missingArgList += (*it)->getName();
552 missingArgList +=
", ";
556 missingArgList = missingArgList.substr(0,missingArgList.length()-2);
560 msg =
"Required arguments missing: ";
562 msg =
"Required argument missing: ";
564 msg += missingArgList;
586 if ( !_userSetOutput )
588 _userSetOutput =
true;
624 return _helpAndVersion;
647 _ignoreUnmatched = ignore;
std::list< Visitor * > _visitorDeleteOnExitList
A list of Visitors to be explicitly deleted when the destructor is called.
CmdLineOutput * _output
Object that handles all output for the CmdLine.
A virtual base class that defines the essential data for all arguments.
std::string _message
A message used to describe the program.
void xorAdd(Arg &a, Arg &b)
Add two Args that will be xor'd.
std::list< Arg * > _argList
The list of arguments that will be tested against the command line.
A simple class that defines and argument exception.
virtual void failure(CmdLineInterface &c, ArgException &e)=0
Generates some sort of output for a failure.
virtual void addToList(std::list< Arg *> &argList) const
Adds this to the specified list of Args.
std::string _progName
The name of the program.
Thrown from CmdLine when the arguments on the command line are not properly specified, e.g.
static char flagStartChar()
std::string & getProgramName()
Returns the program name string.
std::string _version
The version to be displayed with the –version switch.
Thrown when TCLAP thinks the program should exit.
A simple switch argument.
void deleteOnExit(Arg *ptr)
Perform a delete ptr; operation on ptr when this object is deleted.
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
void reset()
Allows the CmdLine object to be reused.
int check(const Arg *a)
Checks whether the specified Arg is in one of the xor lists and if it does match one, returns the size of the xor list that the Arg matched.
virtual bool isRequired() const
Indicates whether the argument is required.
char _delimiter
The character that is used to separate the argument flag/name from the value.
A Visitor that will call the version method of the given CmdLineOutput for the specified CmdLine obje...
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
std::vector< Arg * >::const_iterator ArgVectorIterator
Typedef of an Arg vector iterator.
int _numRequired
The number of arguments that are required to be present on the command line.
virtual ~CmdLine()
Deletes any resources allocated by a CmdLine object.
std::list< Arg * > _argDeleteOnExitList
A list of Args to be explicitly deleted when the destructor is called.
bool _emptyCombined(const std::string &s)
Checks whether a name/flag string matches entirely matches the Arg::blankChar.
A base class that defines the interface for visitors.
bool getExceptionHandling() const
Returns the current state of the internal exception handling.
void add(const std::vector< Arg *> &ors)
Add a list of Arg*'s that will be xor'd together.
The base class that manages the command line definition and passes along the parsing to the appropria...
CmdLineOutput * getOutput()
Returns the CmdLineOutput object.
void setExceptionHandling(const bool state)
Disables or enables CmdLine's internal parsing exception handling.
A class that isolates any output from the CmdLine object so that it may be easily modified...
std::string & getMessage()
Returns the message string.
A Visitor object that calls the usage method of the given CmdLineOutput object for the specified CmdL...
void parse(int argc, const char *const *argv)
Parses the command line.
static bool ignoreRest()
Whether to ignore the rest.
A Visitor that tells the CmdLine to begin ignoring arguments after this one is parsed.
void ignoreUnmatched(const bool ignore)
Allows unmatched args to be ignored.
bool hasHelpAndVersion()
Indicates whether or not the help and version switches were created automatically.
XorHandler _xorHandler
The handler that manages xoring lists of args.
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.
int getExitStatus() const
std::string & getVersion()
Returns the version string.
void add(Arg &a)
Adds an argument to the list of arguments to be parsed.
void setOutput(CmdLineOutput *co)
static char blankChar()
The char used as a place holder when SwitchArgs are combined.
char getDelimiter()
Returns the delimiter string.
std::list< Arg * > & getArgList()
Returns the argList.
The base class that manages the command line definition and passes along the parsing to the appropria...
void missingArgsException()
Throws an exception listing the missing args.
XorHandler & getXorHandler()
Returns the XorHandler.
bool _handleExceptions
Should CmdLine handle parsing exceptions internally?
static const std::string flagStartString()
This class handles lists of Arg's that are to be XOR'd on the command line.
void ClearContainer(C &c)
static void setDelimiter(char c)
Sets the delimiter for all arguments.
The interface that any output object must implement.