iRoCS Toolbox
1.1.0
|
The CmdArgTypeVector<T> class is a CmdArg that takes a list of values of type T. More...
#include <CmdArgs.hh>
Public Types | |
enum | CmdLineFlags { GIVEN = 0x01, VALGIVEN = 0x02, OPTION = 0x04, KEYWORD = 0x08, POSITIONAL = 0x10, VALSEP = 0x20, ALLFLAGS = 0x3F } |
Flags that say how the argument was specied on the command-line. More... | |
typedef CmdArgTypeVector< T >::const_iterator | const_iterator |
enum | Syntax { isOPT = 0x000, isREQ = 0x001, isVALOPT = 0x002, isVALREQ = 0x004, isVALSEP = 0x008, isVALSTICKY = 0x010, isLIST = 0x020, isPOS = 0x040, isHIDDEN = 0x080, isFIXEDLIST = 0x100, isVALTAKEN = (isVALREQ | isVALOPT), isOPTVALOPT = (isOPT | isVALOPT), isOPTVALREQ = (isOPT | isVALREQ), isPOSVALOPT = (isPOS | isVALOPT), isPOSVALREQ = (isPOS | isVALREQ) } |
Flags that define the argument syntax. More... | |
Public Member Functions | |
CmdArgTypeVector (char aShortName, const std::string aLongName, const std::string aValueName, const std::string aDescription, Syntax aSyntax=Syntax(isOPTVALREQ|isLIST)) | |
Constructor. More... | |
CmdArgTypeVector (const std::string aValueName, const std::string aDescription, Syntax aSyntax=Syntax(isPOSVALREQ|isLIST)) | |
Constructor. More... | |
virtual | ~CmdArgTypeVector () |
Destructor. More... | |
void | clearErrorMsg () |
Clears the error message. More... | |
virtual void | clearFixedList () |
If the argument is a fixed list, this function clears all its values. More... | |
const std::string | description () const |
Get the description (help-message) of this argument. More... | |
const std::string | errorMsg () const |
Returns error message of last parsing. More... | |
virtual unsigned int | fixedSize () const |
Return fixed size if this CmdArg is a fixed list, return 0 otherwise. More... | |
CmdArg::CmdLineFlags | flags () const |
Retrieve the flags that say how this argument was specified. More... | |
virtual std::string | getDefaultValueString () const |
Returns the default value as a string. More... | |
bool | given () const |
Returns true if the argument was parsed in any of the parsing runs. More... | |
virtual bool | hasDefaultValue () const |
Returns true if a default value was specified. More... | |
bool | hasFlag (CmdArg::CmdLineFlags f) const |
Returns true if the argument's flags contain f. More... | |
bool | hasSyntax (CmdArg::Syntax s) const |
Returns true if the argument's syntax flags contain s. More... | |
const std::string | longName () const |
Returns the argument's long name. More... | |
bool | modified () const |
Returns true if the argument was parsed at the last parsing run. More... | |
void | modified (bool m) |
Sets the modified flag. More... | |
virtual bool | parse (const char *arg, const char *&endptr, CmdLine &) |
Parse value string and append it to the vector. More... | |
virtual unsigned int | remainingSize () const |
Return number of remaining values if this CmdArg is a fixed list, return 0 otherwise. More... | |
unsigned int | sequence () const |
Get the sequence number corresponding to the last time this argument was matched on the command-line. More... | |
virtual void | setDefaultValue (const std::vector< T > &v) |
Specify default value. More... | |
void | setErrorMsg (const std::string &msg) |
Sets the error message. More... | |
char | shortName () const |
Returns the argument's short name. More... | |
const std::string | synopsis (bool displayShort=true, bool displayLong=true) const |
Generates and returns the arguments synopsis. More... | |
CmdArg::Syntax | syntax () const |
Retrieve the syntax flags for this argument. More... | |
virtual std::string | valueAsString () const |
Return the value as a std::string. More... | |
const std::string | valueName () const |
Returns the argument's value name. More... | |
virtual std::string | valueTypeAsString () const |
Return the value type as a std::string. More... | |
Data Fields | |
T | elements |
STL member. More... | |
Protected Member Functions | |
void | adjustSyntax () |
Adjust and correct specified syntax flags. More... | |
void | clearFlags (CmdArg::CmdLineFlags f=ALLFLAGS) |
Clears the specified flags. More... | |
void | flags (CmdArg::CmdLineFlags f) |
Sets the argument's flags. More... | |
void | sequence (unsigned int num) |
Sets the sequence number. More... | |
void | setFlags (CmdArg::CmdLineFlags f) |
Toggles specified flags. More... | |
Protected Attributes | |
std::string | pDescription |
std::string | pErrorMessage |
CmdArg::CmdLineFlags | pFlags |
std::string | pLongName |
bool | pModified |
unsigned int | pSequence |
char | pShortName |
CmdArg::Syntax | pSyntax |
std::string | pValueName |
The CmdArgTypeVector<T> class is a CmdArg that takes a list of values of type T.
Since it is derived from std::vector<T> you can use it like a std::vector<T>.
The CmdArgTypeVector<T> class is a CmdArg that (optionally) takes a list of values of type T. For parsing it uses the Compiler<T> template class. Since it is derived from std::vector<T> you can use it like a std::vector<T>.
If you execute the program like this
sum 1 2 3
the output is
6
Definition at line 413 of file CmdArgs.hh.
typedef CmdArgTypeVector<T>::const_iterator CmdArgTypeVector< T >::const_iterator |
Definition at line 417 of file CmdArgs.hh.
|
inherited |
Flags that define the argument syntax.
|
inherited |
Flags that say how the argument was specied on the command-line.
|
inline |
Constructor.
Creates a CmdArgTypeVector with short and long name. By default the syntax flags are set so that the argument is optional and its values are required.
aShortName | short name of the argument |
aLongName | long name of the argument |
aValueName | name of the agrument's value |
aDescription | description of the argument |
aSyntax | syntax flags |
CmdLineSyntaxError |
Definition at line 434 of file CmdArgs.hh.
|
inline |
Constructor.
Creates a positional CmdArgTypeVector. By default the syntax flags are set so that the argument's values are required.
aValueName | name of the agrument's value |
aDescription | description of the argument |
aSyntax | syntax flags |
CmdLineSyntaxError |
Definition at line 459 of file CmdArgs.hh.
|
inlinevirtual |
Destructor.
Definition at line 473 of file CmdArgs.hh.
|
inlinevirtual |
|
inlinevirtual |
Returns true if a default value was specified.
Reimplemented from CmdArg.
Definition at line 501 of file CmdArgs.hh.
|
inlinevirtual |
Returns the default value as a string.
Reimplemented from CmdArg.
Definition at line 515 of file CmdArgs.hh.
|
inlinevirtual |
Parse value string and append it to the vector.
If the given arg could not be parsed correctly a CmdLineSyntaxError exception is thrown.
arg | the string that is to be parsed |
endptr | is set to the first unparsed character of arg |
cmd | reference to the CmdLine object that initiated the parsing (is ignored) |
CmdLineSyntaxError |
Implements CmdArg.
Definition at line 547 of file CmdArgs.hh.
|
inlinevirtual |
Return the value type as a std::string.
Implements CmdArg.
Definition at line 580 of file CmdArgs.hh.
|
inlinevirtual |
Return the value as a std::string.
Implements CmdArg.
Definition at line 593 of file CmdArgs.hh.
|
virtualinherited |
Return fixed size if this CmdArg is a fixed list, return 0 otherwise.
Reimplemented in CmdArgTypeFixedVector< T >.
Referenced by CmdArgTypeFixedVector< T >::remainingSize().
|
virtualinherited |
Return number of remaining values if this CmdArg is a fixed list, return 0 otherwise.
Reimplemented in CmdArgTypeFixedVector< T >.
Referenced by CmdArgTypeFixedVector< T >::parse().
|
inherited |
Retrieve the syntax flags for this argument.
|
inherited |
Returns true if the argument's syntax flags contain s.
s | syntax flag to be checked |
|
inherited |
Retrieve the flags that say how this argument was specified.
|
protectedinherited |
Sets the argument's flags.
f | new flags |
|
inherited |
Returns true if the argument's flags contain f.
s | flag to be checked |
|
inherited |
Get the sequence number corresponding to the last time this argument was matched on the command-line.
If this argument was not matched, the sequence number will be zero, otherwise it will be 'N' where the last time this argument was matched, it was the 'N'th argument encountered.
|
protectedinherited |
Sets the sequence number.
num | new sequence number |
|
inherited |
Returns the argument's short name.
Return's 0 if it has none.
|
inherited |
Returns the argument's long name.
Return's "" if it has none.
|
inherited |
Returns the argument's value name.
Return's "" if it takes no value.
|
inherited |
Get the description (help-message) of this argument.
|
inherited |
Generates and returns the arguments synopsis.
displayShort | if true print short name |
displayLong | if true display long name |
|
inherited |
Returns error message of last parsing.
|
inherited |
Clears the error message.
|
inherited |
Sets the error message.
msg | new error message. |
|
inherited |
Returns true if the argument was parsed at the last parsing run.
Referenced by CmdArgType< T >::parse(), CmdArgTypeVector< T >::parse(), CmdArgTypeFixedVector< T >::parse(), and CmdArgSwitch::parse().
|
inherited |
Sets the modified flag.
m |
|
inherited |
Returns true if the argument was parsed in any of the parsing runs.
|
virtualinherited |
If the argument is a fixed list, this function clears all its values.
Reimplemented in CmdArgTypeFixedVector< T >.
|
protectedinherited |
Adjust and correct specified syntax flags.
CmdLineSyntaxError |
Referenced by CmdArgTypeFixedVector< T >::CmdArgTypeFixedVector().
|
protectedinherited |
Toggles specified flags.
f | flags to toggle |
|
protectedinherited |
Clears the specified flags.
f | flags to clear |
|
protectedinherited |
|
protectedinherited |
|
inherited |
STL member.