aGrUM  0.14.2
projectionRegister4MultiDim_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,
42  newFunction) {
43  // insert the new entry
44  ProjectionSet* theset;
45 
46  if (!__set.exists(projection_name)) {
47  theset = __set.insert(projection_name, new ProjectionSet).second;
48 # ifdef GUM_DEBUG_MODE
49  // for debugging purposes, we should inform the aGrUM's debugger that
50  // the hashtable contained within the ProjectionRegister4MultiDim will be
51  // 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  ProjectionSet* 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 >
87  const std::string& projection_name,
88  const std::string& type_multidim) const {
89  ProjectionSet* theset = __set[projection_name];
90  return theset->operator[](type_multidim);
91  }
92 
93  // a named constructor that constructs one and only one Register per data
94  // type
95  template < typename GUM_SCALAR >
96  ProjectionRegister4MultiDim< GUM_SCALAR >&
98  static ProjectionRegister4MultiDim container;
99 
100 # ifdef GUM_DEBUG_MODE
101  static bool first = true;
102 
103  if (first) {
104  first = false;
105  // for debugging purposes, we should inform the aGrUM's debugger that
106  // the hashtable contained within the ProjectionRegister4MultiDim will be
107  // removed at the end of the program's execution.
108  __debug__::__inc_deletion("HashTable",
109  __FILE__,
110  __LINE__,
111  "destructor of",
112  (void*)&container.__set);
113  }
114 
115 # endif /* GUM_DEBUG_MODE */
116 
117  return container;
118  }
119 
120  // Default constructor: creates an empty register
121  template < typename GUM_SCALAR >
123 
124  // destructor
125  template < typename GUM_SCALAR >
127  // remove all the sets
129  __set.beginSafe();
130  iter != __set.endSafe();
131  ++iter)
132  delete iter.val();
133  }
134 
135  // a function to more easily register new projection functions in MultiDims
136  template < typename GUM_SCALAR >
137  void registerProjection(
138  const std::string& projection_name,
139  const std::string& type_multidim,
142  projection_name, type_multidim, function);
143  }
144 
145 } /* namespace gum */
146 
147 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static ProjectionRegister4MultiDim & Register()
a named constructor that constructs one and only one Register per data type
MultiDimImplementation< GUM_SCALAR > *(* ProjectionPtr)(const MultiDimImplementation< GUM_SCALAR > *, const Set< const DiscreteVariable * > &)
the type of functions used by the register
A container for registering projection functions on multiDimImplementations.
void erase(const std::string &projection_name, const std::string &type_multidim)
removes a given entry from the register
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool exists(const std::string &projection_name, const std::string &type_multidim) const
indicates whether a given entry exists in the register
ProjectionPtr 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
void registerProjection(const std::string &projection_name, const std::string &type_multidim, typename ProjectionRegister4MultiDim< GUM_SCALAR >::ProjectionPtr function)
A function to more easily register new projection functions in MultiDims.
void insert(const std::string &projection_name, const std::string &type_multidim, ProjectionPtr newFunction)
adds a new entry into the register
~ProjectionRegister4MultiDim()
Destructor.
ProjectionRegister4MultiDim()
Default constructor: creates an empty register.