aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR > Class Template Reference

Bulds gum::prm:PRMInterface from gum::prm::o3prm::O3Interface. More...

#include <agrum/PRM/o3prm/O3InterfaceFactory.h>

+ Collaboration diagram for gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >:

Public Member Functions

 O3InterfaceFactory (PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
 
 O3InterfaceFactory (const O3InterfaceFactory< GUM_SCALAR > &src)
 
 O3InterfaceFactory (O3InterfaceFactory< GUM_SCALAR > &&src)
 
 ~O3InterfaceFactory ()
 
O3InterfaceFactory< GUM_SCALAR > & operator= (const O3InterfaceFactory< GUM_SCALAR > &src)
 
O3InterfaceFactory< GUM_SCALAR > & operator= (O3InterfaceFactory< GUM_SCALAR > &&src)
 
void buildInterfaces ()
 
void buildElements ()
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >

Bulds gum::prm:PRMInterface from gum::prm::o3prm::O3Interface.

Template Parameters
GUM_SCALARThe scalar type used by the gum::prm::PRM.

Definition at line 58 of file O3InterfaceFactory.h.

Constructor & Destructor Documentation

◆ O3InterfaceFactory() [1/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::O3InterfaceFactory ( PRM< GUM_SCALAR > &  prm,
O3PRM o3_prm,
O3NameSolver< GUM_SCALAR > &  solver,
ErrorsContainer errors 
)

Definition at line 38 of file O3InterfaceFactory_tpl.h.

41  :
42  _prm_(&prm),
43  _o3_prm_(&o3_prm), _solver_(&solver), _errors_(&errors) {
44  GUM_CONSTRUCTOR(O3InterfaceFactory);
45  }
O3InterfaceFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
O3NameSolver< GUM_SCALAR > * _solver_

◆ O3InterfaceFactory() [2/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::O3InterfaceFactory ( const O3InterfaceFactory< GUM_SCALAR > &  src)

Definition at line 48 of file O3InterfaceFactory_tpl.h.

49  :
50  _prm_(src._prm_),
51  _o3_prm_(src._o3_prm_), _solver_(src._solver_), _errors_(src._errors_) {
52  GUM_CONS_CPY(O3InterfaceFactory);
53  }
O3InterfaceFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
O3NameSolver< GUM_SCALAR > * _solver_

◆ O3InterfaceFactory() [3/3]

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::O3InterfaceFactory ( O3InterfaceFactory< GUM_SCALAR > &&  src)

Definition at line 56 of file O3InterfaceFactory_tpl.h.

57  :
58  _prm_(std::move(src._prm_)),
59  _o3_prm_(std::move(src._o3_prm_)), _solver_(std::move(src._solver_)),
60  _errors_(std::move(src._errors_)) {
61  GUM_CONS_MOV(O3InterfaceFactory);
62  }
O3InterfaceFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
O3NameSolver< GUM_SCALAR > * _solver_

◆ ~O3InterfaceFactory()

template<typename GUM_SCALAR >
INLINE gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::~O3InterfaceFactory ( )

Definition at line 65 of file O3InterfaceFactory_tpl.h.

65  {
66  GUM_DESTRUCTOR(O3InterfaceFactory);
67  }
O3InterfaceFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)

Member Function Documentation

◆ _addArcs2Dag_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_addArcs2Dag_ ( )
private

Definition at line 131 of file O3InterfaceFactory_tpl.h.

131  {
132  // Adding arcs to the graph inheritance graph
133  for (auto& i: _o3_prm_->interfaces()) {
134  if (i->superLabel().label() != "") {
135  if (!_solver_->resolveInterface(i->superLabel())) { return false; }
136 
137  auto head = _nameMap_[i->superLabel().label()];
138  auto tail = _nameMap_[i->name().label()];
139 
140  try {
141  _dag_.addArc(tail, head);
142 
143  } catch (InvalidDirectedCycle&) {
144  // Cyclic inheritance
145  O3PRM_INTERFACE_CYCLIC_INHERITANCE(i->name(), i->superLabel(), *_errors_);
146  return false;
147  }
148  }
149  }
150  return true;
151  }
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Definition: DAG_inl.h:42
HashTable< std::string, gum::NodeId > _nameMap_
O3NameSolver< GUM_SCALAR > * _solver_
O3InterfaceList & interfaces()
Definition: O3prm.cpp:527

◆ _addInterface2Dag_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_addInterface2Dag_ ( )
private

Definition at line 112 of file O3InterfaceFactory_tpl.h.

112  {
113  // Adding nodes to the type inheritance graph
114  for (auto& i: _o3_prm_->interfaces()) {
115  auto id = _dag_.addNode();
116  try {
117  _nameMap_.insert(i->name().label(), id);
118  _interfaceMap_.insert(i->name().label(), i.get());
119  _nodeMap_.insert(id, i.get());
120 
121  } catch (DuplicateElement&) {
122  // Raised if duplicate type names
123  O3PRM_INTERFACE_DUPLICATE(i->name(), *_errors_);
124  return false;
125  }
126  }
127  return true;
128  }
HashTable< std::string, O3Interface *> _interfaceMap_
HashTable< std::string, gum::NodeId > _nameMap_
virtual NodeId addNode()
insert a new node and return its id
HashTable< NodeId, O3Interface *> _nodeMap_
O3InterfaceList & interfaces()
Definition: O3prm.cpp:527
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ _checkAttributeOverloadLegality_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkAttributeOverloadLegality_ ( O3Interface i,
O3InterfaceElement elt 
)
private

Definition at line 230 of file O3InterfaceFactory_tpl.h.

232  {
233  const auto& real_i = _prm_->getInterface(i.name().label());
234  const auto& real_elt = real_i.get(elt.name().label());
235 
236  const auto& sub_type = _prm_->type(elt.type().label());
237  const auto& super_type = real_elt.type();
238 
239  if (!sub_type.isSubTypeOf(super_type)) {
240  O3PRM_INTERFACE_ILLEGAL_OVERLOAD(elt, *_errors_);
241  return false;
242  }
243 
244  if (sub_type.name() == super_type.name()) {
245  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *_errors_);
246  return false;
247  }
248 
249  return true;
250  }

◆ _checkCyclicReference_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkCyclicReference_ ( O3Interface i,
O3InterfaceElement elt 
)
private

Definition at line 285 of file O3InterfaceFactory_tpl.h.

286  {
287  if (_prm_->isInterface(elt.type().label()) || _prm_->isClass(elt.type().label())) {
288  auto ref_type = (const PRMClassElementContainer< GUM_SCALAR >*)nullptr;
289 
290  if (_prm_->isInterface(elt.type().label())) {
291  ref_type = &(_prm_->getInterface(elt.type().label()));
292  } else {
293  ref_type = &(_prm_->getClass(elt.type().label()));
294  }
295 
296  const auto& real_i = _prm_->getInterface(i.name().label());
297 
298  if (&real_i == ref_type) {
299  O3PRM_INTERFACE_SELF_REFERENCE(i, elt, *_errors_);
300  return false;
301  }
302 
303  if (ref_type->isSubTypeOf(real_i)) {
304  O3PRM_INTERFACE_ILLEGAL_SUB_REFERENCE(i, elt, *_errors_);
305  return false;
306  }
307  }
308 
309  return true;
310  }

◆ _checkInterfaceElement_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkInterfaceElement_ ( O3Interface i,
O3InterfaceElement elt 
)
private

Definition at line 191 of file O3InterfaceFactory_tpl.h.

192  {
193  if (!_solver_->resolveClassElement(elt.type())) { return false; }
194 
195  if (_prm_->isType(elt.type().label()) && elt.isArray()) {
196  O3PRM_INTERFACE_ILLEGAL_ARRAY(elt.name(), *_errors_);
197  return false;
198  }
199 
200  const auto& real_i = _prm_->getInterface(i.name().label());
201 
202  if (real_i.exists(elt.name().label())) {
203  if (!_checkOverloadLegality_(i, elt)) { return false; }
204  }
205 
206  if (!_checkCyclicReference_(i, elt)) { return false; }
207 
208  return true;
209  }
bool _checkCyclicReference_(O3Interface &i, O3InterfaceElement &elt)
O3NameSolver< GUM_SCALAR > * _solver_
bool _checkOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)

