Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_repository.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-04
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 repository for variant registries.
26  *
27  */
28 
29 #ifndef DATATOOLS_CONFIGURATION_VARIANT_REPOSITORY_H
30 #define DATATOOLS_CONFIGURATION_VARIANT_REPOSITORY_H
31 
32 // Standard library:
33 #include <string>
34 #include <list>
35 #include <map>
36 #include <vector>
37 #include <set>
38 #include <memory>
39 
40 // This project (Bayeux/datatools):
43 #include <datatools/bit_mask.h>
46 
47 namespace datatools {
48 
49  namespace configuration {
50 
51  class variant_registry;
52  class variant_registry_manager;
53  class variant_reporting;
54  class variant_record;
55 
58  {
59  public:
60 
73  static bool parse_variant_path(const std::string & variant_full_path_,
74  std::string & registry_name_,
75  std::string & variant_path_,
76  bool & reversed_);
77 
80  {
81  public:
82 
85 
88 
90  void set_name(const std::string &);
91 
93  const std::string & get_name() const;
94 
97 
99  const variant_registry & get_registry() const;
100 
103 
105  void reset();
106 
108  bool is_external() const;
109 
111  bool is_embedded() const;
112 
114  bool is_valid() const;
115 
118 
121 
123  void set_rank(int);
124 
126  int get_rank() const;
127 
129  bool has_rank() const;
130 
132  bool is_sealed() const;
133 
135  void seal();
136 
137  private:
138 
139  std::string _name_;
140  variant_repository * _parent_repository_ = nullptr;
141  int _rank_ = -1;
142  std::shared_ptr<variant_registry_manager> _embedded_manager_;
143  std::shared_ptr<variant_registry> _embedded_registry_;
144  variant_registry * _external_registry_ = nullptr;
145  bool _last_active_ = false;
146  bool _sealed_ = false;
147 
148  friend class variant_repository;
149 
150  };
151 
153  typedef std::map<std::string, registry_entry> registry_dict_type;
154  typedef std::map<int, std::string> ranked_dict_type;
155 
157  virtual bool is_name_valid(const std::string & name_) const;
158 
161 
164 
166  bool has_organization() const;
167 
169  const std::string & get_organization() const;
170 
172  void set_organization(const std::string &);
173 
175  bool has_application() const;
176 
178  const std::string & get_application() const;
179 
181  void set_application(const std::string &);
182 
184  void initialize(const datatools::properties & config_);
185 
187  void load_registries(const datatools::properties & config_);
188 
190  void load_global_dependency_model(const datatools::properties & gdm_config_);
191 
193  void initialize_simple();
194 
196  void reset();
197 
199  bool is_initialized() const;
200 
202  virtual void tree_dump(std::ostream & out_ = std::clog,
203  const std::string & title_ = "",
204  const std::string & indent_ = "",
205  bool inherit_ = false) const;
206 
208  unsigned int get_number_of_registries() const;
209 
211  void list_of_registry_keys(std::set<std::string> & keys_) const;
212 
214  bool has_registry(const std::string & registry_name_) const;
215 
217  const variant_registry & get_registry(const std::string & registry_name_) const;
218 
220  variant_registry & grab_registry(const std::string & registry_name_);
221 
223  const registry_dict_type & get_registries() const;
224 
227 
229  bool rank_is_used(int rank_) const;
230 
232  void registration_embedded(const std::string & registry_manager_config_,
233  const std::string & top_variant_name_ = "",
234  const std::string & registry_name_ = "",
235  const std::string & registry_display_name_ = "",
236  const std::string & registry_terse_description_ = "",
237  int registry_rank_ = -1,
239 
241  void registration_external(variant_registry & external_registry_,
242  const std::string & registry_name_ = "",
243  int rank_ = -1);
244 
246  void unregistration(const std::string & registry_name_);
247 
249  void build_ordered_registry_keys(std::vector<std::string> & keys_) const;
250 
252  bool is_ranked(const std::string & registry_name_) const;
253 
255  int get_rank(const std::string & registry_name_) const;
256 
258  bool is_active_registry(const std::string & registry_key_) const;
259 
261  bool is_active_variant(const std::string & registry_key_,
262  const std::string & variant_path_) const;
263 
265  void clear_registries();
266 
269 
271  bool is_accomplished() const;
272 
274  void set_requested_lock(bool rl_);
275 
277  bool is_requested_lock() const;
278 
280  bool is_locked() const;
281 
283  void lock();
284 
286  void unlock();
287 
289  bool has_variant(const std::string & registry_key_,
290  const std::string & variant_path_) const;
291 
293  bool has_variant_parameter(const std::string & registry_key_,
294  const std::string & variant_parameter_path_) const;
295 
297  bool has_dependency_model() const;
298 
301 
303  enum rst_flags {
305  };
306 
308  void print_rst(std::ostream & out_, uint32_t flags_ = 0) const;
309 
311  void system_export(uint32_t flags_ = 0);
312 
314  void system_discard() const;
315 
317  bool has_reporting() const;
318 
321 
323  void reset_reporting();
324 
327 
329  void update();
330 
332  class importer
333  {
334  public:
336  enum init_flags {
341  };
343  importer(const datatools::properties & config_, uint32_t flags_ = 0);
345  void operator()(variant_repository & vrep_);
346  protected:
347  void _process_registry(variant_registry & vreg_);
348  void _process_record(variant_record & vrec_);
349  private:
351  bool _noclear_ = false;
352  bool _dont_ignore_unknown_registries_ = false;
353  bool _dont_ignore_unknown_orgapp_ = false;
354  const datatools::properties & _config_;
355  std::vector<std::string> _settings_;
356  std::string _current_registry_name_;
357  std::string _current_setting_;
358  };
359 
361  class exporter
362  {
363  public:
365  enum init_flags {
369  };
371  exporter(datatools::properties & config_, uint32_t flags_ = 0);
372  void set_settings_key(const std::string &);
374  void process(const variant_repository & vrep_);
375  const std::vector<std::string> & get_settings() const;
376  void operator()(const variant_repository & vrep_);
377  protected:
378  void _process_registry(const variant_registry & vreg_);
379  void _process_record(const variant_record & vrec_);
380  private:
382  bool _noclear_ = false;
383  bool _noorgapp_ = false;
384  datatools::properties & _config_;
385  std::string _settings_key_;
386  // Working temporary data:
387  std::vector<std::string> _settings_;
388  std::string _current_registry_name_;
389  };
390 
391  protected:
392 
393  registry_entry & _add_entry(const std::string & registry_name_, int rank_ = -1);
394 
396  void _legacy_load_registries(const datatools::properties & config_);
397 
398  void _at_init_();
399 
400  void _at_reset_();
401 
403 
404  private:
405 
406  // Management:
407  bool _initialized_ = false;
408 
409  // Configuration:
410  std::string _organization_;
411  std::string _application_;
412  bool _requested_lock_ = false;
413 
414  // Working data:
415  bool _locked_ = false;
416  registry_dict_type _registries_;
417  ranked_dict_type _ranked_;
418  std::vector<std::string> _unranked_;
419  std::unique_ptr<variant_dependency_model> _dependency_model_;
420  variant_reporting * _reporting_ = nullptr;
421 
422  };
423 
424  } // end of namespace configuration
425 
426 } // end of namespace datatools
427 
428 #endif // DATATOOLS_CONFIGURATION_VARIANT_REPOSITORY_H
429 
430 // Local Variables: --
431 // mode: c++ --
432 // c-file-style: "gnu" --
433 // tab-width: 2 --
434 // End: --
static bool parse_variant_path(const std::string &variant_full_path_, std::string &registry_name_, std::string &variant_path_, bool &reversed_)
void unlock()
Unlock the repository.
void set_rank(int)
Set the rank of the registry.
bool is_external() const
Check if the registry is external.
void seal()
Place seal on the registry.
init_flags
Import flags.
Definition: variant_repository.h:336
bool is_embedded() const
Check if the registry is embedded.
Registry of configuration variant parameters and associated variants.
Definition: variant_registry.h:53
init_flags
Export flags.
Definition: variant_repository.h:365
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
void unregistration(const std::string &registry_name_)
Unregistration of some specific registry.
std::map< std::string, registry_entry > registry_dict_type
Type of dictionary of configuration variant registries.
Definition: variant_repository.h:153
void registration_embedded(const std::string &registry_manager_config_, const std::string &top_variant_name_="", const std::string &registry_name_="", const std::string &registry_display_name_="", const std::string &registry_terse_description_="", int registry_rank_=-1, const datatools::logger::priority registry_logging_=datatools::logger::PRIO_UNDEFINED)
Registration of an embedded registry.
const variant_dependency_model & get_dependency_model() const
Return the global dependency model.
registry_entry & _add_entry(const std::string &registry_name_, int rank_=-1)
void _process_record(const variant_record &vrec_)
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
static const uint32_t bit01
Definition: bit_mask.h:28
void load_registries(const datatools::properties &config_)
Load embedded registries from a properties container.
static const uint32_t bit03
Definition: bit_mask.h:30
void update()
Update all registries and variant record status.
bool is_sealed() const
Check if registry is sealed (non mutable)
~registry_entry()
Destructor.
virtual bool is_name_valid(const std::string &name_) const
Check if a name is valid.
void set_requested_lock(bool rl_)
Set flag for requested lock after initialization.
int get_rank(const std::string &registry_name_) const
Return the rank of a registry.
const std::string & get_organization() const
Return the name of the organization.
void registration_external(variant_registry &external_registry_, const std::string &registry_name_="", int rank_=-1)
Registration of an external registry.
Import a variant repository from a properties container.
Definition: variant_repository.h:332
const std::vector< std::string > & get_settings() const
void set_reporting(variant_reporting &)
Attach a variant usage reporting.
bool has_organization() const
Check the name of the organization.
bool is_requested_lock() const
Check if lock is requested after initialization.
variant_registry & grab_registry(const std::string &registry_name_)
Return a reference to a mutable registry.
bool has_reporting() const
Check if a variant usage reporting is attached.
Entry that hosts a variant registry.
Definition: variant_repository.h:79
Undefined/invalid priority.
Definition: logger.h:84
void set_external_registry(variant_registry &)
Set the external registry.
void reset_external_registry()
Reset the external registry.
bool has_variant_parameter(const std::string &registry_key_, const std::string &variant_parameter_path_) const
Check if a variant parameter is known.
const std::string & get_name() const
Return the registry name.
bool has_variant(const std::string &registry_key_, const std::string &variant_path_) const
Check if a variant is known.
void load_global_dependency_model(const datatools::properties &gdm_config_)
Load global dependency model.
void external_registries_unregistration()
Unregistration of external registries only.
bool has_registry(const std::string &registry_name_) const
Check if a registry exists.
registry_dict_type & grab_registries()
Return a reference to the mutable dictionary of registries.
variant_registry & grab_registry()
Return the mutable handle to the registry.
variant_reporting & grab_reporting()
Access to the variant usage reporting (if any)
void reset_reporting()
Detach a variant usage reporting (if any)
bool has_rank() const
Check if rank is set.
const registry_dict_type & get_registries() const
Return a reference to the non-mutable dictionary of registries.
void _process_registry(const variant_registry &vreg_)
Export a variant repository to a properties container.
Definition: variant_repository.h:361
const variant_repository & get_parent_repository() const
Return the handle to the parent repository.
void initialize(const datatools::properties &config_)
Initialize from a properties container.
void operator()(variant_repository &vrep_)
Import method.
std::map< int, std::string > ranked_dict_type
Definition: variant_repository.h:154
static const uint32_t bit02
Definition: bit_mask.h:29
const std::string & get_application() const
Return the name of the application.
variant processing reporting
Definition: io.h:124
void system_export(uint32_t flags_=0)
Export to the system variant repository.
bool is_valid() const
Check if the entry is valid.
bool rank_is_used(int rank_) const
Check if a given rank is used.
bool is_accomplished() const
Check if all embedded registries are accomplished.
void system_discard() const
Discard from the system variant repository.
void reset()
Reset.
void operator()(const variant_repository &vrep_)
bool is_locked() const
Check if the repository is locked.
bool is_active_variant(const std::string &registry_key_, const std::string &variant_path_) const
Check if a variant is active.
void set_application(const std::string &)
Set the name of the application.
registry_entry(variant_repository &)
Constructor.
void clear_registries()
Clear all registries.
importer(const datatools::properties &config_, uint32_t flags_=0)
Constructor.
Model of variant dependencies associated to a variant repository.
Definition: variant_dependency_model.h:89
void build_ordered_registry_keys(std::vector< std::string > &keys_) const
Built the ordered list of registry keys.
void list_of_registry_keys(std::set< std::string > &keys_) const
Build the list of registry keys.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
exporter(datatools::properties &config_, uint32_t flags_=0)
Constructor.
void set_organization(const std::string &)
Set the name of the organization.
void print_rst(std::ostream &out_, uint32_t flags_=0) const
Print documentation.
rst_flags
Restructured text formatting.
Definition: variant_repository.h:303
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
bool has_application() const
Check the name of the application.
static const uint32_t bit00
Definition: bit_mask.h:27
bool is_initialized() const
Check the initialization flag.
Variant registry record node.
Definition: variant_record.h:52
void set_name(const std::string &)
Set the registry name.
bool is_active_registry(const std::string &registry_key_) const
Check if a variant registry is active.
void process(const variant_repository &vrep_)
Export method.
unsigned int get_number_of_registries() const
Return the number of registries.
bool is_ranked(const std::string &registry_name_) const
Check if a registry is ranked.
bool has_dependency_model() const
Check if a global dependency model is set.
int get_rank() const
Get the rank of the registry.
Variant repository.
Definition: variant_repository.h:57
const variant_registry & get_registry() const
Return the handle to the registry.
void _legacy_load_registries(const datatools::properties &config_)
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
const variant_registry & get_registry(const std::string &registry_name_) const
Return a reference to a non mutable registry.
A dictionary of arbitrary properties.
Definition: properties.h:125