Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_record.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2014-09-22
4  * Last modified : 2016-11-03
5  *
6  * Copyright (C) 2014-2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * A record for a variant parameter or variant in a registry of
26  * configuration variants and associated parameters.
27  *
28  */
29 
30 #ifndef DATATOOLS_CONFIGURATION_VARIANT_RECORD_H
31 #define DATATOOLS_CONFIGURATION_VARIANT_RECORD_H
32 
33 // Standard library:
34 #include <string>
35 #include <map>
36 #include <vector>
37 
38 // This project (Bayeux/datatools):
41 #include <datatools/ioutils.h>
42 #include <datatools/units.h>
43 #include <datatools/logger.h>
44 
45 namespace datatools {
46 
47  namespace configuration {
48 
49  class variant_registry;
50 
53  {
54  public:
55 
56  // \brief Record for daughter variant record
57  class daughter_type {
58  public:
59  daughter_type(const std::string & name_, variant_record & vrec_, const int rank_ = -1)
60  : _name_(name_)
61  , _handle_(&vrec_)
62  , _rank_((rank_< 0) ? -1 : rank_) {}
63  const std::string & get_name() const { return _name_; }
64  const variant_record & get_record() const { return *_handle_;}
65  variant_record & grab_record() { return *_handle_;}
66  bool is_ranked() const { return _rank_ >= 0; }
67  int get_rank() const { return _rank_; }
68  private:
69  std::string _name_;
70  variant_record * _handle_ = nullptr;
71  int _rank_ = -1;
72  };
73 
75  typedef std::map<std::string, daughter_type> daughter_dict_type;
76 
79 
81  virtual ~variant_record();
82 
85 
88 
90  bool is_valid() const;
91 
93  bool has_path() const;
94 
96  void set_path(const std::string &);
97 
99  const std::string & get_path() const;
100 
102  void set_base_name(const std::string &);
103 
105  const std::string & get_base_name() const;
106 
108  void set_indexes(const std::vector<uint32_t>&);
109 
111  const std::vector<uint32_t> & get_indexes() const;
112 
114  std::size_t get_occurrence_dimension() const;
115 
117  void set_with_update(bool);
118 
120  bool has_with_update() const;
121 
123  std::string get_leaf_name() const;
124 
126  std::string get_parent_name() const;
127 
129  bool has_parent_registry() const;
130 
132  void set_parent_registry(const variant_registry & rep_);
133 
135  const variant_registry & get_parent_registry() const;
136 
138  bool has_parent_repository() const;
139 
142 
144  bool is_top_variant() const;
145 
147  bool has_parent() const;
148 
150  void set_parent(variant_record & parent_, const std::string & daughter_name_, int rank_ = -1);
151 
153  const variant_record & get_parent() const;
154 
157 
159  bool has_daughters() const;
160 
163 
165  const daughter_dict_type & get_daughters() const;
166 
168  const variant_record & get_daughter(const std::string &) const;
169 
171  variant_record & grab_daughter(const std::string &);
172 
174  bool has_parameter_model() const;
175 
177  void set_parameter_model(const parameter_model &);
178 
180  const parameter_model & get_parameter_model() const;
181 
183  bool has_variant_model() const;
184 
186  void set_variant_model(const variant_model &);
187 
189  const variant_model & get_variant_model() const;
190 
192  bool is_variant() const;
193 
195  bool is_parameter() const;
196 
198  bool is_fixed_parameter() const;
199 
201  void set_active(bool active_);
202 
204  bool is_active() const;
205 
207  bool value_is_set() const;
208 
210  bool default_value_is_set() const;
211 
213  bool check_enabled_parameter() const;
214 
216  bool check_enabled_value(const parameter_value_type & value_) const;
217 
219  bool check_enabled_group(const std::string & group_name_) const;
220 
223 
226 
228  bool is_boolean_valid(const bool) const;
229 
232 
234  bool is_integer_valid(const int) const;
235 
238 
240  bool is_real_valid(const double) const;
241 
244 
246  bool is_string_valid(const std::string &) const;
247 
249  command::returned_info set_string_value(const std::string &);
250 
253 
255  command::returned_info value_is_set(bool &) const;
256 
259 
262 
264  command::returned_info get_real_value(double &) const;
265 
267  command::returned_info get_string_value(std::string &) const;
268 
270  command::returned_info value_to_string(std::string & format_) const;
271 
273  command::returned_info string_to_value(const std::string & format_);
274 
276  void build();
277 
281  void build_list_of_ranked_parameter_records(std::vector<std::string> & ranked_) const;
282 
284  void reset();
285 
287  virtual void tree_dump(std::ostream & out_ = std::clog,
288  const std::string & title_ = "",
289  const std::string & indent_ = "",
290  bool inherit_ = false) const;
291 
293  void update();
294 
296  void forced_update();
297 
298  private:
299 
300  // FUTURE: better to have this method
301  // void _add_daughter_(variant_record &, name, rank... );
302 
304  void _compute_ranked_unranked_daughters_();
305 
307  void _update_();
308 
310  void _update_parameter_();
311 
313  void _update_variant_();
314 
316  void _fix_();
317 
319  void _fix_parameter_value_();
320 
322  void _fix_dependers_on_this_variant_();
323 
324  private:
325 
326  // Management:
328  bool _with_update_ = false;
329 
330  // Configuration:
331  std::string _path_;
332  std::string _base_name_;
333  std::vector<uint32_t> _indexes_;
334  const variant_registry * _parent_registry_ = nullptr;
335  const parameter_model * _parameter_model_ = nullptr;
336  const variant_model * _variant_model_ = nullptr;
337  variant_record * _parent_ = nullptr;
338  daughter_dict_type _daughters_;
339  std::vector<std::string> _ranked_daughters_;
340  std::vector<std::string> _unranked_daughters_;
341 
342  // Working data:
343  bool _active_ = false;
344  bool _value_set_ = false;
345  bool _boolean_value_;
346  int32_t _integer_value_;
347  double _real_value_;
348  std::string _string_value_;
349 
350  };
351 
352  } // end of namespace configuration
353 
354 } // end of namespace datatools
355 
356 #endif // DATATOOLS_CONFIGURATION_VARIANT_RECORD_H
357 
358 // Local Variables: --
359 // mode: c++ --
360 // c-file-style: "gnu" --
361 // tab-width: 2 --
362 // End: --
datatools::logger::priority get_logging() const
Return the logging priority threshold.
bool is_variant() const
Check if record is a variant.
command::returned_info set_fixed_value()
Set fixed value.
bool has_variant_model() const
Check if the record is associated to a variant model.
void set_variant_model(const variant_model &)
Set the variant model associated to the record.
Model of a configuration variant.
Definition: variant_model.h:59
daughter_dict_type & grab_daughters()
Return the dictionary of daughter records.
bool is_integer_valid(const int) const
Validate integer value.
Registry of configuration variant parameters and associated variants.
Definition: variant_registry.h:53
command::returned_info value_to_string(std::string &format_) const
Build a formatted string from the value.
const variant_model & get_variant_model() const
Return the variant model associated to the record.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
void set_active(bool active_)
Set the active flag.
bool is_parameter() const
Check if record is a parameter.
variant_record & grab_daughter(const std::string &)
Return a daughter record given its name.
command::returned_info set_default_value()
Set default value.
std::size_t get_occurrence_dimension() const
Return the dimension of the occurence.
bool is_real_valid(const double) const
Validate real value.
command::returned_info get_real_value(double &) const
Get real value.
bool value_is_set() const
Check if a parameter value is set.
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
bool check_enabled_group(const std::string &group_name_) const
Check is a group is enabled.
variant_record & grab_record()
Definition: variant_record.h:65
void set_indexes(const std::vector< uint32_t > &)
Set the vector of indexes.
bool is_ranked() const
Definition: variant_record.h:66
command::returned_info unset_value()
Unset a parameter value.
std::string get_leaf_name() const
Return the leaf name.
Command returned information.
Definition: command_utils.h:78
void build()
Build and finalize the internals of the record.
void set_path(const std::string &)
Set the path.
void set_parent(variant_record &parent_, const std::string &daughter_name_, int rank_=-1)
Set the parent record and register itself as a daughter of the parent record.
command::returned_info set_boolean_value(bool)
Set boolean value.
bool is_string_valid(const std::string &) const
Validate string value.
void set_logging(const datatools::logger::priority)
Set the logging priority threshold.
bool has_parent_repository() const
Check if the parent repository.
command::returned_info get_string_value(std::string &) const
Get string value.
const std::string & get_name() const
Definition: variant_record.h:63
bool check_enabled_value(const parameter_value_type &value_) const
Check if a value is enabled.
const daughter_dict_type & get_daughters() const
Return the dictionary of daughter records.
const parameter_model & get_parameter_model() const
Return the parameter model associated to the record.
bool is_active() const
Check if record is active (parameter or variant)
const variant_registry & get_parent_registry() const
Return the parent registry handle.
boost::variant< bool, int, double, std::string > parameter_value_type
Definition: utils.h:268
variant_record & grab_parent()
Return the parent.
int get_rank() const
Definition: variant_record.h:67
bool has_with_update() const
Check if the with update flag is set.
bool is_top_variant() const
Check if the record is a top variant.
command::returned_info string_to_value(const std::string &format_)
Set the value from a formatted string.
bool default_value_is_set() const
Check if a parameter value is set to default.
void set_base_name(const std::string &)
Set the base name.
bool check_enabled_parameter() const
Check if a parameter is enabled.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
void set_parent_registry(const variant_registry &rep_)
Set the parent registry handle.
void build_list_of_ranked_parameter_records(std::vector< std::string > &ranked_) const
bool is_valid() const
Check if the record is valid.
bool is_boolean_valid(const bool) const
Validate boolean value.
command::returned_info set_real_value(double)
Set real value.
bool has_parent() const
Check if the record has a parent.
void set_parameter_model(const parameter_model &)
Set the parameter model associated to the record.
std::string get_parent_name() const
Return the parent name.
const std::string & get_base_name() const
Return the base name.
const variant_record & get_parent() const
Return the parent.
bool has_path() const
Check if the path is defined.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
command::returned_info get_boolean_value(bool &) const
Get boolean value.
daughter_type(const std::string &name_, variant_record &vrec_, const int rank_=-1)
Definition: variant_record.h:59
const variant_record & get_daughter(const std::string &) const
Return a daughter record given its name.
const variant_record & get_record() const
Definition: variant_record.h:64
command::returned_info set_string_value(const std::string &)
Set string value.
command::returned_info get_integer_value(int &) const
Get integer value.
bool has_parameter_model() const
Check if the record is associated to a parameter model.
Variant registry record node.
Definition: variant_record.h:52
const variant_repository & get_parent_repository() const
Return the parent repository.
bool has_daughters() const
Check if the variant record has daughter records.
void set_with_update(bool)
Set with update.
const std::vector< uint32_t > & get_indexes() const
Return the vector of indexes.
bool has_parent_registry() const
Check if the parent registry handle is set.
bool is_fixed_parameter() const
Check if record is fixed (parameter)
Variant repository.
Definition: variant_repository.h:57
command::returned_info set_integer_value(int)
Set integer value.
Description/model of a configuration parameter.
Definition: parameter_model.h:60
std::map< std::string, daughter_type > daughter_dict_type
Array of pointers to daughter records.
Definition: variant_record.h:75
const std::string & get_path() const
Return the path.