31 #ifndef DATATOOLS_PROPERTIES_H 32 #define DATATOOLS_PROPERTIES_H 46 #include <boost/cstdint.hpp> 47 #include <boost/serialization/access.hpp> 179 typedef std::vector<int32_t>
vint;
288 int32_t
size()
const;
309 int set_value(
bool value_,
int index_ = 0);
312 int set_value(
int value_,
int index_ = 0);
315 int set_value(
double value_,
int index_ = 0,
bool explicit_unit_ =
false);
318 int set_value_with_unit(
double value_,
int index_ = 0,
const std::string & unit_symbol_ =
"");
327 int set_value(
const std::string & value_,
int index_ = 0,
bool explicit_path_flag_ =
false);
330 int set_value(
const char * value_,
int index_ = 0,
bool explicit_path_flag_ =
false);
333 int get_value(
bool & value_,
int index_ = 0)
const;
336 int get_value(
int & value_,
int index_ = 0)
const;
339 int get_value(
double & value_,
int index_ = 0)
const;
342 int get_value(std::string & value_,
int index_ = 0)
const;
354 void dump(std::ostream & out_)
const;
357 void to_string(std::ostream & out_)
const;
363 virtual void tree_dump(std::ostream & out_ = std::clog,
364 const std::string & title_ =
"",
365 const std::string & indent_ =
"",
366 bool inherit_ =
false)
const;
370 void clear_values_();
372 void clear_unit_symbol_();
380 std::
string _description_;
391 vbool _boolean_values_;
392 vint _integer_values_;
395 std::
string _unit_symbol_;
404 : public std::unary_function<std::
string,
bool>
411 virtual bool operator()(
const std::string & key_arg_)
const = 0;
419 static const std::string & allowed_chars();
428 virtual bool operator()(
const std::string & key_arg_)
const;
439 static const std::string & lock_decorator();
440 static const std::string & as_directive();
441 static const std::string & in_directive();
442 static const std::string & path_decorator();
443 static const std::string & metacomment_prefix();
450 MODE_HEADER_FOOTER = 1,
451 MODE_DEFAULT = MODE_BARE,
452 mode_bare = MODE_BARE,
453 mode_header_footer = MODE_HEADER_FOOTER
474 config(uint32_t options_ = 0,
475 const std::string & topic_ =
"",
476 const std::string & section_name_ =
"",
477 int section_start_line_number_ = -1);
663 void read(std::istream & in_,
properties & prop_);
666 void read(
const std::string & in_,
properties & prop_);
669 void write(std::ostream & out_,
const properties & prop_);
672 void write(
const std::string & filename_,
const properties & prop_);
675 int get_current_line_number()
const;
678 void set_reader_input(
const std::string & filename_,
int line_count_ = -1);
681 bool has_topic()
const;
684 void set_topic(
const std::string & topic_);
687 const std::string & get_topic()
const;
690 bool has_section_info()
const;
693 void set_section_info(
const std::string & section_name_,
694 int section_start_line_number_);
697 void reset_section_info();
700 const std::string & get_section_name()
const;
703 int get_section_start_line_number()
const;
709 void write_metacomment(std::ostream & out_,
710 const std::string & tag_,
711 const std::string & value_ =
"",
712 const std::string & comment_ =
"");
715 void write_data(std::ostream & out_,
716 const std::string & data_key_,
718 const std::string & unit_symbol_ =
"",
719 const std::string & unit_label_ =
"",
720 const std::string & comment_ =
"");
725 void _init_defaults_();
728 void _read_(std::istream & in_,
properties & prop_);
731 void _write_(std::ostream & out_,
const properties & prop_);
739 bool _use_smart_modulo_;
740 bool _write_public_only_;
741 bool _forbid_variants_;
742 bool _forbid_includes_;
743 bool _requested_topic_;
745 bool _allow_key_override_ =
false;
747 std::string _section_name_;
748 int _section_start_line_number_;
751 size_t _current_line_number_;
752 std::string _current_filename_;
771 typedef std::map<std::string, data>
pmap;
783 explicit properties(
const std::string & desc_);
798 bool deletion_on_destroy_ =
true);
802 bool deletion_on_destroy_ =
true);
808 int32_t
size()
const;
870 bool deletion_on_destroy_ =
true);
873 std::vector<std::string>
keys()
const;
876 const std::string &
key (
int)
const;
879 void keys(std::vector<std::string> &)
const;
882 const data &
get(
const std::string & prop_key_)
const;
885 void store(
const std::string & key_,
const data & value_);
894 void keys_starting_with(std::vector<std::string> &,
const std::string & prefix_)
const;
906 void keys_ending_with(std::vector<std::string> &,
const std::string & suffix_)
const;
909 std::vector<std::string>
keys_ending_with(
const std::string & suffix_)
const;
912 void lock(
const std::string & prop_key_);
915 void unlock(
const std::string & prop_key_);
918 bool is_locked(
const std::string & prop_key_)
const;
930 bool is_private(
const std::string & prop_key_)
const;
933 bool is_public(
const std::string & prop_key_)
const;
936 bool is_boolean(
const std::string & prop_key_)
const;
939 bool is_integer(
const std::string & prop_key_)
const;
942 bool is_real(
const std::string & prop_key_)
const;
945 bool is_string(
const std::string & prop_key_)
const;
948 bool is_scalar(
const std::string & prop_key_)
const;
951 bool is_vector(
const std::string & prop_key_)
const;
954 int32_t
size(
const std::string & prop_key_)
const;
957 int32_t
key_size(
const std::string & prop_key_)
const;
960 bool has_key(
const std::string & prop_key_)
const;
963 void key_lock (
const std::string & prop_key_);
966 void key_unlock (
const std::string & prop_key_);
979 void erase(
const std::string & key_);
998 const std::string & prop_key_prefix_)
const;
1002 const std::string & prop_key_prefix_,
1003 const std::string & new_prefix_)
const;
1007 const std::string & prop_key_prefix_)
const;
1010 template <
class key_predicate>
1014 template <
class key_predicate>
1016 const key_predicate & predicate_)
const;
1026 const std::string & suffix_)
const;
1030 const std::string & suffix_)
const;
1033 void clean(
const std::string & prop_key_);
1036 virtual void clear();
1042 void store_flag(
const std::string & prop_key_,
const std::string & desc_ =
"",
1043 bool lock_ =
false);
1048 void set_flag(
const std::string & prop_key_);
1053 void unset_flag(
const std::string & prop_key_);
1056 void store(
const std::string & prop_key_,
bool value_,
1057 const std::string & desc_ =
"",
bool lock_ =
false);
1060 void store_boolean(
const std::string & prop_key_,
bool value_,
1061 const std::string & desc_ =
"",
bool lock_ =
false);
1064 void store(
const std::string & prop_key_,
int value_,
1065 const std::string & desc_ =
"",
bool lock_ =
false);
1068 void store_integer(
const std::string & prop_key_,
int value_,
1069 const std::string & desc_ =
"",
1070 bool lock_ =
false);
1073 void store(
const std::string & prop_key_,
double value_,
1074 const std::string & desc_ =
"",
bool lock_ =
false);
1077 void store_real(
const std::string & prop_key_,
double value_,
1078 const std::string & desc_ =
"",
bool lock_ =
false);
1091 const std::string & desc =
"",
bool lock_ =
false);
1096 const std::string & desc =
"",
bool lock_ =
false);
1099 void set_explicit_unit(
const std::string & prop_key_,
bool a_explicit_unit =
true);
1105 void set_unit_symbol(
const std::string & prop_key_,
const std::string & unit_symbol =
"");
1111 const std::string &
get_unit_symbol(
const std::string & prop_key_)
const;
1114 void set_explicit_path(
const std::string & prop_key_,
bool a_explicit_path =
true);
1120 void store(
const std::string & prop_key_,
const std::string & value_,
1121 const std::string & desc_ =
"",
bool lock_ =
false);
1124 void store_string(
const std::string & prop_key_,
const std::string & value_,
1125 const std::string & desc_ =
"",
bool lock_ =
false);
1128 void store_path(
const std::string & prop_key_,
const std::string & path_value_,
1129 const std::string & desc_ =
"",
bool lock_ =
false);
1132 void store(
const std::string & prop_key_,
const char* value_,
1133 const std::string & desc_ =
"",
bool lock_ =
false);
1137 const std::string & desc_ =
"",
bool lock_ =
false);
1141 const std::string & desc_ =
"",
bool lock_ =
false);
1145 const std::string & desc_ =
"",
bool lock_ =
false);
1149 const std::string & desc_ =
"",
bool lock_ =
false);
1153 const std::string & desc_ =
"",
bool lock_ =
false);
1156 void change(
const std::string & key_,
bool value_,
int index_ = 0);
1159 void change_boolean(
const std::string & key_,
bool value_,
int index_ = 0);
1168 void change(
const std::string & key_,
int value_,
int index_ = 0);
1171 void change_integer(
const std::string & key_,
int value_,
int index_ = 0);
1180 void change(
const std::string & key_,
double value_,
int index_ = 0);
1183 void change_real(
const std::string & key_,
double value_,
int index_ = 0);
1192 void change(
const std::string & key_,
const std::string & value_,
1196 void change_string(
const std::string & key_,
const std::string & value_,
1207 void change(
const std::string & key_,
const char * value_,
int index_ = 0);
1225 void update(
const std::string & key_,
bool value_);
1231 void update(
const std::string & key_,
int value_);
1237 void update(
const std::string & key_,
double value_);
1240 void update_real(
const std::string & key_,
double value_);
1249 void update(
const std::string & key_,
const std::string & value_);
1252 void update(
const std::string & key_,
const char* value_);
1255 void update_string(
const std::string & key_,
const std::string & value);
1270 bool has_flag(
const std::string & key_)
const;
1273 void fetch(
const std::string & key_,
bool & value_,
int index_ = 0)
const;
1276 void fetch(
const std::string & key_,
int & value_,
int index_ = 0)
const;
1279 void fetch(
const std::string & key_,
double & value_,
int index_ = 0)
const;
1282 void fetch(
const std::string & key_, std::string & value_,
1283 int index = 0)
const;
1301 void fetch(
const std::string & key_, std::set<std::string> & values_,
bool allow_duplication_ =
false)
const;
1307 void fetch(
const std::string & key_, std::set<int> & values,
bool allow_duplication_ =
false)
const;
1310 void fetch_positive(
const std::string & key_, std::set<unsigned int> & values_,
bool allow_duplication_ =
false)
const;
1313 bool fetch_boolean(
const std::string &,
int index_ = 0)
const;
1322 int fetch_integer(
const std::string & name_,
int index_ = 0)
const;
1331 int fetch_range_integer(
const std::string & name_,
int min_,
int max_,
int index_ = 0)
const;
1340 double fetch_real(
const std::string & name_,
int index_ = 0)
const;
1358 std::string
fetch_string(
const std::string & name_,
int index_ = 0)
const;
1370 std::string
fetch_path(
const std::string & name_,
int index_ = 0)
const;
1379 void dump(std::ostream & out_ = std::clog)
const;
1382 virtual void tree_dump(std::ostream & out_ = std::clog,
1383 const std::string & title_ =
"",
1384 const std::string & indent_ =
"",
1385 bool inherit_ =
false)
const;
1388 void print_tree(std::ostream & out_ = std::clog,
1389 const boost::property_tree::ptree & options_ =
empty_options())
const override;
1396 bool quoted_strings_ =
true)
const;
1409 static void write_config(
const std::string & filename_,
1411 uint32_t options_ = 0);
1416 static void read_config(
const std::string & filename_,
1418 uint32_t options_ = 0);
1422 const std::string & subkey_);
1432 void _check_nokey_(
const std::string & prop_key_)
const;
1434 void _check_key_(
const std::string & prop_key_,
data ** data_);
1436 void _check_key_(
const std::string & prop_key_,
const data ** data_)
const;
1438 void _validate_key_(
const std::string & prop_key_)
const;
1440 void _clear_key_validator_();
1445 std::string _description_;
1450 bool _key_validator_deletion_;
1472 template <
class key_predicate>
1474 const key_predicate & predicate_)
const 1477 std::logic_error,
"Self export is not allowed !");
1479 for (pmap::const_iterator iter = _props_.begin(); iter != _props_.end();
1481 if (predicate_(iter->first)) {
1482 ks.push_back(iter->first);
1485 for (keys_col_type::const_iterator i =
ks.begin(); i !=
ks.end(); ++i) {
1486 properties & ptmp = const_cast<properties &>(*
this);
1487 props_._props_[*i] = ptmp._props_[*i];
1492 template <
class key_predicate>
1494 const key_predicate & predicate_)
const 1497 std::logic_error,
"Self export is not allowed !");
1499 for (pmap::const_iterator iter = _props_.begin(); iter != _props_.end();
1501 if (!predicate_(iter->first)) {
1502 ks.push_back(iter->first);
1505 for (keys_col_type::const_iterator i =
ks.begin(); i !=
ks.end(); ++i) {
1506 properties & ptmp = const_cast<properties &>(*
this);
1507 props_._props_[*i] = ptmp._props_[*i];
1520 #pragma clang diagnostic push 1521 #pragma clang diagnostic ignored "-Wunused-local-typedef" 1523 #include <boost/serialization/export.hpp> 1525 #pragma clang diagnostic pop 1536 #include <boost/serialization/version.hpp> 1538 BOOST_CLASS_VERSION(
datatools::properties, 2)
1540 #endif // DATATOOLS_PROPERTIES_H
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
#define DATATOOLS_CLONEABLE_DECLARATION(Copyable)
Definition: i_cloneable.h:113
#define DATATOOLS_SERIALIZATION_DECLARATION_ADVANCED(ClassName)
Definition: i_serializable.h:371
#define DATATOOLS_SERIALIZATION_EXT_SERIAL_TAG_DECLARATION(ClassName)
Template support for serializable type (backward compatibility support)
Definition: i_serializable.h:101
Utility macros for exception handling.
#define DATATOOLS_SERIALIZATION_EXT_BACKWARD_SERIAL_TAG_DECLARATION(ClassName)
Definition: i_serializable.h:180
#define DATATOOLS_SERIALIZATION_BACKWARD_SERIAL_TAG_SUPPORT()
Definition: i_serializable.h:174
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
#define BOOST_SERIALIZATION_BASIC_DECLARATION()
Definition: serialization_macros.h:62