Bayeux  3.4.1
Core Foundation library for SuperNEMO
object_configuration_description.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2013-01-01
4  * Last modified : 2015-04-29
5  *
6  * Description :
7  *
8  * Classes describing configuration properties for complex objects
9  * that uses a deferred initilization mechanism using 'datatools::properties'
10  * container.
11  *
12  * Copyright (C) 2013-2015 Francois Mauger <mauger@lpccaen.in2p3.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or (at
17  * your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
27  * Boston, MA 02110-1301, USA.
28  *
29  */
30 
31 #ifndef DATATOOLS_OBJECT_CONFIGURATION_DESCRIPTION_H
32 #define DATATOOLS_OBJECT_CONFIGURATION_DESCRIPTION_H
33 
34 // Standard library:
35 #include <iostream>
36 #include <string>
37 #include <vector>
38 #include <set>
39 
40 // Third party:
41 // - Boost:
42 #include <boost/scoped_ptr.hpp>
43 #include <boost/cstdint.hpp>
44 #include <boost/logic/tribool.hpp>
45 
46 // This project:
47 #include <datatools/properties.h>
48 #include <datatools/types.h>
49 #include <datatools/bit_mask.h>
50 
51 namespace datatools {
52 
53  // Forward class declaration:
54  class object_configuration_description;
55 
58  {
59  public:
60 
61  // Some constants
62  static const bool SCALAR = false;
63  static const bool ARRAY = true;
64  static const bool IMPLICIT_UNIT = false;
65  static const bool EXPLICIT_UNIT = true;
66  static const bool MUTABLE = false;
67  static const bool CONST = true;
68 
75  };
76 
79  public:
80  bool dynamic() const;
81  bool by_flag() const;
82  bool by_label() const;
83  bool is_valid() const;
84  bool has_name() const;
85  bool has_address() const;
86  const std::string & get_name() const;
88  void reset();
91  public:
92  int type;
93  std::string name;
95  std::vector<std::string> triggering_labels;
97  };
98 
101 
102  configuration_property_description & set_name_pattern(const std::string & np_);
103  configuration_property_description & set_from(const std::string & from_);
104  configuration_property_description & set_group(const std::string & group_);
105  configuration_property_description & set_terse_description(const std::string & desc_);
106  configuration_property_description & set_long_description(const std::string & desc_);
109  bool array_ = false,
110  int fixed_size_ = -1);
111  configuration_property_description & set_triggered_by_flag(const std::string & prop_name_,
112  bool triggering_status_ = true);
113  configuration_property_description & set_triggered_by_label(const std::string & prop_name_,
114  const std::string & labels_);
119  configuration_property_description & set_unit_label(const std::string &);
122  configuration_property_description & set_section(const std::string & section_name_);
125  configuration_property_description & set_default_value_real(double, const std::string & unit_symbol_ = "");
128  configuration_property_description & add_example(const std::string & example_);
129  configuration_property_description & set_deprecated(bool, const std::string & info_ = "");
130 
131  bool is_deprecated() const;
132  const std::string & get_deprecated_info() const;
133  bool is_valid() const;
134  bool has_type() const;
135  bool has_section() const;
136  const std::string & get_section() const;
137  bool is_const() const;
138  bool is_mutable() const;
139  bool has_single_type() const;
140  bool is_boolean() const;
141  bool is_integer() const;
142  bool is_real() const;
143  bool is_string() const;
144  bool is_path() const;
145  bool is_static() const;
146  bool is_dynamic() const;
147  bool is_trigger() const;
148  bool is_triggered_by_flag() const;
149  bool is_triggered_by_label() const;
150  const std::string & get_name_pattern() const;
151  const std::string & get_from() const;
152  const std::string & get_group() const;
153  bool has_terse_description() const;
154  const std::string & get_terse_description() const;
155  bool has_long_description() const;
156  const std::string & get_long_description() const;
157  unsigned int get_number_of_examples() const;
158  const std::string & get_example(int) const;
159  bool has_default_value() const;
160  bool get_default_value_boolean() const;
161  int get_default_value_integer() const;
162  double get_default_value_real() const;
163  const std::string & get_default_value_real_unit() const;
164  const std::string & get_default_value_string() const;
165  bool has_default_array_size() const;
166  int get_default_array_size() const;
167  bool is_mandatory() const;
168  int get_type() const;
169  bool is_scalar() const;
170  bool is_array() const;
171  bool has_explicit_unit() const;
172  bool has_unit_label() const;
173  const std::string & get_unit_label() const;
174  bool has_unit_symbol() const;
175  const std::string & get_unit_symbol() const;
176  bool is_fixed_sized_array() const;
177  int get_array_fixed_size() const;
178  void print(std::ostream &out_, const std::string & indent_ = "") const;
180  bool has_complex_dependencies() const;
182  const dependency_entry & get_triggered_by_flag() const;
183  const dependency_entry & get_dynamic_dependee() const;
184  bool has_dynamic_dependers() const;
185  unsigned int get_number_of_dynamic_dependers() const;
186  const dependency_entry & get_dynamic_depender(int i_) const;
187  unsigned int get_number_of_triggered_dependers() const;
188  const dependency_entry & get_triggered_depender(int i_) const;
189 
191  void dump(std::ostream & out_ = std::clog,
192  const std::string & title_ = "",
193  const std::string & indent_ = "") const;
194 
195  private:
196 
197  std::string _name_pattern_;
198  std::string _from_;
199  std::string _section_;
200  std::string _group_;
201  std::string _terse_description_;
202  std::string _long_description_;
203  std::vector<std::string> _examples_;
204  int _type_;
205  bool _const_;
206  bool _path_;
207  bool _explicit_unit_;
208  std::string _unit_label_;
209  std::string _unit_symbol_;
210  bool _array_;
211  int _array_fixed_size_;
212  int _default_array_size_;
213  boost::logic::tribool _default_value_boolean_;
214  int _default_value_integer_;
215  double _default_value_real_;
216  std::string _default_value_real_unit_;
217  std::string _default_value_string_;
218  bool _mandatory_;
219  bool _complex_triggering_conditions_;
220  bool _complex_dependencies_;
221  std::vector<dependency_entry> _dynamic_dependers_;
222  dependency_entry _dynamic_dependee_;
223  std::vector<dependency_entry> _triggering_;
224  dependency_entry _triggered_by_flag_;
225  dependency_entry _triggered_by_label_;
226  bool _deprecated_;
227  std::string _deprecated_info_;
228 
230  };
231 
232 
235  {
236  public:
237 
240  po_none = 0,
243  };
244 
247  sgo_none = 0,
251  };
252 
253  /*
254  struct configuration_section_description {
255  std::string name;
256  std::string class_name;
257  bool mandatory;
258  };
259  */
260 
261  typedef std::vector<configuration_property_description> cpd_col_type;
262  //typedef std::map<std::string,configuration_section_description> csd_col_type;
263 
264  bool is_available() const;
265 
267 
269  set_class_name(const std::string &);
270 
272  set_class_description(const std::string &);
273 
275  set_class_documentation(const std::string &);
276 
278  set_class_library(const std::string &);
279 
281  set_configuration_hints(const std::string &);
282 
285 
286  const std::string & get_class_name() const;
287 
288  const std::string & get_class_description() const;
289 
290  const std::string & get_class_documentation() const;
291 
292  const std::string & get_class_library() const;
293 
294  void add_group(const std::string &group_);
295 
296  const std::set<std::string> & get_groups() const;
297 
298  bool has_class_description() const;
299 
300  bool has_class_library() const;
301 
302  bool has_class_documentation() const;
303 
304  const std::string & get_configuration_hints() const;
305 
306  bool has_configuration_hints() const;
307 
308  bool has_validation_support() const;
309 
310  void print(std::ostream & out_, const std::string & indent_ = "", uint32_t po_flags_ = 0) const;
311 
312  unsigned int get_number_of_documented_properties() const;
313 
315 
317 
320 
321  unsigned int get_number_of_examples() const;
322 
323  const std::string & get_example(int) const;
324 
325  void add_example(const std::string &example_);
326 
328  bool validate(const datatools::properties & config_, std::string & error_message_) const;
329 
331  void generate_sample_configuration(std::ostream & out_,
332  const std::string & topic_ = "",
333  uint32_t sgo_flags_ = 0) const;
334 
336  bool is_locked() const;
337 
339  void lock();
340 
342  void dump(std::ostream & out_ = std::clog,
343  const std::string & title_ = "",
344  const std::string & indent_ = "") const;
345 
346  protected:
347 
349  properties & props_) const;
350 
352  const properties & config_,
353  std::string & error_message_) const;
354 
356  const properties & config_,
357  std::string & error_message_) const;
358 
359  private:
360 
362  void _at_lock_();
363 
364  private:
365 
366  bool _locked_;
367  std::string _class_name_;
368  std::string _class_description_;
369  std::string _class_documentation_;
370  std::string _class_library_;
371  std::set<std::string> _groups_;
372  cpd_col_type _configuration_properties_infos_;
373  std::string _configuration_hints_;
374  std::vector<std::string> _examples_;
375  //csd_col_type _configuration_sections_infos_; //!< Collection of documented sections
376  bool _validation_support_;
377 
378  };
379 
380 } // namespace datatools
381 
382 #endif // DATATOOLS_OBJECT_CONFIGURATION_DESCRIPTION_H
383 
384 // Local Variables: --
385 // mode: c++ --
386 // c-file-style: "gnu" --
387 // tab-width: 2 --
388 // End: --
static const bool SCALAR
Definition: object_configuration_description.h:62
dependency_type
Dependency type.
Definition: object_configuration_description.h:70
configuration_property_description()
Default constructor.
configuration_property_description & set_mandatory(bool m_=true)
bool validate(const datatools::properties &config_, std::string &error_message_) const
Check the validity of a container of properties with respect to the OCD description.
Description of a dependency.
Definition: object_configuration_description.h:78
const dependency_entry & get_triggered_by_flag() const
configuration_property_description & add_example(const std::string &example_)
object_configuration_description & set_configuration_hints(const std::string &)
object_configuration_description & set_class_documentation(const std::string &)
configuration_property_description & set_from(const std::string &from_)
bool by_flag() const
const std::string & get_example(int) const
const std::string & get_class_documentation() const
bool _validate_traits(const configuration_property_description &cpd_, const properties &config_, std::string &error_message_) const
Definition: object_configuration_description.h:241
Definition: object_configuration_description.h:247
const configuration_property_description & ref() const
const std::string & get_default_value_real_unit() const
const std::string & get_configuration_hints() const
Definition: object_configuration_description.h:249
An object that describes the way an objet of a given class can be configured from properties.
Definition: object_configuration_description.h:57
const dependency_entry & get_dynamic_depender(int i_) const
Definition: object_configuration_description.h:250
configuration_property_description & set_complex_dependencies(bool=true)
const std::string & get_name() const
const std::string & get_unit_label() const
bool has_address() const
dependency_entry()
const std::set< std::string > & get_groups() const
void print(std::ostream &out_, const std::string &indent_="") const
configuration_property_description & set_traits(int type_, bool array_=false, int fixed_size_=-1)
object_configuration_description & set_class_description(const std::string &)
undefined dependency
Definition: object_configuration_description.h:71
configuration_property_description & set_long_description(const std::string &desc_)
const std::string & get_class_name() const
const configuration_property_description & get_configuration_property_info(int i_) const
configuration_property_description & set_section(const std::string &section_name_)
const std::string & get_deprecated_info() const
const std::string & get_name_pattern() const
static const bool EXPLICIT_UNIT
Definition: object_configuration_description.h:65
An object that describes the way an object of a given class can be configured through properties.
Definition: object_configuration_description.h:234
configuration_property_description & set_deprecated(bool, const std::string &info_="")
po_flags_type
Print option flags.
Definition: object_configuration_description.h:239
bool is_locked() const
Check the lock flag.
const std::string & get_example(int) const
configuration_property_description & set_const(bool=true)
const std::string & get_long_description() const
configuration_property_description & set_unit_symbol(const std::string &)
void add_group(const std::string &group_)
void dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="") const
Raw print.
void _generate_static_property(const configuration_property_description &cpd_, properties &props_) const
bool dynamic() const
const std::string & get_unit_symbol() const
Definition: object_configuration_description.h:240
const dependency_entry & get_triggered_depender(int i_) const
bool has_name() const
object_configuration_description & set_class_library(const std::string &)
sgo_flags_type
Skeleton/sample generator option flags.
Definition: object_configuration_description.h:246
static const bool CONST
Definition: object_configuration_description.h:67
void add_example(const std::string &example_)
void dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="") const
Raw print.
configuration_property_description & set_explicit_unit(bool=true)
void generate_sample_configuration(std::ostream &out_, const std::string &topic_="", uint32_t sgo_flags_=0) const
Generate a sample configuration stream.
const std::string & get_class_library() const
bool by_label() const
Definition: object_configuration_description.h:248
object_configuration_description & set_validation_support(bool)
Dependency from a string property (label) with a specific value.
Definition: object_configuration_description.h:74
configuration_property_description & set_name_pattern(const std::string &np_)
configuration_property_description & set_path(bool=true)
Definition: object_configuration_description.h:242
configuration_property_description & set_triggered_by_flag(const std::string &prop_name_, bool triggering_status_=true)
static const bool ARRAY
Definition: object_configuration_description.h:63
bool _validate_static(const configuration_property_description &cpd_, const properties &config_, std::string &error_message_) const
Dependency from a boolean property (flag) with a specific value (true or false)
Definition: object_configuration_description.h:73
int type
The type of dependency (should be a dependency_type ! TO BE FIXED!)
Definition: object_configuration_description.h:92
configuration_property_description & set_default_value_real(double, const std::string &unit_symbol_="")
configuration_property_description & set_terse_description(const std::string &desc_)
void reset()
unsigned int get_number_of_triggered_dependers() const
const configuration_property_description * address
Definition: object_configuration_description.h:96
std::vector< configuration_property_description > cpd_col_type
Definition: object_configuration_description.h:261
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
static const bool IMPLICIT_UNIT
Definition: object_configuration_description.h:64
configuration_property_description & set_default_value_integer(int)
std::string name
The name of the dependee property.
Definition: object_configuration_description.h:93
bool triggering_status
The triggering value of a flag dependee property (DEP_BY_FLAG)
Definition: object_configuration_description.h:94
const std::string & get_default_value_string() const
const std::string & get_terse_description() const
configuration_property_description & set_default_array_size(int)
configuration_property_description & add_configuration_property_info()
configuration_property_description & set_default_value_boolean(bool)
configuration_property_description & set_group(const std::string &group_)
const std::string & get_section() const
configuration_property_description & set_triggered_by_label(const std::string &prop_name_, const std::string &labels_)
unsigned int get_number_of_documented_properties() const
static const bool MUTABLE
Definition: object_configuration_description.h:66
configuration_property_description & add_property_info()
unsigned int get_number_of_dynamic_dependers() const
void print(std::ostream &out_, const std::string &indent_="", uint32_t po_flags_=0) const
configuration_property_description & set_default_value_string(const std::string &)
const dependency_entry & get_dynamic_dependee() const
bool is_valid() const
const dependency_entry & get_triggered_by_label() const
configuration_property_description & set_complex_triggering_conditions(bool=true)
configuration_property_description & set_unit_label(const std::string &)
std::vector< std::string > triggering_labels
The triggering values of a string dependee property (DEP_BY_LABEL)
Definition: object_configuration_description.h:95
object_configuration_description & set_class_name(const std::string &)
Dynamic dependency from another property of which the name is used to build the property's name.
Definition: object_configuration_description.h:72
~dependency_entry()
A dictionary of arbitrary properties.
Definition: properties.h:125
const std::string & get_class_description() const