tclap 1.6.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TCLAP::ValueArg< T > Class Template Reference

The basic labeled argument that parses a value. More...

#include <ValueArg.h>

Inheritance diagram for TCLAP::ValueArg< T >:
Inheritance graph
[legend]
Collaboration diagram for TCLAP::ValueArg< T >:
Collaboration graph
[legend]

Public Member Functions

 ValueArg (const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, std::string typeDesc, Visitor *v=nullptr)
 Labeled ValueArg constructor.
 
 ValueArg (const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, std::string typeDesc, ArgContainer &parser, Visitor *v=nullptr)
 Labeled ValueArg constructor.
 
 ValueArg (const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, const Constraint< T > *constraint, ArgContainer &parser, Visitor *v=nullptr)
 Labeled ValueArg constructor.
 
 ValueArg (const std::string &flag, const std::string &name, const std::string &desc, bool req, T value, const Constraint< T > *constraint, Visitor *v=nullptr)
 Labeled ValueArg constructor.
 
bool processArg (int *i, std::vector< std::string > &args) override
 Handles the processing of the argument.
 
const T & getValue () const noexcept
 Returns the value of the argument.
 
 operator const T & () const noexcept
 A ValueArg can be used as as its value type (T) This is the same as calling getValue()
 
std::string shortID (const std::string &val="val") const override
 Specialization of shortID.
 
std::string longID (const std::string &val="val") const override
 Specialization of longID.
 
void reset () override
 Clears the Arg object and allows it to be reused by new command lines.
 
 ValueArg (const ValueArg< T > &rhs)=delete
 Prevent accidental copying.
 
ValueArg & operator= (const ValueArg< T > &rhs)=delete
 
- Public Member Functions inherited from TCLAP::Arg
 Arg (const Arg &rhs)=delete
 Prevent accidental copying.
 
Arg & operator= (const Arg &rhs)=delete
 
Arg & addAlias (std::string flag, std::string name={})
 Add equivalent spellings before registration.
 
const std::vector< ArgAlias > & aliases () const noexcept
 Alias spellings in insertion order; no prefixes are stored.
 
virtual ~Arg ()=default
 Destructor.
 
virtual void addToList (std::list< Arg * > &argList) const
 Adds this to the specified list of Args.
 
char getDelimiter () const
 Returns this argument's parser delimiter, or the legacy default.
 
virtual bool operator== (const Arg &a) const
 Operator ==.
 
bool conflictsWith (const Arg &a) const noexcept
 Checks declared registration conflicts: the same object, the same name, or the same nonempty short flag, including aliases.
 
const std::string & getFlag () const noexcept
 Returns the argument flag.
 
const std::string & getName () const noexcept
 Returns the argument name.
 
std::string getDescription () const
 Returns the argument description.
 
virtual void setDescription (const std::string &desc)
 Updates the argument description.
 
std::string getDescription (bool required) const
 Returns the argument description.
 
virtual bool isRequired () const
 Indicates whether the argument is required.
 
bool isValueRequired () const noexcept
 Indicates whether a value must be specified for argument.
 
bool isSet () const noexcept
 Indicates whether the argument has already been set.
 
const std::string & setBy () const noexcept
 Returns the value specified to set this flag (like -a or –all).
 
bool isIgnoreable () const noexcept
 Indicates whether the argument can be ignored, if desired.
 
virtual bool argMatches (const std::string &s) const
 A method that tests whether a string matches this argument.
 
virtual std::string toString () const
 Returns a simple string representation of the argument.
 
virtual void trimFlag (std::string &flag, std::string &value) const
 Trims a value off of the flag.
 
bool _hasBlanks (const std::string &s) const
 Checks whether a given string has blank chars, indicating that it is a combined SwitchArg.
 
virtual bool allowMore ()
 Used for MultiArgs to determine whether args can still be set.
 
virtual bool acceptsMultipleValues ()
 Use by output classes to determine whether an Arg accepts multiple values.
 
