aGrUM  0.14.2
multiDimWithOffset.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  ***************************************************************************/
27 #ifndef GUM_MULTI_DIM_WITH_OFFSET_H
28 #define GUM_MULTI_DIM_WITH_OFFSET_H
29 
30 #include <agrum/agrum.h>
32 #include <vector>
33 
34 namespace gum {
35  // ==========================================================================
36  // === GUM_MULTI_DIM_WITH_OFFSET === */
37  // ==========================================================================
48  template < typename GUM_SCALAR >
49  class MultiDimWithOffset : public MultiDimImplementation< GUM_SCALAR > {
50  public:
51  // =========================================================================
53  // =========================================================================
55 
60 
70 
74  virtual ~MultiDimWithOffset();
75 
83 
84  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const = 0;
85 
87  // =========================================================================
89  // =========================================================================
91 
92  virtual void add(const DiscreteVariable& v);
93 
94  virtual void erase(const DiscreteVariable& v);
95 
96  virtual void fill(const GUM_SCALAR& d) const = 0;
97 
98  virtual const std::string toString(const Instantiation* i) const;
99 
100  virtual void changeNotification(const Instantiation& i,
101  const DiscreteVariable* const var,
102  Idx oldval,
103  Idx newval);
104 
105  virtual void setChangeNotification(const Instantiation& i);
106 
107  virtual void setFirstNotification(const Instantiation& i);
108 
109  virtual void setLastNotification(const Instantiation& i);
110 
111  void setIncNotification(const Instantiation& i);
112 
113  void setDecNotification(const Instantiation& i);
114 
115  virtual bool registerSlave(Instantiation& i);
116 
117  virtual bool unregisterSlave(Instantiation& i);
118 
120  // =========================================================================
122  // =========================================================================
124 
126 
135  Size toOffset(const Instantiation& i) const;
136 
149  Instantiation& fromOffset(Instantiation& i, Size offset) const;
150 
152 
153  protected:
167  Size _getOffs(const Instantiation& i) const;
168 
178 
181 
192  void _computeInstantiationValue(Instantiation& result, Size indice) const;
193 
194  virtual GUM_SCALAR& _get(const Instantiation& i) const = 0;
195  };
196 } /* namespace gum */
197 
199 
200 #endif /* GUM_MULTI_DIM_WITH_OFFSET_H */
virtual void setLastNotification(const Instantiation &i)
Listen to setLast in a given Instantiation.
Instantiation & fromOffset(Instantiation &i, Size offset) const
Set the Instantiation to the values corresponding to the offset (in this array).
void _computeInstantiationValue(Instantiation &result, Size indice) const
For a given index of a value in the vector values, this method computes the corresponding instantiati...
void setDecNotification(const Instantiation &i)
Listen to increment in each recorded Instantiation.
Size toOffset(const Instantiation &i) const
Compute offset from an Instantiation (in this array).
virtual bool unregisterSlave(Instantiation &i)
Unregister i as a slave of this MultiDimAdressable.
virtual void fill(const GUM_SCALAR &d) const =0
Fill the table with d.
HashTable< const Instantiation *, Size > _offsets
The position in the array of each slave Instantiation.
virtual void setChangeNotification(const Instantiation &i)
Listen to an assignment of a value in a Instantiation.
Headers of the MultiDimWithOffset class.
virtual GUM_SCALAR & _get(const Instantiation &i) const =0
Return a data, given a Instantiation.
virtual const std::string toString() const
Returns a representation of this MultiDimContainer.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)
Listen to changes in a given Instantiation.
MultiDimWithOffset< GUM_SCALAR > & operator=(const MultiDimWithOffset< GUM_SCALAR > &from)
Copy operator.
HashTable< const DiscreteVariable *, Size > _gaps
The gaps between consecutive values of a given variable.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
Headers of gum::MultiDimImplementation.
virtual ~MultiDimWithOffset()
Class destrucor.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
The class for generic Hash Tables.
Definition: hashTable.h:676
Abstract class for Multidimensional matrix stored as an array in memory and with an offset associated...
MultiDimWithOffset()
Class constructor.
void setIncNotification(const Instantiation &i)
Listen to increment in a given Instantiation.
virtual void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
Size _getOffs(const Instantiation &i) const
Compute the offset of a Instantiation.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const =0
Class constructor.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual void setFirstNotification(const Instantiation &i)
Listen to setFirst in a given Instantiation.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
virtual bool registerSlave(Instantiation &i)
Register i as a slave of this MultiDimAdressable.