iRoCS Toolbox  1.1.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
CmdArgThrow< E > Class Template Reference

The CmdArgThrow<E> class is a CmdArg that throws an exception of type E when specified on the command line. More...

#include <CmdArgs.hh>

Inheritance diagram for CmdArgThrow< E >:
Collaboration diagram for CmdArgThrow< E >:

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

 CmdArgThrow (char aShortName, const std::string aLongName, const std::string aDescription, Syntax aSyntax=isOPT)
 Constructor. More...
 
virtual ~CmdArgThrow ()
 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 *, const char *&, CmdLine &)
 Throw exception E. 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
 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...
 

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
 

Detailed Description

template<typename E>
class CmdArgThrow< E >

The CmdArgThrow<E> class is a CmdArg that throws an exception of type E when specified on the command line.

Definition at line 1074 of file CmdArgs.hh.

Member Enumeration Documentation

◆ Syntax

enum CmdArg::Syntax
inherited

Flags that define the argument syntax.

Enumerator
isOPT 

argument is optional

isREQ 

argument is required

isVALOPT 

argument value is optional

isVALREQ 

argument value is required

isVALSEP 

argument value must be in a separate token

isVALSTICKY 

argument value must be in the same token

isLIST 

argument is a list

isPOS 

argument is positional

isHIDDEN 

argument is not to be printed in usage

isFIXEDLIST 

argument value is a list of fixed size

isVALTAKEN 

argument takes a value

isOPTVALOPT 
isOPTVALREQ 
isPOSVALOPT 
isPOSVALREQ 

Definition at line 112 of file CmdArg.hh.

◆ CmdLineFlags

enum CmdArg::CmdLineFlags
inherited

Flags that say how the argument was specied on the command-line.

Enumerator
GIVEN 

argument was given

VALGIVEN 

argument value was given

OPTION 

item was matched as an option

KEYWORD 

item was matched as a keyword

POSITIONAL 

item was matched as a positional argument

VALSEP 

value was in a separate token

ALLFLAGS 

Definition at line 136 of file CmdArg.hh.

Constructor & Destructor Documentation

◆ CmdArgThrow()

template<typename E>
CmdArgThrow< E >::CmdArgThrow ( char  aShortName,
const std::string  aLongName,
const std::string  aDescription,
Syntax  aSyntax = isOPT 
)
inline

Constructor.

Creates a CmdArgThrow with short and long name. By default the syntax flags are set so that the argument is optional.

Parameters
aShortNameshort name of the argument
aLongNamelong name of the argument
aDescriptiondescription of the argument
aSyntaxsyntax flags
Exceptions
CmdLineSyntaxError

Definition at line 1091 of file CmdArgs.hh.

◆ ~CmdArgThrow()

template<typename E>
virtual CmdArgThrow< E >::~CmdArgThrow ( )
inlinevirtual

Destructor.

Definition at line 1105 of file CmdArgs.hh.

Member Function Documentation

◆ parse()

template<typename E>
virtual bool CmdArgThrow< E >::parse ( const char *  ,
const char *&  ,
CmdLine  
)
inlinevirtual

Throw exception E.

Parameters
argthe string that is to be parsed (is ignored)
endptris set to the first unparsed character of arg (is ignored)
cmdreference to the CmdLine object that initiated the parsing (is ignored)
Exceptions
E
Returns
true

Implements CmdArg.

Definition at line 1124 of file CmdArgs.hh.

◆ valueTypeAsString()

template<typename E>
virtual std::string CmdArgThrow< E >::valueTypeAsString ( ) const
inlinevirtual

Return the value type as a std::string.

Returns
value type as a std::string

Implements CmdArg.

Definition at line 1142 of file CmdArgs.hh.

◆ valueAsString()

template<typename E>
virtual std::string CmdArgThrow< E >::valueAsString ( ) const
inlinevirtual

Return the value as a std::string.

Returns
value as a std::string

Implements CmdArg.

Definition at line 1155 of file CmdArgs.hh.

◆ fixedSize()

virtual unsigned int CmdArg::fixedSize ( ) const
virtualinherited

Return fixed size if this CmdArg is a fixed list, return 0 otherwise.

Returns
fixed size

Reimplemented in CmdArgTypeFixedVector< T >.

Referenced by CmdArgTypeFixedVector< T >::remainingSize().

◆ remainingSize()

virtual unsigned int CmdArg::remainingSize ( ) const
virtualinherited

Return number of remaining values if this CmdArg is a fixed list, return 0 otherwise.

Returns
remaining number of values

Reimplemented in CmdArgTypeFixedVector< T >.

Referenced by CmdArgTypeFixedVector< T >::parse().

◆ syntax()

CmdArg::Syntax CmdArg::syntax ( ) const
inherited

Retrieve the syntax flags for this argument.

◆ hasSyntax()

bool CmdArg::hasSyntax ( CmdArg::Syntax  s) const
inherited

Returns true if the argument's syntax flags contain s.

Parameters
ssyntax flag to be checked
Returns
true if the argument's syntax flags contain s

◆ flags() [1/2]

CmdArg::CmdLineFlags CmdArg::flags ( ) const
inherited

