aGrUM  0.14.2
completeProjectionRegister4MultiDim_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  ***************************************************************************/
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 # include <agrum/agrum.h>
31 
33 
34 namespace gum {
35 
36  // adds a new entry into the register
37  template < typename GUM_SCALAR >
39  const std::string& projection_name,
40  const std::string& type_multidim,
41  typename CompleteProjectionRegister4MultiDim<
42  GUM_SCALAR >::CompleteProjectionPtr newFunction) {
43  // insert the new entry
44  CompleteProjectionSet* theset;
45 
46  if (!__set.exists(projection_name)) {
47  theset = __set.insert(projection_name, new CompleteProjectionSet).second;
48 # ifdef GUM_DEBUG_MODE
49  // for debugging purposes, we should inform the aGrUM's debugger that
50  // the hashtable contained within the CompleteProjectionRegister4MultiDim
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[projection_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& projection_name, const std::string& type_multidim) {
66  if (!__set.exists(projection_name)) return;
67 
68  CompleteProjectionSet* theset = __set[projection_name];
69 
70  theset->erase(type_multidim);
71  }
72 
73  // indicates whether a given entry exists in the register
74  template < typename GUM_SCALAR >
76  const std::string& projection_name, const std::string& type_multidim) const {
77  if (!__set.exists(projection_name)) return false;
78 
79  return __set[projection_name].exists(type_multidim);
80  }
81 
84  template < typename GUM_SCALAR >
85  INLINE typename CompleteProjectionRegister4MultiDim<
86  GUM_SCALAR >::CompleteProjectionPtr
88  const std::string& projection_name,
89  const std::string& type_multidim) const {
90  CompleteProjectionSet* theset = __set[projection_name];
91  return theset-> operator[](type_multidim);
92  }
93 
94  // a named constructor that constructs one and only one Register per data
95  // type
96  template < typename GUM_SCALAR >
97  CompleteProjectionRegister4MultiDim< GUM_SCALAR >&
99  static CompleteProjectionRegister4MultiDim container;
100 
101 # ifdef GUM_DEBUG_MODE
102  static bool first = true;
103 
104  if (first) {
105  first = false;
106  // for debugging purposes, we should inform the aGrUM's debugger that
107  // the hashtable contained within the CompleteProjectionRegister4MultiDim
108  // will be removed at the end of the program's execution.
109  __debug__::__inc_deletion("HashTable",
110  __FILE__,
111  __LINE__,
112  "destructor of",
113  (void*)&container.__set);
114  }
115 
116 # endif /* GUM_DEBUG_MODE */
117 
118  return container;
119  }
120 
121  // Default constructor: creates an empty register
122  template < typename GUM_SCALAR >
123  CompleteProjectionRegister4MultiDim<
124  GUM_SCALAR >::CompleteProjectionRegister4MultiDim() {}
125 
126  // destructor
127  template < typename GUM_SCALAR >
128  CompleteProjectionRegister4MultiDim<
129  GUM_SCALAR >::~CompleteProjectionRegister4MultiDim() {
130  // remove all the sets
132  iter = __set.beginSafe();
133  iter != __set.endSafe();
134  ++iter)
135  delete iter.val();
136  }
137 
138  // a function to more easily register new projection functions in MultiDims
139  template < typename GUM_SCALAR >
140  void
141  registerCompleteProjection(const std::string& projection_name,
142  const std::string& type_multidim,
143  typename CompleteProjectionRegister4MultiDim<
144  GUM_SCALAR >::CompleteProjectionPtr function) {
146  projection_name, type_multidim, function);
147  }
148 
149 } /* namespace gum */
150 
151 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static CompleteProjectionRegister4MultiDim & Register()
A named constructor that constructs one and only one Register per data type.
void erase(const std::string &projection_name, const std::string &type_multidim)
Removes a given entry from the register.
bool exists(const std::string &projection_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
void registerCompleteProjection(const std::string &projection_name, const std::string &type_multidim, typename CompleteProjectionRegister4MultiDim< GUM_SCALAR >::CompleteProjectionPtr function)
A function to more easily register new projection functions in MultiDims.
void insert(const std::string &projection_name, const std::string &type_multidim, CompleteProjectionPtr newFunction)
Adds a new entry into the register.
CompleteProjectionPtr get(const std::string &projection_name, const std::string &type_multidim) const
returns the specialized projection operator assigned to a given type of MultiDimImplementation ...
HashTableIteratorSafe< Key, Val > iterator_safe
Types for STL compliance.
Definition: hashTable.h:692
A container for registering complete projection functions on multiDimImplementations, i.e., projections over all variables.