csbuild::debian_changes Class Reference

Debian changes file parser. More...

#include <csbuild-debian-changes.h>

Collaboration diagram for csbuild::debian_changes:

Collaboration graph
[legend]

List of all members.

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_changesoperator+= (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 &param), 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 &param), 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_typefind_item (key_type const &key) const
 Find a key by its name.
item_typefind_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.


Detailed Description

Debian changes file parser.

This class is a generic parser for the file format used in Debian changes files for binary and source uploads (.changes and .dsc files).


Member Typedef Documentation

Exception type.

Map between key name and key-value-comment tuple.

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]


Member Enumeration Documentation

Error codes.

Enumerator:
BAD_FILE  The file to parse couldn't be opened.
DEPRECATED_KEY  The key is deprecated.
DEPRECATED_KEY_NL  The key is deprecated (no line specified).
DISALLOWED_KEY  The key is not allowed.
DISALLOWED_KEY_NL  The key is not allowed (no line specified).
DUPLICATE_KEY  The key is a duplicate.
INVALID_LINE  The line is invalid.
MISSING_KEY  The key is missing.
MISSING_KEY_NL  The key is missing (no line specified).
NO_KEY  No key was specified.
OBSOLETE_KEY  The key is obsolete.
OBSOLETE_KEY_NL  The key is obsolete (no line specified).
PASSTHROUGH_K  Pass through exception with key.
PASSTHROUGH_LK  Pass through exception with line and key.

Configuration parameter priority.

Enumerator:
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.


Constructor & Destructor Documentation

debian_changes::debian_changes (  ) 

The constructor.

debian_changes::debian_changes ( std::string const &  file  ) 

The constructor.

Parameters:
file the file to load the configuration from.

References BAD_FILE.

debian_changes::debian_changes ( std::istream &  stream  ) 

The constructor.

Parameters:
stream the stream to load the configuration from.

debian_changes::~debian_changes (  )  [virtual]

The destructor.


Member Function Documentation

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.

Parameters:
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().

Here is the caller graph for this function:

debian_changes::item_type * debian_changes::find_item ( key_type const &  key  )  [private]

Find a key by its name.

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

References items.

const debian_changes::item_type * debian_changes::find_item ( key_type const &  key  )  const [private]

Find a key by its name.

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

References items.

Referenced by get_line(), get_value(), and has_key().

Here is the caller graph for this function:

sbuild::string_list debian_changes::get_keys (  )  const

Get a list of keys.

Returns:
a list of keys.

References items.

debian_changes::size_type debian_changes::get_line ( key_type const &  key  )  const

Get a key line number.

Parameters:
key the key to find.
Returns:
the line number, or 0 if not available.

References find_item().

Referenced by check_priority(), get_list_value(), get_object_list_value(), get_object_value(), and get_value().

Here is the caller graph for this function:

template<typename C >
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.

Parameters:
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.
Returns:
true if the key was found, otherwise false (in which case value will be undefined).

References check_priority(), and get_list_value().

template<typename C >
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.

Parameters:
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.
Returns:
true if the key was found, otherwise false (in which case value will be undefined).

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().

Here is the caller graph for this function:

template<class C , typename T >
static void csbuild::debian_changes::get_object_list_value ( C &  object,
void(C::*)(T const &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 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.

Parameters:
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.

template<class C , typename T >
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.

Parameters:
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.

template<class C , typename T >
static void csbuild::debian_changes::get_object_value ( C &  object,
void(C::*)(T const &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 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.

Parameters:
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.

template<class C , typename T >
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.

Parameters:
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.

Parameters:
key the key to get.
priority the priority of the option.
value the value to store the key's value in.
Returns:
true if the key was found, otherwise false (in which case value will be unchanged).

References check_priority(), and get_value().

bool debian_changes::get_value ( key_type const &  key,
value_type value 
) const

Get a key value.

Parameters:
key the key to get.
value the value to store the key's value in.
Returns:
true if the key was found, otherwise false (in which case value will be unchanged).

References sbuild::DEBUG_INFO, sbuild::DEBUG_NOTICE, find_item(), and sbuild::log_debug().

template<typename T >
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.

Parameters:
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.
Returns:
true if the key was found, otherwise false (in which case value will be unchanged).

References check_priority(), and get_value().

template<typename T >
bool csbuild::debian_changes::get_value ( key_type const &  key,
T &  value 
) const [inline]

Get a key value.

Parameters:
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).

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().

Here is the caller graph for this function:

bool debian_changes::has_key ( key_type const &  key  )  const

Check if a key exists.

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

References find_item().

debian_changes & debian_changes::operator+= ( debian_changes const &  rhs  ) 

Add a debian_changes to the debian_changes.

Parameters:
rhs the debian_changes to add.
Returns:
the modified debian_changes.

References items, and set_value().

void debian_changes::remove_key ( key_type const &  key  ) 

Remove a key.

Parameters:
key the key to remove.

References items.

template<typename I >
void csbuild::debian_changes::set_list_value ( key_type const &  key,
begin,
end,
std::string const &  separator,
size_type  line 
) [inline]

Set a key value from a list.

Parameters:
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().

template<typename I >
void csbuild::debian_changes::set_list_value ( key_type const &  key,
begin,
end 
) [inline]

Set a key value from a list.

Parameters:
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().

Here is the caller graph for this function:

template<class C , typename T >
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.

Parameters:
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().

template<class C , typename T >
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.

Parameters:
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().

template<class C , typename T >
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.

Parameters:
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().

template<class C , typename T >
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.

Parameters:
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.

Parameters:
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.

Parameters:
key the key to set.
value the value to get the key's value from.

References set_value().

template<typename T >
void csbuild::debian_changes::set_value ( key_type const &  key,
T const &  value,
size_type  line 
) [inline]

Set a key value.

Parameters:
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.

template<typename T >
void csbuild::debian_changes::set_value ( key_type const &  key,
T const &  value 
) [inline]

Set a key value.

Parameters:
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().

Here is the caller graph for this function:


Friends And Related Function Documentation

debian_changes operator+ ( debian_changes const &  lhs,
debian_changes const &  rhs 
) [friend]

Add a debian_changes to the debian_changes.

Parameters:
lhs the debian_changes to add to.
rhs the values to add.
Returns:
the new debian_changes.

template<class charT , class traits >
std::basic_ostream<charT,traits>& operator<< ( std::basic_ostream< charT, traits > &  stream,
debian_changes const &  dc 
) [friend]

debian_changes output to an ostream.

Parameters:
stream the stream to output to.
dc the debian_changes to output.
Returns:
the stream.

template<class charT , class traits >
std::basic_istream<charT,traits>& operator>> ( std::basic_istream< charT, traits > &  stream,
debian_changes dc 
) [friend]

debian_changes initialisation from an istream.

Parameters:
stream the stream to input from.
kf the debian_changes to set.
Returns:
the stream.


Member Data Documentation

The top-level items.

Referenced by find_item(), get_keys(), get_list_value(), operator+=(), remove_key(), and set_value().


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

Generated on Sun Mar 22 22:18:29 2009 for schroot by  doxygen 1.5.8