aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
PRMType.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Source implementation of type.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  *
28  */
29 
30 #include <agrum/PRM/elements/PRMType.h>
31 
32 #ifdef GUM_NO_INLINE
33 # include <agrum/PRM/elements/PRMType_inl.h>
34 #endif // GUM_NO_INLINE
35 
36 namespace gum {
37 
38  namespace prm {
39 
40 
42  const void* address = static_cast< const void* >(this);
44  ss << this->name() << "-" << address;
45  this->var__->setName(ss.str());
46  }
47 
48 
52  this->updateName__();
53  }
54 
55 
57  const std::vector< Idx >& label_map,
58  const DiscreteVariable& var) :
59  PRMObject(var.name()),
61  label_map__(new std::vector< Idx >(label_map)) {
63  this->updateName__();
64 
65  if (!isValid__()) {
66  delete label_map__;
67  label_map__ = 0;
68  GUM_ERROR(OperationNotAllowed, "Invalid label map.");
69  }
70  }
71 
72 
75  label_map__(0) {
77  this->updateName__();
78 
79  if (superType__) { label_map__ = new std::vector< Idx >(from.label_map()); }
80  }
81 
82 
85  GUM_ERROR(FatalError, "Move constructor must not be used");
86  }
87 
88 
91  delete var__;
92  if (label_map__) { delete label_map__; }
93  }
94 
95 
97  GUM_ERROR(FatalError, "Copy operator must not be used");
98  }
99 
100 
102  GUM_ERROR(FatalError, "Move operator must not be used");
103  }
104 
105 
106  bool PRMType::isSubTypeOf(const PRMType& super) const {
107  if ((*this) == super) {
108  return true;
109  } else if (superType__) {
110  return superType__->isSubTypeOf(super);
111  } else {
112  return false;
113  }
114  }
115 
116 
117  bool PRMType::isValid__() const {
118  if (!superType__) { return var__->domainSize() > 1; }
119 
120  if (label_map__->size() == var__->domainSize()) {
121  for (size_t i = 0; i < label_map__->size(); ++i) {
122  if (label_map__->at(i) >= (**superType__).domainSize()) { return false; }
123  }
124 
125  return true;
126  }
127 
128  return false;
129  }
130 
131 
132  } /* namespace prm */
133 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)