Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_dependency_logic.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  * Variant dependency logic.
26  *
27  */
28 
29 #ifndef DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_LOGIC_H
30 #define DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_LOGIC_H
31 
32 // Standard library:
33 #include <map>
34 #include <memory>
35 #include <string>
36 
37 // Third party:
38 #include <boost/function.hpp>
39 #include <boost/functional/factory.hpp>
40 
41 // This project (Bayeux/datatools):
42 #include <datatools/i_tree_dump.h>
44 
45 namespace datatools {
46 
47  namespace configuration {
48 
49  class variant_dependency;
50  class variant_object_info;
51  class variant_repository;
52  class variant_registry;
53 
57  {
58  public:
59 
61  typedef std::map<unsigned int, dependency_logic_ptr_type> input_dict_type;
62 
65 
67  virtual ~base_dependency_logic();
68 
70  virtual const char * guid() const = 0;
71 
73  virtual std::size_t min_ports() const;
74 
76  virtual std::size_t max_ports() const;
77 
79  virtual bool is_valid() const;
80 
82  virtual bool operator()() const = 0;
83 
85  bool check_active_variant(const variant_object_info &) const;
86 
88  void connect(const unsigned int input_port_, dependency_logic_ptr_type logic_);
89 
91  void disconnect(const unsigned int input_port_);
92 
94  base_dependency_logic & connect(const unsigned int input_port_, const std::string & guid_);
95 
97  void connect_dependee(const unsigned int input_port_, const unsigned int dependee_slot_);
98 
100  const variant_repository & get_repository() const;
101 
103  virtual void tree_dump(std::ostream & out_ = std::clog,
104  const std::string & title_ = "",
105  const std::string & indent_ = "",
106  bool inherit_ = false) const;
107 
110 
111  protected:
112 
115 
116  private:
117 
118  variant_dependency * _owner_dependency_ = nullptr;
119 
120  protected:
121 
122  const variant_repository * _repository = nullptr;
124 
125  };
126 
128  typedef boost::function<base_dependency_logic*(variant_dependency &)>
130 
132  typedef std::map<std::string, dependency_logic_factory_type>
134 
137 
140  {
141  public:
142 
145 
147  virtual ~slot_logic();
148 
150  virtual const char * guid() const;
151 
153  virtual std::size_t min_ports() const;
154 
156  virtual std::size_t max_ports() const;
157 
159  virtual bool is_valid() const;
160 
162  virtual bool operator()() const;
163 
165  void set_dependee_slot(const unsigned int dependee_slot_);
166 
168  virtual void tree_dump(std::ostream & out_ = std::clog,
169  const std::string & title_ = "",
170  const std::string & indent_ = "",
171  bool inherit_ = false) const;
172  private:
173 
174  unsigned int _dependee_slot_
175  = std::numeric_limits<unsigned int>::max();
176 
177  };
178 
181  {
182  public:
183 
186 
188  virtual ~not_logic();
189 
191  virtual const char * guid() const;
192 
194  virtual std::size_t max_ports() const;
195 
197  virtual bool operator()() const;
198 
199  };
200 
203  {
204  public:
205 
208 
210  virtual ~and_logic();
211 
213  virtual const char * guid() const;
214 
216  virtual bool operator()() const;
217 
218  };
219 
222  {
223  public:
224 
227 
229  virtual ~or_logic();
230 
232  virtual const char * guid() const;
233 
235  virtual bool operator()() const;
236 
237  };
238 
241  {
242  public:
243 
246 
248  virtual ~xor_logic();
249 
251  virtual const char * guid() const;
252 
254  virtual bool operator()() const;
255 
256  };
257 
258  } // end of namespace configuration
259 
260 } // end of namespace datatools
261 
262 #endif // DATATOOLS_CONFIGURATION_VARIANT_DEPENDENCY_LOGIC_H
263 
264 // Local Variables: --
265 // mode: c++ --
266 // c-file-style: "gnu" --
267 // tab-width: 2 --
268 // End: --
OR predicate.
Definition: variant_dependency_logic.h:221
std::shared_ptr< base_dependency_logic > dependency_logic_ptr_type
Definition: variant_dependency_utils.h:39
virtual bool is_valid() const
Check validity.
virtual const char * guid() const =0
Return the global unique class identifier.
virtual std::size_t max_ports() const
Return the maximum number of input ports.
void set_dependee_slot(const unsigned int dependee_slot_)
Set the slot identifier of the dependee.
const variant_repository * _repository
The handle to the parent repository.
Definition: variant_dependency_logic.h:122
virtual bool operator()() const
Check the logic.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
void connect(const unsigned int input_port_, dependency_logic_ptr_type logic_)
Connect an input port to a logic.
XOR predicate.
Definition: variant_dependency_logic.h:240
base_dependency_logic(variant_dependency &)
Constructor.
virtual const char * guid() const
Return the global unique class identifier.
virtual ~or_logic()
Destructor.
virtual const char * guid() const
Return the global unique class identifier.
and_logic(variant_dependency &)
Constructor.
not_logic(variant_dependency &)
Constructor.
std::map< unsigned int, dependency_logic_ptr_type > input_dict_type
Dictionary of input ports.
Definition: variant_dependency_logic.h:61
virtual const char * guid() const
Return the global unique class identifier.
virtual bool is_valid() const
Check validity.
virtual std::size_t min_ports() const
Return the minimum number of input ports.
virtual std::size_t max_ports() const
Return the maximum number of input ports.
virtual bool operator()() const
Check the logic.
NOT predicate.
Definition: variant_dependency_logic.h:180
virtual bool operator()() const =0
Check the logic.
virtual bool operator()() const
Check the logic.
slot_logic(variant_dependency &)
Constructor.
dependency_logic_factory_dict_type & dependency_logic_factories()
Return the dictionary of dependency logic factories:
virtual bool operator()() const
Check the logic.
bool check_active_variant(const variant_object_info &) const
Check if a given variant is active.
AND predicate.
Definition: variant_dependency_logic.h:202
variant_dependency & _grab_owner_dependency()
Return the mutable reference to the owner dependency.
virtual std::size_t min_ports() const
Return the minimum number of input ports.
const variant_repository & get_repository() const
Return the repository handle.
virtual const char * guid() const
Return the global unique class identifier.
input_dict_type _inputs
Connected input ports.
Definition: variant_dependency_logic.h:123
void connect_dependee(const unsigned int input_port_, const unsigned int dependee_slot_)
Connect input port to the dependee variant at given slot.
or_logic(variant_dependency &)
Constructor.
boost::function< base_dependency_logic *(variant_dependency &)> dependency_logic_factory_type
Logic factory type.
Definition: variant_dependency_logic.h:129
virtual std::size_t max_ports() const
Return the maximum number of input ports.
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
Variant slot predicate.
Definition: variant_dependency_logic.h:139
virtual const char * guid() const
Return the global unique class identifier.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
std::map< std::string, dependency_logic_factory_type > dependency_logic_factory_dict_type
Dictionary of logic factories.
Definition: variant_dependency_logic.h:133
xor_logic(variant_dependency &)
Constructor.
Base class for variant enabling logic predicates.
Definition: variant_dependency_logic.h:55
void disconnect(const unsigned int input_port_)
Disconnect an input port from a logic.
virtual bool operator()() const
Check the logic.
A variant dependency associated a depender variant object o a set of dependee variants....
Definition: variant_dependency.h:89
const variant_dependency & get_owner_dependency() const
Return the const reference to the owner dependency.
Variant repository.
Definition: variant_repository.h:57