Go to the documentation of this file.
25 #ifndef TCLAP_ARGUMENT_H
26 #define TCLAP_ARGUMENT_H
41 #if defined(HAVE_SSTREAM)
44 #elif defined(HAVE_STRSTREAM)
48 #error "Need a stringstream (sstream or strstream) to compile!"
75 Arg& operator=(
const Arg& rhs);
80 static bool& ignoreRestRef() {
static bool ign =
false;
return ign; }
86 static char& delimiterRef() {
static char delim =
' ';
return delim; }
178 Arg(
const std::string& flag,
179 const std::string& name,
180 const std::string& desc,
195 virtual void addToList( std::list<Arg*>& argList )
const;
223 #ifndef TCLAP_FLAGSTARTCHAR
224 #define TCLAP_FLAGSTARTCHAR '-'
233 #ifndef TCLAP_FLAGSTARTSTRING
234 #define TCLAP_FLAGSTARTSTRING "-"
242 #ifndef TCLAP_NAMESTARTSTRING
243 #define TCLAP_NAMESTARTSTRING "--"
265 virtual bool processArg(
int *i, std::vector<std::string>& args) = 0;
277 const std::string&
getFlag()
const;
282 const std::string&
getName()
const;
330 virtual bool argMatches(
const std::string& s )
const;
336 virtual std::string
toString()
const;
342 virtual std::string
shortID(
const std::string& valueId =
"val" )
const;
348 virtual std::string
longID(
const std::string& valueId =
"val" )
const;
357 virtual void trimFlag( std::string& flag, std::string& value )
const;
365 bool _hasBlanks(
const std::string& s )
const;
390 virtual void reset();
414 template<
typename T>
void
417 static_cast<void>(vl);
421 while ( is.good() ) {
422 if ( is.peek() != EOF )
423 #ifdef TCLAP_SETBASE_ZERO
424 is >> std::setbase(0) >> destVal;
436 "from string '" + strVal +
"'"));
439 if ( valuesRead > 1 )
441 "string '" + strVal +
"'"));
451 template<
typename T>
void
454 static_cast<void>(sl);
462 inline Arg::Arg(
const std::string& flag,
463 const std::string& name,
464 const std::string& desc,
472 _requireLabel(
"required"),
473 _valueRequired(valreq),
478 _acceptsMultipleValues(false)
480 if (
_flag.length() > 1 )
482 "Argument flag can only be one character long",
toString() ) );
495 (
_name.find(
" ", 0 ) != std::string::npos ) )
523 inline std::string
Arg::longID(
const std::string& valueId )
const
556 std::string desc =
"";
623 for (
int i = 0;
static_cast<unsigned int>(i) < flag.length(); i++ )
632 value = flag.substr(stop+1);
633 flag = flag.substr(0,stop);
643 for (
int i = 1;
static_cast<unsigned int>(i) < s.length(); i++ )
666 argList.push_front(
const_cast<Arg*
>(
this) );
void _checkWithVisitor() const
Performs the special handling described by the Vistitor.
bool _hasBlanks(const std::string &s) const
Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
virtual void visit()
Does nothing.
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.
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
virtual bool operator==(const Arg &a) const
Operator ==.
bool isIgnoreable() const
Indicates whether the argument can be ignored, if desired.
static const std::string flagStartString()
virtual std::string toString() const
Returns a simple string representation of the argument.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
bool _ignoreable
Whether this argument can be ignored, if desired.
A string like argument value type is a value that can be set using operator=(string).
void SetString(T &dst, const std::string &src)
void ExtractValue(T &destVal, const std::string &strVal, ValueLike vl)
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
static bool ignoreRest()
Whether to ignore the rest.
std::string _requireLabel
Label to be used in usage description.
virtual void trimFlag(std::string &flag, std::string &value) const
Trims a value off of the flag.
std::string getDescription() const
Returns the argument description.
static char blankChar()
The char used as a place holder when SwitchArgs are combined.
#define TCLAP_FLAGSTARTCHAR
The char that indicates the beginning of a flag.
std::string _name
A single work namd indentifying the argument.
std::istringstream istringstream
virtual void reset()
Clears the Arg object and allows it to be reused by new command lines.
A value like argument value type is a value that can be set using operator>>.
bool _acceptsMultipleValues
bool _required
Indicating whether the argument is required.
static void setDelimiter(char c)
Sets the delimiter for all arguments.
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
std::string _description
Description of the argument.
virtual ~Arg()
Destructor.
Thrown from within the child Arg classes when it fails to properly parse the argument it has been pas...
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
const std::string & getFlag() const
Returns the argument flag.
virtual void addToList(std::list< Arg * > &argList) const
Adds this to the specified list of Args.
bool isSet() const
Indicates whether the argument has already been set.
static void beginIgnoring()
Begin ignoring arguments since the "--" argument was specified.
std::list< Visitor * >::iterator VisitorListIterator
Typedef of a Visitor list iterator.
Visitor * _visitor
A pointer to a vistitor object.
#define TCLAP_NAMESTARTSTRING
The sting that indicates the beginning of a name.
void forceRequired()
Sets _required to true.
void xorSet()
Sets the _alreadySet value to true.
static char flagStartChar()
static const std::string nameStartString()
A base class that defines the interface for visitors.
bool _xorSet
Indicates that the arg was set as part of an XOR and not on the command line.
virtual bool argMatches(const std::string &s) const
A method that tests whether a string matches this argument.
void setRequireLabel(const std::string &s)
Sets the requireLabel.
bool isValueRequired() const
Indicates whether a value must be specified for argument.
static char delimiter()
The delimiter that separates an argument flag/name from the value.
Thrown from Arg and CmdLine when an Arg is improperly specified, e.g.
bool _valueRequired
Indicates whether a value is required for the argument.
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...
bool _alreadySet
Indicates whether the argument has been set.
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
std::string _flag
The single char flag used to identify the argument.
#define TCLAP_FLAGSTARTSTRING
The sting that indicates the beginning of a flag.
virtual bool isRequired() const
Indicates whether the argument is required.
A virtual base class that defines the essential data for all arguments.