aGrUM  0.14.2
scheduleSeparatorStoreMultiDim_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 <sstream>
30 
31 namespace gum {
32 
34  template < typename GUM_SCALAR >
36  const ScheduleMultiDim< GUM_SCALAR >& table,
37  ArcProperty< Set< const MultiDimImplementation< GUM_SCALAR >* > >&
38  separator_tables,
39  Arc separator) :
40  ScheduleOperation< GUM_SCALAR >(
41  ScheduleOperation< GUM_SCALAR >::Type::SEPARATOR_STORE_MULTIDIM),
42  __table(table), __tableSet(&separator_tables), __separator(separator),
43  __args(0) {
44  // for debugging purposes
45  GUM_CONSTRUCTOR(ScheduleSeparatorStoreMultiDim);
46  }
47 
49  template < typename GUM_SCALAR >
51  const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& from) :
52  ScheduleOperation< GUM_SCALAR >(from),
53  __table(from.__table), __tableSet(from.__tableSet),
54  __separator(from.__separator), __args(0) {
55  // for debugging purposes
56  GUM_CONS_CPY(ScheduleSeparatorStoreMultiDim);
57  }
58 
60  template < typename GUM_SCALAR >
61  ScheduleSeparatorStoreMultiDim< GUM_SCALAR >*
63  return new ScheduleSeparatorStoreMultiDim< GUM_SCALAR >(*this);
64  }
65 
67  template < typename GUM_SCALAR >
69  // for debugging purposes
70  GUM_DESTRUCTOR(ScheduleSeparatorStoreMultiDim);
71 
72  if (__args) delete __args;
73  }
74 
76  template < typename GUM_SCALAR >
77  ScheduleSeparatorStoreMultiDim< GUM_SCALAR >&
79  operator=(const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& from) {
80  // avoid self assignment
81  if (&from != this) {
83  __table = from.__table;
84  __tableSet = from.__tableSet;
85  __separator = from.__separator;
86 
87  if (__args) {
88  __args->clear();
89  __args->insert(&__table);
90  }
91  }
92 
93  return *this;
94  }
95 
97  template < typename GUM_SCALAR >
99  operator==(const ScheduleOperation< GUM_SCALAR >& op) const {
100  if (this->type() != op.type()) return false;
101 
102  const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& real_op =
103  static_cast< const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& >(op);
104  return ((__table == real_op.__table) && (__tableSet == real_op.__tableSet)
105  && (__separator == real_op.__separator));
106  }
107 
109  template < typename GUM_SCALAR >
111  operator!=(const ScheduleOperation< GUM_SCALAR >& op) const {
112  if (this->type() != op.type()) return true;
113 
114  const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& real_op =
115  static_cast< const ScheduleSeparatorStoreMultiDim< GUM_SCALAR >& >(op);
116  return ((__table != real_op.__table) || (__tableSet != real_op.__tableSet)
117  || (__separator != real_op.__separator));
118  }
119 
121  template < typename GUM_SCALAR >
123  const MultiDimImplementation< GUM_SCALAR >& multidim = __table.multiDim();
124 
125  if (!__tableSet->exists(__separator)) {
126  __tableSet->insert(__separator,
127  Set< const MultiDimImplementation< GUM_SCALAR >* >());
128  }
129 
130  __tableSet->operator[](__separator).insert(&multidim);
131  }
132 
135  template < typename GUM_SCALAR >
137  return 1.0f;
138  }
139 
141  template < typename GUM_SCALAR >
142  INLINE std::pair< long, long >
144  return std::pair< long, long >(0, 0);
145  }
146 
148  template < typename GUM_SCALAR >
149  INLINE const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
151  if (!__args) {
152  __args = new Sequence< const ScheduleMultiDim< GUM_SCALAR >* >;
153  __args->insert(&__table);
154  }
155 
156  return *__args;
157  }
158 
160  template < typename GUM_SCALAR >
161  INLINE const Sequence< const ScheduleMultiDim< GUM_SCALAR >* >&
163  static Sequence< const ScheduleMultiDim< GUM_SCALAR >* > empty_seq;
164 # ifdef GUM_DEBUG_MODE
165  // for debugging purposes, we should inform the aGrUM's debugger that
166  // the static sequence used here will be removed at the end of the
167  // program's execution.
168  static bool first_time = true;
169 
170  if (first_time) {
171  first_time = false;
172  __debug__::__inc_deletion(
173  "Sequence", __FILE__, __LINE__, "destructor of", (void*)&empty_seq);
174  __debug__::__inc_deletion("SequenceImplementation",
175  __FILE__,
176  __LINE__,
177  "destructor of",
178  (void*)&empty_seq);
179  }
180 
181 # endif /* [s] */
182  return empty_seq;
183  }
184 
186  template < typename GUM_SCALAR >
188  std::stringstream s;
189  s << "store ( " << __table.toString() << ", separator " << __separator << " )";
190  return s.str();
191  }
192 
193 } /* namespace gum */
194 
195 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual ScheduleSeparatorStoreMultiDim< GUM_SCALAR > * newFactory() const
virtual copy constructor: creates a clone of the operation
const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimResults() const
returns the set of multidims that should be the result of the operation
Type type() const
returns the name of the operation
ArcProperty< Set< const MultiDimImplementation< GUM_SCALAR > *> > * __tableSet
std::pair< long, long > memoryUsage() const
returns the memory consumption used during the operation
float nbOperations() const
returns an estimation of the number of elementary operations needed to perform the ScheduleOperation ...
virtual ~ScheduleSeparatorStoreMultiDim()
destructor
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool operator!=(const ScheduleOperation< GUM_SCALAR > &) const
operator !=
bool operator==(const ScheduleOperation< GUM_SCALAR > &) const
operator ==
const Sequence< const ScheduleMultiDim< GUM_SCALAR > *> & multiDimArgs() const
returns the set of multidims passed in argument to the operation
void execute()
executes the operation
ScheduleSeparatorStoreMultiDim< GUM_SCALAR > & operator=(const ScheduleSeparatorStoreMultiDim< GUM_SCALAR > &)
copy operator
std::string toString() const
displays the content of the operation
ScheduleOperation(Type t)
default constructor
ScheduleSeparatorStoreMultiDim(const ScheduleMultiDim< GUM_SCALAR > &table, ArcProperty< Set< const MultiDimImplementation< GUM_SCALAR > * > > &separator_tables, Arc separator)
default constructor
ScheduleOperation< GUM_SCALAR > & operator=(const ScheduleOperation< GUM_SCALAR > &)
copy operator
Sequence< const ScheduleMultiDim< GUM_SCALAR > *> * __args
the set of ScheduleMultidims passed in arguments
HashTable< Arc, VAL > ArcProperty
Property on graph elements.