25 #ifndef DtCmdLine_ARGUMENT_H
26 #define DtCmdLine_ARGUMENT_H
37 #ifdef DtUSE_UTILITIES_NAMESPACE
38 namespace DtUSE_UTILITIES_NAMESPACE
61 static char&
delimiterRef() {
static char delim =
' ';
return delim; }
136 void _checkWithVisitor()
const;
151 Arg(
const std::string& flag,
152 const std::string& name,
153 const std::string& desc,
168 virtual void addToList( std::list<Arg*>& argList )
const;
228 virtual bool processArg(
int *i, std::vector<std::string>& args) = 0;
247 const std::string& getFlag()
const;
252 const std::string& getName()
const;
257 std::string getDescription()
const;
262 virtual bool isRequired()
const;
268 void forceRequired();
279 bool isValueRequired()
const;
287 bool isAlreadySet()
const;
288 bool isXorSet()
const;
293 bool isIgnoreable()
const;
303 virtual bool argMatches(
const std::string& s )
const;
309 virtual std::string toString()
const;
315 virtual std::string shortID(
const std::string& valueId =
"val" )
const;
321 virtual std::string longID(
const std::string& valueId =
"val" )
const;
330 virtual void trimFlag( std::string& flag, std::string& value )
const;
338 bool _hasBlanks(
const std::string& s )
const;
345 void setRequireLabel(
const std::string& s );
369 inline Arg::Arg(
const std::string& flag,
370 const std::string& name,
371 const std::string& desc,
379 _requireLabel(
"required"),
380 _valueRequired(valreq),
386 if (
_flag.length() > 1 )
388 "Argument flag can only be one character long",
toString() ) );
401 (
_name.find(
" ", 0 ) != std::string::npos ) )
420 std::string delim =
" ";
424 id += delim +
"<" + valueId +
">";
432 inline std::string
Arg::longID(
const std::string& valueId )
const
441 id +=
" <" + valueId +
">";
449 id +=
" <" + valueId +
">";
470 return !(*
this == a);
475 std::string desc =
"";
546 for (
int i = 0; (
unsigned int)i < flag.length(); i++ )
555 value = flag.substr(stop+1);
556 flag = flag.substr(0,stop);
566 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
589 argList.push_front( (
Arg*)
this );
598 #ifdef DtUSE_UTILITIES_NAMESPACE
virtual bool operator==(const Arg &a)
Operator ==.
Definition: cmdArg.h:455
bool isXorSet() const
Definition: cmdArg.h:503
virtual ~Arg()
Destructor.
Definition: cmdArg.h:409
bool isSet() const
Indicates whether the argument has already been set.
Definition: cmdArg.h:494
A base class that defines the interface for visitors.
Definition: cmdVisitor.h:41
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
bool _valueRequired
Indicates whether a value is required for the argument.
Definition: cmdArg.h:105
static void setDelimiter(char c)
Sets the delimiter for all arguments.
Definition: cmdArg.h:219
static const char blankChar()
The char used as a place holder when SwitchArgs are combined.
Definition: cmdArg.h:191
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
Definition: cmdArgException.h:177
This file declares the class DtCmdLine::CmdLineInterface.
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: cmdArg.h:125
virtual bool isRequired() const
Indicates whether the argument is required.
Definition: cmdArg.h:490
bool _hasBlanks(const std::string &s) const
Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
Definition: cmdArg.h:564
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Definition: cmdArg.h:432
bool _alreadySet
Indicates whether the argument has been set.
Definition: cmdArg.h:112
static bool & ignoreRestRef()
Indicates whether the rest of the arguments should be ignored.
Definition: cmdArg.h:55
static const std::string flagStartString()
The sting that indicates the beginning of a flag.
Definition: cmdArg.h:202
static char delimiter()
The delimiter that separates an argument flag/name from the value.
Definition: cmdArg.h:184
static const char flagStartChar()
The char that indicates the beginning of a flag.
Definition: cmdArg.h:196
void forceRequired()
Sets _required to true.
Definition: cmdArg.h:573
std::string getDescription() const
Returns the argument description.
Definition: cmdArg.h:473
const std::string & getName() const
Returns the argument name.
Definition: cmdArg.h:488
bool _xorSet
Indicates that the arg was set as part of an XOR and not on the command line.
Definition: cmdArg.h:131
virtual void addToList(std::list< Arg * > &argList) const
Adds this to the specified list of Args.
Definition: cmdArg.h:587
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition: cmdArg.h:522
std::list< Visitor * >::iterator VisitorListIterator
Typedef of a Visitor list iterator.
Definition: cmdArg.h:362
bool _required
Indicating whether the argument is required.
Definition: cmdArg.h:92
void xorSet()
Sets the _alreadySet value to true.
Definition: cmdArg.h:578
static const std::string nameStartString()
The sting that indicates the beginning of a name.
Definition: cmdArg.h:208
static bool ignoreRest()
Whether to ignore the rest.
Definition: cmdArg.h:178
std::string _description
Description of the argument.
Definition: cmdArg.h:87
std::string _name
A single work namd indentifying the argument.
Definition: cmdArg.h:82
void setRequireLabel(const std::string &s)
Sets the requireLabel.
Definition: cmdArg.h:508
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
Definition: cmdArg.h:411
This file declares the class DtCmdLine::Visitor.
A virtual base class that defines the essential data for all arguments.
Definition: cmdArg.h:48
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
Definition: cmdArg.h:213
static void beginIgnoring()
Begin ignoring arguments since the "--" argument was specified.
Definition: cmdArg.h:173
virtual bool operator!=(const Arg &a)
Operator !=.
Definition: cmdArg.h:468
This file declares the class DtCmdLine::ArgException.
const std::string & getFlag() const
Returns the argument flag.
Definition: cmdArg.h:486
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
Definition: cmdArg.h:352
const bool operator!=(const DtU128 &lhs, const DtU128 &rhs)
virtual void visit()
Does nothing.
Definition: cmdVisitor.h:55
bool isValueRequired() const
Indicates whether a value must be specified for argument.
Definition: cmdArg.h:492
std::string _flag
The single char flag used to identify the argument.
Definition: cmdArg.h:73
virtual void trimFlag(std::string &flag, std::string &value) const
Trims a value off of the flag.
Definition: cmdArg.h:543
Visitor * _visitor
A pointer to a vistitor object.
Definition: cmdArg.h:120
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition: cmdArg.h:357
bool isAlreadySet() const
Definition: cmdArg.h:502
static char & delimiterRef()
The delimiter that separates an argument flag/name from the value.
Definition: cmdArg.h:61
std::string _requireLabel
Label to be used in usage description.
Definition: cmdArg.h:98
void _checkWithVisitor() const
Performs the special handling described by the Vistitor.
Definition: cmdArg.h:534
bool isIgnoreable() const
Indicates whether the argument can be ignored, if desired.
Definition: cmdArg.h:506
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
Definition: cmdArg.h:513