virtual void hideFromHelp (bool hide=true)
 Hide this argument from the help output (e.g., when specifying the –help flag or on error.
 
virtual bool visibleInHelp () const
 Returns true if this Arg is visible in the help output.
 
virtual bool hasLabel () const
 

Protected Member Functions

void _extractValue (const std::string &val)
 Extracts the value from the string.
 
- Protected Member Functions inherited from TCLAP::Arg
bool matchesShortFlag (const std::string &flag) const
 
bool matchesLongName (const std::string &name) const
 
void _checkWithVisitor () const
 Performs the special handling described by the Visitor.
 
 Arg (std::string flag, std::string name, std::string desc, bool req, bool valreq, Visitor *v=nullptr)
 Primary constructor.
 

Protected Attributes

T _value
 The value parsed from the command line.
 
T _default
 Used to support the reset() method so that ValueArg can be reset to their constructed value.
 
std::string _typeDesc
 A human readable description of the type to be parsed.
 
const Constraint< T > * _constraint
 A Constraint this Arg must conform to.
 
- Protected Attributes inherited from TCLAP::Arg
std::string _flag
 The single char flag used to identify the argument.
 
std::string _name
 A single word namd identifying the argument.
 
std::string _description
 Description of the argument.
 
const bool _required
 Indicating whether the argument is required.
 
std::string _requireLabel
 Label to be used in usage description.
 
bool _valueRequired
 Indicates whether a value is required for the argument.
 
bool _alreadySet
 Indicates whether the argument has been set.
 
std::string _setBy
 Indicates the value specified to set this flag (like -a or –all).
 
Visitor * _visitor
 A pointer to a visitor object.
 
bool _ignoreable
 Whether this argument can be ignored, if desired.
 
bool _acceptsMultipleValues
 
bool _visibleInHelp
 Indicates if the argument is visible in the help output (e.g., when specifying –help).
 

Additional Inherited Members

- Static Public Member Functions inherited from TCLAP::Arg
static char delimiter ()
 The delimiter that separates an argument flag/name from the value.
 
static constexpr char blankChar () noexcept
 The char used as a place holder when SwitchArgs are combined.
 
static constexpr char flagStartChar () noexcept
 
static std::string flagStartString ()
 
static std::string nameStartString ()
 
static std::string ignoreNameString ()
 The name used to identify the ignore rest argument.
 
static void setDelimiter (char c)
 Sets the legacy delimiter for unregistered arguments and static callers.
 

Detailed Description

template<class T>
class TCLAP::ValueArg< T >

The basic labeled argument that parses a value.

This is a template class, which means the type T defines the type that a given object will attempt to parse when the flag/name is matched on the command line. While there is nothing stopping you from creating an unflagged ValueArg, it is unwise and would cause significant problems. Instead use an UnlabeledValueArg.

Definition at line 46 of file ValueArg.h.

Constructor & Destructor Documentation

◆ ValueArg() [1/5]

template<class T >
TCLAP::ValueArg< T >::ValueArg ( const std::string &  flag,
const std::string &  name,
const std::string &  desc,
bool  req,
T  value,
std::string  typeDesc,
Visitor *  v = nullptr 
)

Labeled ValueArg constructor.

Constructor implementation.

Parameters
flag- The one character flag that identifies this argument on the command line.
name- A one word name for the argument. Can be used as a long flag on the command line.
desc- A description of what the argument is for or does.
req- Whether the argument is required on the command line.
value- The default value assigned to this argument if it is not present on the command line.
typeDesc- A short, human readable description of the type that this object expects. This is used in the generation of the USAGE statement. The goal is to be helpful to the end user of the program.
v- An optional visitor. You probably should not use this unless you have a very good reason.

Definition at line 233 of file ValueArg.h.

◆ ValueArg() [2/5]

template<class T >
TCLAP::ValueArg< T >::ValueArg ( const std::string &  flag,
const std::string &  name,
const std::string &  desc,
bool  req,
T  value,
std::string  typeDesc,
ArgContainer &  parser,
Visitor *  v = nullptr 
)

Labeled ValueArg constructor.

Parameters
flag- The one character flag that identifies this argument on the command line.
name- A one word name for the argument. Can be used as a long flag on the command line.
desc- A description of what the argument is for or does.
req- Whether the argument is required on the command line.
value- The default value assigned to this argument if it is not present on the command line.
typeDesc- A short, human readable description of the type that this object expects. This is used in the generation of the USAGE statement. The goal is to be helpful to the end user of the program.
parser- A CmdLine parser object to add this Arg to
v- An optional visitor. You probably should not use this unless you have a very good reason.

Definition at line 243 of file ValueArg.h.

References TCLAP::ArgContainer::add().

Here is the call graph for this function:

◆ ValueArg() [3/5]

template<class T >
TCLAP::ValueArg< T >::ValueArg ( const std::string &  flag,
const std::string &  name,
const std::string &  desc,
bool  req,
T  value,
const Constraint< T > *  constraint,
ArgContainer &  parser,
Visitor *  v = nullptr 
)

Labeled ValueArg constructor.

Parameters
flag- The one character flag that identifies this argument on the command line.
name- A one word name for the argument. Can be used as a long flag on the command line.
desc- A description of what the argument is for or does.
req- Whether the argument is required on the command line.
value- The default value assigned to this argument if it is not present on the command line.
constraint- A pointer to a Constraint object used to constrain this Arg.
parser- A CmdLine parser object to add this Arg to.
v- An optional visitor. You probably should not use this unless you have a very good reason.

Definition at line 266 of file ValueArg.h.

References TCLAP::ArgContainer::add().

Here is the call graph for this function:

◆ ValueArg() [4/5]

template<class T >
TCLAP::ValueArg< T >::ValueArg ( const std::string &  flag,
const std::string &  name,
const std::string &  desc,
bool  req,
T  value,
const Constraint< T > *  constraint,
Visitor *  v = nullptr 
)

Labeled ValueArg constructor.

Parameters
flag- The one character flag that identifies this argument on the command line.
name- A one word name for the argument. Can be used as a long flag on the command line.
desc- A description of what the argument is for or does.
req- Whether the argument is required on the command line.
value- The default value assigned to this argument if it is not present on the command line.
constraint- A pointer to a Constraint object used to constrain this Arg.
v- An optional visitor. You probably should not use this unless you have a very good reason.

Definition at line 256 of file ValueArg.h.

◆ ValueArg() [5/5]

template<class T >
TCLAP::ValueArg< T >::ValueArg ( const ValueArg< T > &  rhs)
delete

Prevent accidental copying.

Member Function Documentation

◆ _extractValue()

template<class T >
requires detail::ValidArgValueType<T>
void TCLAP::ValueArg< T >::_extractValue ( const std::string &  val)
protected

Extracts the value from the string.

Attempts to parse string as type T, if this fails an exception is thrown.

Parameters
val- value to be parsed.

Definition at line 341 of file ValueArg.h.

References TCLAP::ArgException::error(), and TCLAP::ExtractValue().

Here is the call graph for this function:

◆ getValue()

template<class T >
const T & TCLAP::ValueArg< T >::getValue ( ) const
inlinenoexcept

Returns the value of the argument.

Definition at line 195 of file ValueArg.h.

References TCLAP::ValueArg< T >::_value.

Referenced by TCLAP::ValueArg< T >::operator const T &().

◆ longID()

template<class T >
std::string TCLAP::ValueArg< T >::longID ( const std::string &  val = "val") const
overridevirtual

Specialization of longID.

Implementation of longID.

Parameters
val- value to be used.

Reimplemented from TCLAP::Arg.

Definition at line 336 of file ValueArg.h.

References TCLAP::Arg::longID().

Here is the call graph for this function:

◆ operator const T &()

template<class T >
TCLAP::ValueArg< T >::operator const T & ( ) const
inlinenoexcept

A ValueArg can be used as as its value type (T) This is the same as calling getValue()

Definition at line 201 of file ValueArg.h.

References TCLAP::ValueArg< T >::getValue().

Here is the call graph for this function:

◆ operator=()

template<class T >
ValueArg & TCLAP::ValueArg< T >::operator= ( const ValueArg< T > &  rhs)
delete

◆ processArg()

template<class T >
bool TCLAP::ValueArg< T >::processArg ( int *  i,
std::vector< std::string > &  args 
)
overridevirtual

Handles the processing of the argument.

Implementation of processArg().

This re-implements the Arg version of this method to set the _value of the argument appropriately. It knows the difference between labeled and unlabeled.

Parameters
i- Pointer the the current argument in the list.
args- Mutable list of strings. Passed in from main().

Implements TCLAP::Arg.

Definition at line 282 of file ValueArg.h.

◆ reset()

template<class T >
void TCLAP::ValueArg< T >::reset ( )
overridevirtual

Clears the Arg object and allows it to be reused by new command lines.

Reimplemented from TCLAP::Arg.

Definition at line 358 of file ValueArg.h.

References TCLAP::Arg::reset().

Here is the call graph for this function:

◆ shortID()

template<class T >
std::string TCLAP::ValueArg< T >::shortID ( const std::string &  val = "val") const
overridevirtual

Specialization of shortID.

Implementation of shortID.

Parameters
val- value to be used.

Reimplemented from TCLAP::Arg.

Definition at line 328 of file ValueArg.h.

References TCLAP::Arg::shortID().

Here is the call graph for this function:

Member Data Documentation

◆ _constraint

template<class T >
const Constraint<T>* TCLAP::ValueArg< T >::_constraint
protected

A Constraint this Arg must conform to.

Definition at line 73 of file ValueArg.h.

◆ _default

template<class T >
T TCLAP::ValueArg< T >::_default
protected

Used to support the reset() method so that ValueArg can be reset to their constructed value.

Definition at line 59 of file ValueArg.h.

◆ _typeDesc

template<class T >
std::string TCLAP::ValueArg< T >::_typeDesc
protected

A human readable description of the type to be parsed.

This is a hack, plain and simple. Ideally we would use RTTI to return the name of type T, but until there is some sort of consistent support for human readable names, we are left to our own devices.

Definition at line 68 of file ValueArg.h.

Referenced by TCLAP::UnlabeledValueArg< T >::longID().

◆ _value

template<class T >
T TCLAP::ValueArg< T >::_value
protected

The value parsed from the command line.

Can be of any type, as long as the >> operator for the type is defined.

Definition at line 53 of file ValueArg.h.

Referenced by TCLAP::ValueArg< T >::getValue().


The documentation for this class was generated from the following file: