aGrUM  0.14.2
scheduleDeleteMultiDim_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  ***************************************************************************/
26 #ifndef DOXYGEN_SHOULD_SKIP_THIS
27 
28 # include <agrum/agrum.h>
29 # include <limits>
30 
31 // to ease ide parser
33 
34 namespace gum {
35 
37  template < typename GUM_SCALAR >
39  const ScheduleMultiDim< GUM_SCALAR >& table) :
40  ScheduleOperation< GUM_SCALAR >(
41  ScheduleOperation< GUM_SCALAR >::Type::DELETE_MULTIDIM),
42  __table(table), __args(0) {
43  // for debugging purposes
44  GUM_CONSTRUCTOR(ScheduleDeleteMultiDim);
45  }
46 
48  template < typename GUM_SCALAR >
50  const ScheduleDeleteMultiDim< GUM_SCALAR >& from) :
51  ScheduleOperation< GUM_SCALAR >(from),
52  __table(from.__table), __args(0) {
53  // for debugging purposes
54  GUM_CONS_CPY(ScheduleDeleteMultiDim);
55  }
56 
58  template < typename GUM_SCALAR >
59  ScheduleDeleteMultiDim< GUM_SCALAR >*
61  return new ScheduleDeleteMultiDim< GUM_SCALAR >(*this);
62  }
63 
65  template < typename GUM_SCALAR >
67  // for debugging purposes
68  GUM_DESTRUCTOR(ScheduleDeleteMultiDim);
69 
70  if (__args) delete __args;
71  }
72 
74  template < typename GUM_SCALAR >
75  ScheduleDeleteMultiDim< GUM_SCALAR >& ScheduleDeleteMultiDim< GUM_SCALAR >::
76  operator=(const ScheduleDeleteMultiDim< GUM_SCALAR >& from) {
77  // avoid self assignment
78  if (&from != this) {
80  __table = from.__table;
81 
82  if (__args) {
83  __args->clear();
84  __args->insert(&__table);
85  }
86  }
87 
88  return *this;
89  }
90 
92  template < typename GUM_SCALAR >
94  operator==(const ScheduleOperation< GUM_SCALAR >& op) const {
95  if (this->type() != op.type()) return false;
96 
97  const ScheduleDeleteMultiDim< GUM_SCALAR >& real_op =
98  static_cast< const ScheduleDeleteMultiDim< GUM_SCALAR >& >(op);
99  return __table == real_op.__table;
100  }
101 
103  template < typename GUM_SCALAR >
105  operator!=(const ScheduleOperation< GUM_SCALAR >& op) const {
106  if (this->type() != op.type()) return true;
107 
108  const ScheduleDeleteMultiDim< GUM_SCALAR >& real_op =
109  static_cast< const ScheduleDeleteMultiDim< GUM_SCALAR >& >(op);
110  return __table != real_op.__table;
111  }
112 
114  template < typename GUM_SCALAR >
116  const MultiDimImplementation< GUM_SCALAR >& multidim = __table.multiDim();
119  delete &multidim;
120  }
121 
124  template < typename GUM_SCALAR >
126  return 1.0f;
127  }
128 
130  template < typename GUM_SCALAR >
131  INLINE std::pair< long, long >
133  long size_table = long(__table.domainSize());
134 
135  if (size_table < 0) {
136  GUM_ERROR(OutOfBounds, "memory usage out of long int range");
137  }
138 
139  return std::pair< long, long >(-size_table, -size_table);
140  }
141 
143  template < typename GUM_SCALAR >
144  INLINE const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
146  if (!__args) {
147  __args = new Sequence< const ScheduleMultiDim< GUM_SCALAR >* >;
148  __args->insert(&__table);
149  }
150 
151  return *__args;
152  }
153 
155  template < typename GUM_SCALAR >
156  INLINE const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
158  static Sequence< const ScheduleMultiDim< GUM_SCALAR >* > empty_seq;
159 # ifdef GUM_DEBUG_MODE
160  // for debugging purposes, we should inform the aGrUM's debugger that
161  // the static sequence used here will be removed at the end of the
162  // program's execution.
163  static bool first_time = true;
164 
165  if (first_time) {
166  first_time = false;
167  __debug__::__inc_deletion(
168  "Sequence", __FILE__, __LINE__, "destructor of", (void*)&empty_seq);
169  __debug__::__inc_deletion("SequenceImplementation",
170  __FILE__,
171  __LINE__,
172  "destructor of",
173  (void*)&empty_seq);
174  __debug__::__inc_deletion(
175  "HashTable", __FILE__, __LINE__, "destructor of", (void*)&empty_seq);
176  __debug__::__inc_deletion("SequenceIteratorSafe",
177  __FILE__,
178  __LINE__,
179  "destructor of",
180  (void*)&empty_seq);
181  __debug__::__inc_deletion("SequenceIteratorSafe",
182  __FILE__,
183  __LINE__,
184  "destructor of",
185  (void*)&empty_seq);
186  }
187 
188 # endif /* GUM_DEBUG_MODE */
189  return empty_seq;
190  }
191 
193  template < typename GUM_SCALAR >
195  return "delete ( " + __table.toString() + " )";
196  }
197 
198 } // namespace gum
199 
200 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static HashTable< const MultiDimImplementation< GUM_SCALAR > *, Idx > & __multidim2id()
returns the id corresponding to a given multidim
std::string toString() const
displays the content of the operation
Type type() const
returns the name of the operation
const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimResults() const
returns the set of multidims that should be the result of the operation
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
std::pair< long, long > memoryUsage() const
returns the memory consumption used during the operation
virtual ~ScheduleDeleteMultiDim()
destructor
ScheduleDeleteMultiDim(const ScheduleMultiDim< GUM_SCALAR > &table)
default constructor
void execute()
executes the operation
ScheduleOperation(Type t)
default constructor
a MultiDim Delete operator class used for scheduling inferences
ScheduleMultiDim< GUM_SCALAR > __table
ScheduleOperation< GUM_SCALAR > & operator=(const ScheduleOperation< GUM_SCALAR > &)
copy operator
float nbOperations() const
returns an estimation of the number of elementary operations needed to perform the ScheduleOperation ...
ScheduleDeleteMultiDim< GUM_SCALAR > & operator=(const ScheduleDeleteMultiDim< GUM_SCALAR > &)
copy operator
static HashTable< Idx, const MultiDimImplementation< GUM_SCALAR > *> & __id2multidim()
returns a mapping from id to multidimImplementations
virtual ScheduleDeleteMultiDim< GUM_SCALAR > * newFactory() const
virtual copy constructor: creates a clone of the operation
const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimArgs() const
returns the set of multidims passed in argument to the operation
bool operator==(const ScheduleOperation< GUM_SCALAR > &) const
operator ==
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
bool operator!=(const ScheduleOperation< GUM_SCALAR > &) const
operator !=
Sequence< const ScheduleMultiDim< GUM_SCALAR > *> * __args
the set of ScheduleMultidims passed in arguments