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;
240 const std::string& getFlag()
const;
245 const std::string& getName()
const;
250 std::string getDescription()
const;
255 virtual bool isRequired()
const;
261 void forceRequired();
272 bool isValueRequired()
const;
283 bool isIgnoreable()
const;
293 virtual bool argMatches(
const std::string& s )
const;
299 virtual std::string toString()
const;
305 virtual std::string shortID(
const std::string& valueId =
"val" )
const;
311 virtual std::string longID(
const std::string& valueId =
"val" )
const;
320 virtual void trimFlag( std::string& flag, std::string& value )
const;
328 bool _hasBlanks(
const std::string& s )
const;
335 void setRequireLabel(
const std::string& s );
359 inline Arg::Arg(
const std::string& flag,
360 const std::string& name,
361 const std::string& desc,
369 _requireLabel(
"required"),
370 _valueRequired(valreq),
376 if (
_flag.length() > 1 )
378 "Argument flag can only be one character long",
toString() ) );
391 (
_name.find(
" ", 0 ) != std::string::npos ) )
410 std::string delim =
" ";
414 id += delim +
"<" + valueId +
">";
422 inline std::string
Arg::longID(
const std::string& valueId )
const
431 id +=
" <" + valueId +
">";
439 id +=
" <" + valueId +
">";
460 std::string desc =
"";
527 for (
int i = 0; (
unsigned int)i < flag.length(); i++ )
536 value = flag.substr(stop+1);
537 flag = flag.substr(0,stop);
547 for (
int i = 1; (
unsigned int)i < s.length(); i++ )
570 argList.push_front( (
Arg*)
this );
579 #ifdef DtUSE_UTILITIES_NAMESPACE
virtual bool operator==(const Arg &a)
Operator ==.
Definition: cmdArg.h:445
virtual ~Arg()
Destructor.
Definition: cmdArg.h:399
bool isSet() const
Indicates whether the argument has already been set.
Definition: cmdArg.h:479
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:475
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:545
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
Definition: cmdArg.h:422
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:554
std::string getDescription() const
Returns the argument description.
Definition: cmdArg.h:458
const std::string & getName() const
Returns the argument name.
Definition: cmdArg.h:473
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:568
virtual std::string toString() const
Returns a simple string representation of the argument.
Definition: cmdArg.h:503
std::list< Visitor * >::iterator VisitorListIterator
Typedef of a Visitor list iterator.
Definition: cmdArg.h:352
bool _required
Indicating whether the argument is required.
Definition: cmdArg.h:92
void xorSet()
Sets the _alreadySet value to true.
Definition: cmdArg.h:559
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:489
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
Definition: cmdArg.h:401
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
This file declares the class DtCmdLine::ArgException.
const std::string & getFlag() const
Returns the argument flag.
Definition: cmdArg.h:471
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
Definition: cmdArg.h:342
virtual void visit()
Does nothing.
Definition: cmdVisitor.h:55
bool isValueRequired() const
Indicates whether a value must be specified for argument.
Definition: cmdArg.h:477
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:524
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:347
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:515
bool isIgnoreable() const
Indicates whether the argument can be ignored, if desired.
Definition: cmdArg.h:487
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
Definition: cmdArg.h:494