aGrUM  0.14.2
PRMType.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
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_RANDOM_VARIABLE_TYPE_H
28 #define GUM_RANDOM_VARIABLE_TYPE_H
29 
30 #include <sstream>
31 #include <vector>
32 
33 #include <agrum/agrum.h>
34 
39 
41 #include <agrum/PRM/utils_prm.h>
42 
43 namespace gum {
44  namespace prm {
45 
46  template < typename GUM_SCALAR >
47  class PRMFactory;
48 
60  class PRMType : public PRMObject {
61  public:
62  // ==========================================================================
64  // ==========================================================================
66 
67  template < typename GUM_SCALAR >
68  friend class PRMFactory;
69 
71  // ==========================================================================
73  // ==========================================================================
75 
77  static PRMType* boolean() {
78  LabelizedVariable var("boolean", "Boolean variable", 0);
79  var.addLabel("false");
80  var.addLabel("true");
81  return new PRMType(var);
82  }
83 
85  // ==========================================================================
87  // ==========================================================================
89 
94  explicit PRMType(const DiscreteVariable& var);
95 
101  PRMType(PRMType& super_type,
102  const std::vector< Idx >& label_map,
103  const DiscreteVariable& var);
104 
109  PRMType(const PRMType& from);
110 
114  virtual ~PRMType();
115 
117  // ==========================================================================
119  // ==========================================================================
121 
124 
126  const DiscreteVariable& variable() const;
127 
129  // ==========================================================================
131  // ==========================================================================
133 
138 
142  const DiscreteVariable& operator*() const;
143 
148 
152  DiscreteVariable const* operator->() const;
153 
157  bool operator==(const PRMObject& from) const;
158 
162  bool operator!=(const PRMObject& from) const;
163 
165  // ==========================================================================
167  // ==========================================================================
169 
173  virtual prm_type obj_type() const;
174 
178  const std::string& name() const;
179 
183  bool isSubType() const;
184 
190  bool isSubTypeOf(const PRMType& super) const;
191 
195  bool isSuperTypeOf(const PRMType& t) const;
196 
201  PRMType& superType();
202 
207  const PRMType& superType() const;
208 
226  void setSuper(PRMType& t);
227 
233  const std::vector< Idx >& label_map() const;
234 
236  // ==========================================================================
237  private:
238  // ==========================================================================
240  // ==========================================================================
242 
247  PRMType(PRMType&& from);
248 
252  PRMType& operator=(const PRMType& from);
253 
257  PRMType& operator=(PRMType&& from);
258 
260  // ==========================================================================
262  // ==========================================================================
264 
266  bool __isValid() const;
267 
270  void __updateName();
271 
274 
277 
280  std::vector< Idx >* __label_map;
281 
283  };
284 
285  } /* namespace prm */
286 
287 } /* namespace gum */
288 
289 #ifndef GUM_NO_INLINE
291 #endif // GUM_NO_INLINE
292 
293 #endif /* GUM_CLASS_H */
const std::string & name() const
Returns the name of this object.
Definition: PRMType_inl.h:65
PRMType & superType()
Returns the super type of this type.
Definition: PRMType_inl.h:33
void setSuper(PRMType &t)
Changes the PRMType of this PRMType super.
Definition: PRMType_inl.h:77
Inline implementation of type.
PRMType * __superType
The super type of this, if any.
Definition: PRMType.h:276
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Definition: PRMType_inl.h:42
Base class for discrete random variable.
class LabelizedVariable
PRMType(const DiscreteVariable &var)
Default Constructor.
Definition: PRMType.cpp:47
virtual ~PRMType()
Destructor.
Definition: PRMType.cpp:87
bool isSuperTypeOf(const PRMType &t) const
Returns true if this is a super type of t.
Definition: PRMType_inl.h:103
Base class for discrete random variable.
bool operator!=(const PRMObject &from) const
Difference operator.
Definition: PRMType_inl.h:113
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Headers of gum::MultiDimImplementation.
DiscreteVariable * __var
The discrete variable.
Definition: PRMType.h:273
bool operator==(const PRMObject &from) const
Equality operator.
Definition: PRMType_inl.h:108
void __updateName()
Used at construction to set a unique name to this class underlying DiscreteVariable.
Definition: PRMType.cpp:39
DiscreteVariable * operator->()
Dereference the DiscreteVariable contained in this.
Definition: PRMType_inl.h:54
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:66
virtual prm_type obj_type() const
Implementation of the pure virtual method of PRMObject.
Definition: PRMType_inl.h:60
Factory which builds a PRM<GUM_SCALAR>.
Definition: PRMType.h:47
std::vector< Idx > * __label_map
A vector in which the i-th element is the Idx of the super type&#39;s label for the i-th label of this...
Definition: PRMType.h:280
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:60
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:53
static PRMType * boolean()
Returns a pointer on type boolean.
Definition: PRMType.h:77
const std::vector< Idx > & label_map() const
Returns the vector in which the i-th element is the Idx of the super type&#39;s label for the i-th label ...
Definition: PRMType_inl.h:91
PRMType & operator=(const PRMType &from)
Copy operator.
Definition: PRMType.cpp:94
Header of the MultiDimArray class.
DiscreteVariable & operator*()
Indirection on the DiscreteVariable contained in this.
Definition: PRMType_inl.h:48
bool isSubType() const
Returns true if this type is a sub-type.
Definition: PRMType_inl.h:100
bool __isValid() const
Returns true if this is a valid type or subtype.
Definition: PRMType.cpp:115
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
bool isSubTypeOf(const PRMType &super) const
Returns true if this is a subtype of super.
Definition: PRMType.cpp:104
Base class for labelized discrete random variables.
Headers of PRMObject.