◆ _checkO3Interfaces_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkO3Interfaces_ ( )
private

◆ _checkOverloadLegality_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkOverloadLegality_ ( O3Interface i,
O3InterfaceElement elt 
)
private

Definition at line 213 of file O3InterfaceFactory_tpl.h.

214  {
215  const auto& real_i = _prm_->getInterface(i.name().label());
216  const auto& real_elt = real_i.get(elt.name().label());
217 
219  return _checkAttributeOverloadLegality_(i, elt);
220  }
221 
223  return _checkReferenceOverloadLegality_(i, elt);
224  }
225 
226  return false;
227  }
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
bool _checkAttributeOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)
bool _checkReferenceOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)

◆ _checkReferenceOverloadLegality_()

template<typename GUM_SCALAR >
INLINE bool gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_checkReferenceOverloadLegality_ ( O3Interface i,
O3InterfaceElement elt 
)
private

Definition at line 253 of file O3InterfaceFactory_tpl.h.

255  {
256  const auto& real_i = _prm_->getInterface(i.name().label());
257  const auto& real_elt
258  = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(real_i.get(elt.name().label()));
259 
260  auto sub_type = (const PRMClassElementContainer< GUM_SCALAR >*)nullptr;
261 
262  if (_prm_->isClass(elt.type().label())) {
263  sub_type = &(_prm_->getClass(elt.type().label()));
264  } else {
265  sub_type = &(_prm_->getInterface(elt.type().label()));
266  }
267 
268  auto super_type = &(real_elt.slotType());
269 
270  if (!sub_type->isSubTypeOf(*super_type)) {
271  O3PRM_INTERFACE_ILLEGAL_OVERLOAD(elt, *_errors_);
272  return false;
273  }
274 
275  if (sub_type->name() == super_type->name()) {
276  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *_errors_);
277  return false;
278  }
279 
280  return true;
281  }

