aGrUM  0.20.2
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 37 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 135 of file O3InterfaceFactory_tpl.h.

135  {
136  // Adding arcs to the graph inheritance graph
137  for (auto& i: o3_prm__->interfaces()) {
138  if (i->superLabel().label() != "") {
139  if (!solver__->resolveInterface(i->superLabel())) { return false; }
140 
141  auto head = nameMap__[i->superLabel().label()];
142  auto tail = nameMap__[i->name().label()];
143 
144  try {
145  dag__.addArc(tail, head);
146 
147  } catch (InvalidDirectedCycle&) {
148  // Cyclic inheritance
149  O3PRM_INTERFACE_CYCLIC_INHERITANCE(i->name(),
150  i->superLabel(),
151  *errors__);
152  return false;
153  }
154  }
155  }
156  return true;
157  }
HashTable< std::string, gum::NodeId > nameMap__
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Definition: DAG_inl.h:42
O3NameSolver< GUM_SCALAR > * solver__
O3InterfaceList & interfaces()
Definition: O3prm.cpp:497

◆ addInterface2Dag__()

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

Definition at line 116 of file O3InterfaceFactory_tpl.h.

116  {
117  // Adding nodes to the type inheritance graph
118  for (auto& i: o3_prm__->interfaces()) {
119  auto id = dag__.addNode();
120  try {
121  nameMap__.insert(i->name().label(), id);
122  interfaceMap__.insert(i->name().label(), i.get());
123  nodeMap__.insert(id, i.get());
124 
125  } catch (DuplicateElement&) {
126  // Raised if duplicate type names
127  O3PRM_INTERFACE_DUPLICATE(i->name(), *errors__);
128  return false;
129  }
130  }
131  return true;
132  }
HashTable< std::string, gum::NodeId > nameMap__
virtual NodeId addNode()
insert a new node and return its id
O3InterfaceList & interfaces()
Definition: O3prm.cpp:497
HashTable< std::string, O3Interface *> interfaceMap__
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
HashTable< NodeId, O3Interface *> nodeMap__

◆ buildElements()

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

Definition at line 169 of file O3InterfaceFactory_tpl.h.

169  {
170  PRMFactory< GUM_SCALAR > factory(prm__);
171 
172  for (auto i: o3Interface__) {
173  prm__->getInterface(i->name().label()).inheritInterface();
174 
175  factory.continueInterface(i->name().label());
176 
177  for (auto& elt: i->elements()) {
178  if (checkInterfaceElement__(*i, elt)) {
179  try {
180  if (prm__->isType(elt.type().label())) {
181  factory.addAttribute(elt.type().label(), elt.name().label());
182  } else {
183  factory.addReferenceSlot(elt.type().label(),
184  elt.name().label(),
185  elt.isArray());
186  }
187 
188  } catch (OperationNotAllowed&) {
189  // Duplicate or Wrong overload
190  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *errors__);
191  }
192  }
193  }
194  factory.endInterface();
195  }
196  }
bool checkInterfaceElement__(O3Interface &i, O3InterfaceElement &elt)
std::vector< O3Interface *> o3Interface__

◆ buildInterfaces()

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

Definition at line 94 of file O3InterfaceFactory_tpl.h.

94  {
95  PRMFactory< GUM_SCALAR > factory(prm__);
96  if (checkO3Interfaces__()) {
98 
99  for (auto i: o3Interface__) {
100  if (solver__->resolveInterface(i->superLabel())) {
101  factory.startInterface(i->name().label(),
102  i->superLabel().label(),
103  true);
104  factory.endInterface();
105  }
106  }
107  }
108  }
O3NameSolver< GUM_SCALAR > * solver__
std::vector< O3Interface *> o3Interface__

◆ checkAttributeOverloadLegality__()

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

Definition at line 240 of file O3InterfaceFactory_tpl.h.

242  {
243  const auto& real_i = prm__->getInterface(i.name().label());
244  const auto& real_elt = real_i.get(elt.name().label());
245 
246  const auto& sub_type = prm__->type(elt.type().label());
247  const auto& super_type = real_elt.type();
248 
249  if (!sub_type.isSubTypeOf(super_type)) {
250  O3PRM_INTERFACE_ILLEGAL_OVERLOAD(elt, *errors__);
251  return false;
252  }
253 
254  if (sub_type.name() == super_type.name()) {
255  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *errors__);
256  return false;
257  }
258 
259  return true;
260  }

◆ checkCyclicReference__()

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

Definition at line 296 of file O3InterfaceFactory_tpl.h.

