aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
partialInstantiationRegister4MultiDim_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 Implementation of PartialInstantiationRegister4MultiDim.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 # include <agrum/agrum.h>
32 # include <agrum/tools/multidim/utils/partialInstantiationRegister4MultiDim.h>
33 
34 namespace gum {
35 
36  // adds a new entry into the register
37  template < typename GUM_SCALAR >
38  void PartialInstantiationRegister4MultiDim< GUM_SCALAR >::insert(
40  const std::string& type_multidim,
43  // insert the new entry
45 
48  .second;
49 # ifdef GUM_DEBUG_MODE
50  // for debugging purposes, we should inform the aGrUM's debugger that
51  // the hashtable contained within the
52  // PartialInstantiationRegister4MultiDim
53  // will be removed at the end of the program's execution.
54  __debug__::inc_deletion__("HashTable",
55  __FILE__,
56  __LINE__,
57  "destructor of",
58  (void*)theset);
59 # endif /* GUM_DEBUG_MODE */
60  } else {
62  }
63 
65  }
66 
67  // removes a given entry from the register
68  template < typename GUM_SCALAR >
71  const std::string& type_multidim) {
72  if (!set__.exists(instantiation_func_name)) return;
73 
75 
77  }
78 
79  // indicates whether a given entry exists in the register
80  template < typename GUM_SCALAR >
83  const std::string& type_multidim) const {
84  if (!set__.exists(instantiation_func_name)) return false;
85 
87  }
88 
89  /** @brief returns the specialized operator assigned to a given subtype of
90  * MultiDimImplementation */
91  template < typename GUM_SCALAR >
96  const std::string& type_multidim) const {
98  return theset-> operator[](type_multidim);
99  }
100 
101  // a named constructor that constructs one and only one Register per data
102  // type
103  template < typename GUM_SCALAR >
107 
108 # ifdef GUM_DEBUG_MODE
109  static bool first = true;
110 
111  if (first) {
112  first = false;
113  // for debugging purposes, we should inform the aGrUM's debugger that
114  // the hashtable contained within the
115  // PartialInstantiationRegister4MultiDim
116  // will be removed at the end of the program's execution.
117  __debug__::inc_deletion__("HashTable",
118  __FILE__,
119  __LINE__,
120  "destructor of",
121  (void*)&container.set__);
122  }
123 
124 # endif /* GUM_DEBUG_MODE */
125 
126  return container;
127  }
128 
129  // Default constructor: creates an empty register
130  template < typename GUM_SCALAR >
133 
134  // destructor
135  template < typename GUM_SCALAR >
138  // remove all the sets
140  iter
141  = set__.beginSafe();
142  iter != set__.endSafe();
143  ++iter)
144  delete iter.val();
145  }
146 
147  // a function to more easily register new instantiation functions in
148  // MultiDims
149  template < typename GUM_SCALAR >
152  const std::string& type_multidim,
158  function);
159  }
160 
161 } /* namespace gum */
162 
163 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669