aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::MultiDimDecorator< GUM_SCALAR > Class Template Referenceabstract

Decorator design pattern in order to separate implementations from multidimensional matrix concepts. More...

#include <agrum/tools/multidim/multiDimDecorator.h>

+ Inheritance diagram for gum::MultiDimDecorator< GUM_SCALAR >:
+ Collaboration diagram for gum::MultiDimDecorator< GUM_SCALAR >:

Public Member Functions

Constructors / Destructors
 MultiDimDecorator (MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
 Class constructor. More...
 
 MultiDimDecorator (const MultiDimDecorator< GUM_SCALAR > &from)
 copy constructor & assignment More...
 
MultiDimDecorator< GUM_SCALAR > & operator= (const MultiDimDecorator &from) noexcept
 copy operator More...
 
 MultiDimDecorator (MultiDimDecorator< GUM_SCALAR > &&) noexcept
 Class move constructor. More...
 
MultiDimDecorator< GUM_SCALAR > & operator= (MultiDimDecorator &&from)
 assignment operator. More...
 
 ~MultiDimDecorator ()
 Class destructor. More...
 
MultiDimInterface implementation
virtual Idx nbrDim () const final
 Returns the number of vars in the multidimensional container. More...
 
virtual Size domainSize () const final
 Returns the product of the variables domain size. More...
 
virtual void add (const DiscreteVariable &v) final
 Adds a new var to the variables of the multidimensional matrix. More...
 
virtual void erase (const DiscreteVariable &var) final
 Removes a var from the variables of the multidimensional matrix. More...
 
virtual void erase (const std::string &name) final
 
virtual const Sequence< const DiscreteVariable *> & variablesSequence () const final
 Returns a const ref to the sequence of DiscreteVariable*. More...
 
virtual const DiscreteVariablevariable (Idx) const final
 Returns a const ref to the ith var. More...
 
virtual const DiscreteVariablevariable (const std::string &name) const final
 Returns the variable with the name. More...
 
virtual Idx pos (const DiscreteVariable &var) const final
 Returns the index of a variable. More...
 
virtual bool contains (const DiscreteVariable &var) const final
 Returns true if var is in *this. More...
 
virtual bool empty () const final
 Returns true if no var is in *this. More...
 
MultiDimAddressable implementation
virtual bool unregisterSlave (Instantiation &i) final
 Unregister i as a slave of this MultiDimAdressable. More...
 
virtual bool registerSlave (Instantiation &i) final
 Register i as a slave of this MultiDimAdressable. More...
 
virtual void changeNotification (const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) final
 Listen to changes in a given Instantiation. More...
 
virtual void setChangeNotification (const Instantiation &i) final
 Listen to an assignment of a value in a Instantiation. More...
 
virtual void setFirstNotification (const Instantiation &i) final
 Listen to setFirst in a given Instantiation. More...
 
virtual void setLastNotification (const Instantiation &i) final
 Listen to setLast in a given Instantiation. More...
 
virtual void setIncNotification (const Instantiation &i) final
 Listen to increment in a given Instantiation. More...
 
virtual void setDecNotification (const Instantiation &i) final
 Listen to increment in each recorded Instantiation. More...
 
virtual void notifyChange () const final
 
MultiDimContainer implementation
virtual void set (const Instantiation &i, const GUM_SCALAR &value) const final
 Default implementation of MultiDimContainer::set(). More...
 
virtual GUM_SCALAR get (const Instantiation &i) const final
 Default implementation of MultiDimContainer::get(). More...
 
virtual void fill (const GUM_SCALAR &d) const final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void populate (const std::vector< GUM_SCALAR > &v) const final
 Automatically fills this MultiDimContainer with the values in v. More...
 
virtual void apply (std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
 Apply a function on every element of the container. More...
 
virtual GUM_SCALAR reduce (std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
 compute lfold for this container More...
 
virtual MultiDimDecorator< GUM_SCALAR > * newFactory () const =0
 Default implementation of MultiDimContainer::set(). More...
 
virtual void beginMultipleChanges () final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void endMultipleChanges () final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void endMultipleChanges (const GUM_SCALAR &) final
 Default implementation of MultiDimContainer::set(). More...
 
virtual std::string toString (const Instantiation *i) const
 Default implementation of MultiDimContainer::set(). More...
 
virtual std::string toString () const
 Default implementation of MultiDimContainer::set(). More...
 
Various methods.
virtual const MultiDimImplementation< GUM_SCALAR > * content () const final
 Returns the implementation for this object (may be *this). More...
 
virtual MultiDimImplementation< GUM_SCALAR > * content () final
 Returns the implementation for this object (may be *this). More...
 
Accessors / Modifiers
GUM_SCALAR operator[] (const Instantiation &i) const
 An [] operator using a Instantiation as argument. More...
 
virtual void populate (std::initializer_list< GUM_SCALAR > l) const
 Automatically fills this MultiDimContainer with the values in l. More...
 
Copy methods.
virtual void copyFrom (const MultiDimContainer< GUM_SCALAR > &src) const
 Basic copy of a MultiDimContainer. More...
 
virtual void copyFrom (const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i) const
 Basic copy of a MultiDimContainer. More...
 
virtual void extractFrom (const MultiDimContainer< GUM_SCALAR > &src, const Instantiation &mask)
 Basic extraction of a MultiDimContainer. More...
 
virtual MultiDimAdressablegetMasterRef ()
 In order to insure the dereference for decorators, we need to virtualize the access to master pointer. More...
 
virtual const MultiDimAdressablegetMasterRef () const
 In order to insure the dereference for decorators, we need to virtualize the access to master pointer. More...
 
virtual void copy (const MultiDimContainer< GUM_SCALAR > &src)
 Removes all variables in this MultiDimContainer and copy the content of src, variables included. More...
 
Various methods.
bool operator== (const MultiDimContainer< GUM_SCALAR > &p) const
 Test if this MultiDimContainer is equal to p. More...
 
bool operator!= (const MultiDimContainer< GUM_SCALAR > &p) const
 Test if this MultiDimContainer is different of p. More...
 
Accessors / Modifiers
void replace (const DiscreteVariable &x, const DiscreteVariable &y)
 Replace variables in this multidim. More...
 

Protected Attributes

MultiDimImplementation< GUM_SCALAR > * content_
 The true container. More...
 
GUM_SCALAR empty_value_
 value of the MultiDimDecorator if no dimension. More...
 

Protected Member Functions

virtual void replace_ (const DiscreteVariable *x, const DiscreteVariable *y)
 This is called by MultiDimContainer::replace() to proceed with the replacing between x and y. More...
 
void swapContent_ (MultiDimImplementation< GUM_SCALAR > *aContent) const
 protecte method to swap the implementation behind the Potential More...
 
GUM_SCALAR & get_ (const Instantiation &i) const final
 Return a data, given a Insantiation - final method. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::MultiDimDecorator< GUM_SCALAR >

Decorator design pattern in order to separate implementations from multidimensional matrix concepts.

A MultiDimDecorator is a virtual class for all encapsulation of MultiDimImplementation, for example probability, utility, etc. It implements a decorator design pattern in order to have a array, tree, sparse or matrix (...) implementation of MultiDimImplementation.

Template Parameters
GUM_SCALARThe type of the scalar stored in this multidimensional matrix.

Definition at line 58 of file multiDimDecorator.h.

Constructor & Destructor Documentation

◆ MultiDimDecorator() [1/3]

template<typename GUM_SCALAR >
INLINE gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator ( MultiDimImplementation< GUM_SCALAR > *  aContent = nullptr,
GUM_SCALAR  empty_value = (GUM_SCALAR)0 
)

Class constructor.

Parameters
aContentThe implementation used by this MultiDimDecorator.

Definition at line 66 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

68  :
69  content_(aContent),
70  empty_value_(empty_value) {
71  _initPotentialOperators__< GUM_SCALAR >();
72  GUM_CONSTRUCTOR(MultiDimDecorator);
73  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ MultiDimDecorator() [2/3]

template<typename GUM_SCALAR >
INLINE gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator ( const MultiDimDecorator< GUM_SCALAR > &  from)

copy constructor & assignment

Definition at line 76 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

77  :
78  MultiDimContainer< GUM_SCALAR >(from) {
79  GUM_CONS_CPY(MultiDimDecorator);
80  _initPotentialOperators__< GUM_SCALAR >();
81  empty_value_ = from.empty_value_;
82  content()->copy(from.content());
83  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ MultiDimDecorator() [3/3]

template<typename GUM_SCALAR >
INLINE gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator ( MultiDimDecorator< GUM_SCALAR > &&  from)
noexcept

Class move constructor.

Definition at line 105 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

106  :
107  MultiDimContainer< GUM_SCALAR >(std::forward< MultiDimContainer< GUM_SCALAR > >(from)) {
108  GUM_CONS_MOV(MultiDimDecorator);
109 
110  empty_value_ = from.empty_value_;
111  content_ = from.content_;
112  from.content_ = nullptr;
113  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ ~MultiDimDecorator()

template<typename GUM_SCALAR >
INLINE gum::MultiDimDecorator< GUM_SCALAR >::~MultiDimDecorator ( )

Class destructor.

Definition at line 133 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

133  {
134  if (content_ != nullptr) { delete (content_); }
135 
136  GUM_DESTRUCTOR(MultiDimDecorator);
137  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ add()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::add ( const DiscreteVariable v)
finalvirtual

Adds a new var to the variables of the multidimensional matrix.

See also
operator<<(MultiDimInterface& c, const DiscreteVariable& v)
Warning
Note that the variable passed in argument is not duplicated, that is, only a pointer toward the variable is kept by the MultiDimInterface.
Parameters
vThe new var.
Exceptions
DuplicateElementRaised if the variable already belongs to the sequence of variables.
OperationNotAllowedRaised if this object is non mutable.

Implements gum::MultiDimInterface.

Definition at line 175 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

175  {
176  if (v.domainSize() < 1) {
177  GUM_ERROR(InvalidArgument, "Empty variable " << v << " cannot be added in a Potential")
178  }
179  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->add(v);
180  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ apply()

template<typename GUM_SCALAR >
void gum::MultiDimDecorator< GUM_SCALAR >::apply ( std::function< GUM_SCALAR(GUM_SCALAR) >  f) const
finalvirtual

Apply a function on every element of the container.

Parameters
fthe function to apply

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 325 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

325  {
326  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
328  } else {
329  content_->apply(f);
330  }
331  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ beginMultipleChanges()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges ( )
finalvirtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 358 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

358  {
359  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->beginMultipleChanges();
360  }
virtual void beginMultipleChanges() final
Default implementation of MultiDimContainer::set().
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ changeNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::changeNotification ( const Instantiation i,
const DiscreteVariable *const  var,
Idx  oldval,
Idx  newval 
)
finalvirtual

Listen to changes in a given Instantiation.

Parameters
iThe Instantiation to listen.
varThe changed dim.
oldvalThe old value.
newvalThe changed value.

Implements gum::MultiDimAdressable.

Definition at line 185 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

188  {
189  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->changeNotification(i,
190  var,
191  oldval,
192  newval);
193  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) final
Listen to changes in a given Instantiation.
+ Here is the call graph for this function:

◆ contains()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::contains ( const DiscreteVariable v) const
finalvirtual

Returns true if var is in *this.

Parameters
vA DiscreteVariable.
Returns
Returns true if var is in *this.

Implements gum::MultiDimInterface.

Definition at line 264 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

264  {
265  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->contains(var);
266  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
+ Here is the call graph for this function:

◆ content() [1/2]

template<typename GUM_SCALAR >
INLINE const MultiDimImplementation< GUM_SCALAR > * gum::MultiDimDecorator< GUM_SCALAR >::content ( ) const
finalvirtual

Returns the implementation for this object (may be *this).

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 353 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

353  {
354  return content_;
355  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ content() [2/2]

template<typename GUM_SCALAR >
INLINE MultiDimImplementation< GUM_SCALAR > * gum::MultiDimDecorator< GUM_SCALAR >::content ( )
finalvirtual

Returns the implementation for this object (may be *this).

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 346 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

346  {
347  return content_;
348  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ copy()

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copy ( const MultiDimContainer< GUM_SCALAR > &  src)
virtualinherited

Removes all variables in this MultiDimContainer and copy the content of src, variables included.

Parameters
srcThe MultiDimContainer to copy.

Reimplemented in gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 272 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

272  {
273  this->beginMultipleChanges();
274 
275  Size nbr = this->nbrDim();
276 
277  for (Idx i = 0; i < nbr; i++) {
278  this->erase(this->variable(0));
279  }
280 
281  for (Idx i = 0; i < src.nbrDim(); i++) {
282  this->add(src.variable(i));
283  }
284 
285  this->endMultipleChanges();
286  this->copyFrom(src);
287  }
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
virtual void add(const DiscreteVariable &v)=0
Adds a new var to the variables of the multidimensional matrix.
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx i) const =0
Returns a const ref to the ith var.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Basic copy of a MultiDimContainer.
virtual void erase(const DiscreteVariable &v)=0
Removes a var from the variables of the multidimensional matrix.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ copyFrom() [1/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copyFrom ( const MultiDimContainer< GUM_SCALAR > &  src) const
virtualinherited

Basic copy of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which values are copied. This is a full copy with no verification of dimensions.
Exceptions
OperationNotAllowedRaised if src does not have the same domain size than this MultiDimContainer.

Reimplemented in gum::aggregator::MultiDimAggregator< GUM_SCALAR >, gum::MultiDimICIModel< GUM_SCALAR >, and gum::MultiDimArray< GUM_SCALAR >.

Definition at line 255 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

255  {
256  if (src.domainSize() != domainSize()) {
257  GUM_ERROR(OperationNotAllowed,
258  "Domain sizes do not fit : " << src.domainSize() << "!=" << domainSize());
259  }
260 
261  Instantiation i_dest(*this);
262  Instantiation i_src(src);
263 
264  for (i_dest.setFirst(), i_src.setFirst(); !i_dest.end(); ++i_dest, ++i_src) {
265  set(i_dest, src[i_src]);
266  }
267  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ copyFrom() [2/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copyFrom ( const MultiDimContainer< GUM_SCALAR > &  src,
Instantiation p_i 
) const
virtualinherited

Basic copy of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which values are copied.
p_iGive the order to iterate in this MultiDimContainer during the copy (nullptr will correctly copy if this is a reorganization of src).
Exceptions
OperationNotAllowedRaised if src does not have the same domain size than this MultiDimContainer.

Reimplemented in gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 209 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

210  {
211  if (src.domainSize() != domainSize()) {
212  GUM_ERROR(OperationNotAllowed,
213  "Domain sizes do not fit : " << src.domainSize() << "!=" << domainSize());
214  }
215 
216  if (p_i == nullptr) { // if null, we just follow the same order
217  Instantiation i(src);
218  for (i.setFirst(); !i.end(); ++i) {
219  set(i, src[i]);
220  }
221  } else {
222  Instantiation i_dest(*this);
223  Instantiation i_src(src);
224  for (i_dest.setFirst(), i_src.setFirst(); !i_dest.end(); i_dest.incIn(*p_i), ++i_src) {
225  set(i_dest, src[i_src]);
226  }
227  }
228  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ domainSize()

template<typename GUM_SCALAR >
INLINE Size gum::MultiDimDecorator< GUM_SCALAR >::domainSize ( ) const
finalvirtual

Returns the product of the variables domain size.

Returns
Returns the product of the variables domain size.

Implements gum::MultiDimInterface.

Definition at line 168 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

168  {
169  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->domainSize();
170  }
virtual Size domainSize() const final
Returns the product of the variables domain size.
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ empty()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::empty ( ) const
finalvirtual

Returns true if no var is in *this.

Returns
Returns true if no var is in *this.

Implements gum::MultiDimInterface.

Definition at line 269 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

269  {
270  if (content_ == nullptr) return true;
271  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty();
272  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:

◆ endMultipleChanges() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges ( )
finalvirtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 363 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

363  {
364  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->endMultipleChanges();
365  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:

◆ endMultipleChanges() [2/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges ( const GUM_SCALAR &  x)
finalvirtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 368 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

368  {
369  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->endMultipleChanges(x);
370  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:

◆ erase() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::erase ( const DiscreteVariable v)
finalvirtual

Removes a var from the variables of the multidimensional matrix.

See also
operator>>(MultiDimInterface& c, const DiscreteVariable& v)
Exceptions
OperationNotAllowedRaised if this object is non mutable.
NotFoundRaised if v does not belong to this.

Implements gum::MultiDimInterface.

Definition at line 238 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

238  {
239  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->erase(var);
240  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void erase(const DiscreteVariable &var) final
Removes a var from the variables of the multidimensional matrix.
+ Here is the call graph for this function:

◆ erase() [2/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::erase ( const std::string &  name)
finalvirtual

Definition at line 243 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

243  {
244  erase(variable(name));
245  }
virtual void erase(const DiscreteVariable &var) final
Removes a var from the variables of the multidimensional matrix.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
+ Here is the call graph for this function:

◆ extractFrom()

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::extractFrom ( const MultiDimContainer< GUM_SCALAR > &  src,
const Instantiation mask 
)
virtualinherited

Basic extraction of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which datas are copied.
maskpartial instantiation of variables of the Potential : the

extraction will concern every variable not in the instantiation and the copy of data will use the (relevant) values in this instantiation.

Definition at line 231 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

232  {
233  this->beginMultipleChanges();
234 
235  Size nbr = this->nbrDim();
236  for (Idx i = 0; i < nbr; i++) {
237  this->erase(this->variable(0));
238  }
239 
240  for (Idx i = 0; i < src.nbrDim(); i++) {
241  if (!imask.contains(src.variable(i))) this->add(src.variable(i));
242  }
243 
244  this->endMultipleChanges();
245 
246  if (this->nbrDim() == 0) { GUM_ERROR(FatalError, "Empty potential") }
247 
248  Instantiation inst(src);
249  inst.setVals(imask);
250  for (inst.setFirstOut(imask); !inst.end(); inst.incOut(imask))
251  set(inst, src[inst]);
252  }
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
virtual void add(const DiscreteVariable &v)=0
Adds a new var to the variables of the multidimensional matrix.
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx i) const =0
Returns a const ref to the ith var.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual void erase(const DiscreteVariable &v)=0
Removes a var from the variables of the multidimensional matrix.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ fill()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::fill ( const GUM_SCALAR &  d) const
finalvirtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 280 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

280  {
281  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
282  empty_value_ = d;
283  } else {
284  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->fill(d);
285  }
286  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
virtual void fill(const GUM_SCALAR &d) const final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:

◆ get()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::get ( const Instantiation i) const
finalvirtual

Default implementation of MultiDimContainer::get().

Calls get_ as a l-value.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 147 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

147  {
148  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
149  return empty_value_;
150  } else {
151  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->get(i);
152  }
153  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ get_()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR & gum::MultiDimDecorator< GUM_SCALAR >::get_ ( const Instantiation i) const
finalprotectedvirtual

Return a data, given a Insantiation - final method.

Parameters
iThe instantiation.
Exceptions
NullElement
NotFound

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 142 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

142  {
143  GUM_ERROR(OperationNotAllowed, "_get in the implementation !")
144  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ getMasterRef() [1/2]

template<typename GUM_SCALAR >
INLINE MultiDimAdressable & gum::MultiDimContainer< GUM_SCALAR >::getMasterRef ( )
virtualinherited

In order to insure the dereference for decorators, we need to virtualize the access to master pointer.

Returns
Returns the ref to content as MultiDimAdressable&

Implements gum::MultiDimAdressable.

Reimplemented in gum::MultiDimBucket< GUM_SCALAR >.

Definition at line 290 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

290  {
291  return static_cast< MultiDimAdressable& >(*content());
292  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimAdressable()
Default constructor.
+ Here is the call graph for this function:

◆ getMasterRef() [2/2]

template<typename GUM_SCALAR >
INLINE const MultiDimAdressable & gum::MultiDimContainer< GUM_SCALAR >::getMasterRef ( ) const
virtualinherited

In order to insure the dereference for decorators, we need to virtualize the access to master pointer.

Returns
Returns the master of this MultiDimAdressable.

Implements gum::MultiDimAdressable.

Reimplemented in gum::MultiDimBucket< GUM_SCALAR >.

Definition at line 295 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

295  {
296  return static_cast< const MultiDimAdressable& >(*content());
297  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimAdressable()
Default constructor.
+ Here is the call graph for this function:

◆ nbrDim()

template<typename GUM_SCALAR >
INLINE Idx gum::MultiDimDecorator< GUM_SCALAR >::nbrDim ( ) const
finalvirtual

Returns the number of vars in the multidimensional container.

Returns
Returns the number of vars in the multidimensional container.

Implements gum::MultiDimInterface.

Definition at line 307 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

307  {
308  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->nbrDim();
309  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ newFactory()

template<typename GUM_SCALAR >
virtual MultiDimDecorator< GUM_SCALAR >* gum::MultiDimDecorator< GUM_SCALAR >::newFactory ( ) const
pure virtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Implemented in gum::Potential< GUM_SCALAR >.

◆ notifyChange()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::notifyChange ( ) const
finalvirtual

Definition at line 291 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

291  {
292  /*( (MultiDimContainer<GUM_SCALAR> *) content_)->notifyChange();*/
293  GUM_ERROR(OperationNotAllowed, "Not implemented yet")
294  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ operator!=()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimContainer< GUM_SCALAR >::operator!= ( const MultiDimContainer< GUM_SCALAR > &  p) const
inherited

Test if this MultiDimContainer is different of p.

Parameters
pThe MultiDimContainer to test for inequality.
Returns
Returns true if this MultiDimContainer is different of p.

Definition at line 154 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

154  {
155  return !operator==(p);
156  }
bool operator==(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is equal to p.
+ Here is the call graph for this function:

◆ operator=() [1/2]

template<typename GUM_SCALAR >
INLINE MultiDimDecorator< GUM_SCALAR > & gum::MultiDimDecorator< GUM_SCALAR >::operator= ( const MultiDimDecorator< GUM_SCALAR > &  from)
noexcept

copy operator

Definition at line 117 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

118  {
119  GUM_OP_CPY(MultiDimDecorator);
120  _initPotentialOperators__< GUM_SCALAR >();
122  empty_value_ = from.empty_value_;
123  if (content_ == nullptr)
124  content_ = static_cast< MultiDimImplementation< GUM_SCALAR >* >(from.content()->newFactory());
125  MultiDimDecorator< GUM_SCALAR >::content()->copy(*from.content());
126  return *this;
127  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
MultiDimContainer & operator=(const MultiDimContainer< GUM_SCALAR > &src)
Default constructor.
+ Here is the call graph for this function:

◆ operator=() [2/2]

template<typename GUM_SCALAR >
INLINE MultiDimDecorator< GUM_SCALAR > & gum::MultiDimDecorator< GUM_SCALAR >::operator= ( MultiDimDecorator< GUM_SCALAR > &&  from)

assignment operator.

Definition at line 88 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

88  {
90  std::forward< MultiDimContainer< GUM_SCALAR > >(from));
91  GUM_OP_MOV(MultiDimDecorator);
92 
93  if (this != &from) {
94  if (content_ != nullptr) delete (content_); // should be the case
95  empty_value_ = from.empty_value_;
96  content_ = from.content_;
97  from.content_ = nullptr;
98  }
99 
100  return *this;
101  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
MultiDimContainer & operator=(const MultiDimContainer< GUM_SCALAR > &src)
Default constructor.
+ Here is the call graph for this function:

◆ operator==()

template<typename GUM_SCALAR >
bool gum::MultiDimContainer< GUM_SCALAR >::operator== ( const MultiDimContainer< GUM_SCALAR > &  p) const
inherited

Test if this MultiDimContainer is equal to p.

Parameters
pThe MultiDimContainer to test for equality.
Returns
Returns true if this MultiDimContainer is equal to p.

Definition at line 124 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

124  {
125  if ((nbrDim() == p.nbrDim()) && (domainSize() == p.domainSize())) {
126  if (nbrDim() == 0) return true;
127 
129 
130  for (var_iterator iter = variablesSequence().beginSafe();
131  iter != variablesSequence().endSafe();
132  ++iter) {
133  if (!p.variablesSequence().exists(*iter)) { return false; }
134  }
135  } else {
136  return false;
137  }
138 
139  Instantiation i(*this);
140 
141  AlmostDifferent< GUM_SCALAR > cmp;
142 
143  for (i.setFirst(); !i.end(); ++i) {
144  if (cmp(get(i), p.get(i))) { return false; }
145  }
146 
147  return true;
148  }
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual Size domainSize() const =0
Returns the product of the variables domain size.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
SequenceIteratorSafe< Key > const_iterator_safe
Types for STL compliance.
Definition: sequence.h:1032
+ Here is the call graph for this function:

◆ operator[]()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MultiDimContainer< GUM_SCALAR >::operator[] ( const Instantiation i) const
inherited

An [] operator using a Instantiation as argument.

Warning
If i variables set is disjoint with this MultiDimContainer then 0 is assumed for dimensions (i.e. variables) not prensent in the instantiation.
Parameters
iAn Instantiation.
Returns
Returns the adressed (GUM_SCALAR) value.

Definition at line 79 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

79  {
80  return get(i);
81  }
+ Here is the call graph for this function:

◆ populate() [1/2]

template<typename GUM_SCALAR >
void gum::MultiDimDecorator< GUM_SCALAR >::populate ( const std::vector< GUM_SCALAR > &  v) const
finalvirtual

Automatically fills this MultiDimContainer with the values in v.

The order used to fill this MultiDimContainer is the same as with an instantiation over it.

Size cpt = 0;
Instantiation i( *this );
for (i.setFirst(); !i.end(); ++i, ++cpt) {
set(i, v[cpt]);
}
Parameters
vVector of values.
Exceptions
SizeErrorRaised if v size's does not matches this MultiDimContainer domain size.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 312 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

312  {
313  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
314  if (v.size() == 1) {
315  empty_value_ = v[0];
316  } else {
317  GUM_ERROR(SizeError, "Size do not match in populate")
318  }
319  } else {
320  content_->populate(v);
321  }
322  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ populate() [2/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::populate ( std::initializer_list< GUM_SCALAR >  l) const
virtualinherited

Automatically fills this MultiDimContainer with the values in l.

The order used to fill this MultiDimContainer is the same as with an instantiation over it.

Size cpt = 0;
Instantiation i( *this );
for (i.setFirst(); !i.end(); ++i, ++cpt) {
set(i, v[cpt]);
}
Parameters
lcontains the data.
Exceptions
SizeErrorRaised if l size's does not matches this MultiDimContainer domain size.

Reimplemented in gum::MultiDimBijArray< GUM_SCALAR >, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 174 of file multiDimContainer_tpl.h.

References gum::Set< Key, Alloc >::emplace().

174  {
175  if (domainSize() != l.size()) {
176  GUM_ERROR(SizeError, "Sizes do not match : " << domainSize() << "!=" << l.size())
177  }
178 
179  Instantiation i(*this);
180  // insert all the elements
181  for (const auto& elt: l) {
182  set(i, elt);
183  ++i;
184  }
185  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ pos()

template<typename GUM_SCALAR >
INLINE Idx gum::MultiDimDecorator< GUM_SCALAR >::pos ( const DiscreteVariable v) const
finalvirtual

Returns the index of a variable.

Parameters
vThe variable for which the index is returned.
Returns
Returns the index of a variable.
Exceptions
NotFoundRaised if v is not in this multidimensional matrix.

Implements gum::MultiDimInterface.

Definition at line 259 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

259  {
260  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->pos(var);
261  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual Idx pos(const DiscreteVariable &var) const final
Returns the index of a variable.
+ Here is the call graph for this function:

◆ reduce()

template<typename GUM_SCALAR >
GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::reduce ( std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) >  f,
GUM_SCALAR  base 
) const
finalvirtual

compute lfold for this container

Parameters
fthe function to apply
basethe initial value

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 335 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

336  {
337  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
338  return base;
339  } else {
340  return content_->reduce(f, base);
341  }
342  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:

◆ registerSlave()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::registerSlave ( Instantiation i)
finalvirtual

Register i as a slave of this MultiDimAdressable.

Parameters
iThe Instantiation to enslave.
Returns
Returns true if i becomes a slave of this MultiDimAdressable.

Implements gum::MultiDimAdressable.

Definition at line 233 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

233  {
234  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->registerSlave(i);
235  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool registerSlave(Instantiation &i) final
Register i as a slave of this MultiDimAdressable.
+ Here is the call graph for this function:

◆ replace()

INLINE void gum::MultiDimInterface::replace ( const DiscreteVariable x,
const DiscreteVariable y 
)
inherited

Replace variables in this multidim.

If x is in this MultiDim and y has the same domain size, then x will be replace by y in this MultiDim.

Parameters
xThe variable in this which will be replaced.
yThe variable replacing y.
Exceptions
NotFoundRaised if x does not belong to this MultiDim.
OperationNotAllowedIf y and x are not interchangeable.
DuplicateElementIf y is already in this MultiDim.

Definition at line 35 of file multiDimInterface_inl.h.

References gum::Set< Key, Alloc >::emplace().

35  {
36  if (!contains(x)) { GUM_ERROR(NotFound, "could not find the variable") }
37 
38  if (contains(y)) { GUM_ERROR(DuplicateElement, "variable " << y << " already in MultiDim") }
39 
40  if (x.domainSize() != y.domainSize()) {
41  GUM_ERROR(OperationNotAllowed, "incompatible variables")
42  }
43 
44  replace_(&x, &y);
45  }
virtual bool contains(const DiscreteVariable &v) const =0
Returns true if var is in *this.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)=0
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ replace_()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::replace_ ( const DiscreteVariable x,
const DiscreteVariable y 
)
protectedvirtual

This is called by MultiDimContainer::replace() to proceed with the replacing between x and y.

This is called only when everything have been checked.

Parameters
xThe variable to replace in
yThe second variable to swap.

Implements gum::MultiDimInterface.

Definition at line 394 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

395  {
396  this->content()->replace(*x, *y);
397  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ set()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::set ( const Instantiation i,
const GUM_SCALAR &  value 
) const
finalvirtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 156 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

157  {
158  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->nbrDim() == 0) {
159  empty_value_ = value;
160  } else {
161  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->set(i, value);
162  }
163  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ setChangeNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setChangeNotification ( const Instantiation i)
finalvirtual

Listen to an assignment of a value in a Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 198 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

198  {
199  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->setChangeNotification(i);
200  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void setChangeNotification(const Instantiation &i) final
Listen to an assignment of a value in a Instantiation.
+ Here is the call graph for this function:

◆ setDecNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setDecNotification ( const Instantiation i)
finalvirtual

Listen to increment in each recorded Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 226 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

226  {
227  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->setDecNotification(i);
228  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void setDecNotification(const Instantiation &i) final
Listen to increment in each recorded Instantiation.
+ Here is the call graph for this function:

◆ setFirstNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setFirstNotification ( const Instantiation i)
finalvirtual

Listen to setFirst in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 205 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

205  {
206  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->setFirstNotification(i);
207  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void setFirstNotification(const Instantiation &i) final
Listen to setFirst in a given Instantiation.
+ Here is the call graph for this function:

◆ setIncNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setIncNotification ( const Instantiation i)
finalvirtual

Listen to increment in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 219 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

219  {
220  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->setIncNotification(i);
221  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void setIncNotification(const Instantiation &i) final
Listen to increment in a given Instantiation.
+ Here is the call graph for this function:

◆ setLastNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setLastNotification ( const Instantiation i)
finalvirtual

Listen to setLast in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 212 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

212  {
213  static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->setLastNotification(i);
214  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual void setLastNotification(const Instantiation &i) final
Listen to setLast in a given Instantiation.
+ Here is the call graph for this function:

◆ swapContent_()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::swapContent_ ( MultiDimImplementation< GUM_SCALAR > *  aContent) const
protected

protecte method to swap the implementation behind the Potential

Warning
unsafe method for slave Instantiations !

Definition at line 373 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

374  {
375  if (aContent != nullptr) {
376  // TODO : frees all slave instantiations
377  // TODO : control the dimensions ?
378  MultiDimImplementation< GUM_SCALAR >* tmp = content_;
379  content_ = aContent;
380  // registers all instantiations
381  delete (tmp);
382  }
383  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ toString() [1/2]

template<typename GUM_SCALAR >
INLINE std::string gum::MultiDimDecorator< GUM_SCALAR >::toString ( const Instantiation i) const
virtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 388 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

388  {
389  return content_->toString(i);
390  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ toString() [2/2]

template<typename GUM_SCALAR >
INLINE std::string gum::MultiDimDecorator< GUM_SCALAR >::toString ( ) const
virtual

Default implementation of MultiDimContainer::set().

Calls get_ as a r-value.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Reimplemented in gum::Potential< GUM_SCALAR >.

Definition at line 400 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

400  {
401  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->empty()) {
402  std::stringstream ss;
403  ss << "<> :: " << empty_value_;
404  return ss.str();
405  } else {
406  return content_->toString();
407  }
408  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:

◆ unregisterSlave()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::unregisterSlave ( Instantiation i)
finalvirtual

Unregister i as a slave of this MultiDimAdressable.

Parameters
iThe Instantiation to free.
Returns
Returns true, whatever happens.

Implements gum::MultiDimAdressable.

Definition at line 275 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

275  {
276  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->unregisterSlave(i);
277  }
virtual bool unregisterSlave(Instantiation &i) final
Unregister i as a slave of this MultiDimAdressable.
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
+ Here is the call graph for this function:

◆ variable() [1/2]

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::MultiDimDecorator< GUM_SCALAR >::variable ( Idx  i) const
finalvirtual

Returns a const ref to the ith var.

param i An index of this multidimensional matrix.

Returns
Returns a const ref to the ith var.
Exceptions
NotFoundRaised if i does not reference a variable in this multidimensional matrix.

Implements gum::MultiDimInterface.

Definition at line 248 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

248  {
249  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->variable(i);
250  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
+ Here is the call graph for this function:

◆ variable() [2/2]

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::MultiDimDecorator< GUM_SCALAR >::variable ( const std::string &  name) const
finalvirtual

Returns the variable with the name.

Parameters
nameThe index of the variable
Returns
Returns the variable qith the name in the tuple. This function is not O(1)
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 254 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

254  {
255  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->variable(name);
256  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
+ Here is the call graph for this function:

◆ variablesSequence()

template<typename GUM_SCALAR >
INLINE const Sequence< const DiscreteVariable *> & gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence ( ) const
finalvirtual

Returns a const ref to the sequence of DiscreteVariable*.

Returns
Returns a const ref to the sequence of DiscreteVariable*.

Implements gum::MultiDimInterface.

Definition at line 300 of file multiDimDecorator_tpl.h.

References gum::Set< Key, Alloc >::emplace().

300  {
301  return static_cast< MultiDimContainer< GUM_SCALAR >* >(content_)->variablesSequence();
302  }
MultiDimImplementation< GUM_SCALAR > * content_
The true container.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
+ Here is the call graph for this function:

Member Data Documentation

◆ content_

template<typename GUM_SCALAR >
MultiDimImplementation< GUM_SCALAR >* gum::MultiDimDecorator< GUM_SCALAR >::content_
mutableprotected

The true container.

Definition at line 247 of file multiDimDecorator.h.

◆ empty_value_

template<typename GUM_SCALAR >
GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::empty_value_
mutableprotected

value of the MultiDimDecorator if no dimension.

Definition at line 261 of file multiDimDecorator.h.


The documentation for this class was generated from the following files: