OpenSceneGraph
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
osg::ArgumentParser Class Reference

Classes

class  Parameter
 

Public Types

enum  ErrorSeverity { BENIGN = 0, CRITICAL = 1 }
 
typedef std::map< std::string, ErrorSeverityErrorMessageMap
 

Public Member Functions

 ArgumentParser (int *argc, char **argv)
 
void setApplicationUsage (ApplicationUsage *usage)
 
ApplicationUsagegetApplicationUsage ()
 
const ApplicationUsagegetApplicationUsage () const
 
int & argc ()
 Return the argument count. More...
 
char ** argv ()
 Return the argument array. More...
 
char * operator[] (int pos)
 Return the char* argument at the specified position. More...
 
const char * operator[] (int pos) const
 Return the const char* argument at the specified position. More...
 
std::string getApplicationName () const
 Return the application name, as specified by argv[0]. More...
 
int find (const std::string &str) const
 Return the position of an occurrence of a string in the argument list. More...
 
bool isOption (int pos) const
 Return true if the specified parameter is an option in the form of -option or –option. More...
 
bool isString (int pos) const
 Return true if the specified parameter is a string not in the form of an option. More...
 
bool isNumber (int pos) const
 Return true if the specified parameter is a number. More...
 
bool containsOptions () const
 
void remove (int pos, int num=1)
 Remove one or more arguments from the argv argument list, and decrement the argc respectively. More...
 
bool match (int pos, const std::string &str) const
 Return true if the specified argument matches the given string. More...
 
bool read (const std::string &str)
 Search for an occurrence of a string in the argument list. More...
 
bool read (const std::string &str, Parameter value1)
 
bool read (const std::string &str, Parameter value1, Parameter value2)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
 
bool read (const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
 
bool read (int pos, const std::string &str)
 If the argument value at the specified position matches the given string, and subsequent parameters are also matched, then set the parameter values, remove the arguments from the list, and return true. More...
 
bool read (int pos, const std::string &str, Parameter value1)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7)
 
bool read (int pos, const std::string &str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8)
 
bool errors (ErrorSeverity severity=BENIGN) const
 Return the error flag, true if an error has occurred when reading arguments. More...
 
void reportError (const std::string &message, ErrorSeverity severity=CRITICAL)
 Report an error message by adding to the ErrorMessageMap. More...
 
void reportRemainingOptionsAsUnrecognized (ErrorSeverity severity=BENIGN)
 For each remaining option, report it as unrecognized. More...
 
ErrorMessageMapgetErrorMessageMap ()
 Return the error message, if any has occurred. More...
 
const ErrorMessageMapgetErrorMessageMap () const
 Return the error message, if any has occurred. More...
 
void writeErrorMessages (std::ostream &output, ErrorSeverity sevrity=BENIGN)
 Write error messages to the given ostream, if at or above the given severity. More...
 
ApplicationUsage::Type readHelpType ()
 This convenience method handles help requests on the command line. More...
 

Static Public Member Functions

static bool isOption (const char *str)
 Return true if the specified string is an option in the form -option or –option. More...
 
static bool isString (const char *str)
 Return true if string is non-NULL and not an option in the form -option or –option. More...
 
static bool isNumber (const char *str)
 Return true if specified parameter is a number. More...
 
static bool isBool (const char *str)
 Return true if specified parameter is a bool. More...
 

Protected Attributes

int * _argc
 
char ** _argv
 
ErrorMessageMap _errorMessageMap
 
ref_ptr< ApplicationUsage_usage
 

Member Typedef Documentation

◆ ErrorMessageMap

typedef std::map<std::string,ErrorSeverity> osg::ArgumentParser::ErrorMessageMap

Member Enumeration Documentation

◆ ErrorSeverity

Enumerator
BENIGN 
CRITICAL 

Constructor & Destructor Documentation

◆ ArgumentParser()

osg::ArgumentParser::ArgumentParser ( int *  argc,
char **  argv 
)

Member Function Documentation

◆ argc()

int& osg::ArgumentParser::argc ( )
inline

Return the argument count.

◆ argv()

char** osg::ArgumentParser::argv ( )
inline

Return the argument array.

◆ containsOptions()

bool osg::ArgumentParser::containsOptions ( ) const

◆ errors()

bool osg::ArgumentParser::errors ( ErrorSeverity  severity = BENIGN) const

Return the error flag, true if an error has occurred when reading arguments.

◆ find()

int osg::ArgumentParser::find ( const std::string &  str) const

Return the position of an occurrence of a string in the argument list.

Return -1 if no string is found.

◆ getApplicationName()

std::string osg::ArgumentParser::getApplicationName ( ) const

Return the application name, as specified by argv[0].

◆ getApplicationUsage() [1/2]

ApplicationUsage* osg::ArgumentParser::getApplicationUsage ( )
inline

◆ getApplicationUsage() [2/2]

