aGrUM  0.14.2
PRMType.cpp
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  ***************************************************************************/
29 
30 #ifdef GUM_NO_INLINE
32 #endif // GUM_NO_INLINE
33 
34 namespace gum {
35 
36  namespace prm {
37 
38 
40  const void* address = static_cast< const void* >(this);
41  std::stringstream ss;
42  ss << this->name() << "-" << address;
43  this->__var->setName(ss.str());
44  }
45 
46 
48  PRMObject(var.name()), __var(var.clone()), __superType(0), __label_map(0) {
49  GUM_CONSTRUCTOR(PRMType);
50  this->__updateName();
51  }
52 
53 
55  const std::vector< Idx >& label_map,
56  const DiscreteVariable& var) :
57  PRMObject(var.name()),
58  __var(var.clone()), __superType(&super_type),
59  __label_map(new std::vector< Idx >(label_map)) {
60  GUM_CONSTRUCTOR(PRMType);
61  this->__updateName();
62 
63  if (!__isValid()) {
64  delete __label_map;
65  __label_map = 0;
66  GUM_ERROR(OperationNotAllowed, "Invalid label map.");
67  }
68  }
69 
70 
71  PRMType::PRMType(const PRMType& from) :
72  PRMObject(from), __var(from.__var->clone()), __superType(from.__superType),
73  __label_map(0) {
74  GUM_CONS_CPY(PRMType);
75  this->__updateName();
76 
77  if (__superType) { __label_map = new std::vector< Idx >(from.label_map()); }
78  }
79 
80 
82  GUM_CONS_MOV(PRMType);
83  GUM_ERROR(FatalError, "Move constructor must not be used");
84  }
85 
86 
88  GUM_DESTRUCTOR(PRMType);
89  delete __var;
90  if (__label_map) { delete __label_map; }
91  }
92 
93 
95  GUM_ERROR(FatalError, "Copy operator must not be used");
96  }
97 
98 
100  GUM_ERROR(FatalError, "Move operator must not be used");
101  }
102 
103 
104  bool PRMType::isSubTypeOf(const PRMType& super) const {
105  if ((*this) == super) {
106  return true;
107  } else if (__superType) {
108  return __superType->isSubTypeOf(super);
109  } else {
110  return false;
111  }
112  }
113 
114 
115  bool PRMType::__isValid() const {
116  if (!__superType) { return __var->domainSize() > 1; }
117 
118  if (__label_map->size() == __var->domainSize()) {
119  for (size_t i = 0; i < __label_map->size(); ++i) {
120  if (__label_map->at(i) >= (**__superType).domainSize()) { return false; }
121  }
122 
123  return true;
124  }
125 
126  return false;
127  }
128 
129 
130  } /* namespace prm */
131 } /* namespace gum */
void setName(const std::string &theValue)
sets the name of the variable
const std::string & name() const
Returns the name of this object.
Definition: PRMType_inl.h:65
Inline implementation of type.
PRMType * __superType
The super type of this, if any.
Definition: PRMType.h:276
PRMType(const DiscreteVariable &var)
Default Constructor.
Definition: PRMType.cpp:47
virtual ~PRMType()
Destructor.
Definition: PRMType.cpp:87
STL namespace.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DiscreteVariable * __var
The discrete variable.
Definition: PRMType.h:273
void __updateName()
Used at construction to set a unique name to this class underlying DiscreteVariable.
Definition: PRMType.cpp:39
virtual Size domainSize() const =0
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
Size Idx
Type for indexes.
Definition: types.h:50
PRMType & operator=(const PRMType &from)
Copy operator.
Definition: PRMType.cpp:94
bool __isValid() const
Returns true if this is a valid type or subtype.
Definition: PRMType.cpp:115
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