Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_registry.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-10-31
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 registry of configuration variants and associated parameters.
26  *
27  */
28 
29 #ifndef DATATOOLS_CONFIGURATION_VARIANT_REGISTRY_H
30 #define DATATOOLS_CONFIGURATION_VARIANT_REGISTRY_H
31 
32 // Standard library:
33 #include <string>
34 #include <map>
35 #include <vector>
36 #include <memory>
37 
38 // This project (Bayeux/datatools):
42 
43 namespace datatools {
44 
45  namespace configuration {
46 
47  // Forward declaration:
48  class variant_registry_manager;
49  class variant_record;
50  class variant_repository;
51 
54  {
55  public:
56 
58  typedef std::map<std::string, variant_record> record_dict_type;
59 
61  static const std::string & default_top_variant_name();
62 
64  virtual bool is_name_valid(const std::string & name_) const;
65 
68 
70  virtual ~variant_registry();
71 
73  bool has_top_variant_name() const;
74 
76  const std::string & get_top_variant_name() const;
77 
80 
82  const record_dict_type & get_records() const;
83 
85  bool is_mounted() const;
86 
88  const std::string & get_mounting_name() const;
89 
91  bool has_parent_repository() const;
92 
94  void set_parent_repository(const variant_repository &, const std::string & mounting_name_);
95 
98 
101 
103  bool is_initialized() const;
104 
106  void initialize_from(const variant_registry_manager & mgr_,
107  const std::string & top_variant_ = "",
108  const std::string & name_ = "",
109  const std::string & display_name_ = "",
110  const std::string & terse_description_ = "");
111 
113  void reset();
114 
116  variant_record & add_record(const std::string & record_path_);
117 
119  bool has_variant_record(const std::string & record_path_) const;
120 
122  variant_record & grab_variant_record(const std::string & record_path_);
123 
125  bool parameter_exists(const std::string & variant_path_) const;
126 
128  bool variant_exists(const std::string & variant_path_) const;
129 
131  bool is_active_variant(const std::string & variant_path_) const;
132 
134  const variant_record & get_variant_record(const std::string & record_path_) const;
135 
137  bool has_parameter_record(const std::string & record_path_) const;
138 
140  bool has_parameter_record_value_group(const std::string & param_group_path_) const;
141 
143  variant_record & grab_parameter_record(const std::string & record_path_);
144 
146  const variant_record & get_parameter_record(const std::string & record_path_) const;
147 
149  const variant_record & get_top_variant_record() const;
150 
152  bool has_dependency_model() const;
153 
156 
158  void load_local_dependency_model(const datatools::properties & ldm_config_);
159 
161  virtual void tree_dump(std::ostream & out_ = std::clog,
162  const std::string & title_ = "",
163  const std::string & inden_ = "",
164  bool inherit_ = false) const;
165 
167  enum list_flags {
175  };
176 
178  void list_of_ranked_parameters(std::vector<std::string> & paths_) const;
179 
181  void list_of_ranked_records(std::vector<std::string> & paths_,
182  uint32_t flags_ = 0) const;
183 
185  void list_of_parameters(std::vector<std::string> &_paths_,
186  uint32_t flags_ = 0) const;
187 
189  void list_of_unset_parameters(std::vector<std::string> & unset_paths_) const;
190 
196  std::vector<std::string> & ranked_) const;
197 
199  bool is_accomplished() const;
200 
202  void update();
203 
204  private:
205 
206  void _build_parameter_records_from_variant_(const variant_model & varmod_,
207  variant_record * parent_variant_record_);
208 
209  void _build_variant_records_from_parameter_(const parameter_model & varmod_,
210  variant_record * parent_param_record_);
211 
212  private:
213 
214  // Management:
215  bool _initialized_ = false;
216 
217  // Configuration:
218  std::string _top_variant_name_;
219 
220  // Internal data:
221  record_dict_type _records_;
222  const variant_repository * _parent_repository_ = nullptr;
223  std::string _mounting_name_;
224  std::unique_ptr<variant_dependency_model> _dependency_model_;
225 
226  };
227 
228  } // end of namespace configuration
229 
230 } // end of namespace datatools
231 
232 #endif // DATATOOLS_CONFIGURATION_VARIANT_REGISTRY_H
233 
234 // Local Variables: --
235 // mode: c++ --
236 // c-file-style: "gnu" --
237 // tab-width: 2 --
238 // End: --
Model of a configuration variant.
Definition: variant_model.h:59
record_dict_type & grab_records()
Return a reference to the mutable dictionary of records.
Registry of configuration variant parameters and associated variants.
Definition: variant_registry.h:53
std::map< std::string, variant_record > record_dict_type
Type of dictionary of configuration variant records.
Definition: variant_registry.h:58
bool has_parameter_record(const std::string &record_path_) const
Check if a parameter record exists.
static const std::string & default_top_variant_name()
Return the default root variant name.
variant_record & add_record(const std::string &record_path_)
Add a new record.
variant_record & grab_parameter_record(const std::string &record_path_)
Return a reference to a mutable parameter record.
void update()
Update record status.
static const uint32_t bit01
Definition: bit_mask.h:28
static const uint32_t bit03
Definition: bit_mask.h:30
variant_record & grab_variant_record(const std::string &record_path_)
Return a reference to a mutable variant record.
static const uint32_t bit04
Definition: bit_mask.h:31
const variant_dependency_model & get_dependency_model() const
Return the local dependency model.
static const uint32_t bit06
Definition: bit_mask.h:33
bool has_parameter_record_value_group(const std::string &param_group_path_) const
Check if a parameter record group exists.
const variant_repository & get_parent_repository() const
Return the handle to the parent repository.
const variant_record & get_parameter_record(const std::string &record_path_) const
Return a reference to a non mutable parameter record.
void build_recursive_list_of_ranked_records(const variant_record &record_, std::vector< std::string > &ranked_) const
A Factory/manager for configuration variants and associated parameters.
Definition: variant_registry_manager.h:51
bool has_dependency_model() const
Check if a local dependency model is set.
bool has_top_variant_name() const
Check if the top variant name is set.
void reset_parent_repository()
Reset the parent repository.
void load_local_dependency_model(const datatools::properties &ldm_config_)
Load local dependency model.
void list_of_ranked_records(std::vector< std::string > &paths_, uint32_t flags_=0) const
Compute the ranked list of records.
static const uint32_t bit02
Definition: bit_mask.h:29
static const uint32_t bit05
Definition: bit_mask.h:32
bool is_active_variant(const std::string &variant_path_) const
Check if a variant is active.
bool is_accomplished() const
Check if all parameters are set.
const std::string & get_top_variant_name() const
Return the name of the top variant used to initialize the registry.
bool has_parent_repository() const
Check the parent repository.
bool variant_exists(const std::string &variant_path_) const
Check if a variant exists (active or not)
list_flags
Flags for building the list of parameters.
Definition: variant_registry.h:167
Model of variant dependencies associated to a variant repository.
Definition: variant_dependency_model.h:89
const record_dict_type & get_records() const
Return a reference to the non-mutable dictionary of records.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
void set_parent_repository(const variant_repository &, const std::string &mounting_name_)
Set the parent repository.
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
void initialize_from(const variant_registry_manager &mgr_, const std::string &top_variant_="", const std::string &name_="", const std::string &display_name_="", const std::string &terse_description_="")
Initialize.
bool is_mounted() const
Check if the registry is mounted in some parent repository.
const variant_record & get_variant_record(const std::string &record_path_) const
Return a reference to a non mutable variant record.
static const uint32_t bit00
Definition: bit_mask.h:27
const std::string & get_mounting_name() const
Return the mounting name.
Variant registry record node.
Definition: variant_record.h:52
virtual bool is_name_valid(const std::string &name_) const
Check if a name is valid.
bool is_initialized() const
Check initialization.
const variant_record & get_top_variant_record() const
Return a reference to the non mutable top variant record.
void list_of_unset_parameters(std::vector< std::string > &unset_paths_) const
Compute the list of unset parameters.
void list_of_parameters(std::vector< std::string > &_paths_, uint32_t flags_=0) const
Compute the list of parameters.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &inden_="", bool inherit_=false) const
Smart print.
bool has_variant_record(const std::string &record_path_) const
Check if a variant record exists.
void list_of_ranked_parameters(std::vector< std::string > &paths_) const
Compute the ranked list of parameters.
Variant repository.
Definition: variant_repository.h:57
Description/model of a configuration parameter.
Definition: parameter_model.h:60
bool parameter_exists(const std::string &variant_path_) const
Check if a variant parameter exists (active or not)
A dictionary of arbitrary properties.
Definition: properties.h:125