25 #ifndef TCLAP_CMD_LINE_H 26 #define TCLAP_CMD_LINE_H 65 "Argument with same flag/name already exists!",
152 void missingArgsException(
const std::list<ArgGroup *> &missing);
160 bool _emptyCombined(
const std::string &s);
178 bool _helpAndVersion;
183 bool _ignoreUnmatched;
203 CmdLine(
const std::string &message,
const char delimiter =
' ',
204 const std::string &version =
"none",
bool helpAndVersion =
true);
240 void addToArgList(
Arg *a);
245 void xorAdd(
Arg &a,
Arg &b);
250 void xorAdd(
const std::vector<Arg *> &xors);
257 void parse(
int argc,
const char *
const *argv);
264 void parse(std::vector<std::string> &args);
275 std::list<ArgGroup *> groups = _argGroups;
276 groups.push_back(&_autoArgs);
289 void setExceptionHandling(
const bool state);
310 void ignoreUnmatched(
const bool ignore);
320 inline CmdLine::CmdLine(
const std::string &m,
char delim,
const std::string &v,
326 _progName(
"not_set_yet"),
333 _output(&_defaultOutput),
334 _handleExceptions(true),
335 _helpAndVersion(help),
336 _ignoreUnmatched(false),
341 inline void CmdLine::_constructor() {
352 "Ignores the rest of the labeled arguments following this flag.",
false,
359 if (_helpAndVersion) {
362 "h",
"help",
"Displays usage information and exits.",
false, v);
368 "",
"version",
"Displays version information and exits.",
false, v);
385 for (std::vector<Arg *>::const_iterator it = args.begin(); it != args.end();
392 std::vector<Arg *> ors;
413 "Argument with same flag/name already exists!", a->
longID()));
430 std::vector<std::string> args;
431 for (
int i = 0; i < argc; i++) args.push_back(argv[i]);
437 bool shouldExit =
false;
444 "The args vector must not be empty, " 445 "the first entry should contain the " 451 args.erase(args.begin());
453 int requiredCount = 0;
454 std::list<ArgGroup *> missingArgGroups;
470 for (
int i = 0;
static_cast<unsigned int>(i) < args.size(); i++) {
471 bool matched =
false;
483 bool alreadySet = arg.
isSet();
486 requiredCount += (!alreadySet && arg.
isRequired()) ? 1 : 0;
496 if (!matched && !
ignoreRest() && !_ignoreUnmatched)
505 for (std::list<ArgGroup *>::iterator it =
_argGroups.begin();
507 bool missingRequired = (*it)->validate();
508 if (missingRequired) {
509 missingArgGroups.push_back(*it);
513 if (requiredCount <
_numRequired || !missingArgGroups.empty()) {
542 if (shouldExit) exit(estat);
548 for (
int i = 1;
static_cast<unsigned int>(i) < s.length(); i++)
555 const std::list<ArgGroup *> &missing) {
558 std::string missingArgList;
560 if ((*it)->isRequired() && !(*it)->isSet()) {
561 missingArgList += (*it)->getName();
562 missingArgList +=
", ";
567 for (std::list<ArgGroup *>::const_iterator it = missing.begin();
568 it != missing.end(); it++) {
569 missingArgList += (*it)->getName();
570 missingArgList +=
", ";
574 missingArgList = missingArgList.substr(0, missingArgList.length() - 2);
578 msg =
"Required arguments missing: ";
580 msg =
"Required argument missing: ";
582 msg += missingArgList;
602 _ignoreUnmatched = ignore;
611 #endif // TCLAP_CMD_LINE_H bool hasExceptionHandling() const
Returns the current state of the internal exception handling.
std::list< Arg * > _argList
The list of arguments that will be tested against the command line.
Implements a group of arguments where exactly one must be selected.
CmdLineOutput * _output
Object that handles all output for the CmdLine.
void setParser(CmdLineInterface &parser)
Used by the parser to connect itself to this arg group.
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)
A simple class that defines and argument exception.
virtual void failure(CmdLineInterface &c, ArgException &e)=0
Generates some sort of output for a failure.
ArgContainer & add(Arg *arg)
Add an argument to this arg group.
void beginIgnoring()
Begin ignoring arguments since the "--" argument was specified.
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()
bool ignoreRest()
Whether to ignore the rest.
std::string _version
The version to be displayed with the –version switch.
Thrown when TCLAP thinks the program should exit.
A simple switch argument.
virtual ~CmdLine()
Deletes any resources allocated by a CmdLine object.
bool isSet() const
Indicates whether the argument has already been set.
bool hasHelpAndVersion() const
Indicates whether or not the help and version switches were created automatically.
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.
StdOutput _defaultOutput
Default output handler if nothing is specified.
ArgContainer & add(Arg &a)
Adds an argument to the list of arguments to be parsed.
void reset()
Allows the CmdLine object to be reused.
char getDelimiter() const
Returns the delimiter string.
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.
DeferDelete can be used by objects that need to allocate arbitrary other objects to live for the dura...
A Visitor that will call the version method of the given CmdLineOutput for the specified CmdLine obje...
std::string getVersion() const
Returns the version string.
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
std::string getMessage() const
Returns the message string.
Interface that allows adding an Arg to a "container".
int _numRequired
The number of arguments that are required to be present on the command line.
std::string getProgramName() const
Returns the program name string.
bool _emptyCombined(const std::string &s)
Checks whether a name/flag string matches entirely matches the Arg::blankChar.
Container::iterator iterator
A base class that defines the interface for visitors.
DeferDelete _deleteOnExit
Add pointers that should be deleted as part of cleanup when this object is destroyed.
ArgContainer & add(Arg &arg)
Add an argument to this arg group.
std::string basename(std::string s)
The base class that manages the command line definition and passes along the parsing to the appropria...
void missingArgsException(const std::list< ArgGroup *> &missing)
Throws an exception listing the missing args.
void setExceptionHandling(const bool state)
Disables or enables CmdLine's internal parsing exception handling.
std::list< ArgGroup * > _argGroups
Some args have set constraints on them (i.e., exactly or at most one must be specified.
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 lin...
A class that isolates any output from the CmdLine object so that it may be easily modified...
StandaloneArgs _standaloneArgs
std::list< ArgGroup * > getArgGroups()
Returns the list of ArgGroups.
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.
bool isIgnoreable() const
Indicates whether the argument can be ignored, if desired.
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.
int getExitStatus() const
void setOutput(CmdLineOutput *co)
static char blankChar()
The char used as a place holder when SwitchArgs are combined.
Implements a group of arguments where any combination is possible (including all or none)...
std::list< Arg * > getArgList() const
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.
ArgGroup is the base class for implementing groups of arguments that are mutually exclusive (it repla...
The base class that manages the command line definition and passes along the parsing to the appropria...
bool _handleExceptions
Should CmdLine handle parsing exceptions internally?
bool showAsGroup() const
If arguments in this group should show up as grouped in help.
static const std::string flagStartString()
void addToArgList(Arg *a)
static void setDelimiter(char c)
Sets the delimiter for all arguments.
The interface that any output object must implement.