strusBase  0.17
Classes | Public Member Functions | List of all members
strus::ProgramOptions Class Reference

Program options parser. More...

#include <programOptions.hpp>

Public Member Functions

 ProgramOptions (ErrorBufferInterface *errorhnd_)
 Default constructor. More...
 
 ProgramOptions (const ProgramOptions &o)
 Copy constructor. More...
 
 ProgramOptions (ErrorBufferInterface *errorhnd_, int argc_, const char **argv_, int nofopt,...)
 Constructor. More...
 
bool operator() (const std::string &optname) const
 Test if an option specified by its long name is defined. More...
 
const char * operator[] (std::size_t idx) const
 Get the value of an argument specified by its index. More...
 
const char * operator[] (const std::string &optname) const
 Get the value of an option specified by its long name. More...
 
int asInt (const std::string &optname) const
 Get the value of an option specified by its long name as signed integer. More...
 
unsigned int asUint (const std::string &optname) const
 Get the value of an option specified by its long name as unsigned integer. More...
 
double asDouble (const std::string &optname) const
 Get the value of an option specified by its long name as unsigned integer. More...
 
std::vector< std::string > list (const std::string &optname) const
 Get the list of values of an option specified by its long name. More...
 
int nofargs () const
 Get the number of program arguments. More...
 
const char ** argv () const
 Get the list of program arguments. More...
 
void print (std::ostream &out)
 Print all proram options defined. More...
 

Detailed Description

Program options parser.

Constructor & Destructor Documentation

strus::ProgramOptions::ProgramOptions ( ErrorBufferInterface errorhnd_)
inline

Default constructor.

strus::ProgramOptions::ProgramOptions ( const ProgramOptions o)
inline

Copy constructor.

strus::ProgramOptions::ProgramOptions ( ErrorBufferInterface errorhnd_,
int  argc_,
const char **  argv_,
int  nofopt,
  ... 
)

Constructor.

Member Function Documentation

const char** strus::ProgramOptions::argv ( ) const

Get the list of program arguments.

Returns
the list of program arguments without options and the program name
double strus::ProgramOptions::asDouble ( const std::string &  optname) const

Get the value of an option specified by its long name as unsigned integer.

Parameters
[in]optnamelong name of the option
Returns
the option value as integer or 0 on failure
int strus::ProgramOptions::asInt ( const std::string &  optname) const

Get the value of an option specified by its long name as signed integer.

Parameters
[in]optnamelong name of the option
Returns
the option value as integer or 0 on failure
unsigned int strus::ProgramOptions::asUint ( const std::string &  optname) const

Get the value of an option specified by its long name as unsigned integer.

Parameters
[in]optnamelong name of the option
Returns
the option value as integer or 0 on failure
std::vector<std::string> strus::ProgramOptions::list ( const std::string &  optname) const

Get the list of values of an option specified by its long name.

Parameters
[in]optnamelong name of the option
Returns
the option values as vector, empty on failure
int strus::ProgramOptions::nofargs ( ) const

Get the number of program arguments.

Returns
the number of program arguments without options and the program name
bool strus::ProgramOptions::operator() ( const std::string &  optname) const

Test if an option specified by its long name is defined.

const char* strus::ProgramOptions::operator[] ( std::size_t  idx) const

Get the value of an argument specified by its index.

Parameters
[in]indexof the argument starting with 0
Note
first argument (not the program name!) has index 0
Returns
the argument value as string or NULL on failure
const char* strus::ProgramOptions::operator[] ( const std::string &  optname) const

Get the value of an option specified by its long name.

Parameters
[in]optnamelong name of the option
Returns
the option value as string or NULL on failure
void strus::ProgramOptions::print ( std::ostream &  out)

Print all proram options defined.

Parameters
[in]whereto print the options to

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