#include <source/ariba/utility/transport/tcpip/protlib/configuration.h>
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< hostaddress > | get_ipv4_address_list (const std::string &key) const throw () |
std::list< hostaddress > | get_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< hostaddress > | parse_ipv4_address_list (std::istream &in) const |
std::list< hostaddress > | parse_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 |
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.
typedef std::map<std::string, config_entry>::const_iterator natfw::configuration::c_iter [private] |
Definition at line 156 of file configuration.h.
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.
void configuration::dump | ( | std::ostream & | out | ) | throw (config_error) |
Write the configuration data to a stream.
If there is a write error, a config_error exception is thrown. This method doesn't close the stream after writing. It is up to the caller to do that.
out | the output stream to read data from |
Definition at line 169 of file configuration.cpp.
References natfw::config_entry::address_list, natfw::config_entry::bool_value, natfw::config_entry::defined, natfw::config_entry::float_value, natfw::config_entry::int_value, natfw::config_entry::ipv4_value, natfw::config_entry::ipv6_value, natfw::config_entry::key, natfw::config_entry::str_value, natfw::config_entry::T_BOOL, natfw::config_entry::T_FLOAT, natfw::config_entry::T_INT, natfw::config_entry::T_IPv4, natfw::config_entry::T_IPv4_LIST, natfw::config_entry::T_IPv6, natfw::config_entry::T_IPv6_LIST, natfw::config_entry::T_STR, and natfw::config_entry::type.
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the key |
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.
key | the name of the 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.
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.
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] |
Definition at line 377 of file configuration.cpp.
References parse_bool(), parse_float(), parse_int(), parse_ipv4_address(), parse_ipv4_address_list(), parse_ipv6_address(), parse_ipv6_address_list(), parse_string(), natfw::config_entry::T_BOOL, natfw::config_entry::T_FLOAT, natfw::config_entry::T_INT, natfw::config_entry::T_IPv4, natfw::config_entry::T_IPv4_LIST, natfw::config_entry::T_IPv6, natfw::config_entry::T_IPv6_LIST, natfw::config_entry::T_STR, and values.
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] |
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] |
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] |
Definition at line 595 of file configuration.cpp.
Referenced by parse_bool(), parse_float(), parse_int(), parse_ipv4_address(), parse_ipv6_address(), and parse_string().
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.
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().