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