sbuild  1.6.10
sbuild-basic-keyfile.h
1 /* Copyright © 2005-2009 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_BASIC_KEYFILE_H
20 #define SBUILD_BASIC_KEYFILE_H
21 
22 #include <sbuild/sbuild-i18n.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>
28 #include <sbuild/sbuild-tr1types.h>
29 #include <sbuild/sbuild-util.h>
30 
31 #include <cassert>
32 #include <map>
33 #include <string>
34 #include <sstream>
35 
36 #include <boost/format.hpp>
37 
38 namespace sbuild
39 {
43  template <typename K>
45  {
46  public:
49 
52  group(),
53  group_set(false),
54  key(),
55  key_set(false),
56  value(),
57  value_set(false),
58  comment(),
59  comment_set(false),
60  line_number(0)
61  {
62  }
63 
66  {
67  }
68 
70  typename K::group_name_type group;
71 
73  bool group_set;
74 
76  typename K::key_type key;
77 
79  bool key_set;
80 
82  typename K::value_type value;
83 
85  bool value_set;
86 
88  typename K::comment_type comment;
89 
92 
94  typename K::size_type line_number;
95 
100  virtual void
101  begin ()
102  {
103  line_number = 0;
104  }
105 
116  virtual void
117  parse_line (std::string const& line)
118  {
119  ++line_number;
120  }
121 
126  virtual void
127  end()
128  {
129  }
130  };
131 
137  template <typename K, typename P = basic_keyfile_parser<K> >
139  {
140  public:
142  typedef typename K::group_name_type group_name_type;
143 
145  typedef typename K::key_type key_type;
146 
148  typedef typename K::value_type value_type;
149 
151  typedef typename K::comment_type comment_type;
152 
154  typedef typename K::size_type size_type;
155 
157  typedef std::vector<group_name_type> group_list;
158 
160  typedef std::vector<value_type> value_list;
161 
162  private:
164  typedef P parse_type;
165 
167  typedef std::tuple<key_type,value_type,comment_type,size_type>
169 
171  typedef std::map<key_type,item_type> item_map_type;
172 
174  typedef std::tuple<group_name_type,item_map_type,comment_type,size_type> group_type;
175 
177  typedef std::map<group_name_type,group_type> group_map_type;
178 
180  typedef std::vector<key_type> key_list;
181 
182  public:
184  basic_keyfile ();
185 
191  basic_keyfile (std::string const& file);
192 
198  basic_keyfile (std::istream& stream);
199 
201  virtual ~basic_keyfile ();
202 
209  group_list
210  get_groups () const;
211 
219  key_list
220  get_keys (group_name_type const& group) const;
221 
230  void
231  check_keys (group_name_type const& group,
232  key_list const& keys) const;
233 
240  bool
241  has_group (group_name_type const& group) const;
242 
250  bool
251  has_key (group_name_type const& group,
252  key_type const& key) const;
253 
261  void
262  set_group (group_name_type const& group,
263  comment_type const& comment);
264 
273  void
274  set_group (group_name_type const& group,
275  comment_type const& comment,
276  size_type line);
277 
284  comment_type
285  get_comment (group_name_type const& group) const;
286 
294  comment_type
295  get_comment (group_name_type const& group,
296  key_type const& key) const;
297 
304  size_type
305  get_line (group_name_type const& group) const;
306 
314  size_type
315  get_line (group_name_type const& group,
316  key_type const& key) const;
317 
328  template <typename T>
329  bool
330  get_value (group_name_type const& group,
331  key_type const& key,
332  T& value) const
333  {
334  log_debug(DEBUG_INFO) << "Getting keyfile group=" << group
335  << ", key=" << key << std::endl;
336  const item_type *found_item = find_item(group, key);
337  if (found_item)
338  {
339  value_type const& strval(std::get<1>(*found_item));
340  try
341  {
342  parse_value(strval, value);
343  return true;
344  }
345  catch (parse_value_error const& e)
346  {
347  size_type line = get_line(group, key);
348  if (line)
349  {
350  error ep(line, group, key, PASSTHROUGH_LGK, e);
352  }
353  else
354  {
355  error ep(group, key, PASSTHROUGH_GK, e);
357  }
358  return false;
359  }
360  }
361  log_debug(DEBUG_NOTICE) << "key not found" << std::endl;
362  return false;
363  }
364 
377  template <typename T>
378  bool
379  get_value (group_name_type const& group,
380  key_type const& key,
382  T& value) const
383  {
384  bool status = get_value(group, key, value);
385  check_priority(group, key, priority, status);
386  return status;
387  }
388 
398  bool
399  get_locale_string (group_name_type const& group,
400  key_type const& key,
401  value_type& value) const;
402 
414  bool
415  get_locale_string (group_name_type const& group,
416  key_type const& key,
418  value_type& value) const;
419 
430  bool
431  get_locale_string (group_name_type const& group,
432  key_type const& key,
433  std::string const& locale,
434  value_type& value) const;
435 
449  bool
450  get_locale_string (group_name_type const& group,
451  key_type const& key,
452  std::string const& locale,
453  priority priority,
454  value_type& value) const;
455 
468  template <typename C>
469  bool
470  get_list_value (group_name_type const& group,
471  key_type const& key,
472  C& container) const
473  {
474  value_type item_value;
475  if (get_value(group, key, item_value))
476  {
477  value_list items = split_string(item_value,
478  this->separator);
479  for (typename value_list::const_iterator pos = items.begin();
480  pos != items.end();
481  ++pos
482  )
483  {
484  typename C::value_type tmp;
485 
486  try
487  {
488  parse_value(*pos, tmp);
489  }
490  catch (parse_value_error const& e)
491  {
492  size_type line = get_line(group, key);
493  if (line)
494  {
495  error ep(line, group, key, PASSTHROUGH_LGK, e);
497  }
498  else
499  {
500  error ep(group, key, PASSTHROUGH_GK, e);
502  }
503  return false;
504  }
505 
506  container.push_back(tmp);
507  }
508  return true;
509  }
510  return false;
511  }
512 
527  template <typename C>
528  bool
529  get_list_value (group_name_type const& group,
530  key_type const& key,
531  priority priority,
532  C& container) const
533  {
534  bool status = get_list_value(group, key, container);
535  check_priority(group, key, priority, status);
536  return status;
537  }
538 
551  template <typename C>
552  bool
553  get_set_value (group_name_type const& group,
554  key_type const& key,
555  C& container) const
556  {
557  value_type item_value;
558  if (get_value(group, key, item_value))
559  {
560  value_list items = split_string(item_value,
561  this->separator);
562  for (typename value_list::const_iterator pos = items.begin();
563  pos != items.end();
564  ++pos
565  )
566  {
567  typename C::value_type tmp;
568 
569  try
570  {
571  parse_value(*pos, tmp);
572  }
573  catch (parse_value_error const& e)
574  {
575  size_type line = get_line(group, key);
576  if (line)
577  {
578  error ep(line, group, key, PASSTHROUGH_LGK, e);
580  }
581  else
582  {
583  error ep(group, key, PASSTHROUGH_GK, e);
585  }
586  return false;
587  }
588 
589  container.insert(tmp);
590  }
591  return true;
592  }
593  return false;
594  }
595 
610  template <typename C>
611  bool
612  get_set_value (group_name_type const& group,
613  key_type const& key,
614  priority priority,
615  C& container) const
616  {
617  bool status = get_set_value(group, key, container);
618  check_priority(group, key, priority, status);
619  return status;
620  }
621 
630  template <typename T>
631  void
632  set_value (group_name_type const& group,
633  key_type const& key,
634  T const& value)
635  {
636  set_value(group, key, value, comment_type());
637  }
638 
648  template <typename T>
649  void
650  set_value (group_name_type const& group,
651  key_type const& key,
652  T const& value,
653  comment_type const& comment)
654  {
655  set_value(group, key, value, comment, 0);
656  }
657 
668  template <typename T>
669  void
670  set_value (group_name_type const& group,
671  key_type const& key,
672  T const& value,
673  comment_type const& comment,
674  size_type line)
675  {
676  std::ostringstream os;
677  os.imbue(std::locale::classic());
678  os << std::boolalpha << value;
679 
680  set_group(group, "");
681  group_type *found_group = find_group(group);
682  assert (found_group != 0); // should not fail
683 
684  item_map_type& items = std::get<1>(*found_group);
685 
686  typename item_map_type::iterator pos = items.find(key);
687  if (pos != items.end())
688  items.erase(pos);
689  items.insert
690  (typename item_map_type::value_type(key,
691  item_type(key, os.str(),
692  comment, line)));
693  }
694 
704  template <typename I>
705  void
706  set_list_value (group_name_type const& group,
707  key_type const& key,
708  I begin,
709  I end)
710  {
711  set_list_value(group, key, begin, end, comment_type());
712  }
713 
724  template <typename I>
725  void
726  set_list_value (group_name_type const& group,
727  key_type const& key,
728  I begin,
729  I end,
730  comment_type const& comment)
731  {
732  set_list_value (group, key, begin, end, comment, 0);
733  }
734 
746  template <typename I>
747  void
748  set_list_value (group_name_type const& group,
749  key_type const& key,
750  I begin,
751  I end,
752  comment_type const& comment,
753  size_type line)
754  {
755  value_type strval;
756 
757  for (I pos = begin; pos != end;)
758  {
759  std::ostringstream os;
760  os.imbue(std::locale::classic());
761  os << std::boolalpha << *pos;
762  if (os)
763  {
764  strval += os.str();
765  if (++pos != end)
766  strval += this->separator;
767  }
768  }
769 
770  set_value (group, key, strval, comment, line);
771  }
772 
782  template <typename I>
783  void
784  set_set_value (group_name_type const& group,
785  key_type const& key,
786  I begin,
787  I end)
788  {
789  std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
790  std::sort(l.begin(), l.end());
791  set_list_value(group, key, l.begin(), l.end());
792  }
793 
804  template <typename I>
805  void
806  set_set_value (group_name_type const& group,
807  key_type const& key,
808  I begin,
809  I end,
810  comment_type const& comment)
811  {
812  std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
813  std::sort(l.begin(), l.end());
814  set_list_value(group, key, l.begin(), l.end(), comment);
815  }
816 
828  template <typename I>
829  void
830  set_set_value (group_name_type const& group,
831  key_type const& key,
832  I begin,
833  I end,
834  comment_type const& comment,
835  size_type line)
836  {
837  std::vector<typename std::iterator_traits<I>::value_type> l(begin, end);
838  std::sort(l.begin(), l.end());
839  set_list_value(group, key, l.begin(), l.end(), comment, line);
840  }
841 
847  void
848  remove_group (group_name_type const& group);
849 
856  void
857  remove_key (group_name_type const& group,
858  key_type const& key);
859 
867  operator += (basic_keyfile const& rhs);
868 
876  template <typename _K, typename _P>
877  friend basic_keyfile<_K, _P>
878  operator + (basic_keyfile<_K, _P> const& lhs,
879  basic_keyfile<_K, _P> const& rhs);
880 
888  template <class charT, class traits>
889  friend
890  std::basic_istream<charT,traits>&
891  operator >> (std::basic_istream<charT,traits>& stream,
892  basic_keyfile& kf)
893  {
894  basic_keyfile tmp;
895  parse_type state;
896  std::string line;
897 
898  state.begin();
899 
900  while (std::getline(stream, line))
901  {
902  state.parse_line(line);
903 
904  // Insert group
905  if (state.group_set)
906  {
907  if (tmp.has_group(state.group))
908  throw error(state.line_number, DUPLICATE_GROUP, state.group);
909  else
910  tmp.set_group(state.group, state.comment, state.line_number);
911  }
912 
913  // Insert item
914  if (state.key_set && state.value_set)
915  {
916  if (tmp.has_key(state.group, state.key))
917  throw error(state.line_number, state.group, DUPLICATE_KEY, state.key);
918  else
919  tmp.set_value(state.group, state.key, state.value, state.comment, state.line_number);
920  }
921  }
922 
923  state.end();
924  // TODO: do inserts here as well.
925 
926  kf += tmp;
927 
928  return stream;
929  }
930 
938  template <class charT, class traits>
939  friend
940  std::basic_ostream<charT,traits>&
941  operator << (std::basic_ostream<charT,traits>& stream,
942  basic_keyfile const& kf)
943  {
944  size_type group_count = 0;
945 
946  for (typename group_map_type::const_iterator gp = kf.groups.begin();
947  gp != kf.groups.end();
948  ++gp, ++group_count)
949  {
950  if (group_count > 0)
951  stream << '\n';
952 
953  group_type const& group = gp->second;
954  group_name_type const& groupname = std::get<0>(group);
955  comment_type const& comment = std::get<2>(group);
956 
957  if (comment.length() > 0)
958  print_comment(comment, stream);
959 
960  stream << '[' << groupname << ']' << '\n';
961 
962  item_map_type const& items(std::get<1>(group));
963  for (typename item_map_type::const_iterator it = items.begin();
964  it != items.end();
965  ++it)
966  {
967  item_type const& item = it->second;
968  key_type const& key(std::get<0>(item));
969  value_type const& value(std::get<1>(item));
970  comment_type const& comment(std::get<2>(item));
971 
972  if (comment.length() > 0)
973  print_comment(comment, stream);
974 
975  stream << key << '=' << value << '\n';
976  }
977  }
978 
979  return stream;
980  }
981 
982  private:
989  const group_type *
990  find_group (group_name_type const& group) const;
991 
998  group_type *
999  find_group (group_name_type const& group);
1000 
1008  const item_type *
1009  find_item (group_name_type const& group,
1010  key_type const& key) const;
1011 
1019  item_type *
1020  find_item (group_name_type const& group,
1021  key_type const& key);
1022 
1031  void
1032  check_priority (group_name_type const& group,
1033  key_type const& key,
1034  priority priority,
1035  bool valid) const;
1036 
1048  static void
1049  print_comment (comment_type const& comment,
1050  std::ostream& stream);
1051 
1053  group_map_type groups;
1055  value_type separator;
1056 
1057  public:
1070  template<class C, typename T>
1071  static void
1072  set_object_value (C const& object,
1073  T (C::* method)() const,
1075  group_name_type const& group,
1076  key_type const& key)
1077  {
1078  try
1079  {
1080  if (method)
1081  basic_keyfile.set_value(group, key, (object.*method)());
1082  }
1083  catch (std::runtime_error const& e)
1084  {
1085  throw error(group, key, PASSTHROUGH_GK, e);
1086  }
1087  }
1088 
1101  template<class C, typename T>
1102  static void
1103  set_object_value (C const& object,
1104  T const& (C::* method)() const,
1106  group_name_type const& group,
1107  key_type const& key)
1108  {
1109  try
1110  {
1111  if (method)
1112  basic_keyfile.set_value(group, key, (object.*method)());
1113  }
1114  catch (std::runtime_error const& e)
1115  {
1116  throw error(group, key, PASSTHROUGH_GK, e);
1117  }
1118  }
1119 
1133  template<class C, typename T>
1134  static void
1135  set_object_list_value (C const& object,
1136  T (C::* method)() const,
1138  group_name_type const& group,
1139  key_type const& key)
1140  {
1141  try
1142  {
1143  if (method)
1144  basic_keyfile.set_list_value(group, key,
1145  (object.*method)().begin(),
1146  (object.*method)().end());
1147  }
1148  catch (std::runtime_error const& e)
1149  {
1150  throw error(group, key, PASSTHROUGH_GK, e);
1151  }
1152  }
1153 
1168  template<class C, typename T>
1169  static void
1170  set_object_list_value (C const& object,
1171  T const& (C::* method)() const,
1173  group_name_type const& group,
1174  key_type const& key)
1175  {
1176  try
1177  {
1178  if (method)
1179  basic_keyfile.set_list_value(group, key,
1180  (object.*method)().begin(),
1181  (object.*method)().end());
1182  }
1183  catch (std::runtime_error const& e)
1184  {
1185  throw error(group, key, PASSTHROUGH_GK, e);
1186  }
1187  }
1188 
1202  template<class C, typename T>
1203  static void
1204  set_object_set_value (C const& object,
1205  T (C::* method)() const,
1207  group_name_type const& group,
1208  key_type const& key)
1209  {
1210  try
1211  {
1212  if (method)
1213  basic_keyfile.set_set_value(group, key,
1214  (object.*method)().begin(),
1215  (object.*method)().end());
1216  }
1217  catch (std::runtime_error const& e)
1218  {
1219  throw error(group, key, PASSTHROUGH_GK, e);
1220  }
1221  }
1222 
1237  template<class C, typename T>
1238  static void
1239  set_object_set_value (C const& object,
1240  T const& (C::* method)() const,
1242  group_name_type const& group,
1243  key_type const& key)
1244  {
1245  try
1246  {
1247  if (method)
1248  basic_keyfile.set_set_value(group, key,
1249  (object.*method)().begin(),
1250  (object.*method)().end());
1251  }
1252  catch (std::runtime_error const& e)
1253  {
1254  throw error(group, key, PASSTHROUGH_GK, e);
1255  }
1256  }
1257 
1272  template<class C, typename T>
1273  static void
1274  get_object_value (C& object,
1275  void (C::* method)(T param),
1277  group_name_type const& group,
1278  key_type const& key,
1279  basic_keyfile::priority priority)
1280  {
1281  try
1282  {
1283  T value;
1284  if (basic_keyfile.get_value(group, key, priority, value)
1285  && method)
1286  (object.*method)(value);
1287  }
1288  catch (std::runtime_error const& e)
1289  {
1290  size_type line = basic_keyfile.get_line(group, key);
1291  if (line)
1292  throw error(line, group, key, PASSTHROUGH_LGK, e);
1293  else
1294  throw error(group, key, PASSTHROUGH_GK, e);
1295  }
1296  }
1297 
1312  template<class C, typename T>
1313  static void
1314  get_object_value (C& object,
1315  void (C::* method)(T const& param),
1317  group_name_type const& group,
1318  key_type const& key,
1319  basic_keyfile::priority priority)
1320  {
1321  try
1322  {
1323  T value;
1324  if (basic_keyfile.get_value(group, key, priority, value)
1325  && method)
1326  (object.*method)(value);
1327  }
1328  catch (std::runtime_error const& e)
1329  {
1330  size_type line = basic_keyfile.get_line(group, key);
1331  if (line)
1332  throw error(line, group, key, PASSTHROUGH_LGK, e);
1333  else
1334  throw error(group, key, PASSTHROUGH_GK, e);
1335  }
1336  }
1337 
1352  template<class C, typename T>
1353  static void
1355  void (C::* method)(T param),
1357  group_name_type const& group,
1358  key_type const& key,
1359  basic_keyfile::priority priority)
1360  {
1361  try
1362  {
1363  T value;
1364  if (basic_keyfile.get_list_value(group, key, priority, value)
1365  && method)
1366  (object.*method)(value);
1367  }
1368  catch (std::runtime_error const& e)
1369  {
1370  size_type line = basic_keyfile.get_line(group, key);
1371  if (line)
1372  throw error(line, group, key, PASSTHROUGH_LGK, e);
1373  else
1374  throw error(group, key, PASSTHROUGH_GK, e);
1375  throw error(basic_keyfile.get_line(group, key),
1376  group, key, e);
1377  }
1378  }
1379 
1395  template<class C, typename T>
1396  static void
1398  void (C::* method)(T const& param),
1400  group_name_type const& group,
1401  key_type const& key,
1402  basic_keyfile::priority priority)
1403  {
1404  try
1405  {
1406  T value;
1407  if (basic_keyfile.get_list_value(group, key, priority, value)
1408  && method)
1409  (object.*method)(value);
1410  }
1411  catch (std::runtime_error const& e)
1412  {
1413  size_type line = basic_keyfile.get_line(group, key);
1414  if (line)
1415  throw error(line, group, key, PASSTHROUGH_LGK, e);
1416  else
1417  throw error(group, key, PASSTHROUGH_GK, e);
1418  throw error(basic_keyfile.get_line(group, key),
1419  group, key, e);
1420  }
1421  }
1422 
1437  template<class C, typename T>
1438  static void
1440  void (C::* method)(T param),
1442  group_name_type const& group,
1443  key_type const& key,
1444  basic_keyfile::priority priority)
1445  {
1446  try
1447  {
1448  T value;
1449  if (basic_keyfile.get_set_value(group, key, priority, value)
1450  && method)
1451  (object.*method)(value);
1452  }
1453  catch (std::runtime_error const& e)
1454  {
1455  size_type line = basic_keyfile.get_line(group, key);
1456  if (line)
1457  throw error(line, group, key, PASSTHROUGH_LGK, e);
1458  else
1459  throw error(group, key, PASSTHROUGH_GK, e);
1460  throw error(basic_keyfile.get_line(group, key),
1461  group, key, e);
1462  }
1463  }
1464 
1480  template<class C, typename T>
1481  static void
1483  void (C::* method)(T const& param),
1485  group_name_type const& group,
1486  key_type const& key,
1487  basic_keyfile::priority priority)
1488  {
1489  try
1490  {
1491  T value;
1492  if (basic_keyfile.get_set_value(group, key, priority, value)
1493  && method)
1494  (object.*method)(value);
1495  }
1496  catch (std::runtime_error const& e)
1497  {
1498  size_type line = basic_keyfile.get_line(group, key);
1499  if (line)
1500  throw error(line, group, key, PASSTHROUGH_LGK, e);
1501  else
1502  throw error(group, key, PASSTHROUGH_GK, e);
1503  throw error(basic_keyfile.get_line(group, key),
1504  group, key, e);
1505  }
1506  }
1507  };
1508 
1509 }
1510 
1511 #include <sbuild/sbuild-basic-keyfile.tcc>
1512 
1513 #endif /* SBUILD_BASIC_KEYFILE_H */
1514 
1515 /*
1516  * Local Variables:
1517  * mode:C++
1518  * End:
1519  */
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 &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 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
TR1 type substitution.
Debian source builder components.
Definition: sbuild-auth-null.h:24
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
K::value_type value_type
Value.
Definition: sbuild-basic-keyfile.h:148
Notification messages.
Definition: sbuild-log.h:31
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.
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
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
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.
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
mntstream & operator>>(mntstream &stream, mntstream::mntentry &entry)
The overloaded extraction operator.
Definition: sbuild-mntstream.cc:168
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
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
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.
System group database entry.
Definition: sbuild-util.h:795
static void get_object_list_value(C &object, void(C::*method)(T const &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 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
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
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
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 &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 by reference in an object using an object method.
Definition: sbuild-basic-keyfile.h:1482
basic_keyfile_parser()
The constructor.
Definition: sbuild-basic-keyfile.h:51
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
size_type get_line(group_name_type const &group) const
Get a group line number.
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.