LTL  2.0.x
Public Member Functions | Protected Types | Protected Attributes | Friends | Related Functions | List of all members
util::OptionParser Class Reference

Generic parser object for options. More...

Public Member Functions

 OptionParser (OptionReader *reader)
 construct using an OptionReader, i.e. either a CommandLineReader or a ConfigFileReader. More...
 
virtual ~OptionParser ()
 
 OptionParser (const OptionParser &other)
 copy ctor. More...
 
void deleteOptions (void)
 delete all the Option objects we are holding. More...
 
void changeReader (OptionReader *reader)
 
void addOption (Option *option)
 add an option to our list of accepted options. More...
 
OptiongetOption (const std::string &name)
 retrieve an option by its name. More...
 
const std::list< std::string > getOptionNames () const
 retrieve a list of the option names. More...
 
void parseOptions ()
 read the options, parse them, and set their values. More...
 
void printUsage (std::ostream &os) const
 
void writeConfig (const std::string &filename, const bool withComment=true, const bool order_by_n=true) const
 
void logConfig (const int priority=LOG_INFO, const bool withComment=true, const bool order_by_n=true) const
 
std::string toString (const bool withComment=false) const
 get a string representation. More...
 

Protected Types

typedef std::map< std::string,
Option * > 
omap
 
typedef std::map< int, Option * > onmap
 

Protected Attributes

OptionReaderreader_
 the OptionReader object we will use to read-in the options, either a CommandLineReader or a ConfigFileReader More...
 
omap options_
 holds all options we know of indexed by name More...
 
omap cmd_options_
 index of options by command line character More...
 
onmap n_options_
 holds options indexed by order of definition More...
 
int nopts_
 number of options More...
 

Friends

std::ostream & operator<< (std::ostream &os, const OptionParser &op)
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const OptionParser &op)
 

Detailed Description

Generic parser object for options.

Uses an object of type util::OptionReader to retrieve the options from whereever (config file, command-line, etc.)

Member Typedef Documentation

typedef std::map<std::string,Option*> util::OptionParser::omap
protected
typedef std::map<int,Option*> util::OptionParser::onmap
protected

Constructor & Destructor Documentation

util::OptionParser::OptionParser ( OptionReader reader)

construct using an OptionReader, i.e. either a CommandLineReader or a ConfigFileReader.

virtual util::OptionParser::~OptionParser ( )
virtual
util::OptionParser::OptionParser ( const OptionParser other)

copy ctor.

Member Function Documentation

void util::OptionParser::deleteOptions ( void  )

delete all the Option objects we are holding.

void util::OptionParser::changeReader ( OptionReader reader)

switch the OptionReader to a different one, used when first reading a config file and then allowing to override option on the command line.

void util::OptionParser::addOption ( Option option)

add an option to our list of accepted options.

Option* util::OptionParser::getOption ( const std::string &  name)

retrieve an option by its name.

const std::list<std::string> util::OptionParser::getOptionNames ( ) const

retrieve a list of the option names.

void util::OptionParser::parseOptions ( )

read the options, parse them, and set their values.

void util::OptionParser::printUsage ( std::ostream &  os) const

pretty-print the options, their descriptions, and default values in a format similar to man pages. automatic formatting and line-breaking. very nice!

void util::OptionParser::writeConfig ( const std::string &  filename,
const bool  withComment = true,
const bool  order_by_n = true 
) const

write out the options in a format compatible with the ConfigFileReader. Convenient way to create a default config file. order_by_n specifies the order the options were added, otherwise alphabetic by name.

void util::OptionParser::logConfig ( const int  priority = LOG_INFO,
const bool  withComment = true,
const bool  order_by_n = true 
) const

write out the options in a format compatible with the ConfigFileReader into syslog. order_by_n specifies the order the options were added, otherwise alphabetic by name.

std::string util::OptionParser::toString ( const bool  withComment = false) const

get a string representation.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const OptionParser op 
)
friend

Member Data Documentation

OptionReader* util::OptionParser::reader_
protected

the OptionReader object we will use to read-in the options, either a CommandLineReader or a ConfigFileReader

omap util::OptionParser::options_
protected

holds all options we know of indexed by name

omap util::OptionParser::cmd_options_
protected

index of options by command line character

onmap util::OptionParser::n_options_
protected

holds options indexed by order of definition

int util::OptionParser::nopts_
protected

number of options