aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
operatorRegister4MultiDim_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief A container for registering binary functions on
25  * multiDimImplementations
26  *
27  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28  */
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 # include <agrum/agrum.h>
33 
34 # include <agrum/tools/multidim/utils/operators/operatorRegister4MultiDim.h>
35 
36 namespace gum {
37 
38  // adds a new entry into the register
39  template < typename GUM_SCALAR >
40  void OperatorRegister4MultiDim< GUM_SCALAR >::insert(
41  const std::string& operation_name,
42  const std::string& type1,
43  const std::string& type2,
45  // insert the new entry
47 
48  if (!_set_.exists(operation_name)) {
50 # ifdef GUM_DEBUG_MODE
51  // for debugging purposes, we should inform the aGrUM's debugger that
52  // the hashtable contained within the OperatorRegister4MultiDim will be
53  // removed at the end of the program's execution.
54  __debug__::_inc_deletion_("HashTable", __FILE__, __LINE__, "destructor of", (void*)theset);
55 # endif /* GUM_DEBUG_MODE */
56  } else {
58  }
59 
61 
63  }
64 
65  // removes a given entry from the register
66  template < typename GUM_SCALAR >
68  const std::string& type1,
69  const std::string& type2) {
70  if (!_set_.exists(operation_name)) return;
71 
73 
75  }
76 
77  // indicates whether a given entry exists in the register
78  template < typename GUM_SCALAR >
80  const std::string& type1,
81  const std::string& type2) const {
82  if (!_set_.exists(operation_name)) return false;
84  return theset->exists(std::pair< std::string, std::string >(type1, type2));
85  }
86 
87  /** @brief returns the specialized operator assigned to a given pair of
88  * MultiDimImplementations */
89  template < typename GUM_SCALAR >
92  const std::string& type1,
93  const std::string& type2) const {
95  return (*theset)[std::pair< std::string, std::string >(type1, type2)];
96  }
97 
98  // a named constructor that constructs one and only one Register per data
99  // type
100  template < typename GUM_SCALAR >
102  static OperatorRegister4MultiDim< GUM_SCALAR >* container = nullptr;
103  static bool first = true;
104 
105  if (first) {
106  first = false;
108 
109 # ifdef GUM_DEBUG_MODE
110  // for debugging purposes, we should inform the aGrUM's debugger that
111  // the hashtable contained within the OperatorRegister4MultiDim will be
112  // removed at the end of the program's execution.
113  __debug__::_inc_deletion_("HashTable",
114  __FILE__,
115  __LINE__,
116  "destructor of",
117  (void*)&container->_set_);
118 # endif /* GUM_DEBUG_MODE */
119  }
120 
121  return *container;
122  }
123 
124 
125  // Default constructor: creates an empty register
126  template < typename GUM_SCALAR >
128 
129  // destructor
130  template < typename GUM_SCALAR >
132  // remove all the sets
133  for (typename HashTable< std::string, OperatorSet* >::iterator_safe iter = _set_.beginSafe();
134  iter != _set_.endSafe();
135  ++iter)
136  delete iter.val();
137  }
138 
139  // a function to more easily register new operators in MultiDims
140  template < typename GUM_SCALAR >
142  const std::string& type1,
143  const std::string& type2,
146  type1,
147  type2,
148  function);
149  }
150 
151 } /* namespace gum */
152 
153 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643