◆ _setO3InterfaceCreationOrder_()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_setO3InterfaceCreationOrder_ ( )
private

Definition at line 154 of file O3InterfaceFactory_tpl.h.

154  {
155  auto topo_order = _dag_.topologicalOrder();
156  for (auto id = topo_order.rbegin(); id != topo_order.rend(); --id) {
157  _o3Interface_.push_back(_nodeMap_[*id]);
158  }
159  }
std::vector< O3Interface *> _o3Interface_
HashTable< NodeId, O3Interface *> _nodeMap_
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:88

◆ buildElements()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements ( )

Definition at line 162 of file O3InterfaceFactory_tpl.h.

162  {
163  PRMFactory< GUM_SCALAR > factory(_prm_);
164 
165  for (auto i: _o3Interface_) {
166  _prm_->getInterface(i->name().label()).inheritInterface();
167 
168  factory.continueInterface(i->name().label());
169 
170  for (auto& elt: i->elements()) {
171  if (_checkInterfaceElement_(*i, elt)) {
172  try {
173  if (_prm_->isType(elt.type().label())) {
174  factory.addAttribute(elt.type().label(), elt.name().label());
175  } else {
176  factory.addReferenceSlot(elt.type().label(), elt.name().label(), elt.isArray());
177  }
178 
179  } catch (OperationNotAllowed&) {
180  // Duplicate or Wrong overload
181  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *_errors_);
182  }
183  }
184  }
185  factory.endInterface();
186  }
187  }
std::vector< O3Interface *> _o3Interface_
bool _checkInterfaceElement_(O3Interface &i, O3InterfaceElement &elt)

