26 #ifndef TCLAP_ARGUMENT_H
27 #define TCLAP_ARGUMENT_H
66 Arg& operator=(
const Arg& rhs);
71 static bool& ignoreRestRef() {
static bool ign =
false;
return ign; }
77 static char& delimiterRef() {
static char delim =
' ';
return delim; }
169 Arg(
const std::string& flag,
170 const std::string& name,
171 const std::string& desc,
186 virtual void addToList( std::list<Arg*>& argList )
const;
214 #ifndef TCLAP_FLAGSTARTCHAR
215 #define TCLAP_FLAGSTARTCHAR '-'
224 #ifndef TCLAP_FLAGSTARTSTRING
225 #define TCLAP_FLAGSTARTSTRING "-"
233 #ifndef TCLAP_NAMESTARTSTRING
234 #define TCLAP_NAMESTARTSTRING "--"
256 virtual bool processArg(
int *i, std::vector<std::string>& args) = 0;
268 const std::string&
getFlag()
const;
273 const std::string&
getName()
const;
321 virtual bool argMatches(
const std::string& s )
const;
327 virtual std::string
toString()
const;
333 virtual std::string
shortID(
const std::string& valueId =
"val" )
const;
339 virtual std::string
longID(
const std::string& valueId =
"val" )
const;
348 virtual void trimFlag( std::string& flag, std::string& value )
const;
356 bool _hasBlanks(
const std::string& s )
const;
381 virtual void reset();
405 template<
typename T>
void
408 static_cast<void>(vl);
412 while ( is.good() ) {
413 if ( is.peek() != EOF )
414 #ifdef TCLAP_SETBASE_ZERO
415 is >> std::setbase(0) >> destVal;
427 "from string '" + strVal +
"'"));
430 if ( valuesRead > 1 )
432 "string '" + strVal +
"'"));
442 template<
typename T>
void
445 static_cast<void>(sl);
453 inline Arg::Arg(
const std::string& flag,
454 const std::string& name,
455 const std::string& desc,
463 _requireLabel(
"required"),
464 _valueRequired(valreq),
469 _acceptsMultipleValues(false)
471 if (
_flag.length() > 1 )
473 "Argument flag can only be one character long",
toString() ) );
486 (
_name.find(
" ", 0 ) != std::string::npos ) )
514 inline std::string
Arg::longID(
const std::string& valueId )
const
547 std::string desc =
"";
614 for (
int i = 0;
static_cast<unsigned int>(i) < flag.length(); i++ )
623 value = flag.substr(stop+1);
624 flag = flag.substr(0,stop);
634 for (
int i = 1;
static_cast<unsigned int>(i) < s.length(); i++ )
657 argList.push_front(
const_cast<Arg*
>(
this) );
#define TCLAP_FLAGSTARTSTRING
The sting that indicates the beginning of a flag.
#define TCLAP_FLAGSTARTCHAR
The char that indicates the beginning of a flag.
#define TCLAP_NAMESTARTSTRING
The sting that indicates the beginning of a name.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
A virtual base class that defines the essential data for all arguments.
static char blankChar()
The char used as a place holder when SwitchArgs are combined.
void _checkWithVisitor() const
Performs the special handling described by the Visitor.
bool _acceptsMultipleValues
virtual ~Arg()
Destructor.
bool isSet() const
Indicates whether the argument has already been set.
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
static const std::string nameStartString()
static void beginIgnoring()
Begin ignoring arguments since the "--" argument was specified.
std::string _requireLabel
Label to be used in usage description.
bool _hasBlanks(const std::string &s) const
Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
static bool ignoreRest()
Whether to ignore the rest.
bool isIgnoreable() const
Indicates whether the argument can be ignored, if desired.
void forceRequired()
Sets _required to true.
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...
const std::string & getFlag() const
Returns the argument flag.
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
bool _valueRequired
Indicates whether a value is required for the argument.
bool isValueRequired() const
Indicates whether a value must be specified for argument.
static char flagStartChar()
bool _alreadySet
Indicates whether the argument has been set.
bool _ignoreable
Whether this argument can be ignored, if desired.
std::string _description
Description of the argument.
virtual void addToList(std::list< Arg * > &argList) const
Adds this to the specified list of Args.
virtual bool allowMore()
Used for MultiArgs and XorHandler to determine whether args can still be set.
const std::string & getName() const
Returns the argument name.
Visitor * _visitor
A pointer to a visitor object.
static char delimiter()
The delimiter that separates an argument flag/name from the value.
void setRequireLabel(const std::string &s)
Sets the requireLabel.
std::string getDescription() const
Returns the argument description.
bool _xorSet
Indicates that the arg was set as part of an XOR and not on the command line.
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
std::string _name
A single word namd identifying the argument.
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
static void setDelimiter(char c)
Sets the delimiter for all arguments.
bool _required
Indicating whether the argument is required.
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
virtual void trimFlag(std::string &flag, std::string &value) const
Trims a value off of the flag.
virtual std::string toString() const
Returns a simple string representation of the argument.
std::string _flag
The single char flag used to identify the argument.
void xorSet()
Sets the _alreadySet value to true.
virtual bool isRequired() const
Indicates whether the argument is required.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
virtual bool operator==(const Arg &a) const
Operator ==.
static const std::string flagStartString()
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
A base class that defines the interface for visitors.
virtual void visit()=0
This method (to implemented by children) will be called when the visitor is visited.
std::vector< Arg * >::const_iterator ArgVectorIterator
Typedef of an Arg vector iterator.
std::istringstream istringstream
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.
std::list< Visitor * >::const_iterator VisitorListIterator
Typedef of a Visitor list iterator.
void SetString(T &dst, const std::string &src)
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
A string like argument value type is a value that can be set using operator=(string).
A value like argument value type is a value that can be set using operator>>.