Puma Reference Manual Puma::OptsParser Class Reference



Puma::OptsParser Class Reference

The Options Parser searches command line parameters for options and handles their option arguments, if applicable. More...

#include <OptsParser.h>

Inheritance diagram for Puma::OptsParser:
Inheritance graph

Classes

struct  Option
 

Public Types

enum  {
  NOARG =-4,
  ERR = -3,
  NOOPTION = -2,
  UNKNOWN = -1,
  FINISH = 0
}
 
enum  ArgType {
  AT_NONE = 0,
  AT_MANDATORY = 1,
  AT_OPTIONAL = 2
}
 

Public Member Functions

 OptsParser (int argc, char **argv, const Option *opts)
 Constructor of OptsParser. More...
 
 OptsParser (const string &line, const Option *opts)
 Constructor of OptsParser. More...
 
int getRawOption ()
 Get next parameter without modification. More...
 
int getOption ()
 Get next option. More...
 
int getResult () const
 Get result of last processed parameter. More...
 
const string & getArgument ()
 Get option argument of last processed parameter. More...
 
const string & getUnstrippedArgument () const
 Get option argument of last processed parameter without stripping. More...
 
const string & getOptionName () const
 Get option name of last processed parameter. More...
 
int getCurrentArgNum () const
 Get position of current argument. More...
 
int getNextArgNum () const
 Get position of next argument. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Puma::SimpleParser
static string strip (const string &str)
 Remove enclosing double-quotes from a string. More...
 
static int tokenize (const string &str, vector< string > &tokens, const string &delimiters=" ")
 Splits a given string into tokens recognized by the given delimiters. More...
 

Detailed Description

The Options Parser searches command line parameters for options and handles their option arguments, if applicable.

Member Enumeration Documentation

anonymous enum
Enumerator
NOARG 

Option has no argument

ERR 

Error when parsing option.

NOOPTION 

Command line parameter is not an option.

UNKNOWN 

Parameter is an unknown option.

FINISH 

All options are handled.

Enumerator
AT_NONE 

Option receives no argument

AT_MANDATORY 

Option requires an argument

AT_OPTIONAL 

Option has optionally an argument

Constructor & Destructor Documentation

Puma::OptsParser::OptsParser ( int  argc,
char **  argv,
const Option opts 
)

Constructor of OptsParser.

Parameters
argcNumber of parameters to be analyzed
argvParameters to be analyzed
optsPointer to array of options which shall be recognized by the options parser
Puma::OptsParser::OptsParser ( const string &  line,
const Option opts 
)

Constructor of OptsParser.

Parameters
lineReference to string with parameters to analyse The paramaters are extracted from the string by splitting it up into tokens at:
  • space character
  • tabs
  • newline
  • carriage return
optsPointer to array of options which shall be recognized by the options parser

Member Function Documentation

const string& Puma::OptsParser::getArgument ( )

Get option argument of last processed parameter.

This function returns the argument of the option processed during OptsParser::getOption. If the option does not provide any argument the string will be empty.

If OptsParser::getOption or respectively OptsParser::getResult returns with OptsParser::NOOPTION this function (OptsParser::getArgument) returns the last processed parameter, which is no option, of course.

Returns
Argument of last processed parameter
int Puma::OptsParser::getCurrentArgNum ( ) const

Get position of current argument.

Returns
Position of currently processed parameter previously passed to OptsParser::OptsParser()
int Puma::OptsParser::getNextArgNum ( ) const

Get position of next argument.

Returns
Position of next parameter which will be processed by the Options Parser
int Puma::OptsParser::getOption ( )

Get next option.

This function processes the next parameter passed to the constructor OptsParser::OptsParser(). That is, search for options and eventually process option and option arguement.

Returns
Number of option recognized by the options parser or OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION, OptsParser::UNKNOWN or OptsParser::FINISH.
const string& Puma::OptsParser::getOptionName ( ) const

Get option name of last processed parameter.

If the last processed parameter did not contain an option the string returned by this function is empty.

Returns
Name of last processed parameter
int Puma::OptsParser::getRawOption ( )

Get next parameter without modification.

No option parsing is done

Returns
OptsParser::NOOPTION or OptsParser::FINISH
int Puma::OptsParser::getResult ( ) const

Get result of last processed parameter.

The number returned by this function is identical to the number returned by the last call of OptsParser::getOption

Returns
Number of option recognized by the options parser or OptsParser::NOARG, OptsParser::ERR, OptsParser::NOOPTION, OptsParser::UNKNOWN or OptsParser::FINISH.
const string& Puma::OptsParser::getUnstrippedArgument ( ) const

Get option argument of last processed parameter without stripping.

This function returns the argument of the option processed during OptsParser::getOption. If the option does not provide any argument the string will be empty.

If OptsParser::getOption or respectively OptsParser::getResult returns with OptsParser::NOOPTION this function (OptsParser::getArgument) returns the last processed parameter, which is no option, of course.

Returns
Argument of last processed parameter



Puma Reference Manual. Created on Sat Dec 21 2019.