#include <sbuild-keyfile.h>
Collaboration diagram for sbuild::keyfile:
Public Types | |
typedef parse_error | error |
Exception type. | |
PRIORITY_OPTIONAL | |
The parameter is optional. | |
PRIORITY_REQUIRED | |
The parameter is required. | |
PRIORITY_DISALLOWED | |
The parameter is not allowed in this context. | |
PRIORITY_DEPRECATED | |
The parameter is deprecated, but functional. | |
PRIORITY_OBSOLETE | |
The parameter is obsolete, and not functional. | |
enum | priority { PRIORITY_OPTIONAL, PRIORITY_REQUIRED, PRIORITY_DISALLOWED, PRIORITY_DEPRECATED, PRIORITY_OBSOLETE } |
Configuration parameter priority. More... | |
Public Member Functions | |
keyfile () | |
The constructor. | |
keyfile (std::string const &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 (std::string const &group) const |
Get a list of keys in a group. | |
bool | has_group (std::string const &group) const |
Check if a group exists. | |
bool | has_key (std::string const &group, std::string const &key) const |
Check if a key exists. | |
void | set_group (std::string const &group, std::string const &comment) |
Set a group. | |
std::string | get_comment (std::string const &group) const |
Get a group comment. | |
std::string | get_comment (std::string const &group, std::string const &key) const |
Get a key comment. | |
template<typename T> | |
bool | get_value (std::string const &group, std::string const &key, T &value) const |
Get a key value. | |
template<typename T> | |
bool | get_value (std::string const &group, std::string const &key, priority priority, T &value) const |
Get a key value. | |
bool | get_locale_string (std::string const &group, std::string const &key, std::string &value) const |
Get a localised key string value. | |
bool | get_locale_string (std::string const &group, std::string const &key, priority priority, std::string &value) const |
Get a localised key string value. | |
bool | get_locale_string (std::string const &group, std::string const &key, std::string const &locale, std::string &value) const |
Get a localised key string value for a specific locale. | |
bool | get_locale_string (std::string const &group, std::string const &key, std::string const &locale, priority priority, std::string &value) const |
Get a localised key string value for a specific locale. | |
template<typename C> | |
bool | get_list_value (std::string const &group, std::string const &key, C &container) const |
Get a key value as a list. | |
template<typename C> | |
bool | get_list_value (std::string const &group, std::string const &key, priority priority, C &container) const |
Get a key value as a list. | |
template<typename T> | |
void | set_value (std::string const &group, std::string const &key, T const &value) |
Set a key value. | |
template<typename T> | |
void | set_value (std::string const &group, std::string const &key, T const &value, std::string const &comment) |
Set a key value. | |
template<typename I> | |
void | set_list_value (std::string const &group, std::string const &key, I begin, I end) |
Set a key value from a list. | |
template<typename I> | |
void | set_list_value (std::string const &group, std::string const &key, I begin, I end, std::string const &comment) |
Set a key value from a list. | |
void | remove_group (std::string const &group) |
Remove a group. | |
void | remove_key (std::string const &group, std::string const &key) |
Remove a key. | |
keyfile & | operator+= (keyfile const &rhs) |
Add a keyfile to the keyfile. | |
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 | |
const group_type * | find_group (std::string const &group) const |
Find a group by it's name. | |
group_type * | find_group (std::string const &group) |
Find a group by it's name. | |
const item_type * | find_item (std::string const &group, std::string const &key) const |
Find a key by it's group and name. | |
item_type * | find_item (std::string const &group, std::string const &key) |
Find a key by it's group and name. | |
void | check_priority (std::string const &group, std::string const &key, priority priority, bool valid) const |
Check if a key is missing or present when not permitted. | |
Static Private Member Functions | |
static void | print_comment (std::string const &comment, std::ostream &stream) |
Print a comment to a stream. | |
Private Attributes | |
group_map_type | groups |
The top-level groups. | |
char | separator |
The separator used as a list item delimiter. | |
Friends | |
keyfile | operator+ (keyfile const &lhs, keyfile const &rhs) |
Add a keyfile to the keyfile. | |
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, keyfile const &kf) |
keyfile output to an ostream. |
This class loads an INI-style configuration file from a file or stream. The format is documented in schroot.conf(5). It is based upon the Glib GKeyFile class, which it is intended to replace.
typedef parse_error sbuild::keyfile::error |
Exception type.
typedef std::map<std::string,group_type> sbuild::keyfile::group_map_type [private] |
Map between group name and group-items-comment tuple.
typedef std::tr1::tuple<std::string,item_map_type,std::string> sbuild::keyfile::group_type [private] |
Group-items-comment tuple.
typedef std::map<std::string,item_type> sbuild::keyfile::item_map_type [private] |
Map between key name and key-value-comment tuple.
typedef std::tr1::tuple<std::string,std::string,std::string> sbuild::keyfile::item_type [private] |
Key-value-comment tuple.
Configuration parameter priority.
keyfile::keyfile | ( | ) |
The constructor.
keyfile::keyfile | ( | std::string const & | file | ) |
The constructor.
file | the file to load the configuration from. |
keyfile::keyfile | ( | std::istream & | stream | ) |
The constructor.
stream | the stream to load the configuration from. |
keyfile::~keyfile | ( | ) | [virtual] |
The destructor.
void keyfile::check_priority | ( | std::string const & | group, | |
std::string const & | key, | |||
priority | priority, | |||
bool | valid | |||
) | const [private] |
Check if a key is missing or present when not permitted.
group | the group the key is in. | |
key | the key to get. | |
priority | the key priority. | |
valid | true if key exists, false if not existing. |
keyfile::group_type * keyfile::find_group | ( | std::string const & | group | ) | [private] |
Find a group by it's name.
group | the group to find. |
const keyfile::group_type * keyfile::find_group | ( | std::string const & | group | ) | const [private] |
Find a group by it's name.
group | the group to find. |
keyfile::item_type * keyfile::find_item | ( | std::string const & | group, | |
std::string const & | key | |||
) | [private] |
Find a key by it's group and name.
group | the group the key is in. | |
key | the key to find |
const keyfile::item_type * keyfile::find_item | ( | std::string const & | group, | |
std::string const & | key | |||
) | const [private] |
Find a key by it's group and name.
group | the group the key is in. | |
key | the key to find |
std::string keyfile::get_comment | ( | std::string const & | group, | |
std::string const & | key | |||
) | const |
Get a key comment.
group | the group to find. | |
key | the key to find. |
std::string keyfile::get_comment | ( | std::string const & | group | ) | const |
Get a group comment.
group | the group to find. |
string_list keyfile::get_groups | ( | ) | const |
Get a list of groups.
string_list keyfile::get_keys | ( | std::string const & | group | ) | const |
Get a list of keys in a group.
group | the group to use. |
bool sbuild::keyfile::get_list_value | ( | std::string const & | group, | |
std::string const & | key, | |||
priority | priority, | |||
C & | container | |||
) | const [inline] |
Get a key value as a list.
If the value does not exist, is deprecated or obsolete, warn appropriately.
group | the group the key is in. | |
key | the key to get. | |
priority | the priority of the option. | |
container | the container 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. |
Here is the call graph for this function:
bool sbuild::keyfile::get_list_value | ( | std::string const & | group, | |
std::string const & | key, | |||
C & | container | |||
) | const [inline] |
Get a key value as a list.
group | the group the key is in. | |
key | the key to get. | |
container | the container 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. |
Here is the call graph for this function:
bool keyfile::get_locale_string | ( | std::string const & | group, | |
std::string const & | key, | |||
std::string const & | locale, | |||
priority | priority, | |||
std::string & | value | |||
) | const |
Get a localised key string value for a specific locale.
If the value does not exist, is deprecated or obsolete, warn appropriately.
group | the group the key is in. | |
key | the key to get. | |
locale | the locale to use. | |
priority | the priority of the option. | |
value | the string to store the key's localised value in. |
bool keyfile::get_locale_string | ( | std::string const & | group, | |
std::string const & | key, | |||
std::string const & | locale, | |||
std::string & | value | |||
) | const |
Get a localised key string value for a specific locale.
group | the group the key is in. | |
key | the key to get. | |
locale | the locale to use. | |
value | the string to store the key's localised value in. |
bool keyfile::get_locale_string | ( | std::string const & | group, | |
std::string const & | key, | |||
priority | priority, | |||
std::string & | value | |||
) | const |
Get a localised key string value.
If the value does not exist, is deprecated or obsolete, warn appropriately.
group | the group the key is in. | |
key | the key to get. | |
priority | the priority of the option. | |
value | the string to store the key's localised value in. |
bool keyfile::get_locale_string | ( | std::string const & | group, | |
std::string const & | key, | |||
std::string & | value | |||
) | const |
Get a localised key string value.
group | the group the key is in. | |
key | the key to get. | |
value | the string to store the key's localised value in. |
bool sbuild::keyfile::get_value | ( | std::string const & | group, | |
std::string const & | key, | |||
priority | priority, | |||
T & | value | |||
) | const [inline] |
Get a key value.
If the value does not exist, is deprecated or obsolete, warn appropriately.
group | the group the key is in. | |
key | the key to get. | |
priority | the priority of the option. | |
value | the value to store the key's value in. This must be settable from an istream and be copyable. |
Here is the call graph for this function:
bool sbuild::keyfile::get_value | ( | std::string const & | group, | |
std::string const & | key, | |||
T & | value | |||
) | const [inline] |
Get a key value.
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. |
Here is the call graph for this function:
bool keyfile::has_group | ( | std::string const & | group | ) | const |
Check if a group exists.
group | the group to check for. |
bool keyfile::has_key | ( | std::string const & | group, | |
std::string const & | key | |||
) | const |
Check if a key exists.
group | the group the key is in. | |
key | the key to check for. |
Add a keyfile to the keyfile.
rhs | the keyfile to add. |
void keyfile::print_comment | ( | std::string const & | comment, | |
std::ostream & | stream | |||
) | [static, private] |
Print a comment to a stream.
The comment will have hash ('#') marks printed at the start of each line.
comment | the comment to print. | |
stream | the stream to output to. |
void keyfile::remove_group | ( | std::string const & | group | ) |
Remove a group.
group | the group to remove. |
void keyfile::remove_key | ( | std::string const & | group, | |
std::string const & | key | |||
) |
Remove a key.
group | the group the key is in. | |
key | the key to remove. |
void keyfile::set_group | ( | std::string const & | group, | |
std::string const & | comment | |||
) |
Set a group.
The group will be created (and the comment set) only if the group does not already exist.
group | the group to set. | |
comment | the comment to set. |
void sbuild::keyfile::set_list_value | ( | std::string const & | group, | |
std::string const & | key, | |||
I | begin, | |||
I | end, | |||
std::string const & | comment | |||
) | [inline] |
Set a key value from a list.
group | the group the key is in. | |
key | the key to set. | |
begin | an iterator referring to the start of the list. The value type must allow output to an ostream. | |
end | an iterator referring to the end of the list. | |
comment | the comment for this key. |
Here is the call graph for this function:
void sbuild::keyfile::set_list_value | ( | std::string const & | group, | |
std::string const & | key, | |||
I | begin, | |||
I | end | |||
) | [inline] |
Set a key value from a list.
group | the group the key is in. | |
key | the key to set. | |
begin | an iterator referring to the start of the list. The value type must allow output to an ostream. | |
end | an iterator referring to the end of the list. |
void sbuild::keyfile::set_value | ( | std::string const & | group, | |
std::string const & | key, | |||
T const & | value, | |||
std::string const & | comment | |||
) | [inline] |
Set a key value.
group | the group the key is in. | |
key | the key to set. | |
value | the value to get the key's value from. This must | |
comment | the comment for this key. allow output to an ostream. |
Here is the call graph for this function:
void sbuild::keyfile::set_value | ( | std::string const & | group, | |
std::string const & | key, | |||
T const & | value | |||
) | [inline] |
Set a key value.
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. |
Add a keyfile to the keyfile.
lhs | the keyfile to add to. | |
rhs | the values to add. |
std::basic_ostream<charT,traits>& operator<< | ( | std::basic_ostream< charT, traits > & | stream, | |
keyfile const & | kf | |||
) | [friend] |
keyfile output to an ostream.
std::basic_istream<charT,traits>& operator>> | ( | std::basic_istream< charT, traits > & | stream, | |
keyfile & | kf | |||
) | [friend] |
keyfile initialisation from an istream.
group_map_type sbuild::keyfile::groups [private] |
The top-level groups.
char sbuild::keyfile::separator [private] |
The separator used as a list item delimiter.