aGrUM  0.14.2
partialInstantiationRegister4MultiDim_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 
29 # include <agrum/agrum.h>
31 
32 namespace gum {
33 
34  // adds a new entry into the register
35  template < typename GUM_SCALAR >
37  const std::string& instantiation_func_name,
38  const std::string& type_multidim,
39  typename PartialInstantiationRegister4MultiDim<
40  GUM_SCALAR >::PartialInstantiationPtr newFunction) {
41  // insert the new entry
42  PartialInstantiationSet* theset;
43 
44  if (!__set.exists(instantiation_func_name)) {
45  theset =
46  __set.insert(instantiation_func_name, new PartialInstantiationSet).second;
47 # ifdef GUM_DEBUG_MODE
48  // for debugging purposes, we should inform the aGrUM's debugger that
49  // the hashtable contained within the
50  // PartialInstantiationRegister4MultiDim
51  // will be removed at the end of the program's execution.
52  __debug__::__inc_deletion(
53  "HashTable", __FILE__, __LINE__, "destructor of", (void*)theset);
54 # endif /* GUM_DEBUG_MODE */
55  } else {
56  theset = __set[instantiation_func_name];
57  }
58 
59  theset->insert(type_multidim, newFunction);
60  }
61 
62  // removes a given entry from the register
63  template < typename GUM_SCALAR >
65  const std::string& instantiation_func_name,
66  const std::string& type_multidim) {
67  if (!__set.exists(instantiation_func_name)) return;
68 
69  PartialInstantiationSet* theset = __set[instantiation_func_name];
70 
71  theset->erase(type_multidim);
72  }
73 
74  // indicates whether a given entry exists in the register
75  template < typename GUM_SCALAR >
77  const std::string& instantiation_func_name,
78  const std::string& type_multidim) const {
79  if (!__set.exists(instantiation_func_name)) return false;
80 
81  return __set[instantiation_func_name].exists(type_multidim);
82  }
83 
86  template < typename GUM_SCALAR >
87  INLINE typename PartialInstantiationRegister4MultiDim<
88  GUM_SCALAR >::PartialInstantiationPtr
90  const std::string& instantiation_func_name,
91  const std::string& type_multidim) const {
92  PartialInstantiationSet* theset = __set[instantiation_func_name];
93  return theset-> operator[](type_multidim);
94  }
95 
96  // a named constructor that constructs one and only one Register per data
97  // type
98  template < typename GUM_SCALAR >
99  PartialInstantiationRegister4MultiDim< GUM_SCALAR >&
101  static PartialInstantiationRegister4MultiDim container;
102 
103 # ifdef GUM_DEBUG_MODE
104  static bool first = true;
105 
106  if (first) {
107  first = false;
108  // for debugging purposes, we should inform the aGrUM's debugger that
109  // the hashtable contained within the
110  // PartialInstantiationRegister4MultiDim
111  // will be removed at the end of the program's execution.
112  __debug__::__inc_deletion("HashTable",
113  __FILE__,
114  __LINE__,
115  "destructor of",
116  (void*)&container.__set);
117  }
118 
119 # endif /* GUM_DEBUG_MODE */
120 
121  return container;
122  }
123 
124  // Default constructor: creates an empty register
125  template < typename GUM_SCALAR >
126  PartialInstantiationRegister4MultiDim<
127  GUM_SCALAR >::PartialInstantiationRegister4MultiDim() {}
128 
129  // destructor
130  template < typename GUM_SCALAR >
131  PartialInstantiationRegister4MultiDim<
132  GUM_SCALAR >::~PartialInstantiationRegister4MultiDim() {
133  // remove all the sets
135  iter = __set.beginSafe();
136  iter != __set.endSafe();
137  ++iter)
138  delete iter.val();
139  }
140 
141  // a function to more easily register new instantiation functions in
142  // MultiDims
143  template < typename GUM_SCALAR >
145  const std::string& instantiation_func_name,
146  const std::string& type_multidim,
147  typename PartialInstantiationRegister4MultiDim<
148  GUM_SCALAR >::PartialInstantiationPtr function) {
150  instantiation_func_name, type_multidim, function);
151  }
152 
153 } /* namespace gum */
154 
155 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
Headers for PartialInstantiationRegister4MultiDim.
static PartialInstantiationRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
PartialInstantiationPtr get(const std::string &instantiation_func_name, const std::string &type_multidim) const
Returns the specialized partial instantiation operator assigned to a given type of MultiDimImplementa...
void erase(const std::string &instantiation_func_name, const std::string &type_multidim)
Removes a given entry from the register.
bool exists(const std::string &instantiation_func_name, const std::string &type_multidim) const
Indicates whether a given entry exists in the register.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition: hashTable.h:692
void registerPartialInstantiation(const std::string &instantiation_func_name, const std::string &type_multidim, typename PartialInstantiationRegister4MultiDim< GUM_SCALAR >::PartialInstantiationPtr function)
A function to more easily register new instantiation functions in MultiDims.
void insert(const std::string &instantiation_func_name, const std::string &type_multidim, PartialInstantiationPtr newFunction)
Adds a new entry into the register.