#include <csbuild-debian-changes.h>
Public Types | |
enum | priority { PRIORITY_OPTIONAL, PRIORITY_REQUIRED, PRIORITY_DISALLOWED, PRIORITY_DEPRECATED, PRIORITY_OBSOLETE } |
Configuration parameter priority. More... | |
enum | error_code { BAD_FILE, DEPRECATED_KEY, DEPRECATED_KEY_NL, DISALLOWED_KEY, DISALLOWED_KEY_NL, DUPLICATE_KEY, INVALID_LINE, MISSING_KEY, MISSING_KEY_NL, NO_KEY, OBSOLETE_KEY, OBSOLETE_KEY_NL, PASSTHROUGH_K, PASSTHROUGH_LK } |
Error codes. More... | |
typedef sbuild::parse_error < error_code > | error |
Exception type. | |
Public Member Functions | |
debian_changes () | |
The constructor. | |
debian_changes (std::string const &file) | |
The constructor. | |
debian_changes (std::istream &stream) | |
The constructor. | |
virtual | ~debian_changes () |
The destructor. | |
sbuild::string_list | get_keys () const |
Get a list of keys. | |
bool | has_key (key_type const &key) const |
Check if a key exists. | |
size_type | get_line (key_type const &key) const |
Get a key line number. | |
template<typename T > | |
bool | get_value (key_type const &key, T &value) const |
Get a key value. | |
template<typename T > | |
bool | get_value (key_type const &key, priority priority, T &value) const |
Get a key value. | |
bool | get_value (key_type const &key, value_type &value) const |
Get a key value. | |
bool | get_value (key_type const &key, priority priority, value_type &value) const |
Get a key value. | |
template<typename C > | |
bool | get_list_value (key_type const &key, C &container, std::string const &separator) const |
Get a key value as a list. | |
template<typename C > | |
bool | get_list_value (key_type const &key, priority priority, C &container) const |
Get a key value as a list. | |
template<typename T > | |
void | set_value (key_type const &key, T const &value) |
Set a key value. | |
template<typename T > | |
void | set_value (key_type const &key, T const &value, size_type line) |
Set a key value. | |
void | set_value (key_type const &key, value_type const &value) |
Set a key value. | |
void | set_value (key_type const &key, value_type const &value, size_type line) |
Set a key value. | |
template<typename I > | |
void | set_list_value (key_type const &key, I begin, I end) |
Set a key value from a list. | |
template<typename I > | |
void | set_list_value (key_type const &key, I begin, I end, std::string const &separator, size_type line) |
Set a key value from a list. | |
void | remove_key (key_type const &key) |
Remove a key. | |
debian_changes & | operator+= (debian_changes const &rhs) |
Add a debian_changes to the debian_changes. | |
Static Public Member Functions | |
template<class C , typename T > | |
static void | set_object_value (C const &object, T(C::*method)() const, debian_changes &debian_changes, debian_changes::key_type const &key) |
Set a key value from an object method return value. | |
template<class C , typename T > | |
static void | set_object_value (C const &object, T const &(C::*method)() const, debian_changes &debian_changes, debian_changes::key_type const &key) |
Set a key value from an object method return value reference. | |
template<class C , typename T > | |
static void | set_object_list_value (C const &object, T(C::*method)() const, debian_changes &debian_changes, debian_changes::key_type const &key) |
Set a key list value from an object method return value. | |
template<class C , typename T > | |
static void | set_object_list_value (C const &object, T const &(C::*method)() const, debian_changes &debian_changes, debian_changes::key_type const &key) |
Set a key list value from an object method return value. | |
template<class C , typename T > | |
static void | get_object_value (C &object, void(C::*method)(T param), debian_changes const &debian_changes, debian_changes::key_type const &key, debian_changes::priority priority) |
Get a key value and set it in an object using an object method. | |
template<class C , typename T > | |
static void | get_object_value (C &object, void(C::*method)(T const ¶m), debian_changes const &debian_changes, debian_changes::key_type const &key, debian_changes::priority priority) |
Get a key value and set it by reference in an object using an object method. | |
template<class C , typename T > | |
static void | get_object_list_value (C &object, void(C::*method)(T param), debian_changes const &debian_changes, debian_changes::key_type const &key, debian_changes::priority priority) |
Get a key list value and set it in an object using an object method. | |
template<class C , typename T > | |
static void | get_object_list_value (C &object, void(C::*method)(T const ¶m), debian_changes const &debian_changes, debian_changes::key_type const &key, debian_changes::priority priority) |
Get a key list value and set it by reference in an object using an object method. | |
Private Types | |
typedef std::string | key_type |
typedef std::vector< std::string > | value_type |
typedef unsigned int | size_type |
typedef std::tr1::tuple < key_type, value_type, size_type > | item_type |
Key-value-line tuple. | |
typedef std::map< key_type, item_type > | item_map_type |
Map between key name and key-value-comment tuple. | |
Private Member Functions | |
const item_type * | find_item (key_type const &key) const |
Find a key by its name. | |
item_type * | find_item (key_type const &key) |
Find a key by its name. | |
void | check_priority (key_type const &key, priority priority, bool valid) const |
Check if a key is missing or present when not permitted. | |
Private Attributes | |
item_map_type | items |
The top-level items. | |
Friends | |
debian_changes | operator+ (debian_changes const &lhs, debian_changes const &rhs) |
Add a debian_changes to the debian_changes. | |
template<class charT , class traits > | |
std::basic_istream< charT, traits > & | operator>> (std::basic_istream< charT, traits > &stream, debian_changes &dc) |
debian_changes initialisation from an istream. | |
template<class charT , class traits > | |
std::basic_ostream< charT, traits > & | operator<< (std::basic_ostream< charT, traits > &stream, debian_changes const &dc) |
debian_changes output to an ostream. |
This class is a generic parser for the file format used in Debian changes files for binary and source uploads (.changes and .dsc files).
Exception type.
typedef std::map<key_type,item_type> csbuild::debian_changes::item_map_type [private] |
Map between key name and key-value-comment tuple.
typedef std::tr1::tuple<key_type,value_type,size_type> csbuild::debian_changes::item_type [private] |
Key-value-line tuple.
typedef std::string csbuild::debian_changes::key_type [private] |
typedef unsigned int csbuild::debian_changes::size_type [private] |
typedef std::vector<std::string> csbuild::debian_changes::value_type [private] |
Error codes.
Configuration parameter priority.
debian_changes::debian_changes | ( | ) |
The constructor.
debian_changes::debian_changes | ( | std::string const & | file | ) |
debian_changes::debian_changes | ( | std::istream & | stream | ) |
The constructor.
stream | the stream to load the configuration from. |
debian_changes::~debian_changes | ( | ) | [virtual] |
The destructor.
void debian_changes::check_priority | ( | key_type const & | key, | |
priority | priority, | |||
bool | valid | |||
) | const [private] |
Check if a key is missing or present when not permitted.
key | the key to get. | |
priority | the key priority. | |
valid | true if key exists, false if not existing. |
References DEPRECATED_KEY, DEPRECATED_KEY_NL, DISALLOWED_KEY, DISALLOWED_KEY_NL, get_line(), log_exception_warning(), MISSING_KEY, MISSING_KEY_NL, OBSOLETE_KEY, OBSOLETE_KEY_NL, PRIORITY_DEPRECATED, PRIORITY_DISALLOWED, PRIORITY_OBSOLETE, PRIORITY_REQUIRED, and sbuild::error_base::set_reason().
Referenced by get_list_value(), and get_value().
debian_changes::item_type * debian_changes::find_item | ( | key_type const & | key | ) | [private] |
Find a key by its name.
key | the key to find |
References items.
const debian_changes::item_type * debian_changes::find_item | ( | key_type const & | key | ) | const [private] |
Find a key by its name.
key | the key to find |
References items.
Referenced by get_line(), get_value(), and has_key().
sbuild::string_list debian_changes::get_keys | ( | ) | const |
debian_changes::size_type debian_changes::get_line | ( | key_type const & | key | ) | const |
Get a key line number.
key | the key to find. |
References find_item().
Referenced by check_priority(), get_list_value(), get_object_list_value(), get_object_value(), and get_value().
bool csbuild::debian_changes::get_list_value | ( | key_type 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.
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. |
References check_priority(), and get_list_value().
bool csbuild::debian_changes::get_list_value | ( | key_type const & | key, | |
C & | container, | |||
std::string const & | separator | |||
) | const [inline] |
Get a key value as a list.
key | the key to get. Note that if the key contains multiple lines, each line will be split using the separator. | |
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. | |
separator | the characters to separate the values. |
References get_line(), get_value(), items, log_exception_warning(), sbuild::parse_value(), PASSTHROUGH_K, PASSTHROUGH_LK, and sbuild::split_string().
Referenced by get_list_value(), and get_object_list_value().
static void csbuild::debian_changes::get_object_list_value | ( | C & | object, | |
void(C::*)(T const ¶m) | method, | |||
debian_changes const & | debian_changes, | |||
debian_changes::key_type const & | key, | |||
debian_changes::priority | priority | |||
) | [inline, static] |
Get a key list value and set it by reference in an object using an object method.
This is the same as calling get_list_value directly, but handles exceptions being thrown by the object method, and deserialisation errors, which are turned into error exceptions pointing to the key and line number in the input file.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. | |
priority | the key priority. |
References get_line(), get_list_value(), PASSTHROUGH_K, and PASSTHROUGH_LK.
static void csbuild::debian_changes::get_object_list_value | ( | C & | object, | |
void(C::*)(T param) | method, | |||
debian_changes const & | debian_changes, | |||
debian_changes::key_type const & | key, | |||
debian_changes::priority | priority | |||
) | [inline, static] |
Get a key list value and set it in an object using an object method.
This is the same as calling get_list_value directly, but handles exceptions being thrown by the object method, and deserialisation errors, which are turned into error exceptions pointing to the key and line number in the input file.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. | |
priority | the key priority. |
References get_line(), get_list_value(), PASSTHROUGH_K, and PASSTHROUGH_LK.
static void csbuild::debian_changes::get_object_value | ( | C & | object, | |
void(C::*)(T const ¶m) | method, | |||
debian_changes const & | debian_changes, | |||
debian_changes::key_type const & | key, | |||
debian_changes::priority | priority | |||
) | [inline, static] |
Get a key value and set it by reference in an object using an object method.
This is the same as calling get_value directly, but handles exceptions being thrown by the object method, and deserialisation errors, which are turned into error exceptions pointing to the key and line number in the input file.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. | |
priority | the key priority. |
References get_line(), get_value(), PASSTHROUGH_K, and PASSTHROUGH_LK.
static void csbuild::debian_changes::get_object_value | ( | C & | object, | |
void(C::*)(T param) | method, | |||
debian_changes const & | debian_changes, | |||
debian_changes::key_type const & | key, | |||
debian_changes::priority | priority | |||
) | [inline, static] |
Get a key value and set it in an object using an object method.
This is the same as calling get_value directly, but handles exceptions being thrown by the object method, and deserialisation errors, which are turned into error exceptions pointing to the key and line number in the input file.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. | |
priority | the key priority. |
References get_line(), get_value(), PASSTHROUGH_K, and PASSTHROUGH_LK.
bool debian_changes::get_value | ( | key_type const & | key, | |
priority | priority, | |||
value_type & | value | |||
) | const |
Get a key value.
If the value does not exist, is deprecated or obsolete, warn appropriately.
key | the key to get. | |
priority | the priority of the option. | |
value | the value to store the key's value in. |
References check_priority(), and get_value().
bool debian_changes::get_value | ( | key_type const & | key, | |
value_type & | value | |||
) | const |
Get a key value.
key | the key to get. | |
value | the value to store the key's value in. |
References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, find_item(), and sbuild::log_debug().
bool csbuild::debian_changes::get_value | ( | key_type const & | key, | |
priority | priority, | |||
T & | value | |||
) | const [inline] |
Get a key value.
If the value does not exist, is deprecated or obsolete, warn appropriately.
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. |
References check_priority(), and get_value().
bool csbuild::debian_changes::get_value | ( | key_type const & | key, | |
T & | value | |||
) | const [inline] |
Get a key value.
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. |
References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, find_item(), get_line(), sbuild::log_debug(), log_exception_warning(), sbuild::parse_value(), PASSTHROUGH_K, and PASSTHROUGH_LK.
Referenced by get_list_value(), get_object_value(), and get_value().
bool debian_changes::has_key | ( | key_type const & | key | ) | const |
Check if a key exists.
key | the key to check for. |
References find_item().
debian_changes & debian_changes::operator+= | ( | debian_changes const & | rhs | ) |
Add a debian_changes to the debian_changes.
rhs | the debian_changes to add. |
References items, and set_value().
void debian_changes::remove_key | ( | key_type const & | key | ) |
void csbuild::debian_changes::set_list_value | ( | key_type const & | key, | |
I | begin, | |||
I | end, | |||
std::string const & | separator, | |||
size_type | line | |||
) | [inline] |
Set a key value from a list.
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. | |
separator | the characters to separate the values. | |
line | the line number in the input file, or 0 otherwise. |
References set_value().
void csbuild::debian_changes::set_list_value | ( | key_type const & | key, | |
I | begin, | |||
I | end | |||
) | [inline] |
Set a key value from a list.
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. |
Referenced by set_object_list_value().
static void csbuild::debian_changes::set_object_list_value | ( | C const & | object, | |
T const &(C::*)() const | method, | |||
debian_changes & | debian_changes, | |||
debian_changes::key_type const & | key | |||
) | [inline, static] |
Set a key list value from an object method return value.
The method must return a container reference with begin() and end() methods which return forward iterators. This is the same as calling set_list_value directly, but handles exceptions being thrown by the object method, which are turned into error exceptions.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. |
References PASSTHROUGH_K, and set_list_value().
static void csbuild::debian_changes::set_object_list_value | ( | C const & | object, | |
T(C::*)() const | method, | |||
debian_changes & | debian_changes, | |||
debian_changes::key_type const & | key | |||
) | [inline, static] |
Set a key list value from an object method return value.
The method must return a container with begin() and end() methods which return forward iterators. This is the same as calling set_list_value directly, but handles exceptions being thrown by the object method, which are turned into error exceptions.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. |
References PASSTHROUGH_K, and set_list_value().
static void csbuild::debian_changes::set_object_value | ( | C const & | object, | |
T const &(C::*)() const | method, | |||
debian_changes & | debian_changes, | |||
debian_changes::key_type const & | key | |||
) | [inline, static] |
Set a key value from an object method return value reference.
This is the same as calling set_value directly, but handles exceptions being thrown by the object method, which are turned into error exceptions.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. |
References PASSTHROUGH_K, and set_value().
static void csbuild::debian_changes::set_object_value | ( | C const & | object, | |
T(C::*)() const | method, | |||
debian_changes & | debian_changes, | |||
debian_changes::key_type const & | key | |||
) | [inline, static] |
Set a key value from an object method return value.
This is the same as calling set_value directly, but handles exceptions being thrown by the object method, which are turned into error exceptions.
object | the object to use. | |
method | the object method to call. | |
debian_changes | the debian_changes to use. | |
key | the key to set. |
References PASSTHROUGH_K, and set_value().
void debian_changes::set_value | ( | key_type const & | key, | |
value_type const & | value, | |||
size_type | line | |||
) |
Set a key value.
key | the key to set. | |
value | the value to get the key's value from. | |
line | the line number in the input file, or 0 otherwise. |
References items.
void csbuild::debian_changes::set_value | ( | key_type const & | key, | |
value_type const & | value | |||
) | [inline] |
Set a key value.
key | the key to set. | |
value | the value to get the key's value from. |
References set_value().
void csbuild::debian_changes::set_value | ( | key_type const & | key, | |
T const & | value, | |||
size_type | line | |||
) | [inline] |
Set a key value.
key | the key to set. | |
value | the value to get the key's value from. This must allow output to an ostream. | |
line | the line number in the input file, or 0 otherwise. |
References items.
void csbuild::debian_changes::set_value | ( | key_type const & | key, | |
T const & | value | |||
) | [inline] |
Set a key value.
key | the key to set. | |
value | the value to get the key's value from. This must allow output to an ostream. |
Referenced by operator+=(), set_list_value(), set_object_value(), and set_value().
debian_changes operator+ | ( | debian_changes const & | lhs, | |
debian_changes const & | rhs | |||
) | [friend] |
Add a debian_changes to the debian_changes.
lhs | the debian_changes to add to. | |
rhs | the values to add. |
std::basic_ostream<charT,traits>& operator<< | ( | std::basic_ostream< charT, traits > & | stream, | |
debian_changes const & | dc | |||
) | [friend] |
debian_changes output to an ostream.
stream | the stream to output to. | |
dc | the debian_changes to output. |
std::basic_istream<charT,traits>& operator>> | ( | std::basic_istream< charT, traits > & | stream, | |
debian_changes & | dc | |||
) | [friend] |
debian_changes initialisation from an istream.
stream | the stream to input from. | |
kf | the debian_changes to set. |
item_map_type csbuild::debian_changes::items [private] |
The top-level items.
Referenced by find_item(), get_keys(), get_list_value(), operator+=(), remove_key(), and set_value().