iRoCS Toolbox
1.1.0
|
The CmdArg class is the abstract base class for all command line arguments. More...
#include <CmdArg.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... | |
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 | |
CmdArg (char shortName, const std::string longName, const std::string valueName, const std::string description, CmdArg::Syntax syntax_flags=isOPTVALREQ) | |
Create an argument that takes a value. More... | |
CmdArg (char shortName, const std::string longName, const std::string description, CmdArg::Syntax syntax_flags=isOPT) | |
Create an argument that takes no value. More... | |
CmdArg (const std::string value, const std::string description, CmdArg::Syntax syntax=isPOSVALREQ) | |
Create a positional argument (no short and long names). More... | |
virtual | ~CmdArg () |
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 &cmd)=0 |
Parse a value string. 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... | |
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 =0 |
Returns the argument's value. More... | |
const std::string | valueName () const |
Returns the argument's value name. More... | |
virtual std::string | valueTypeAsString () const =0 |
Returns the argument's value type. 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 |
Friends | |
class | CmdLine |
The CmdArg class is the abstract base class for all command line arguments.
enum CmdArg::Syntax |
Flags that define the argument syntax.
enum CmdArg::CmdLineFlags |
Flags that say how the argument was specied on the command-line.
CmdArg::CmdArg | ( | char | shortName, |
const std::string | longName, | ||
const std::string | valueName, | ||
const std::string | description, | ||
CmdArg::Syntax | syntax_flags = isOPTVALREQ |
||
) |
Create an argument that takes a value.
The default flags are to assume that the argument is optional and that the value is required. If you don't want the argument to have a short name, set shortName=0. If you don't want the argument to have a long name, set longName="".
shortName | the short name of the argument |
longName | the long name of the argument |
valueName | the name of the value |
description | the argument's description |
syntax_flags |
CmdLineSyntaxError |
CmdArg::CmdArg | ( | char | shortName, |
const std::string | longName, | ||
const std::string | description, | ||
CmdArg::Syntax | syntax_flags = isOPT |
||
) |
Create an argument that takes no value.
The default flags are to assume that the argument is optional. If you don't want the argument to have a short name, set shortName=0. If you don't want the argument to have a long name, set longName="".
shortName | the short name of the argument |
longName | the long name of the argument |
description | the argument's description |
syntax_flags |
CmdLineSyntaxError |
CmdArg::CmdArg | ( | const std::string | value, |
const std::string | description, | ||
CmdArg::Syntax | syntax = isPOSVALREQ |
||
) |
Create a positional argument (no short and long names).
The default flags are to assume that the argument is positional and that the value is required.
valueName | the name of the value |
description | the argument's description |
syntax_flags |
CmdLineSyntaxError |
|
virtual |
Destructor.
|
virtual |
Return fixed size if this CmdArg is a fixed list, return 0 otherwise.
Reimplemented in CmdArgTypeFixedVector< T >.
Referenced by CmdArgTypeFixedVector< T >::remainingSize().
|
virtual |
Return number of remaining values if this CmdArg is a fixed list, return 0 otherwise.
Reimplemented in CmdArgTypeFixedVector< T >.
Referenced by CmdArgTypeFixedVector< T >::parse().
|
pure virtual |
Parse a value string.
If this argument does not take a value, or the value is optional and was NOT supplied, then "" is passed as arg. If arg was completely accepted, endptr is set to NULL. Otherwise it points to the first unparsed character in arg. If the parsing was successful, true is returned.
arg | string to parse |
endptr | pointer to the first unused char of arg, or NULL if all chars were parsed successfully |
cmd | reference to the CmdLine object that called the function |
Implemented in CmdArgThrow< E >, CmdArgThrow< CmdLineUsageXMLError >, CmdArgThrow< CmdLineUsageHTMLError >, CmdArgThrow< CmdLineUsageError >, CmdArgSwitch, CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.
CmdArg::Syntax CmdArg::syntax | ( | ) | const |
Retrieve the syntax flags for this argument.
bool CmdArg::hasSyntax | ( | CmdArg::Syntax | s | ) | const |
Returns true if the argument's syntax flags contain s.
s | syntax flag to be checked |
CmdArg::CmdLineFlags CmdArg::flags | ( | ) | const |
Retrieve the flags that say how this argument was specified.
bool CmdArg::hasFlag | ( | CmdArg::CmdLineFlags | f | ) | const |
Returns true if the argument's flags contain f.
s | flag to be checked |
unsigned int CmdArg::sequence | ( | ) | const |
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.
char CmdArg::shortName | ( | ) | const |
Returns the argument's short name.
Return's 0 if it has none.
const std::string CmdArg::longName | ( | ) | const |
Returns the argument's long name.
Return's "" if it has none.
const std::string CmdArg::valueName | ( | ) | const |
Returns the argument's value name.
Return's "" if it takes no value.
|
pure virtual |
Returns the argument's value type.
Implemented in CmdArgThrow< E >, CmdArgThrow< CmdLineUsageXMLError >, CmdArgThrow< CmdLineUsageHTMLError >, CmdArgThrow< CmdLineUsageError >, CmdArgSwitch, CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.
|
pure virtual |
Returns the argument's value.
Implemented in CmdArgThrow< E >, CmdArgThrow< CmdLineUsageXMLError >, CmdArgThrow< CmdLineUsageHTMLError >, CmdArgThrow< CmdLineUsageError >, CmdArgSwitch, CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.
const std::string CmdArg::description | ( | ) | const |
Get the description (help-message) of this argument.
const std::string CmdArg::synopsis | ( | bool | displayShort = true , |
bool | displayLong = true |
||
) | const |
Generates and returns the arguments synopsis.
displayShort | if true print short name |
displayLong | if true display long name |
const std::string CmdArg::errorMsg | ( | ) | const |
Returns error message of last parsing.
void CmdArg::clearErrorMsg | ( | ) |
Clears the error message.
void CmdArg::setErrorMsg | ( | const std::string & | msg | ) |
Sets the error message.
msg | new error message. |
bool CmdArg::modified | ( | ) | const |
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().
void CmdArg::modified | ( | bool | m | ) |
Sets the modified flag.
m |
bool CmdArg::given | ( | ) | const |
Returns true if the argument was parsed in any of the parsing runs.
|
virtual |
Returns true if a default value was specified.
Reimplemented in CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.
|
virtual |
Returns the default value as a string.
Reimplemented in CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.
|
virtual |
If the argument is a fixed list, this function clears all its values.
Reimplemented in CmdArgTypeFixedVector< T >.
|
protected |
Adjust and correct specified syntax flags.
CmdLineSyntaxError |
Referenced by CmdArgTypeFixedVector< T >::CmdArgTypeFixedVector().
|
protected |
Sets the argument's flags.
f | new flags |
|
protected |
Toggles specified flags.
f | flags to toggle |
|
protected |
Clears the specified flags.
f | flags to clear |
|
protected |
Sets the sequence number.
num | new sequence number |
|
protected |
|
protected |