298  {
299  if (prm__->isInterface(elt.type().label())
300  || prm__->isClass(elt.type().label())) {
301  auto ref_type = (const PRMClassElementContainer< GUM_SCALAR >*)nullptr;
302 
303  if (prm__->isInterface(elt.type().label())) {
304  ref_type = &(prm__->getInterface(elt.type().label()));
305  } else {
306  ref_type = &(prm__->getClass(elt.type().label()));
307  }
308 
309  const auto& real_i = prm__->getInterface(i.name().label());
310 
311  if (&real_i == ref_type) {
312  O3PRM_INTERFACE_SELF_REFERENCE(i, elt, *errors__);
313  return false;
314  }
315 
316  if (ref_type->isSubTypeOf(real_i)) {
317  O3PRM_INTERFACE_ILLEGAL_SUB_REFERENCE(i, elt, *errors__);
318  return false;
319  }
320  }
321 
322  return true;
323  }

◆ checkInterfaceElement__()

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

Definition at line 199 of file O3InterfaceFactory_tpl.h.

201  {
202  if (!solver__->resolveClassElement(elt.type())) { return false; }
203 
204  if (prm__->isType(elt.type().label()) && elt.isArray()) {
205  O3PRM_INTERFACE_ILLEGAL_ARRAY(elt.name(), *errors__);
206  return false;
207  }
208 
209  const auto& real_i = prm__->getInterface(i.name().label());
210 
211  if (real_i.exists(elt.name().label())) {
212  if (!checkOverloadLegality__(i, elt)) { return false; }
213  }
214 
215  if (!checkCyclicReference__(i, elt)) { return false; }
216 
217  return true;
218  }
bool checkOverloadLegality__(O3Interface &i, O3InterfaceElement &elt)
O3NameSolver< GUM_SCALAR > * solver__
bool checkCyclicReference__(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 221 of file O3InterfaceFactory_tpl.h.

223  {
224  const auto& real_i = prm__->getInterface(i.name().label());
225  const auto& real_elt = real_i.get(elt.name().label());
226 
228  return checkAttributeOverloadLegality__(i, elt);
229  }
230 
232  return checkReferenceOverloadLegality__(i, elt);
233  }
234 
235  return false;
236  }
bool checkReferenceOverloadLegality__(O3Interface &i, O3InterfaceElement &elt)
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)

◆ checkReferenceOverloadLegality__()

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

Definition at line 264 of file O3InterfaceFactory_tpl.h.

266  {
267  const auto& real_i = prm__->getInterface(i.name().label());
268  const auto& real_elt
269  = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(
270  real_i.get(elt.name().label()));
271 
272  auto sub_type = (const PRMClassElementContainer< GUM_SCALAR >*)nullptr;
273 
274  if (prm__->isClass(elt.type().label())) {
275  sub_type = &(prm__->getClass(elt.type().label()));
276  } else {
277  sub_type = &(prm__->getInterface(elt.type().label()));
278  }
279 
280  auto super_type = &(real_elt.slotType());
281 
282  if (!sub_type->isSubTypeOf(*super_type)) {
283  O3PRM_INTERFACE_ILLEGAL_OVERLOAD(elt, *errors__);
284  return false;
285  }
286 
287  if (sub_type->name() == super_type->name()) {
288  O3PRM_INTERFACE_DUPLICATE_ELEMENT(elt, *errors__);
289  return false;
290  }
291 
292  return true;
293  }

◆ 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.

72  {
73  if (this == &src) { return *this; }
74  prm__ = src.prm__;
75  o3_prm__ = src.o3_prm__;
76  solver__ = src.solver__;
77  errors__ = src.errors__;
78  return *this;
79  }
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 83 of file O3InterfaceFactory_tpl.h.

84  {
85  if (this == &src) { return *this; }
86  prm__ = std::move(src.prm__);
87  o3_prm__ = std::move(src.o3_prm__);
88  solver__ = std::move(src.solver__);
89  errors__ = std::move(src.errors__);
90  return *this;
91  }
O3NameSolver< GUM_SCALAR > * solver__

◆ setO3InterfaceCreationOrder__()

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

Definition at line 161 of file O3InterfaceFactory_tpl.h.

161  {
162  auto topo_order = dag__.topologicalOrder();
163  for (auto id = topo_order.rbegin(); id != topo_order.rend(); --id) {
164  o3Interface__.push_back(nodeMap__[*id]);
165  }
166  }
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:90
std::vector< O3Interface *> o3Interface__
HashTable< NodeId, O3Interface *> nodeMap__

Member Data Documentation

◆ dag__

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

Definition at line 86 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 82 of file O3InterfaceFactory.h.

◆ errors__

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

Definition at line 80 of file O3InterfaceFactory.h.

◆ interfaceMap__

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

Definition at line 84 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 83 of file O3InterfaceFactory.h.

◆ nodeMap__

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

Definition at line 85 of file O3InterfaceFactory.h.

◆ o3_prm__

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

Definition at line 78 of file O3InterfaceFactory.h.

◆ o3Interface__

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

Definition at line 87 of file O3InterfaceFactory.h.

◆ prm__

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

Definition at line 77 of file O3InterfaceFactory.h.

◆ solver__

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

Definition at line 79 of file O3InterfaceFactory.h.


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