49#ifndef DOXYGEN_SHOULD_SKIP_THIS
60 template <
typename TABLE >
62 if (_table_contained_ && (_table_ !=
nullptr))
delete _table_;
67 template <
typename TABLE >
72 _table_ =
new TABLE(table);
73 _table_contained_ =
true;
75 _table_ =
const_cast< TABLE*
>(&table);
76 _table_contained_ =
false;
80 _domain_size_ = _table_->domainSize();
83 GUM_CONSTRUCTOR(ScheduleMultiDim);
87 template <
typename TABLE >
88 ScheduleMultiDim< TABLE >::ScheduleMultiDim(TABLE&& table,
const Idx
id) : IScheduleMultiDim(id) {
90 _table_ =
new TABLE(std::move(table));
91 _var_sequence_ = _table_->variablesSequence();
92 _domain_size_ = _table_->domainSize();
95 GUM_CONSTRUCTOR(ScheduleMultiDim);
99 template <
typename TABLE >
100 ScheduleMultiDim< TABLE >::ScheduleMultiDim(
const Sequence< const DiscreteVariable* >& vars,
102 IScheduleMultiDim(id), _var_sequence_(vars) {
103 if (!_var_sequence_.empty()) {
105 _domain_size_ = Size(1);
106 for (const auto var: vars)
107 _domain_size_ *= var->domainSize();
111 GUM_CONSTRUCTOR(ScheduleMultiDim);
115 template <
typename TABLE >
116 ScheduleMultiDim< TABLE >::ScheduleMultiDim(
const ScheduleMultiDim< TABLE >& from) :
117 IScheduleMultiDim(from), _table_contained_(from._table_contained_),
118 _var_sequence_(from._var_sequence_), _domain_size_(from._domain_size_) {
119 if (from._table_ !=
nullptr) {
120 if (from._table_contained_) {
122 _table_ = new TABLE(*(from._table_));
124 _table_ = from._table_;
129 GUM_CONS_CPY(ScheduleMultiDim);
133 template <
typename TABLE >
134 ScheduleMultiDim< TABLE >::ScheduleMultiDim(ScheduleMultiDim< TABLE >&& from) :
135 IScheduleMultiDim(from), _table_contained_(from._table_contained_),
136 _var_sequence_(from._var_sequence_), _domain_size_(from._domain_size_) {
137 if (from._table_ !=
nullptr) {
138 _table_ = from._table_;
139 from._table_ = nullptr;
143 GUM_CONS_MOV(ScheduleMultiDim);
147 template <
typename TABLE >
148 INLINE ScheduleMultiDim< TABLE >* ScheduleMultiDim< TABLE >::clone()
const {
149 return new ScheduleMultiDim< TABLE >(*
this);
153 template <
typename TABLE >
154 ScheduleMultiDim< TABLE >* ScheduleMultiDim< TABLE >::clone(
bool force_copy)
const {
155 ScheduleMultiDim< TABLE >* new_sched;
157 if (!force_copy) new_sched =
new ScheduleMultiDim< TABLE >(*
this);
159 if (!isAbstract()) new_sched =
new ScheduleMultiDim< TABLE >(*_table_,
true, this->
id());
161 new_sched =
new ScheduleMultiDim< TABLE >(_var_sequence_, this->
id());
162 new_sched->_table_contained_ =
true;
170 template <
typename TABLE >
171 ScheduleMultiDim< TABLE >::~ScheduleMultiDim() {
175 GUM_DESTRUCTOR(ScheduleMultiDim);
179 template <
typename TABLE >
180 ScheduleMultiDim< TABLE >&
181 ScheduleMultiDim< TABLE >::operator=(
const ScheduleMultiDim< TABLE >& from) {
185 if (from._table_ !=
nullptr) {
186 if (from._table_contained_) {
189 TABLE* old_table = _table_;
190 if (!_table_contained_) _table_ =
nullptr;
192 if (_table_ ==
nullptr) {
194 _table_ =
new TABLE(*(from._table_));
202 *_table_ = *(from._table_);
204 _table_contained_ =
true;
207 _table_ = from._table_;
208 _table_contained_ =
false;
214 _table_contained_ = from._table_contained_;
217 _var_sequence_ = from._var_sequence_;
218 _domain_size_ = from._domain_size_;
219 IScheduleMultiDim::operator=(from);
226 template <
typename TABLE >
227 ScheduleMultiDim< TABLE >&
228 ScheduleMultiDim< TABLE >::operator=(ScheduleMultiDim< TABLE >&& from) {
233 _table_ = from._table_;
234 from._table_ =
nullptr;
235 _table_contained_ = from._table_contained_;
237 _var_sequence_ = from._var_sequence_;
238 _domain_size_ = from._domain_size_;
239 IScheduleMultiDim::operator=(std::move(from));
246 template <
typename TABLE >
247 INLINE
bool ScheduleMultiDim< TABLE >::operator==(
const ScheduleMultiDim< TABLE >& m)
const {
248 return IScheduleMultiDim::operator==(m);
252 template <
typename TABLE >
253 bool ScheduleMultiDim< TABLE >::operator==(
const IScheduleMultiDim& m)
const {
255 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
256 return ScheduleMultiDim< TABLE >::operator==(real_m);
257 }
catch (std::bad_cast&) {
return false; }
261 template <
typename TABLE >
262 INLINE
bool ScheduleMultiDim< TABLE >::operator!=(
const ScheduleMultiDim< TABLE >& m)
const {
263 return !ScheduleMultiDim< TABLE >::operator==(m);
267 template <
typename TABLE >
268 INLINE
bool ScheduleMultiDim< TABLE >::operator!=(
const IScheduleMultiDim& m)
const {
269 return !ScheduleMultiDim< TABLE >::operator==(m);
273 template <
typename TABLE >
275 ScheduleMultiDim< TABLE >::hasSameVariables(
const ScheduleMultiDim< TABLE >& m)
const {
276 return ((_domain_size_ == m._domain_size_) && (_var_sequence_ == m._var_sequence_));
280 template <
typename TABLE >
281 bool ScheduleMultiDim< TABLE >::hasSameVariables(
const IScheduleMultiDim& m)
const {
283 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
284 return ScheduleMultiDim< TABLE >::hasSameVariables(real_m);
285 }
catch (std::bad_cast&) {
return false; }
289 template <
typename TABLE >
290 bool ScheduleMultiDim< TABLE >::hasSameContent(
const ScheduleMultiDim< TABLE >& m)
const {
291 if (!hasSameVariables(m))
return false;
293 if (_table_ ==
nullptr)
return (m._table_ ==
nullptr);
295 if (m._table_ ==
nullptr)
return false;
296 else {
return (_table_ == m._table_) || (*_table_ == *(m._table_)); }
301 template <
typename TABLE >
302 bool ScheduleMultiDim< TABLE >::hasSameContent(
const IScheduleMultiDim& m)
const {
304 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
305 return ScheduleMultiDim< TABLE >::hasSameContent(real_m);
306 }
catch (std::bad_cast&) {
return false; }
311 template <
typename TABLE >
312 INLINE
const TABLE& ScheduleMultiDim< TABLE >::multiDim()
const {
313 if (_table_ ==
nullptr) {
315 "the ScheduleMultiDim is abstract, so its table " <<
"cannot be returned");
321 template <
typename TABLE >
322 INLINE
bool ScheduleMultiDim< TABLE >::isAbstract()
const {
323 return (_table_ ==
nullptr);
327 template <
typename TABLE >
328 INLINE
bool ScheduleMultiDim< TABLE >::containsMultiDim()
const {
329 return _table_contained_ && (_table_ !=
nullptr);
333 template <
typename TABLE >
334 INLINE
void ScheduleMultiDim< TABLE >::makeAbstract() {
339 template <
typename TABLE >
340 TABLE* ScheduleMultiDim< TABLE >::exportMultiDim() {
341 if (_table_ ==
nullptr) {
343 "The ScheduleMultiDim being abstract, " <<
"it is impossible to export its table");
345 if (!_table_contained_) {
347 "a ScheduleMultiDim cannot export a table it does not contain. "
348 "Use method multiDim() instead.");
351 auto table = _table_;
358 template <
typename TABLE >
359 INLINE
const Sequence< const DiscreteVariable* >&
360 ScheduleMultiDim< TABLE >::variablesSequence()
const {
361 return _var_sequence_;
365 template <
typename TABLE >
366 INLINE Size ScheduleMultiDim< TABLE >::domainSize()
const {
367 return _domain_size_;
371 template <
typename TABLE >
372 INLINE
double ScheduleMultiDim< TABLE >::sizeOfContent()
const {
373 return double(
sizeof(
typename ElementType< TABLE >::value_type));
377 template <
typename TABLE >
378 void ScheduleMultiDim< TABLE >::setMultiDim(
const TABLE& table,
const bool copy) {
382 TABLE* old_table = _table_;
383 if (!_table_contained_) _table_ =
nullptr;
385 if (_table_ ==
nullptr) {
387 _table_ =
new TABLE(table);
402 _table_contained_ =
true;
405 _table_ =
const_cast< TABLE*
>(&table);
406 _table_contained_ =
false;
409 _var_sequence_ = _table_->variablesSequence();
410 _domain_size_ = _table_->domainSize();
414 template <
typename TABLE >
415 void ScheduleMultiDim< TABLE >::setMultiDim(TABLE&& table) {
418 TABLE* old_table = _table_;
419 if (!_table_contained_) _table_ =
nullptr;
421 if (_table_ ==
nullptr) {
423 _table_ =
new TABLE(std::move(table));
432 *_table_ = std::move(table);
438 _table_contained_ =
true;
439 _var_sequence_ = _table_->variablesSequence();
440 _domain_size_ = _table_->domainSize();
444 template <
typename TABLE >
445 std::string ScheduleMultiDim< TABLE >::toString()
const {
446 std::stringstream str;
447 str <<
"<id: " << this->id() <<
", table: ";
448 if (_table_ ==
nullptr) str <<
"--";
449 else str << _table_->content();
The Table-agnostic base class of scheduleMultiDim.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const =0
returns the set of variables involved in the ScheduleMultiDim
Exception : a pointer or a reference on a nullptr (0) object.
Exception : operation not allowed.
ScheduleMultiDim(const TABLE &table, const bool copy, const Idx id=0)
constructs a ScheduleMultiDim by copying/referencing table
void _removeTable_()
remove the table if it is contained in the ScheduleMultiDim
#define GUM_ERROR(type, msg)
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities
a Wrapper for multi-dimensional tables used for scheduling inferences