aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRMType.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 
76  this->_updateName_();
77 
78  if (_superType_) { _label_map_ = new std::vector< Idx >(from.label_map()); }
79  }
80 
81 
84  GUM_ERROR(FatalError, "Move constructor must not be used")
85  }
86 
87 
90  delete _var_;
91  if (_label_map_) { delete _label_map_; }
92  }
93 
94 
96  GUM_ERROR(FatalError, "Copy operator must not be used")}
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 */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)