Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_dependency.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-10-26
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  * Description of long range dependencies between variant parameters
26  * and variants.
27  *
28  */
29 
30 #ifndef DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_H
31 #define DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_H
32 
33 // Standard library:
34 #include <string>
35 #include <map>
36 #include <memory>
37 #include <limits>
38 #include <set>
39 
40 // This project (Bayeux/datatools):
41 #include <datatools/i_tree_dump.h>
42 #include <datatools/logger.h>
45 
46 namespace datatools {
47 
48  namespace configuration {
49 
50  class variant_repository;
51  class variant_registry;
52  class base_dependency_logic;
53 
91  {
92  public:
93 
94  typedef std::map<unsigned int, variant_object_info> dependee_dict_type;
95 
97  variant_dependency(const variant_repository & repository_);
98 
100  variant_dependency(const variant_registry & registry_);
101 
104 
106  bool has_repository() const;
107 
109  const variant_repository & get_repository() const;
110 
112  bool has_registry() const;
113 
115  const variant_registry & get_registry() const;
116 
118  bool has_global_scope() const;
119 
121  bool has_local_scope() const;
122 
124  bool is_local() const;
125 
127  bool is_valid() const;
128 
130  void set_depender_by_path(const std::string & depender_name_, bool registry_scope_ = false);
131 
133  void set_depender(const variant_object_info & depender_);
134 
136  const variant_object_info & get_depender() const;
137 
139  std::size_t get_number_of_dependees() const;
140 
142  unsigned int add_dependee_by_path(const std::string & dependee_path_,
143  const unsigned int slot_ = std::numeric_limits<unsigned int>::max());
144 
146  unsigned int add_dependee(const variant_object_info & dependee_,
147  const unsigned int slot_ = std::numeric_limits<unsigned int>::max());
148 
150  void build_list_of_dependee_slots(std::set<unsigned int> & slots_) const;
151 
153  bool has_dependee(const unsigned int slot_) const;
154 
156  bool has_dependee_by_path(const std::string & dependee_path_) const;
157 
159  const variant_object_info & get_dependee(const unsigned int slot_) const;
160 
162  virtual void tree_dump(std::ostream & out_ = std::clog,
163  const std::string & title_ = "",
164  const std::string & indent_ = "",
165  bool inherit_ = false) const;
166 
168  base_dependency_logic & create_logic(const std::string & guid_);
169 
171  const base_dependency_logic & get_logic() const;
172 
175 
177  void build_logic_from_formula(const std::string & logic_expression_);
178 
180  bool is_locked() const;
181 
183  void lock();
184 
186  bool operator()() const;
187 
190 
193 
194  protected:
195 
196  void _lock();
197 
198  void _check();
199 
232  void _install_default_logic();
233 
234  private:
235 
237  bool _locked_ = false;
238  const variant_repository * _repository_ = nullptr;
239  const variant_registry * _registry_ = nullptr;
240  variant_object_info _depender_;
241  dependee_dict_type _dependees_;
242  std::shared_ptr<base_dependency_logic> _logic_;
243 
244  };
245 
246  } // end of namespace configuration
247 
248 } // end of namespace datatools
249 
250 #endif // DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_H
251 
252 // Local Variables: --
253 // mode: c++ --
254 // c-file-style: "gnu" --
255 // tab-width: 2 --
256 // End: --
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
bool has_local_scope() const
Check registry.
void build_logic_from_formula(const std::string &logic_expression_)
Buil the logic from formula.
variant_dependency(const variant_repository &repository_)
Constructor.
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
const variant_object_info & get_dependee(const unsigned int slot_) const
Return the dependee associated to a given slot.
bool is_local() const
Check if the dependency model is local to a registry.
const variant_object_info & get_depender() const
Return the depender.
std::size_t get_number_of_dependees() const
Return the number of dependee slots.
base_dependency_logic & create_logic(const std::string &guid_)
Instantiate the embedded predicate:
const variant_repository & get_repository() const
Return the repository handle.
bool is_locked() const
Check if dependency is locked.
const variant_registry & get_registry() const
Return the repository handle.
const base_dependency_logic & get_logic() const
Return the embedded predicate.
base_dependency_logic & grab_logic()
Return the embedded predicate.
bool has_global_scope() const
Check registry.
bool has_dependee(const unsigned int slot_) const
Check if a dependee is set at given slot.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
bool operator()() const
Check if the dependency is fulfilled.
bool is_valid() const
Check validity.
void set_depender_by_path(const std::string &depender_name_, bool registry_scope_=false)
Set the depender from its identifier.
void set_depender(const variant_object_info &depender_)
Set the depender.
Structure describing a variant object of interest which may have (dynamic) dependencies.
Definition: variant_object_info.h:55
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
unsigned int add_dependee_by_path(const std::string &dependee_path_, const unsigned int slot_=std::numeric_limits< unsigned int >::max())
Associate a dependee from its identifier to a slot.
bool has_registry() const
Check registry.
bool has_repository() const
Check repository.
Base class for variant enabling logic predicates.
Definition: variant_dependency_logic.h:55
void set_logging(const datatools::logger::priority)
Set the logging priority threshold.
unsigned int add_dependee(const variant_object_info &dependee_, const unsigned int slot_=std::numeric_limits< unsigned int >::max())
Associate a dependee to a slot.
void build_list_of_dependee_slots(std::set< unsigned int > &slots_) const
Build set of dependee slots.
std::map< unsigned int, variant_object_info > dependee_dict_type
Definition: variant_dependency.h:94
datatools::logger::priority get_logging() const
Return the logging priority threshold.
A variant dependency associated a depender variant object o a set of dependee variants....
Definition: variant_dependency.h:89
bool has_dependee_by_path(const std::string &dependee_path_) const
Check if a dependee is set with given path.
Variant repository.
Definition: variant_repository.h:57