aGrUM  0.14.2
multiDimContainer.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_MULTIDIM_CONTAINER_H
28 #define GUM_MULTIDIM_CONTAINER_H
29 
30 #include <functional>
31 #include <initializer_list>
32 #include <iostream>
33 #include <vector>
34 
35 #include <agrum/agrum.h>
36 #include <agrum/core/math/math.h>
37 
39 
40 namespace gum {
41  // needed for content()
42  template < typename GUM_SCALAR >
44 
45  // ==========================================================================
46  // === GUM_MULTI_DIM ===
47  // ==========================================================================
89  template < typename GUM_SCALAR >
91  public:
92  // =========================================================================
94  // =========================================================================
96 
101 
107 
109 
114 
116 
120  virtual ~MultiDimContainer();
121 
123  // =========================================================================
125  // =========================================================================
127 
137  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
138 
149  virtual GUM_SCALAR get(const Instantiation& i) const;
150 
161  GUM_SCALAR operator[](const Instantiation& i) const;
162 
167  virtual void fill(const GUM_SCALAR& d) const = 0;
168 
187  virtual void populate(const std::vector< GUM_SCALAR >& v) const;
188 
207  virtual void populate(std::initializer_list< GUM_SCALAR > l) const;
208 
210  // =========================================================================
212  // =========================================================================
214 
227  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const;
228 
243  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src,
244  Instantiation* p_i) const;
245 
257  virtual void extractFrom(const MultiDimContainer< GUM_SCALAR >& src,
258  const Instantiation& mask);
259 
263  virtual const MultiDimImplementation< GUM_SCALAR >* content() const = 0;
264 
269 
275  virtual MultiDimAdressable& getMasterRef();
276 
282  virtual const MultiDimAdressable& getMasterRef() const;
283 
284 
291  virtual void copy(const MultiDimContainer< GUM_SCALAR >& src);
292 
311  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const = 0;
312 
314  // =========================================================================
316  // =========================================================================
318 
323  virtual const std::string toString() const;
324 
329  virtual const std::string toString(const Instantiation* i) const = 0;
330 
336  bool operator==(const MultiDimContainer< GUM_SCALAR >& p) const;
337 
343  bool operator!=(const MultiDimContainer< GUM_SCALAR >& p) const;
344 
349  virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const;
350 
356  virtual GUM_SCALAR
357  reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f,
358  GUM_SCALAR base) const;
359 
360 
362  // =========================================================================
364  // =========================================================================
366 
374  virtual void beginMultipleChanges() = 0;
375 
380  virtual void endMultipleChanges() = 0;
381 
386  virtual void endMultipleChanges(const GUM_SCALAR& v) = 0;
387 
389 
390  protected:
404  virtual GUM_SCALAR& _get(const Instantiation& i) const = 0;
405  };
406 } /* namespace gum */
407 
409 
410 #endif /* GUM_MULTIDIM_CONTAINER_H */
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
Useful macros for maths.
virtual ~MultiDimContainer()
Destructor.
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.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included...
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const
compute lfold for this container
Implementation of the MultiDimContainer class.
bool operator!=(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is different of p.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const =0
Creates an empty clone of this MultiDimContainer.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Basic copy of a MultiDimContainer.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
Abstract base class for all multi dimensionnal addressable.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
GUM_SCALAR operator[](const Instantiation &i) const
An [] operator using a Instantiation as argument.
MultiDimContainer()
Default constructor.
<agrum/multidim/multiDimImplementation.h>
virtual void fill(const GUM_SCALAR &d) const =0
Fill the table with d.
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const
Apply a function on every element of the container.
bool operator==(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is equal to p.
Headers for the abstract base class for all multi dimensionnal containers.
virtual MultiDimAdressable & getMasterRef()
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
virtual void populate(const std::vector< GUM_SCALAR > &v) const
Automatically fills this MultiDimContainer with the values in v.
virtual void extractFrom(const MultiDimContainer< GUM_SCALAR > &src, const Instantiation &mask)
Basic extraction of a MultiDimContainer.
MultiDimContainer & operator=(const MultiDimContainer< GUM_SCALAR > &src)
Default constructor.