natfw::configuration Class Reference

#include <source/ariba/utility/transport/tcpip/protlib/configuration.h>

List of all members.

Public Member Functions

 configuration (config_entry defaults[])
void load (const std::string &filename) throw (config_error)
void load (std::istream &in) throw (config_error)
void dump (std::ostream &out) throw (config_error)
bool is_defined (const std::string &key) const throw ()
std::string get_string (const std::string &key) const throw ()
bool get_bool (const std::string &key) const throw ()
int get_int (const std::string &key) const throw ()
float get_float (const std::string &key) const throw ()
hostaddress get_ipv4_address (const std::string &key) const throw ()
hostaddress get_ipv6_address (const std::string &key) const throw ()
std::list< hostaddressget_ipv4_address_list (const std::string &key) const throw ()
std::list< hostaddressget_ipv6_address_list (const std::string &key) const throw ()

Private Types

typedef std::map< std::string,
config_entry >::const_iterator 
c_iter

Private Member Functions

void strip_leading_space (std::istream &in) const
void skip_rest_of_line (std::istream &in) const
void parse_and_assign (const std::string &key, std::istream &in)
bool parse_bool (std::istream &in) const
int parse_int (std::istream &in) const
float parse_float (std::istream &in) const
std::string parse_string (std::istream &in) const
hostaddress parse_ipv4_address (std::istream &in) const
hostaddress parse_ipv6_address (std::istream &in) const
std::list< hostaddressparse_ipv4_address_list (std::istream &in) const
std::list< hostaddressparse_ipv6_address_list (std::istream &in) const
void write_string (std::ostream &out, const std::string &str) const
void dump_address_list (std::ostream &out, const std::list< hostaddress > &addresses) const

Private Attributes

std::map< std::string,
config_entry
values


Detailed Description

A class for handling simple configuration files.

The configuration consists of (key, value) pairs, where both key and value are strings.

A configuration file is line-oriented and has the following format: [space] key [space] = [space] value [space] EOL

Value can be a boolean value, an integer, a float, an IP address (either IPv4 or IPv6), or a string. String values have to be quoted using double quotes. If a double quote should appear in the string, you have to quote it using a backslash. A backslash in turn has to be quoted using another backslash.

Lines starting with '#' and empty lines are ignored.

Definition at line 133 of file configuration.h.


Member Typedef Documentation

typedef std::map<std::string, config_entry>::const_iterator natfw::configuration::c_iter [private]

Definition at line 156 of file configuration.h.


Constructor & Destructor Documentation

configuration::configuration ( config_entry  rules[]  ) 

Constructor.

Definition at line 54 of file configuration.cpp.

References natfw::config_entry::T_END, natfw::config_entry::type, and values.


Member Function Documentation

void configuration::dump ( std::ostream &  out  )  throw (config_error)

void configuration::dump_address_list ( std::ostream &  out,
const std::list< hostaddress > &  addresses 
) const [private]

Definition at line 216 of file configuration.cpp.

bool configuration::get_bool ( const std::string &  key  )  const throw ()

Get a boolean configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 263 of file configuration.cpp.

References natfw::config_entry::T_BOOL.

float configuration::get_float ( const std::string &  key  )  const throw ()

Get a floating point configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 293 of file configuration.cpp.

References natfw::config_entry::T_FLOAT.

int configuration::get_int ( const std::string &  key  )  const throw ()

Get an integer configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 278 of file configuration.cpp.

References natfw::config_entry::T_INT.

hostaddress configuration::get_ipv4_address ( const std::string &  key  )  const throw ()

Get an IPv4 hostaddress configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 308 of file configuration.cpp.

References natfw::config_entry::T_IPv4.

std::list< hostaddress > configuration::get_ipv4_address_list ( const std::string &  key  )  const throw ()

Get a list of IPv4 hostaddress objects.

Parameters:
key the name of the key
Returns:
the list of values from the configuration

Definition at line 342 of file configuration.cpp.

References natfw::config_entry::T_IPv4_LIST.

hostaddress configuration::get_ipv6_address ( const std::string &  key  )  const throw ()

Get an IPv6 hostaddress configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 325 of file configuration.cpp.

References natfw::config_entry::T_IPv6.

std::list< hostaddress > configuration::get_ipv6_address_list ( const std::string &  key  )  const throw ()

Get a list of IPv6 hostaddress objects.

Parameters:
key the name of the key
Returns:
the list of values from the configuration

Definition at line 359 of file configuration.cpp.

References natfw::config_entry::T_IPv6_LIST.

std::string configuration::get_string ( const std::string &  key  )  const throw ()

Get a string configuration value.

Parameters:
key the name of the key
Returns:
the value from the configuration

Definition at line 248 of file configuration.cpp.

References natfw::config_entry::T_STR.

bool configuration::is_defined ( const std::string &  key  )  const throw ()

Test if the configuration contains the given value.

Parameters:
key the name of the key
Returns:
true, if the configuraiton has that key

Definition at line 232 of file configuration.cpp.

void configuration::load ( std::istream &  in_stream  )  throw (config_error)

Load configuration data from a stream.

If there is a parse error, a config_error exception is thrown. This method will read until end of file. It is up to the caller to close the stream.

Parameters:
in_stream the input stream to read data from

Definition at line 99 of file configuration.cpp.

References natfw::config_entry::defined, parse_error::get_msg(), natfw::config_entry::key, and natfw::config_entry::required.

void configuration::load ( const std::string &  filename  )  throw (config_error)

Load a configuration file.

If there's a parse error or the file can't be opened, a config_error exception is thrown.

Parameters:
filename the file to load

Definition at line 68 of file configuration.cpp.

void configuration::parse_and_assign ( const std::string &  key,
std::istream &  in 
) [private]

bool configuration::parse_bool ( std::istream &  in  )  const [private]

Definition at line 575 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

float configuration::parse_float ( std::istream &  in  )  const [private]

Definition at line 561 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

int configuration::parse_int ( std::istream &  in  )  const [private]

Definition at line 547 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

hostaddress configuration::parse_ipv4_address ( std::istream &  in  )  const [private]

Definition at line 474 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

std::list< hostaddress > configuration::parse_ipv4_address_list ( std::istream &  in  )  const [private]

Definition at line 509 of file configuration.cpp.

Referenced by parse_and_assign().

hostaddress configuration::parse_ipv6_address ( std::istream &  in  )  const [private]

Definition at line 492 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

std::list< hostaddress > configuration::parse_ipv6_address_list ( std::istream &  in  )  const [private]

Definition at line 528 of file configuration.cpp.

Referenced by parse_and_assign().

std::string configuration::parse_string ( std::istream &  in  )  const [private]

Definition at line 436 of file configuration.cpp.

References skip_rest_of_line().

Referenced by parse_and_assign().

void configuration::skip_rest_of_line ( std::istream &  in  )  const [private]

void configuration::strip_leading_space ( std::istream &  in  )  const [private]

Definition at line 370 of file configuration.cpp.

void configuration::write_string ( std::ostream &  out,
const std::string &  str 
) const [private]

Definition at line 415 of file configuration.cpp.


Member Data Documentation

std::map<std::string, config_entry> natfw::configuration::values [private]

Definition at line 157 of file configuration.h.

Referenced by configuration(), and parse_and_assign().


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

Generated on Fri Aug 14 23:39:45 2009 for Ariba by  doxygen 1.5.8