iRoCS Toolbox
1.1.0
|
The CmdLine class is a parser for command line arguments. More...
#include <CmdLine.hh>
Public Types | |
enum | CmdLineFlags { FLAG_ANY_CASE_OPTS = 0x001, FLAG_PROMPT_USER = 0x002, FLAG_NO_ABORT = 0x004, FLAG_OPTS_FIRST = 0x008, FLAG_QUIET = 0x080, FLAG_ALL = 0x0FF } |
Configuration flags for CmdLine. More... | |
enum | CmdLineParseState { PARSE_START_STATE = 0x00, PARSE_TOK_REQUIRED = 0x01, PARSE_WANT_VAL = 0x02, PARSE_NEED_VAL = (PARSE_WANT_VAL | PARSE_TOK_REQUIRED), PARSE_ALL = 0x07 } |
Parsing state flags for CmdLine. More... | |
enum | CmdLineState { STATE_START_STATE = 0x00, STATE_END_OF_OPTIONS = 0x01, STATE_SHORT_USED = 0x02, STATE_LONG_USED = 0x04, STATE_ALL = 0x07 } |
State flags for CmdLine. More... | |
enum | CmdLineStatus { STATUS_NO_ERROR = 0x000, STATUS_ARG_MISSING = 0x001, STATUS_VAL_MISSING = 0x002, STATUS_VAL_NOTSTICKY = 0x004, STATUS_VAL_NOTSEP = 0x008, STATUS_KWD_AMBIGUOUS = 0x010, STATUS_BAD_OPTION = 0x020, STATUS_BAD_KEYWORD = 0x040, STATUS_BAD_VALUE = 0x080, STATUS_TOO_MANY_ARGS = 0x100 } |
Status flags for CmdLine. More... | |
Public Member Functions | |
CmdLine (std::string name, std::string longname, bool help=true) | |
Constructor. More... | |
CmdLine (std::string name, std::string longname, bool help, CmdArg *cmdarg1 ...) | |
Constructor. More... | |
virtual | ~CmdLine () |
Destructor. More... | |
CmdLine & | append (CmdArg *cmdarg) |
Append specified CmdArg to the list of CmdArgs. More... | |
CmdLine & | append (CmdArg &cmdarg) |
Append specified CmdArg to the list of CmdArgs. More... | |
void | clearFlags (CmdLine::CmdLineFlags f=FLAG_ALL) |
Clear only the given flags. More... | |
void | clearState (CmdLine::CmdLineState s=STATE_ALL) |
Clear only the given state flags. More... | |
std::string | description () const |
Return previously specified program description. More... | |
void | description (const std::string &description) |
Specify program description. More... | |
CmdLine::CmdLineStatus | epilogue () |
Perform the necessary post-processing. More... | |
std::ostream & | error () const |
Return CmdLine's error output stream. More... | |
void | error (std::ostream &os) |
Specify CmdLine's error output stream. More... | |
CmdLine::CmdLineFlags | flags () const |
Return CmdLine's flags. More... | |
void | flags (CmdLine::CmdLineFlags f) |
Specify new set of flags. More... | |
CmdArg * | getArg (char shortName) const |
Retrieve an argument based on its short name. More... | |
CmdArg * | getArg (const std::string &keyword) const |
Retrieve an argument based on its long name. More... | |
bool | hasFlag (CmdLine::CmdLineFlags f) const |
Checks if the given flags are set. More... | |
bool | hasState (CmdLine::CmdLineState s) const |
Checks if the given state flags are set. More... | |
bool | hasStatus (CmdLine::CmdLineStatus s) const |
Checks if the given status flags are set. More... | |
std::string | longname () const |
Return previously specified program long name. More... | |
void | longname (const std::string &value) |
Specify program long name. More... | |
std::string | name () const |
Return previously specified program name. More... | |
void | name (const std::string &value) |
Specify program name. More... | |
unsigned int | nargsParsed () const |
Find out the number of arguments parsed so far. More... | |
CmdLine::CmdLineStatus | parse (ArgIter &argiter, bool autoProcessing=true) |
Parse a set of arguments. More... | |
CmdLine::CmdLineStatus | parseArg (const char *arg) |
Parse a single argument. More... | |
CmdLine::CmdLineStatus | prologue () |
Perform the necessary pre-processing. More... | |
void | setFlags (CmdLine::CmdLineFlags f) |
Set only the given flags. More... | |
void | setState (CmdLine::CmdLineState s) |
Set only given state flags. More... | |
void | setStatus (CmdLine::CmdLineStatus s) |
Set only given status flags. More... | |
CmdLine::CmdLineState | state () const |
Return CmdLine's state. More... | |
void | state (CmdLine::CmdLineState s) |
Specify new set of state flags. More... | |
CmdLine::CmdLineStatus | status () const |
Return CmdLine's status. More... | |
void | status (CmdLine::CmdLineStatus s) |
Specify new set of status flags. More... | |
std::ostream & | usage (std::ostream &os) const |
Print usage message on the given output stream. More... | |
std::ostream & | usage () const |
Print usage message on CmdLine's error output stream. More... | |
std::ostream & | usageHTML (std::ostream &os) const |
Print HTML usage message on the given output stream. More... | |
std::ostream & | usageLATEX (std::ostream &os) const |
Print LATEX usage message on the given output stream. More... | |
std::ostream & | usageXML (std::ostream &os) const |
Print XML usage information on the given output stream. More... | |
The CmdLine class is a parser for command line arguments.
Definition at line 137 of file CmdLine.hh.
Configuration flags for CmdLine.
Definition at line 145 of file CmdLine.hh.
Status flags for CmdLine.
Definition at line 161 of file CmdLine.hh.
State flags for CmdLine.
Enumerator | |
---|---|
STATE_START_STATE | |
STATE_END_OF_OPTIONS | End of options (–) occured. |
STATE_SHORT_USED | Short options were used. |
STATE_LONG_USED | Long options were used. |
STATE_ALL |
Definition at line 181 of file CmdLine.hh.
Parsing state flags for CmdLine.
Enumerator | |
---|---|
PARSE_START_STATE | Parsing of a CmdArg is completely finished. |
PARSE_TOK_REQUIRED | The next token is required. |
PARSE_WANT_VAL | The last parsed CmdArg may optionally get a value. |
PARSE_NEED_VAL | The last parsed CmdArg requires a value. |
PARSE_ALL |
Definition at line 196 of file CmdLine.hh.
CmdLine::CmdLine | ( | std::string | name, |
std::string | longname, | ||
bool | help = true |
||
) |
Constructor.
Sets the program name and longname.
name | program name |
longname | program long name |
help | automatically add default help arguments? |
CmdLine::CmdLine | ( | std::string | name, |
std::string | longname, | ||
bool | help, | ||
CmdArg * | cmdarg1 ... | ||
) |
Constructor.
Sets the program name and longname. Adds given CmdArgs. ATTENTION: the last element in the CmdArg list must be NULL!
name | program name |
longname | program long name |
help | automatically add default help arguments? |
cmdarg1 | ... CmdArgs to add |
CmdLineDublicateArgError |
|
virtual |
Destructor.
std::string CmdLine::name | ( | ) | const |
Return previously specified program name.
void CmdLine::name | ( | const std::string & | value | ) |
Specify program name.
name | program name |
std::string CmdLine::longname | ( | ) | const |
Return previously specified program long name.
void CmdLine::longname | ( | const std::string & | value | ) |
Specify program long name.
name | program long name |
std::string CmdLine::description | ( | ) | const |
Return previously specified program description.
void CmdLine::description | ( | const std::string & | description | ) |
Specify program description.
description | program description |
Append specified CmdArg to the list of CmdArgs.
cmdarg | pointer to CmdArg to append |
CmdLineDublicateArgError |
Append specified CmdArg to the list of CmdArgs.
cmdarg | reference to CmdArg to append |
CmdLineDublicateArgError |
std::ostream& CmdLine::usage | ( | std::ostream & | os | ) | const |
Print usage message on the given output stream.
os | output stream |
std::ostream& CmdLine::usage | ( | ) | const |
Print usage message on CmdLine's error output stream.
std::ostream& CmdLine::usageXML | ( | std::ostream & | os | ) | const |
Print XML usage information on the given output stream.
os | output stream |
std::ostream& CmdLine::usageHTML | ( | std::ostream & | os | ) | const |
Print HTML usage message on the given output stream.
os | output stream |
std::ostream& CmdLine::usageLATEX | ( | std::ostream & | os | ) | const |
Print LATEX usage message on the given output stream.
os | output stream |
CmdLine::CmdLineStatus CmdLine::status | ( | ) | const |
Return CmdLine's status.
void CmdLine::status | ( | CmdLine::CmdLineStatus | s | ) |
Specify new set of status flags.
s | status to set |
void CmdLine::setStatus | ( | CmdLine::CmdLineStatus | s | ) |
Set only given status flags.
Other status flags are not modified.
s | status to set |
bool CmdLine::hasStatus | ( | CmdLine::CmdLineStatus | s | ) | const |
Checks if the given status flags are set.
s | status to check |
CmdLine::CmdLineState CmdLine::state | ( | ) | const |
Return CmdLine's state.
void CmdLine::state | ( | CmdLine::CmdLineState | s | ) |
Specify new set of state flags.
s | state to set |
void CmdLine::setState | ( | CmdLine::CmdLineState | s | ) |
Set only given state flags.
Other state flags are not modified.
s | state to set |
void CmdLine::clearState | ( | CmdLine::CmdLineState | s = STATE_ALL | ) |
Clear only the given state flags.
Other state flags are not modified.
s | state to clear |
bool CmdLine::hasState | ( | CmdLine::CmdLineState | s | ) | const |
Checks if the given state flags are set.
s | state to check |
CmdLine::CmdLineFlags CmdLine::flags | ( | ) | const |
Return CmdLine's flags.
void CmdLine::flags | ( | CmdLine::CmdLineFlags | f | ) |
Specify new set of flags.
f | Flags to set |
void CmdLine::setFlags | ( | CmdLine::CmdLineFlags | f | ) |
Set only the given flags.
Other flags are not modified.
f | Flags to set |
void CmdLine::clearFlags | ( | CmdLine::CmdLineFlags | f = FLAG_ALL | ) |
Clear only the given flags.
Other flags are not modified.
f | Flags to clear |
bool CmdLine::hasFlag | ( | CmdLine::CmdLineFlags | f | ) | const |
Checks if the given flags are set.
f | flags to check |
std::ostream& CmdLine::error | ( | ) | const |
Return CmdLine's error output stream.
void CmdLine::error | ( | std::ostream & | os | ) |
Specify CmdLine's error output stream.
os | error output stream |
CmdLine::CmdLineStatus CmdLine::parse | ( | ArgIter & | argiter, |
bool | autoProcessing = true |
||
) |
Parse a set of arguments.
Pre- and post-processing (resetting arguments, ...) is automatically performed (by calling prologue() and epilogue()) if autoProcessing is true.
argiter | ArgIter that provides the arguments |
autoProcessing | if true perform pre- and post-processing |
CmdLine::CmdLineStatus CmdLine::prologue | ( | ) |
Perform the necessary pre-processing.
CmdLine::CmdLineStatus CmdLine::parseArg | ( | const char * | arg | ) |
Parse a single argument.
arg | argument to be processed |
CmdLine::CmdLineStatus CmdLine::epilogue | ( | ) |
unsigned int CmdLine::nargsParsed | ( | ) | const |
Find out the number of arguments parsed so far.
CmdArg* CmdLine::getArg | ( | char | shortName | ) | const |
Retrieve an argument based on its short name.
Returns NULL if no argument matches the given character.
shortName | short name to find |
CmdArg* CmdLine::getArg | ( | const std::string & | keyword | ) | const |
Retrieve an argument based on its long name.
Returns NULL if no argument matches the given character.
longName | long name to find |