◆ buildInterfaces()

template<typename GUM_SCALAR >
INLINE void gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildInterfaces ( )

Definition at line 92 of file O3InterfaceFactory_tpl.h.

92  {
93  PRMFactory< GUM_SCALAR > factory(_prm_);
94  if (_checkO3Interfaces_()) {
96 
97  for (auto i: _o3Interface_) {
98  if (_solver_->resolveInterface(i->superLabel())) {
99  factory.startInterface(i->name().label(), i->superLabel().label(), true);
100  factory.endInterface();
101  }
102  }
103  }
104  }
std::vector< O3Interface *> _o3Interface_
O3NameSolver< GUM_SCALAR > * _solver_

◆ operator=() [1/2]

template<typename GUM_SCALAR >
INLINE O3InterfaceFactory< GUM_SCALAR > & gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::operator= ( const O3InterfaceFactory< GUM_SCALAR > &  src)

Definition at line 71 of file O3InterfaceFactory_tpl.h.

71  {
72  if (this == &src) { return *this; }
73  _prm_ = src._prm_;
74  _o3_prm_ = src._o3_prm_;
75  _solver_ = src._solver_;
76  _errors_ = src._errors_;
77  return *this;
78  }
O3NameSolver< GUM_SCALAR > * _solver_

◆ operator=() [2/2]

template<typename GUM_SCALAR >
INLINE O3InterfaceFactory< GUM_SCALAR > & gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::operator= ( O3InterfaceFactory< GUM_SCALAR > &&  src)

Definition at line 82 of file O3InterfaceFactory_tpl.h.

82  {
83  if (this == &src) { return *this; }
84  _prm_ = std::move(src._prm_);
85  _o3_prm_ = std::move(src._o3_prm_);
86  _solver_ = std::move(src._solver_);
87  _errors_ = std::move(src._errors_);
88  return *this;
89  }
O3NameSolver< GUM_SCALAR > * _solver_

Member Data Documentation

◆ _dag_

template<typename GUM_SCALAR >
DAG gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_dag_
private

Definition at line 84 of file O3InterfaceFactory.h.

◆ _eltName_

template<typename GUM_SCALAR >
HashTable< std::string, std::string > gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_eltName_
private

Definition at line 80 of file O3InterfaceFactory.h.

◆ _errors_

template<typename GUM_SCALAR >
ErrorsContainer* gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_errors_
private

Definition at line 78 of file O3InterfaceFactory.h.

◆ _interfaceMap_

template<typename GUM_SCALAR >
HashTable< std::string, O3Interface* > gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_interfaceMap_
private

Definition at line 82 of file O3InterfaceFactory.h.

◆ _nameMap_

template<typename GUM_SCALAR >
HashTable< std::string, gum::NodeId > gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_nameMap_
private

Definition at line 81 of file O3InterfaceFactory.h.

◆ _nodeMap_

template<typename GUM_SCALAR >
HashTable< NodeId, O3Interface* > gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_nodeMap_
private

Definition at line 83 of file O3InterfaceFactory.h.

◆ _o3_prm_

template<typename GUM_SCALAR >
O3PRM* gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_o3_prm_
private

Definition at line 76 of file O3InterfaceFactory.h.

◆ _o3Interface_

template<typename GUM_SCALAR >
std::vector< O3Interface* > gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_o3Interface_
private

Definition at line 85 of file O3InterfaceFactory.h.

◆ _prm_

template<typename GUM_SCALAR >
PRM< GUM_SCALAR >* gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_prm_
private

Definition at line 75 of file O3InterfaceFactory.h.

◆ _solver_

template<typename GUM_SCALAR >
O3NameSolver< GUM_SCALAR >* gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::_solver_
private

Definition at line 77 of file O3InterfaceFactory.h.


The documentation for this class was generated from the following files: