19 #ifndef SBUILD_BASIC_KEYFILE_H
20 #define SBUILD_BASIC_KEYFILE_H
23 #include <sbuild/sbuild-log.h>
24 #include <sbuild/sbuild-keyfile-base.h>
25 #include <sbuild/sbuild-parse-error.h>
26 #include <sbuild/sbuild-parse-value.h>
27 #include <sbuild/sbuild-types.h>
29 #include <sbuild/sbuild-util.h>
36 #include <boost/format.hpp>
70 typename K::group_name_type
group;
76 typename K::key_type
key;
137 template <
typename K,
typename P = basic_keyfile_parser<K> >
167 typedef std::tuple<key_type,value_type,comment_type,size_type>
174 typedef std::tuple<group_name_type,item_map_type,comment_type,size_type>
group_type;
328 template <
typename T>
335 <<
", key=" << key << std::endl;
339 value_type const& strval(std::get<1>(*found_item));
377 template <
typename T>
384 bool status =
get_value(group, key, value);
433 std::string
const& locale,
452 std::string
const& locale,
468 template <
typename C>
479 for (
typename value_list::const_iterator pos = items.begin();
484 typename C::value_type tmp;
506 container.push_back(tmp);
527 template <
typename C>
551 template <
typename C>
562 for (
typename value_list::const_iterator pos = items.begin();
567 typename C::value_type tmp;
589 container.insert(tmp);
610 template <
typename C>
630 template <
typename T>
648 template <
typename T>
655 set_value(group, key, value, comment, 0);
668 template <
typename T>
676 std::ostringstream os;
677 os.imbue(std::locale::classic());
678 os << std::boolalpha << value;
682 assert (found_group != 0);
686 typename item_map_type::iterator pos = items.find(key);
687 if (pos != items.end())
690 (
typename item_map_type::value_type(key,
704 template <
typename I>
724 template <
typename I>
746 template <
typename I>
757 for (I pos = begin; pos != end;)
759 std::ostringstream os;
760 os.imbue(std::locale::classic());
761 os << std::boolalpha << *pos;
770 set_value (group, key, strval, comment, line);
782 template <
typename I>
789 std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
790 std::sort(l.begin(), l.end());
804 template <
typename I>
812 std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
813 std::sort(l.begin(), l.end());
828 template <
typename I>
837 std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
838 std::sort(l.begin(), l.end());
876 template <
typename _K,
typename _P>
888 template <
class charT,
class traits>
890 std::basic_istream<charT,traits>&
900 while (std::getline(stream, line))
902 state.parse_line(line);
910 tmp.
set_group(state.group, state.comment, state.line_number);
914 if (state.key_set && state.value_set)
916 if (tmp.
has_key(state.group, state.key))
919 tmp.
set_value(state.group, state.key, state.value, state.comment, state.line_number);
938 template <
class charT,
class traits>
940 std::basic_ostream<charT,traits>&
941 operator << (std::basic_ostream<charT,traits>& stream,
946 for (
typename group_map_type::const_iterator gp = kf.groups.begin();
947 gp != kf.groups.end();
957 if (comment.length() > 0)
960 stream <<
'[' << groupname <<
']' <<
'\n';
963 for (
typename item_map_type::const_iterator it = items.begin();
968 key_type const& key(std::get<0>(item));
972 if (comment.length() > 0)
975 stream << key <<
'=' << value <<
'\n';
1050 std::ostream& stream);
1070 template<
class C,
typename T>
1073 T (C::* method)()
const,
1081 basic_keyfile.
set_value(group, key, (
object.*method)());
1083 catch (std::runtime_error
const& e)
1101 template<
class C,
typename T>
1104 T
const& (C::* method)()
const,
1112 basic_keyfile.
set_value(group, key, (
object.*method)());
1114 catch (std::runtime_error
const& e)
1133 template<
class C,
typename T>
1136 T (C::* method)()
const,
1145 (
object.*method)().begin(),
1146 (
object.*method)().end());
1148 catch (std::runtime_error
const& e)
1168 template<
class C,
typename T>
1171 T
const& (C::* method)()
const,
1180 (
object.*method)().begin(),
1181 (
object.*method)().end());
1183 catch (std::runtime_error
const& e)
1202 template<
class C,
typename T>
1205 T (C::* method)()
const,
1214 (
object.*method)().begin(),
1215 (
object.*method)().end());
1217 catch (std::runtime_error
const& e)
1237 template<
class C,
typename T>
1240 T
const& (C::* method)()
const,
1249 (
object.*method)().begin(),
1250 (
object.*method)().end());
1252 catch (std::runtime_error
const& e)
1272 template<
class C,
typename T>
1275 void (C::* method)(T param),
1284 if (basic_keyfile.
get_value(group, key, priority, value)
1286 (
object.*method)(value);
1288 catch (std::runtime_error
const& e)
1312 template<
class C,
typename T>
1315 void (C::* method)(T
const& param),
1324 if (basic_keyfile.
get_value(group, key, priority, value)
1326 (
object.*method)(value);
1328 catch (std::runtime_error
const& e)
1352 template<
class C,
typename T>
1355 void (C::* method)(T param),
1366 (
object.*method)(value);
1368 catch (std::runtime_error
const& e)
1395 template<
class C,
typename T>
1398 void (C::* method)(T
const& param),
1409 (
object.*method)(value);
1411 catch (std::runtime_error
const& e)
1437 template<
class C,
typename T>
1440 void (C::* method)(T param),
1449 if (basic_keyfile.
get_set_value(group, key, priority, value)
1451 (
object.*method)(value);
1453 catch (std::runtime_error
const& e)
1480 template<
class C,
typename T>
1483 void (C::* method)(T
const& param),
1492 if (basic_keyfile.
get_set_value(group, key, priority, value)
1494 (
object.*method)(value);
1496 catch (std::runtime_error
const& e)
1511 #include <sbuild/sbuild-basic-keyfile.tcc>
virtual ~basic_keyfile()
The destructor.
Definition: sbuild-basic-keyfile.tcc:56
static void set_object_list_value(C const &object, T const &(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key list value from an object method return value.
Definition: sbuild-basic-keyfile.h:1170
static void get_object_value(C &object, void(C::*method)(T const ¶m), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key value and set it by reference in an object using an object method.
Definition: sbuild-basic-keyfile.h:1314
K::size_type line_number
Line number.
Definition: sbuild-basic-keyfile.h:94
K::comment_type comment_type
Comment.
Definition: sbuild-basic-keyfile.h:151
std::vector< group_name_type > group_list
Vector of groups.
Definition: sbuild-basic-keyfile.h:157
virtual void end()
Stop processing input.
Definition: sbuild-basic-keyfile.h:127
bool get_set_value(group_name_type const &group, key_type const &key, priority priority, C &container) const
Get a key value as a set.
Definition: sbuild-basic-keyfile.h:612
void set_value(group_name_type const &group, key_type const &key, T const &value, comment_type const &comment)
Set a key value.
Definition: sbuild-basic-keyfile.h:650
priority
Configuration parameter priority.
Definition: sbuild-keyfile-base.h:47
void set_set_value(group_name_type const &group, key_type const &key, I begin, I end, comment_type const &comment)
Set a key value from a set.
Definition: sbuild-basic-keyfile.h:806
virtual ~basic_keyfile_parser()
The destructor.
Definition: sbuild-basic-keyfile.h:65
The group is a duplicate.
Definition: sbuild-keyfile-base.h:64
K::value_type value_type
Value.
Definition: sbuild-basic-keyfile.h:148
static void print_comment(comment_type const &comment, std::ostream &stream)
Print a comment to a stream.
Definition: sbuild-basic-keyfile.tcc:400
Notification messages.
Definition: sbuild-log.h:31
Pass through exception with line, group and key.
Definition: sbuild-keyfile-base.h:78
bool key_set
Key name is set.
Definition: sbuild-basic-keyfile.h:79
static void set_object_value(C const &object, T(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key value from an object method return value.
Definition: sbuild-basic-keyfile.h:1072
bool comment_set
Comment is set.
Definition: sbuild-basic-keyfile.h:91
void set_group(group_name_type const &group, comment_type const &comment)
Set a group.
Definition: sbuild-basic-keyfile.tcc:137
bool get_set_value(group_name_type const &group, key_type const &key, C &container) const
Get a key value as a set.
Definition: sbuild-basic-keyfile.h:553
std::tuple< group_name_type, item_map_type, comment_type, size_type > group_type
Group-items-comment-line tuple.
Definition: sbuild-basic-keyfile.h:174
parse_error< error_code > error
Exception type.
Definition: sbuild-keyfile-base.h:83
value_type separator
The separator used as a list item delimiter.
Definition: sbuild-basic-keyfile.h:1055
void set_set_value(group_name_type const &group, key_type const &key, I begin, I end, comment_type const &comment, size_type line)
Set a key value from a set.
Definition: sbuild-basic-keyfile.h:830
std::ostream & log_debug(debug_level level)
Log a debug message.
Definition: sbuild-log.cc:110
friend std::basic_istream< charT, traits > & operator>>(std::basic_istream< charT, traits > &stream, basic_keyfile &kf)
basic_keyfile initialisation from an istream.
Definition: sbuild-basic-keyfile.h:891
static void set_object_value(C const &object, T const &(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key value from an object method return value reference.
Definition: sbuild-basic-keyfile.h:1103
void log_exception_warning(std::exception const &e)
Log an exception as a warning.
Definition: sbuild-log.cc:143
Basic keyfile parser template.
Definition: sbuild-basic-keyfile.h:44
bool get_list_value(group_name_type const &group, key_type const &key, priority priority, C &container) const
Get a key value as a list.
Definition: sbuild-basic-keyfile.h:529
static void get_object_value(C &object, void(C::*method)(T param), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key value and set it in an object using an object method.
Definition: sbuild-basic-keyfile.h:1274
bool group_set
Group name is set.
Definition: sbuild-basic-keyfile.h:73
void set_list_value(group_name_type const &group, key_type const &key, I begin, I end)
Set a key value from a list.
Definition: sbuild-basic-keyfile.h:706
Configuration file parser.
Definition: sbuild-basic-keyfile.h:138
virtual void parse_line(std::string const &line)
Parse a line of input.
Definition: sbuild-basic-keyfile.h:117
group_map_type groups
The top-level groups.
Definition: sbuild-basic-keyfile.h:1053
std::vector< S > split_string(S const &value, S const &separator)
Split a string into a string_list.
Definition: sbuild-util.h:152
bool get_list_value(group_name_type const &group, key_type const &key, C &container) const
Get a key value as a list.
Definition: sbuild-basic-keyfile.h:470
std::vector< value_type > value_list
Vector of values.
Definition: sbuild-basic-keyfile.h:160
std::map< key_type, item_type > item_map_type
Map between key name and key-value-comment tuple.
Definition: sbuild-basic-keyfile.h:171
void set_list_value(group_name_type const &group, key_type const &key, I begin, I end, comment_type const &comment, size_type line)
Set a key value from a list.
Definition: sbuild-basic-keyfile.h:748
bool has_group(group_name_type const &group) const
Check if a group exists.
Definition: sbuild-basic-keyfile.tcc:122
void set_list_value(group_name_type const &group, key_type const &key, I begin, I end, comment_type const &comment)
Set a key value from a list.
Definition: sbuild-basic-keyfile.h:726
std::tuple< key_type, value_type, comment_type, size_type > item_type
Key-value-comment-line tuple.
Definition: sbuild-basic-keyfile.h:168
virtual void begin()
Start processing input.
Definition: sbuild-basic-keyfile.h:101
K::value_type value
Value.
Definition: sbuild-basic-keyfile.h:82
K::key_type key_type
Key name.
Definition: sbuild-basic-keyfile.h:145
key_list get_keys(group_name_type const &group) const
Get a list of keys in a group.
Definition: sbuild-basic-keyfile.tcc:76
comment_type get_comment(group_name_type const &group) const
Get a group comment.
Definition: sbuild-basic-keyfile.tcc:160
void set_value(group_name_type const &group, key_type const &key, T const &value, comment_type const &comment, size_type line)
Set a key value.
Definition: sbuild-basic-keyfile.h:670
K::group_name_type group_name_type
Group name.
Definition: sbuild-basic-keyfile.h:142
void check_keys(group_name_type const &group, key_list const &keys) const
Check for unused keys in a group.
Definition: sbuild-basic-keyfile.tcc:95
bool get_value(group_name_type const &group, key_type const &key, T &value) const
Get a key value.
Definition: sbuild-basic-keyfile.h:330
static void get_object_list_value(C &object, void(C::*method)(T param), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key list value and set it in an object using an object method.
Definition: sbuild-basic-keyfile.h:1354
std::map< group_name_type, group_type > group_map_type
Map between group name and group-items-comment tuple.
Definition: sbuild-basic-keyfile.h:177
K::group_name_type group
Group name.
Definition: sbuild-basic-keyfile.h:70
void set_value(group_name_type const &group, key_type const &key, T const &value)
Set a key value.
Definition: sbuild-basic-keyfile.h:632
Parse error.
Definition: sbuild-parse-error.h:35
const item_type * find_item(group_name_type const &group, key_type const &key) const
Find a key by it's group and name.
Definition: sbuild-basic-keyfile.tcc:366
static void set_object_list_value(C const &object, T(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key list value from an object method return value.
Definition: sbuild-basic-keyfile.h:1135
std::vector< key_type > key_list
Vector of keys.
Definition: sbuild-basic-keyfile.h:180
Internationalisation functions.
basic_keyfile()
The constructor.
Definition: sbuild-basic-keyfile.tcc:24
System group database entry.
Definition: sbuild-util.h:795
void remove_key(group_name_type const &group, key_type const &key)
Remove a key.
Definition: sbuild-basic-keyfile.tcc:289
static void get_object_list_value(C &object, void(C::*method)(T const ¶m), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key list value and set it by reference in an object using an object method. ...
Definition: sbuild-basic-keyfile.h:1397
K::key_type key
Key name.
Definition: sbuild-basic-keyfile.h:76
K::size_type size_type
Line number.
Definition: sbuild-basic-keyfile.h:154
const group_type * find_group(group_name_type const &group) const
Find a group by it's name.
Definition: sbuild-basic-keyfile.tcc:344
size_type get_line(group_name_type const &group) const
Get a group line number.
Definition: sbuild-basic-keyfile.tcc:183
bool get_value(group_name_type const &group, key_type const &key, priority priority, T &value) const
Get a key value.
Definition: sbuild-basic-keyfile.h:379
void set_set_value(group_name_type const &group, key_type const &key, I begin, I end)
Set a key value from a set.
Definition: sbuild-basic-keyfile.h:784
K::comment_type comment
Comment.
Definition: sbuild-basic-keyfile.h:88
void remove_group(group_name_type const &group)
Remove a group.
Definition: sbuild-basic-keyfile.tcc:280
group_list get_groups() const
Get a list of groups.
Definition: sbuild-basic-keyfile.tcc:62
Informational messages.
Definition: sbuild-log.h:32
void parse_value(std::string const &value, bool &parsed_value)
Parse a boolean value.
Definition: sbuild-parse-value.cc:49
Base class for key-value configuration file formats.
Definition: sbuild-keyfile-base.h:43
bool get_locale_string(group_name_type const &group, key_type const &key, value_type &value) const
Get a localised key string value.
Definition: sbuild-basic-keyfile.tcc:206
static void get_object_set_value(C &object, void(C::*method)(T param), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key set value and set it in an object using an object method.
Definition: sbuild-basic-keyfile.h:1439
static void get_object_set_value(C &object, void(C::*method)(T const ¶m), basic_keyfile const &basic_keyfile, group_name_type const &group, key_type const &key, basic_keyfile::priority priority)
Get a key set value and set it by reference in an object using an object method.
Definition: sbuild-basic-keyfile.h:1482
void check_priority(group_name_type const &group, key_type const &key, priority priority, bool valid) const
Check if a key is missing or present when not permitted.
Definition: sbuild-basic-keyfile.tcc:426
The key is a duplicate.
Definition: sbuild-keyfile-base.h:65
basic_keyfile_parser()
The constructor.
Definition: sbuild-basic-keyfile.h:51
basic_keyfile & operator+=(basic_keyfile const &rhs)
Add a basic_keyfile to the basic_keyfile.
Definition: sbuild-basic-keyfile.tcc:304
Pass through exception with group and key.
Definition: sbuild-keyfile-base.h:76
friend basic_keyfile< _K, _P > operator+(basic_keyfile< _K, _P > const &lhs, basic_keyfile< _K, _P > const &rhs)
Add a basic_keyfile to the basic_keyfile.
bool value_set
Value is set.
Definition: sbuild-basic-keyfile.h:85
static void set_object_set_value(C const &object, T(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key set value from an object method return value.
Definition: sbuild-basic-keyfile.h:1204
keyfile_base::error error
Exception type.
Definition: sbuild-basic-keyfile.h:48
static void set_object_set_value(C const &object, T const &(C::*method)() const, basic_keyfile &basic_keyfile, group_name_type const &group, key_type const &key)
Set a key set value from an object method return value.
Definition: sbuild-basic-keyfile.h:1239
P parse_type
Parse type.
Definition: sbuild-basic-keyfile.h:164
bool has_key(group_name_type const &group, key_type const &key) const
Check if a key exists.
Definition: sbuild-basic-keyfile.tcc:129