const ApplicationUsage* osg::ArgumentParser::getApplicationUsage ( ) const
inline

◆ getErrorMessageMap() [1/2]

ErrorMessageMap& osg::ArgumentParser::getErrorMessageMap ( )
inline

Return the error message, if any has occurred.

◆ getErrorMessageMap() [2/2]

const ErrorMessageMap& osg::ArgumentParser::getErrorMessageMap ( ) const
inline

Return the error message, if any has occurred.

◆ isBool()

static bool osg::ArgumentParser::isBool ( const char *  str)
static

Return true if specified parameter is a bool.

◆ isNumber() [1/2]

static bool osg::ArgumentParser::isNumber ( const char *  str)
static

Return true if specified parameter is a number.

◆ isNumber() [2/2]

bool osg::ArgumentParser::isNumber ( int  pos) const

Return true if the specified parameter is a number.

◆ isOption() [1/2]

static bool osg::ArgumentParser::isOption ( const char *  str)
static

Return true if the specified string is an option in the form -option or –option.

◆ isOption() [2/2]

bool osg::ArgumentParser::isOption ( int  pos) const

Return true if the specified parameter is an option in the form of -option or –option.

◆ isString() [1/2]

static bool osg::ArgumentParser::isString ( const char *  str)
static

Return true if string is non-NULL and not an option in the form -option or –option.

◆ isString() [2/2]

bool osg::ArgumentParser::isString ( int  pos) const

Return true if the specified parameter is a string not in the form of an option.

◆ match()

bool osg::ArgumentParser::match ( int  pos,
const std::string &  str 
) const

Return true if the specified argument matches the given string.

◆ operator[]() [1/2]

char* osg::ArgumentParser::operator[] ( int  pos)
inline

Return the char* argument at the specified position.

◆ operator[]() [2/2]

const char* osg::ArgumentParser::operator[] ( int  pos) const
inline

Return the const char* argument at the specified position.

◆ read() [1/18]

bool osg::ArgumentParser::read ( const std::string &  str)

Search for an occurrence of a string in the argument list.

If found, remove that occurrence and return true. Otherwise, return false.

◆ read() [2/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1 
)

◆ read() [3/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2 
)

◆ read() [4/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3 
)

◆ read() [5/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4 
)

◆ read() [6/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5 
)

◆ read() [7/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6 
)

◆ read() [8/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6,
Parameter  value7 
)

◆ read() [9/18]

bool osg::ArgumentParser::read ( const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6,
Parameter  value7,
Parameter  value8 
)

◆ read() [10/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str 
)

If the argument value at the specified position matches the given string, and subsequent parameters are also matched, then set the parameter values, remove the arguments from the list, and return true.

Otherwise, return false.

◆ read() [11/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1 
)

◆ read() [12/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2 
)

◆ read() [13/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3 
)

◆ read() [14/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4 
)

◆ read() [15/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5 
)

◆ read() [16/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6 
)

◆ read() [17/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6,
Parameter  value7 
)

◆ read() [18/18]

bool osg::ArgumentParser::read ( int  pos,
const std::string &  str,
Parameter  value1,
Parameter  value2,
Parameter  value3,
Parameter  value4,
Parameter  value5,
Parameter  value6,
Parameter  value7,
Parameter  value8 
)

◆ readHelpType()

ApplicationUsage::Type osg::ArgumentParser::readHelpType ( )

This convenience method handles help requests on the command line.

Return the type(s) of help requested. The return value of this function is suitable for passing into getApplicationUsage()->write(). If ApplicationUsage::NO_HELP is returned then no help commandline option was found on the command line.

◆ remove()

void osg::ArgumentParser::remove ( int  pos,
int  num = 1 
)

Remove one or more arguments from the argv argument list, and decrement the argc respectively.

◆ reportError()

void osg::ArgumentParser::reportError ( const std::string &  message,
ErrorSeverity  severity = CRITICAL 
)

Report an error message by adding to the ErrorMessageMap.

◆ reportRemainingOptionsAsUnrecognized()

void osg::ArgumentParser::reportRemainingOptionsAsUnrecognized ( ErrorSeverity  severity = BENIGN)

For each remaining option, report it as unrecognized.

◆ setApplicationUsage()

void osg::ArgumentParser::setApplicationUsage ( ApplicationUsage usage)
inline

◆ writeErrorMessages()

void osg::ArgumentParser::writeErrorMessages ( std::ostream &  output,
ErrorSeverity  sevrity = BENIGN 
)

Write error messages to the given ostream, if at or above the given severity.

Member Data Documentation

◆ _argc

int* osg::ArgumentParser::_argc
protected

◆ _argv

char** osg::ArgumentParser::_argv
protected

◆ _errorMessageMap

ErrorMessageMap osg::ArgumentParser::_errorMessageMap
protected

◆ _usage

ref_ptr<ApplicationUsage> osg::ArgumentParser::_usage
protected

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