Retrieve the flags that say how this argument was specified.

◆ flags() [2/2]

void CmdArg::flags ( CmdArg::CmdLineFlags  f)
protectedinherited

Sets the argument's flags.

Parameters
fnew flags

◆ hasFlag()

bool CmdArg::hasFlag ( CmdArg::CmdLineFlags  f) const
inherited

Returns true if the argument's flags contain f.

Parameters
sflag to be checked
Returns
true if the argument's flags contain f

◆ sequence() [1/2]

unsigned int CmdArg::sequence ( ) const
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.

Returns
sequence number

◆ sequence() [2/2]

void CmdArg::sequence ( unsigned int  num)
protectedinherited

Sets the sequence number.

Parameters
numnew sequence number

◆ shortName()

char CmdArg::shortName ( ) const
inherited

Returns the argument's short name.

Return's 0 if it has none.

Returns
short name

◆ longName()

const std::string CmdArg::longName ( ) const
inherited

Returns the argument's long name.

Return's "" if it has none.

Returns
long name

◆ valueName()

const std::string CmdArg::valueName ( ) const
inherited

Returns the argument's value name.

Return's "" if it takes no value.

Returns
value name

◆ description()

const std::string CmdArg::description ( ) const
inherited

Get the description (help-message) of this argument.

Returns
description

◆ synopsis()

const std::string CmdArg::synopsis ( bool  displayShort = true,
bool  displayLong = true 
) const
inherited

Generates and returns the arguments synopsis.

Parameters
displayShortif true print short name
displayLongif true display long name
Returns
synopsis string

◆ errorMsg()

const std::string CmdArg::errorMsg ( ) const
inherited

Returns error message of last parsing.

Returns
last error message

◆ clearErrorMsg()

void CmdArg::clearErrorMsg ( )
inherited

Clears the error message.

◆ setErrorMsg()

void CmdArg::setErrorMsg ( const std::string &  msg)
inherited

Sets the error message.

Parameters
msgnew error message.

◆ modified() [1/2]

bool CmdArg::modified ( ) const
inherited

Returns true if the argument was parsed at the last parsing run.

Returns
if the argument was parsed

Referenced by CmdArgType< T >::parse(), CmdArgTypeVector< T >::parse(), CmdArgTypeFixedVector< T >::parse(), and CmdArgSwitch::parse().

◆ modified() [2/2]

void CmdArg::modified ( bool  m)
inherited

Sets the modified flag.

Parameters
m

◆ given()

bool CmdArg::given ( ) const
inherited

Returns true if the argument was parsed in any of the parsing runs.

Returns
if the argument was ever parsed

◆ hasDefaultValue()

virtual bool CmdArg::hasDefaultValue ( ) const
virtualinherited

Returns true if a default value was specified.

Returns
true if a default value was specified

Reimplemented in CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.

◆ getDefaultValueString()

virtual std::string CmdArg::getDefaultValueString ( ) const
virtualinherited

Returns the default value as a string.

Returns
default value as a string

Reimplemented in CmdArgTypeFixedVector< T >, CmdArgTypeVector< T >, and CmdArgType< T >.

◆ clearFixedList()

virtual void CmdArg::clearFixedList ( )
virtualinherited

If the argument is a fixed list, this function clears all its values.

Reimplemented in CmdArgTypeFixedVector< T >.

◆ adjustSyntax()

void CmdArg::adjustSyntax ( )
protectedinherited

Adjust and correct specified syntax flags.

Exceptions
CmdLineSyntaxError

Referenced by CmdArgTypeFixedVector< T >::CmdArgTypeFixedVector().

◆ setFlags()

void CmdArg::setFlags ( CmdArg::CmdLineFlags  f)
protectedinherited

Toggles specified flags.

Parameters
fflags to toggle

◆ clearFlags()

void CmdArg::clearFlags ( CmdArg::CmdLineFlags  f = ALLFLAGS)
protectedinherited

Clears the specified flags.

Parameters
fflags to clear

Field Documentation

◆ pFlags

CmdArg::CmdLineFlags CmdArg::pFlags
protectedinherited

Definition at line 541 of file CmdArg.hh.

◆ pSyntax

CmdArg::Syntax CmdArg::pSyntax
protectedinherited

Definition at line 542 of file CmdArg.hh.

◆ pSequence

unsigned int CmdArg::pSequence
protectedinherited

Definition at line 544 of file CmdArg.hh.

◆ pShortName

char CmdArg::pShortName
protectedinherited

Definition at line 545 of file CmdArg.hh.

◆ pLongName

std::string CmdArg::pLongName
protectedinherited

Definition at line 546 of file CmdArg.hh.

◆ pValueName

std::string CmdArg::pValueName
protectedinherited

Definition at line 547 of file CmdArg.hh.

◆ pDescription

std::string CmdArg::pDescription
protectedinherited

Definition at line 548 of file CmdArg.hh.

◆ pErrorMessage

std::string CmdArg::pErrorMessage
protectedinherited

Definition at line 550 of file CmdArg.hh.

◆ pModified

bool CmdArg::pModified
protectedinherited

Definition at line 552 of file CmdArg.hh.


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