conf::Config Class Reference

A class for defining, storing and querying options. More...

#include <conf.hh>

List of all members.

Public Types

typedef std::map< unsigned
char, int > 
ShortMap
 A type for mapping short option names to option indices.
typedef std::map< std::string,
int > 
LongMap
 A type for mapping long option names to option indices.

Public Member Functions

 Config ()
 Create an empty config.
Configoperator() (std::string usage)
 Add a usage line for the help screen.
Configoperator() (unsigned char short_name, std::string long_name, std::string type="", std::string default_value="", std::string help="")
 Add a new option.
void parse (int argc, char *argv[], bool override=true)
 Parse command line arguments.
void default_parse (int argc, char *argv[])
 Default parsing with "help" option.
void check_required () const
 Check if all required options are specified.
void print_help (FILE *file=stdout, int exit_value=0) const
 Prints usage information.
std::string help_string () const
 Returns the usage information.
const Optionoperator[] (unsigned char short_name) const
 Get a value of an option.
const Optionoperator[] (std::string long_name) const
 Get a value of an option.

Public Attributes

std::string usage_line
 Usage line printed in help if specified.
std::vector< Optionoptions
 Options added to the configuration.
ShortMap short_map
 Mapping short names to options.
LongMap long_map
 Mapping long names to options.
std::vector< std::string > arguments
 Rest of the non-option arguments.
int longest_name_length
 The length of the longest long name.

Private Member Functions

void parse_aux (std::deque< std::string > &argument_queue, bool override)
 The actual parsing of command line (or config file) options.


Detailed Description

A class for defining, storing and querying options.

Bug:
An option added to config can not be deleted anymore.


Member Typedef Documentation

typedef std::map<std::string, int> conf::Config::LongMap
 

A type for mapping long option names to option indices.

typedef std::map<unsigned char, int> conf::Config::ShortMap
 

A type for mapping short option names to option indices.


Constructor & Destructor Documentation

conf::Config::Config  ) 
 

Create an empty config.


Member Function Documentation

void conf::Config::check_required  )  const
 

Check if all required options are specified.

void conf::Config::default_parse int  argc,
char *  argv[]
 

Default parsing with "help" option.

Parameters:
argc = the number of arguments
argv = the arguments

std::string conf::Config::help_string  )  const
 

Returns the usage information.

Config & conf::Config::operator() unsigned char  short_name,
std::string  long_name,
std::string  type = "",
std::string  default_value = "",
std::string  help = ""
 

Add a new option.

Parameters:
short_name = the short name of the option used after a hyphen
long_name = the long name of the option used after two hyphens
type = a space seperated list of type specifiers:
  • "arg" = argument must follow the option
  • "must" = the argument must be specified by the user
default_value = the default value of the option
help = the help string of the option

Config & conf::Config::operator() std::string  usage  ) 
 

Add a usage line for the help screen.

const Option & conf::Config::operator[] std::string  long_name  )  const
 

Get a value of an option.

const Option & conf::Config::operator[] unsigned char  short_name  )  const
 

Get a value of an option.

void conf::Config::parse int  argc,
char *  argv[],
bool  override = true
 

Parse command line arguments.

Parameters:
argc = the number of arguments
argv = the arguments
override = should we override options specified already

void conf::Config::parse_aux std::deque< std::string > &  argument_queue,
bool  override
[private]
 

The actual parsing of command line (or config file) options.

void conf::Config::print_help FILE *  file = stdout,
int  exit_value = 0
const
 

Prints usage information.


Member Data Documentation

std::vector<std::string> conf::Config::arguments
 

Rest of the non-option arguments.

LongMap conf::Config::long_map
 

Mapping long names to options.

int conf::Config::longest_name_length
 

The length of the longest long name.

std::vector<Option> conf::Config::options
 

Options added to the configuration.

ShortMap conf::Config::short_map
 

Mapping short names to options.

std::string conf::Config::usage_line
 

Usage line printed in help if specified.


The documentation for this class was generated from the following files:
Generated on Mon Jan 8 15:51:04 2007 for bit by  doxygen 1.4.6