51#ifndef DOXYGEN_SHOULD_SKIP_THIS
62 template <
typename TABLE >
64 if (_table_contained_ && (_table_ !=
nullptr))
delete _table_;
69 template <
typename TABLE >
74 _table_ =
new TABLE(table);
75 _table_contained_ =
true;
77 _table_ =
const_cast< TABLE*
>(&table);
78 _table_contained_ =
false;
82 _domain_size_ = _table_->domainSize();
85 GUM_CONSTRUCTOR(ScheduleMultiDim);
89 template <
typename TABLE >
90 ScheduleMultiDim< TABLE >::ScheduleMultiDim(TABLE&& table,
const Idx
id) : IScheduleMultiDim(id) {
92 _table_ =
new TABLE(std::move(table));
93 _var_sequence_ = _table_->variablesSequence();
94 _domain_size_ = _table_->domainSize();
97 GUM_CONSTRUCTOR(ScheduleMultiDim);
101 template <
typename TABLE >
102 ScheduleMultiDim< TABLE >::ScheduleMultiDim(
const Sequence< const DiscreteVariable* >& vars,
104 IScheduleMultiDim(id), _var_sequence_(vars) {
105 if (!_var_sequence_.empty()) {
107 _domain_size_ = Size(1);
108 for (const auto var: vars)
109 _domain_size_ *= var->domainSize();
113 GUM_CONSTRUCTOR(ScheduleMultiDim);
117 template <
typename TABLE >
118 ScheduleMultiDim< TABLE >::ScheduleMultiDim(
const ScheduleMultiDim< TABLE >& from) :
119 IScheduleMultiDim(from), _table_contained_(from._table_contained_),
120 _var_sequence_(from._var_sequence_), _domain_size_(from._domain_size_) {
121 if (from._table_ !=
nullptr) {
122 if (from._table_contained_) {
124 _table_ = new TABLE(*(from._table_));
126 _table_ = from._table_;
131 GUM_CONS_CPY(ScheduleMultiDim);
135 template <
typename TABLE >
136 ScheduleMultiDim< TABLE >::ScheduleMultiDim(ScheduleMultiDim< TABLE >&& from) :
137 IScheduleMultiDim(from), _table_contained_(from._table_contained_),
138 _var_sequence_(from._var_sequence_), _domain_size_(from._domain_size_) {
139 if (from._table_ !=
nullptr) {
140 _table_ = from._table_;
141 from._table_ = nullptr;
145 GUM_CONS_MOV(ScheduleMultiDim);
149 template <
typename TABLE >
150 ScheduleMultiDim< TABLE >* ScheduleMultiDim< TABLE >::clone()
const {
151 return new ScheduleMultiDim< TABLE >(*
this);
155 template <
typename TABLE >
156 ScheduleMultiDim< TABLE >* ScheduleMultiDim< TABLE >::clone(
bool force_copy)
const {
157 ScheduleMultiDim< TABLE >* new_sched;
159 if (!force_copy) new_sched =
new ScheduleMultiDim< TABLE >(*
this);
161 if (!isAbstract()) new_sched =
new ScheduleMultiDim< TABLE >(*_table_,
true, this->
id());
163 new_sched =
new ScheduleMultiDim< TABLE >(_var_sequence_, this->
id());
164 new_sched->_table_contained_ =
true;
172 template <
typename TABLE >
173 ScheduleMultiDim< TABLE >::~ScheduleMultiDim() {
177 GUM_DESTRUCTOR(ScheduleMultiDim);
181 template <
typename TABLE >
182 ScheduleMultiDim< TABLE >&
183 ScheduleMultiDim< TABLE >::operator=(
const ScheduleMultiDim< TABLE >& from) {
187 if (from._table_ !=
nullptr) {
188 if (from._table_contained_) {
191 TABLE* old_table = _table_;
192 if (!_table_contained_) _table_ =
nullptr;
194 if (_table_ ==
nullptr) {
196 _table_ =
new TABLE(*(from._table_));
204 *_table_ = *(from._table_);
206 _table_contained_ =
true;
209 _table_ = from._table_;
210 _table_contained_ =
false;
216 _table_contained_ = from._table_contained_;
219 _var_sequence_ = from._var_sequence_;
220 _domain_size_ = from._domain_size_;
221 IScheduleMultiDim::operator=(from);
228 template <
typename TABLE >
229 ScheduleMultiDim< TABLE >&
230 ScheduleMultiDim< TABLE >::operator=(ScheduleMultiDim< TABLE >&& from) {
235 _table_ = from._table_;
236 from._table_ =
nullptr;
237 _table_contained_ = from._table_contained_;
239 _var_sequence_ = from._var_sequence_;
240 _domain_size_ = from._domain_size_;
241 IScheduleMultiDim::operator=(std::move(from));
248 template <
typename TABLE >
249 bool ScheduleMultiDim< TABLE >::operator==(
const ScheduleMultiDim< TABLE >& m)
const {
250 return IScheduleMultiDim::operator==(m);
254 template <
typename TABLE >
255 bool ScheduleMultiDim< TABLE >::operator==(
const IScheduleMultiDim& m)
const {
257 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
258 return ScheduleMultiDim< TABLE >::operator==(real_m);
259 }
catch (std::bad_cast&) {
return false; }
263 template <
typename TABLE >
264 bool ScheduleMultiDim< TABLE >::operator!=(
const ScheduleMultiDim< TABLE >& m)
const {
265 return !ScheduleMultiDim< TABLE >::operator==(m);
269 template <
typename TABLE >
270 bool ScheduleMultiDim< TABLE >::operator!=(
const IScheduleMultiDim& m)
const {
271 return !ScheduleMultiDim< TABLE >::operator==(m);
275 template <
typename TABLE >
276 bool ScheduleMultiDim< TABLE >::hasSameVariables(
const ScheduleMultiDim< TABLE >& m)
const {
277 return ((_domain_size_ == m._domain_size_) && (_var_sequence_ == m._var_sequence_));
281 template <
typename TABLE >
282 bool ScheduleMultiDim< TABLE >::hasSameVariables(
const IScheduleMultiDim& m)
const {
284 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
285 return ScheduleMultiDim< TABLE >::hasSameVariables(real_m);
286 }
catch (std::bad_cast&) {
return false; }
290 template <
typename TABLE >
291 bool ScheduleMultiDim< TABLE >::hasSameContent(
const ScheduleMultiDim< TABLE >& m)
const {
292 if (!hasSameVariables(m))
return false;
294 if (_table_ ==
nullptr)
return (m._table_ ==
nullptr);
296 if (m._table_ ==
nullptr)
return false;
297 else {
return (_table_ == m._table_) || (*_table_ == *(m._table_)); }
302 template <
typename TABLE >
303 bool ScheduleMultiDim< TABLE >::hasSameContent(
const IScheduleMultiDim& m)
const {
305 const ScheduleMultiDim< TABLE >& real_m =
dynamic_cast< const ScheduleMultiDim< TABLE >&
>(m);
306 return ScheduleMultiDim< TABLE >::hasSameContent(real_m);
307 }
catch (std::bad_cast&) {
return false; }
312 template <
typename TABLE >
313 const TABLE& ScheduleMultiDim< TABLE >::multiDim()
const {
314 if (_table_ ==
nullptr) {
316 "the ScheduleMultiDim is abstract, so its table " <<
"cannot be returned");
322 template <
typename TABLE >
323 bool ScheduleMultiDim< TABLE >::isAbstract()
const {
324 return (_table_ ==
nullptr);
328 template <
typename TABLE >
329 bool ScheduleMultiDim< TABLE >::containsMultiDim()
const {
330 return _table_contained_ && (_table_ !=
nullptr);
334 template <
typename TABLE >
335 void ScheduleMultiDim< TABLE >::makeAbstract() {
340 template <
typename TABLE >
341 TABLE* ScheduleMultiDim< TABLE >::exportMultiDim() {
342 if (_table_ ==
nullptr) {
344 "The ScheduleMultiDim being abstract, " <<
"it is impossible to export its table");
346 if (!_table_contained_) {
348 "a ScheduleMultiDim cannot export a table it does not contain. "
349 "Use method multiDim() instead.");
352 auto table = _table_;
359 template <
typename TABLE >
360 const Sequence< const DiscreteVariable* >& ScheduleMultiDim< TABLE >::variablesSequence()
const {
361 return _var_sequence_;
365 template <
typename TABLE >
366 Size ScheduleMultiDim< TABLE >::domainSize()
const {
367 return _domain_size_;
371 template <
typename TABLE >
372 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