Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_dependency_model.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2016-10-26
4  * Last modified : 2016-11-01
5  *
6  * Copyright (C) 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 model of variant dependencies between variant parameters
26  * and variants.
27  *
28  */
29 
30 #ifndef DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_MODEL_H
31 #define DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_MODEL_H
32 
33 // Standard library:
34 #include <string>
35 #include <set>
36 #include <map>
37 #include <memory>
38 
39 // This project (Bayeux/datatools):
40 #include <datatools/i_tree_dump.h>
41 #include <datatools/properties.h>
42 #include <datatools/logger.h>
44 
45 namespace datatools {
46 
47  namespace configuration {
48 
49  class variant_repository;
50  class variant_registry;
51 
91  {
92  public:
93 
95  struct dependee_record {
96  std::string dependee_path;
97  };
98  typedef std::map<unsigned int, dependee_record> dependee_record_dict_type;
99 
102  std::string depender_path;
103  std::set<unsigned int> input_slots;
104  std::string logic_expression;
106  };
107  typedef std::map<std::string, dependency_record> dependency_record_dict_type;
108 
109  typedef std::shared_ptr<variant_dependency> dependency_ptr_type;
110  typedef std::map<std::string, dependency_ptr_type> dependency_dict_type;
111  typedef std::map<std::string, std::set<std::string>> dependers_table_type;
112 
114  variant_dependency_model(const variant_repository & repository_);
115 
117  variant_dependency_model(const variant_registry & registry_);
118 
120  bool has_repository() const;
121 
123  const variant_repository & get_repository() const;
124 
126  bool has_registry() const;
127 
129  const variant_registry & get_registry() const;
130 
133 
136 
138  bool is_local() const;
139 
141  bool has_dependee_record_by_path(const std::string & dependee_path_) const;
142 
144  bool has_dependee_record(unsigned int slot_) const;
145 
147  unsigned int add_dependee_record(unsigned int slot_, const std::string & dependee_path_);
148 
150  const std::string & get_dependee_record_path(unsigned int slot_) const;
151 
154 
156  void build_list_of_dependee_slots(std::set<unsigned int> & dep_slots_) const;
157 
159  bool has_dependency_record(const std::string & name_) const;
160 
162  bool has_dependency_record_by_depender_path(const std::string & name_) const;
163 
165  void build_list_of_dependency_records(std::set<std::string> & dep_names_) const;
166 
168  void add_dependency_record(const std::string & name_,
169  const std::string & depender_path_,
170  const std::set<unsigned int> & input_slots_,
171  const std::string & logic_expression_ = "",
173 
176 
178  bool is_valid() const;
179 
181  bool is_initialized() const;
182 
184  void initialize(const datatools::properties & config_);
185 
187  void reset();
188 
190  virtual void tree_dump(std::ostream & out_ = std::clog,
191  const std::string & title_ = "",
192  const std::string & indent_ = "",
193  bool inherit_ = false) const;
194 
196  bool has_dependency(const std::string & path_) const;
197 
199  const variant_dependency & get_dependency(const std::string & path_) const;
200 
202  const dependency_ptr_type & get_dependency_ptr(const std::string & path_) const;
203 
205  const dependency_dict_type & get_dependencies() const;
206 
209 
211  enum rst_flags {
214  };
215 
217  void print_rst(std::ostream & out_,
218  const uint32_t flags_ = 0,
219  const std::string & indent_ = "") const;
220 
221  protected:
222 
223  void _at_init();
224 
226 
227  void _at_reset();
228 
229  private:
230 
231  // Management:
233  bool _initialized_ = false;
234  const variant_repository * _repository_ = nullptr;
235  const variant_registry * _registry_ = nullptr;
236 
237  // Configuration:
238  dependee_record_dict_type _dependee_records_;
239  dependency_record_dict_type _dependency_records_;
240 
241  // Working:
242  dependency_dict_type _dependencies_;
243  dependers_table_type _dependers_;
244 
245  };
246 
247  } // end of namespace configuration
248 
249 } // end of namespace datatools
250 
251 #endif // DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_MODEL_H
252 
253 // Local Variables: --
254 // mode: c++ --
255 // c-file-style: "gnu" --
256 // tab-width: 2 --
257 // End: --
bool has_dependency_record_by_depender_path(const std::string &name_) const
Check if a dependency is set given its depender path.
std::string depender_path
Definition: variant_dependency_model.h:102
void add_dependency_record(const std::string &name_, const std::string &depender_path_, const std::set< unsigned int > &input_slots_, const std::string &logic_expression_="", const datatools::logger::priority logging_=datatools::logger::PRIO_FATAL)
Add a dependency.
Registry of configuration variant parameters and associated variants.
Definition: variant_registry.h:53
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
rst_flags
Restructured text formatting.
Definition: variant_dependency_model.h:211
bool has_dependee_record_by_path(const std::string &dependee_path_) const
Check if a variant is used as a dependee.
const variant_dependency & get_dependency(const std::string &path_) const
Return the dependency associated to a variant object given its path.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
bool has_dependency(const std::string &path_) const
Check if a dependency is associated to a variant object given its path.
static const uint32_t bit01
Definition: bit_mask.h:28
std::map< unsigned int, dependee_record > dependee_record_dict_type
Definition: variant_dependency_model.h:98
const std::string & get_dependee_record_path(unsigned int slot_) const
Return the dependee path at given slot.
datatools::logger::priority logging
Definition: variant_dependency_model.h:105
std::set< unsigned int > input_slots
Definition: variant_dependency_model.h:103
const variant_repository & get_repository() const
Return the repository.
variant_dependency_model(const variant_repository &repository_)
Constructor.
const dependency_record_dict_type & get_dependency_records() const
Return the dictionary of dependency records.
const dependency_dict_type & get_dependencies() const
Return the collection of dependencies.
Description of a dependency:
Definition: variant_dependency_model.h:101
void set_logging(const datatools::logger::priority)
Set the logging priority threshold.
datatools::logger::priority get_logging() const
Return the logging priority threshold.
void print_rst(std::ostream &out_, const uint32_t flags_=0, const std::string &indent_="") const
Print documentation.
const dependee_record_dict_type & get_dependee_records() const
Return the dictionary of dependee records.
Description of a dependee slot:
Definition: variant_dependency_model.h:95
bool has_dependee_record(unsigned int slot_) const
Check if a dependee is set at given slot.
std::map< std::string, dependency_ptr_type > dependency_dict_type
Definition: variant_dependency_model.h:110
const dependency_ptr_type & get_dependency_ptr(const std::string &path_) const
Return the handle on the dependency associated to a variant object given its path.
std::shared_ptr< variant_dependency > dependency_ptr_type
Definition: variant_dependency_model.h:109
std::string dependee_path
Definition: variant_dependency_model.h:96
void build_list_of_dependee_slots(std::set< unsigned int > &dep_slots_) const
Build the list of dependee slots.
Model of variant dependencies associated to a variant repository.
Definition: variant_dependency_model.h:89
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
bool has_repository() const
Check repository.
bool has_dependency_record(const std::string &name_) const
Check if a dependency record is set.
std::string logic_expression
Definition: variant_dependency_model.h:104
static const uint32_t bit00
Definition: bit_mask.h:27
const dependers_table_type & get_dependers_per_dependee() const
Return the table of dependers' paths addressed by their respective dependees' paths.
unsigned int add_dependee_record(unsigned int slot_, const std::string &dependee_path_)
Add a dependee at given slot.
bool is_initialized() const
Check initialization flag.
std::map< std::string, dependency_record > dependency_record_dict_type
Definition: variant_dependency_model.h:107
A variant dependency associated a depender variant object o a set of dependee variants....
Definition: variant_dependency.h:89
void build_list_of_dependency_records(std::set< std::string > &dep_names_) const
Build the list of dependency records by name.
std::map< std::string, std::set< std::string > > dependers_table_type
Definition: variant_dependency_model.h:111
bool is_local() const
Check if the dependency model is local to a registry.
Variant repository.
Definition: variant_repository.h:57
const variant_registry & get_registry() const
Return the registry.
void initialize(const datatools::properties &config_)
Initialization.
A dictionary of arbitrary properties.
Definition: properties.h:125