aGrUM  0.14.2
PRMType_inl.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  ***************************************************************************/
28 
29 namespace gum {
30  namespace prm {
31 
32 
34  if (__superType) {
35  return *__superType;
36  } else {
37  GUM_ERROR(NotFound, "No super type for this type.");
38  }
39  }
40 
41 
42  INLINE DiscreteVariable& PRMType::variable() { return *__var; }
43 
44 
45  INLINE const DiscreteVariable& PRMType::variable() const { return *__var; }
46 
47 
48  INLINE DiscreteVariable& PRMType::operator*() { return *__var; }
49 
50 
51  INLINE const DiscreteVariable& PRMType::operator*() const { return *__var; }
52 
53 
55 
56 
57  INLINE DiscreteVariable const* PRMType::operator->() const { return __var; }
58 
59 
62  }
63 
64 
65  INLINE const std::string& PRMType::name() const { return PRMObject::name(); }
66 
67 
68  INLINE const PRMType& PRMType::superType() const {
69  if (__superType) {
70  return *__superType;
71  } else {
72  GUM_ERROR(NotFound, "No super type for this type.");
73  }
74  }
75 
76 
77  INLINE void PRMType::setSuper(PRMType& t) {
78  try {
79  if (t != superType()) {
81  "The given type is not a valid super type for this Type");
82  }
83  } catch (NotFound&) {
84  GUM_ERROR(OperationNotAllowed, "This Type has no super Type");
85  }
86 
87  __superType = &t;
88  }
89 
90 
91  INLINE const std::vector< Idx >& PRMType::label_map() const {
92  if (__label_map) {
93  return *__label_map;
94  } else {
95  GUM_ERROR(NotFound, "No super type for this type.");
96  }
97  }
98 
99 
100  INLINE bool PRMType::isSubType() const { return __superType != nullptr; }
101 
102 
103  INLINE bool PRMType::isSuperTypeOf(const PRMType& t) const {
104  return t.isSubTypeOf(*this);
105  }
106 
107 
108  INLINE bool PRMType::operator==(const PRMObject& obj) const {
109  return name() == obj.name();
110  }
111 
112 
113  INLINE bool PRMType::operator!=(const PRMObject& obj) const {
114  return name() != obj.name();
115  }
116 
117  } /* namespace prm */
118 } /* namespace gum */
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
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
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
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
DiscreteVariable * __var
The discrete variable.
Definition: PRMType.h:273
bool operator==(const PRMObject &from) const
Equality operator.
Definition: PRMType_inl.h:108
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
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
Headers of Class.
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:53
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
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 isSubTypeOf(const PRMType &super) const
Returns true if this is a subtype of super.
Definition: PRMType.cpp:104
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52