sbuild::keyfile Class Reference

Configuration file parser. More...

#include <sbuild-keyfile.h>

List of all members.

Public Types

typedef runtime_error_custom<
keyfile
error
 Exception type.

Public Member Functions

 keyfile (const std::string &file)
 The constructor.
 keyfile (std::istream &stream)
 The constructor.
virtual ~keyfile ()
 The destructor.
string_list get_groups () const
 Get a list of groups.
string_list get_keys (const std::string &group) const
 Get a list of keys in a group.
bool has_group (const std::string &group) const
 Check if a group exists.
bool has_key (const std::string &group, const std::string &key) const
 Check if a key exists.
template<typename T>
bool get_value (const std::string &group, const std::string &key, T &value) const
 Get a key value.
template<typename T, template< typename T > class C>
bool get_list_value (const std::string &group, const std::string &key, C< T > &value) const
 Get a key value as a list.
template<typename T>
void set_value (const std::string &group, const std::string &key, const T &value)
 Set a key value.
template<typename T, template< typename T > class C>
void set_list_value (const std::string &group, const std::string &key, const C< T > &value)
 Set a key value from a list.
void remove_group (const std::string &group)
 Remove a group.
void remove_key (const std::string &group, const std::string &key)
 Remove a key.

Private Types

typedef std::tr1::tuple< std::string,
std::string, std::string > 
item_type
 Key-value-comment tuple.
typedef std::map< std::string,
item_type
item_map_type
 Map between key name and key-value-comment tuple.
typedef std::tr1::tuple< std::string,
item_map_type, std::string > 
group_type
 Group-items-comment tuple.
typedef std::map< std::string,
group_type
group_map_type
 Map between group name and group-items-comment tuple.

Private Member Functions

void print_comment (const std::string &comment, std::ostream &stream) const
 Print a comment to a stream.
const group_typefind_group (const std::string &group) const
 Find a group by it's name.
group_typefind_group (const std::string &group)
 Find a group by it's name.
const item_typefind_item (const std::string &group, const std::string &key) const
 Find a key by it's group and name.
item_typefind_item (const std::string &group, const std::string &key)
 Find a key by it's group and name.

Private Attributes

group_map_type groups
 The top-level groups.
char separator
 The separator used as a list item delimiter.

Friends

template<class charT, class traits>
std::basic_istream< charT,
traits > & 
operator>> (std::basic_istream< charT, traits > &stream, keyfile &kf)
 keyfile initialisation from an istream.
template<class charT, class traits>
std::basic_ostream< charT,
traits > & 
operator<< (std::basic_ostream< charT, traits > &stream, const keyfile &kf)
 keyfile output to an ostream.


Detailed Description

Configuration file parser.

This class loads an INI-style configuration file from disk. The format is documented in schroot.conf(5). It is based upon the Glib GKeyFile class, which it is intended to replace.

Todo:
Add support for locale strings.

Add support for comments.


Constructor & Destructor Documentation

keyfile::keyfile const std::string &  file  ) 
 

The constructor.

Parameters:
file the file to load the configuration from.

keyfile::keyfile std::istream &  stream  ) 
 

The constructor.

Parameters:
stream the stream to load the configuration from.


Member Function Documentation

keyfile::group_type * keyfile::find_group const std::string &  group  )  [private]
 

Find a group by it's name.

Parameters:
group the group to find.
Returns:
the group, or 0 if not found.

const keyfile::group_type * keyfile::find_group const std::string &  group  )  const [private]
 

Find a group by it's name.

Parameters:
group the group to find.
Returns:
the group, or 0 if not found.

keyfile::item_type * keyfile::find_item const std::string &  group,
const std::string &  key
[private]
 

Find a key by it's group and name.

Parameters:
group the group the key is in.
key the key to find
Returns:
the key, or 0 if not found.

const keyfile::item_type * keyfile::find_item const std::string &  group,
const std::string &  key
const [private]
 

Find a key by it's group and name.

Parameters:
group the group the key is in.
key the key to find
Returns:
the key, or 0 if not found.

string_list keyfile::get_groups  )  const
 

Get a list of groups.

Returns:
a list of groups in the keyfile. If no groups exist, the list will be empty.

string_list keyfile::get_keys const std::string &  group  )  const
 

Get a list of keys in a group.

Parameters:
group the group to use.
Returns:
a list of keys in a group. If no keys exist in the group, or the group does not exist, the list will be empty.

template<typename T, template< typename T > class C>
bool sbuild::keyfile::get_list_value const std::string &  group,
const std::string &  key,
C< T > &  value
const [inline]
 

Get a key value as a list.

Parameters:
group the group the key is in.
key the key to get.
value the list value to store the key's value in. The value type must be settable from an istream and be copyable. The list must be a container with a standard insert method.
Returns:
true if the key was found, otherwise false (in which case value will be unchanged).

Here is the call graph for this function:

template<typename T>
bool sbuild::keyfile::get_value const std::string &  group,
const std::string &  key,
T &  value
const [inline]
 

Get a key value.

Parameters:
group the group the key is in.
key the key to get.
value the value to store the key's value in. This must be settable from an istream and be copyable.
Returns:
true if the key was found, otherwise false (in which case value will be unchanged).

Here is the call graph for this function:

bool keyfile::has_group const std::string &  group  )  const
 

Check if a group exists.

Parameters:
group the group to check for.
Returns:
true if the group exists, otherwise false.

bool keyfile::has_key const std::string &  group,
const std::string &  key
const
 

Check if a key exists.

Parameters:
group the group the key is in.
key the key to check for.
Returns:
true if the key exists, otherwise false.

void keyfile::print_comment const std::string &  comment,
std::ostream &  stream
const [private]
 

Print a comment to a stream.

The comment will have hash ('#') marks printed at the start of each line.

Parameters:
comment the comment to print.
stream the stream to output to.

void keyfile::remove_group const std::string &  group  ) 
 

Remove a group.

Parameters:
group the group to remove.

void keyfile::remove_key const std::string &  group,
const std::string &  key
 

Remove a key.

Parameters:
group the group the key is in.
key the key to remove.

template<typename T, template< typename T > class C>
void sbuild::keyfile::set_list_value const std::string &  group,
const std::string &  key,
const C< T > &  value
[inline]
 

Set a key value from a list.

Parameters:
group the group the key is in.
key the key to set.
value the list value to get the key's value from. The value type must allow output to an ostream. The list must be a container with a standard forward iterator.

template<typename T>
void sbuild::keyfile::set_value const std::string &  group,
const std::string &  key,
const T &  value
[inline]
 

Set a key value.

Parameters:
group the group the key is in.
key the key to set.
value the value to get the key's value from. This must allow output to an ostream.

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Thu Dec 29 17:20:06 2005 for schroot by  doxygen 1.4.5