49#ifndef DOXYGEN_SHOULD_SKIP_THIS
57 namespace ScheduleStorageMethod {
60 template <
typename TABLE >
61 INLINE
void Execution< TABLE, TABLE*, Set >::execute(TABLE& table, Set< TABLE* >& container) {
62 container.insert(&table);
66 template <
typename TABLE >
67 INLINE
void Execution< TABLE, TABLE, std::vector >::execute(TABLE& table,
68 std::vector< TABLE >& container) {
69 container.push_back(std::move(table));
75 template <
typename TABLE,
template <
typename... >
class CONTAINER >
77 CONTAINER< TABLE >& container) :
78 ScheduleOperator(ScheduleOperatorType::STORE_MULTIDIM, true, false), _container_(&container) {
84 _arg_ =
dynamic_cast< ScheduleMultiDim< SCHED_TABLE >*
>(
85 const_cast< IScheduleMultiDim*
>(&table));
86 }
catch (std::bad_cast&) {
88 "The ScheduleMultiDim cannot be stored in the container "
89 "because their types are incompatible.");
96 GUM_CONSTRUCTOR(ScheduleStorage);
100 template <
typename TABLE,
template <
typename... >
class CONTAINER >
102 const ScheduleStorage< TABLE, CONTAINER >& from) :
104 _is_executed_(from._is_executed_) {
109 GUM_CONS_CPY(ScheduleStorage);
113 template <
typename TABLE,
template <
typename... >
class CONTAINER >
115 ScheduleOperator(std::move(from)), _arg_(from._arg_), _container_(from._container_),
116 _is_executed_(from._is_executed_) {
121 GUM_CONS_MOV(ScheduleStorage);
125 template <
typename TABLE,
template <
typename... >
class CONTAINER >
131 template <
typename TABLE,
template <
typename... >
class CONTAINER >
134 GUM_DESTRUCTOR(ScheduleStorage);
138 template <
typename TABLE,
template <
typename... >
class CONTAINER >
145 _container_ = from._container_;
146 _is_executed_ = from._is_executed_;
153 template <
typename TABLE,
template <
typename... >
class CONTAINER >
160 _container_ = from._container_;
161 _is_executed_ = from._is_executed_;
168 template <
typename TABLE,
template <
typename... >
class CONTAINER >
170 const ScheduleStorage< TABLE, CONTAINER >& op) const {
171 return (_container_ == op._container_) && (*_arg_ == *op._arg_);
175 template <
typename TABLE,
template <
typename... >
class CONTAINER >
176 bool
ScheduleStorage< TABLE, CONTAINER >::operator==(const ScheduleOperator& op) const {
178 const ScheduleStorage< TABLE, CONTAINER >& real_op
179 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
180 return ScheduleStorage< TABLE, CONTAINER >::operator==(real_op);
181 }
catch (std::bad_cast&) {
return false; }
185 template <
typename TABLE,
template <
typename... >
class CONTAINER >
187 const ScheduleStorage< TABLE, CONTAINER >& op) const {
188 return !ScheduleStorage< TABLE, CONTAINER >::operator==(op);
192 template <
typename TABLE,
template <
typename... >
class CONTAINER >
193 INLINE bool
ScheduleStorage< TABLE, CONTAINER >::operator!=(const ScheduleOperator& op) const {
194 return !ScheduleStorage< TABLE, CONTAINER >::operator==(op);
198 template <
typename TABLE,
template <
typename... >
class CONTAINER >
200 const ScheduleStorage< TABLE, CONTAINER >& op) const {
201 return _arg_->hasSameVariables(*op._arg_);
205 template <
typename TABLE,
template <
typename... >
class CONTAINER >
206 bool
ScheduleStorage< TABLE, CONTAINER >::hasSimilarArguments(const ScheduleOperator& op) const {
208 const ScheduleStorage< TABLE, CONTAINER >& real_op
209 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
210 return ScheduleStorage< TABLE, CONTAINER >::hasSimilarArguments(real_op);
211 }
catch (std::bad_cast&) {
return false; }
215 template <
typename TABLE,
template <
typename... >
class CONTAINER >
217 const ScheduleStorage< TABLE, CONTAINER >& op) const {
218 return (_container_ == op._container_) && _arg_->hasSameVariables(*op._arg_)
219 && _arg_->hasSameContent(*op._arg_);
223 template <
typename TABLE,
template <
typename... >
class CONTAINER >
224 bool
ScheduleStorage< TABLE, CONTAINER >::hasSameArguments(const ScheduleOperator& op) const {
226 const ScheduleStorage< TABLE, CONTAINER >& real_op
227 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
228 return ScheduleStorage< TABLE, CONTAINER >::hasSameArguments(real_op);
229 }
catch (std::bad_cast&) {
return false; }
233 template <
typename TABLE,
template <
typename... >
class CONTAINER >
235 const ScheduleStorage< TABLE, CONTAINER >& op) const {
240 template <
typename TABLE,
template <
typename... >
class CONTAINER >
241 bool
ScheduleStorage< TABLE, CONTAINER >::isSameOperator(const ScheduleOperator& op) const {
243 const ScheduleStorage< TABLE, CONTAINER >& real_op
244 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
245 return ScheduleStorage< TABLE, CONTAINER >::isSameOperator(real_op);
246 }
catch (std::bad_cast&) {
return false; }
250 template <
typename TABLE,
template <
typename... >
class CONTAINER >
251 INLINE const
ScheduleMultiDim< typename std::remove_pointer< TABLE >::type >&
257 template <
typename TABLE,
template <
typename... >
class CONTAINER >
263 template <
typename TABLE,
template <
typename... >
class CONTAINER >
269 template <
typename TABLE,
template <
typename... >
class CONTAINER >
271 if (_arg_->isAbstract()) {
273 "It is impossible to store an abstract ScheduleMultiDim"
274 "into a container.");
281 if (std::is_same< SCHED_TABLE, TABLE >::value) {
283 if (_arg_->containsMultiDim()) {
286 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(
287 const_cast< SCHED_TABLE&
>(_arg_->multiDim()),
293 SCHED_TABLE table = _arg_->multiDim();
294 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(table,
304 if (_arg_->containsMultiDim()) {
305 table =
new SCHED_TABLE(std::move(
const_cast< SCHED_TABLE&
>(_arg_->multiDim())));
307 table =
new SCHED_TABLE(
const_cast< SCHED_TABLE&
>(_arg_->multiDim()));
310 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(*table,
315 _arg_->makeAbstract();
316 _is_executed_ =
true;
320 template <
typename TABLE,
template <
typename... >
class CONTAINER >
322 return _is_executed_;
326 template <
typename TABLE,
template <
typename... >
class CONTAINER >
328 GUM_ERROR(OperationNotAllowed,
"ScheduleStorage cannot be undone.");
332 template <
typename TABLE,
template <
typename... >
class CONTAINER >
334 const Sequence< const IScheduleMultiDim* >& new_args) {
337 if (new_args.size() !=
Size(1)) {
339 "Method ScheduleStorage::updateArgs expects 1 new "
340 <<
"argument, but " << new_args.size() <<
" were passed.");
342 ScheduleMultiDim< SCHED_TABLE >* arg;
344 arg =
dynamic_cast< ScheduleMultiDim< SCHED_TABLE >*
>(
345 const_cast< IScheduleMultiDim*
>(new_args[0]));
346 }
catch (std::bad_cast&) {
348 "The type of the argument passed to "
349 <<
"ScheduleStorage::updateArgs does not match what "
350 <<
"the ScheduleOperator expects");
354 _arg_ = (ScheduleMultiDim< SCHED_TABLE >*)arg;
357 _is_executed_ =
false;
362 template <
typename TABLE,
template <
typename... >
class CONTAINER >
363 INLINE double
ScheduleStorage< TABLE, CONTAINER >::nbOperations() const {
368 template <
typename TABLE,
template <
typename... >
class CONTAINER >
369 INLINE std::pair< double, double >
ScheduleStorage< TABLE, CONTAINER >::memoryUsage() const {
370 const double size_table = double(_arg_->domainSize()) * _arg_->sizeOfContent() +
sizeof(TABLE);
371 return {-size_table, -size_table};
375 template <
typename TABLE,
template <
typename... >
class CONTAINER >
377 return "store ( " + _arg_->
toString() +
" )";
The Table-agnostic base class of scheduleMultiDim.
a Wrapper for multi-dimensional tables used for scheduling inferences
the base class for "low-level" operators used to schedule inferences
ScheduleOperator & operator=(const ScheduleOperator &from)
copy operator
Class for storing multidimensional tables into containers (sets, etc.).
ScheduleStorage< TABLE, CONTAINER > * clone() const final
virtual copy constructor
std::string toString() const final
displays the content of the operator
const Sequence< const IScheduleMultiDim * > & args() const final
returns the sequence of arguments passed to the operator
ScheduleStorage< TABLE, CONTAINER > & operator=(const ScheduleStorage< TABLE, CONTAINER > &)
copy operator
const Sequence< const IScheduleMultiDim * > & results() const final
returns the sequence of ScheduleMultidim output by the operator
The generic class for storing (ordered) sequences of objects.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
Class for storing multidimensional tables in scheduling inferences.