aGrUM 3.1.1
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 ()

Private Member Functions

bool _addInterface2Dag_ ()
bool _addArcs2Dag_ ()
void _setO3InterfaceCreationOrder_ ()
bool _checkO3Interfaces_ ()
bool _checkInterfaceElement_ (O3Interface &i, O3InterfaceElement &elt)
bool _checkOverloadLegality_ (O3Interface &i, O3InterfaceElement &elt)
bool _checkAttributeOverloadLegality_ (O3Interface &i, O3InterfaceElement &elt)
bool _checkReferenceOverloadLegality_ (O3Interface &i, O3InterfaceElement &elt)
bool _checkCyclicReference_ (O3Interface &i, O3InterfaceElement &elt)

Private Attributes

PRM< GUM_SCALAR > * _prm_
O3PRM_o3_prm_
O3NameSolver< GUM_SCALAR > * _solver_
ErrorsContainer_errors_
HashTable< std::string, std::string > _eltName_
HashTable< std::string, gum::NodeId_nameMap_
HashTable< std::string, O3Interface * > _interfaceMap_
HashTable< NodeId, O3Interface * > _nodeMap_
DAG _dag_
std::vector< O3Interface * > _o3Interface_

Detailed Description

template<GUM_Numeric 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 73 of file O3InterfaceFactory.h.

Constructor & Destructor Documentation

◆ O3InterfaceFactory() [1/3]

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

Definition at line 59 of file O3InterfaceFactory_tpl.h.

62 :
65 }
Bulds gum::prm:PRMInterface from gum::prm::o3prm::O3Interface.
O3InterfaceFactory(PRM< GUM_SCALAR > &prm, O3PRM &o3_prm, O3NameSolver< GUM_SCALAR > &solver, ErrorsContainer &errors)
O3NameSolver< GUM_SCALAR > * _solver_

References O3InterfaceFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Referenced by O3InterfaceFactory(), O3InterfaceFactory(), O3InterfaceFactory(), ~O3InterfaceFactory(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ O3InterfaceFactory() [2/3]

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

Definition at line 68 of file O3InterfaceFactory_tpl.h.

References O3InterfaceFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ O3InterfaceFactory() [3/3]

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

Definition at line 75 of file O3InterfaceFactory_tpl.h.

References O3InterfaceFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ ~O3InterfaceFactory()

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

Definition at line 82 of file O3InterfaceFactory_tpl.h.

References O3InterfaceFactory().

Here is the call graph for this function:

Member Function Documentation

◆ _addArcs2Dag_()

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

Definition at line 148 of file O3InterfaceFactory_tpl.h.

148 {
149 // Adding arcs to the graph inheritance graph
150 for (auto& i: _o3_prm_->interfaces()) {
151 if (i->superLabel().label() != "") {
152 if (!_solver_->resolveInterface(i->superLabel())) { return false; }
153
154 auto head = _nameMap_[i->superLabel().label()];
155 auto tail = _nameMap_[i->name().label()];
156
157 try {
158 _dag_.addArc(tail, head);
159
160 } catch (InvalidDirectedCycle const&) {
161 // Cyclic inheritance
162 O3PRM_INTERFACE_CYCLIC_INHERITANCE(i->name(), i->superLabel(), *_errors_);
163 return false;
164 }
165 }
166 }
167 return true;
168 }
HashTable< std::string, gum::NodeId > _nameMap_

References _dag_, _errors_, _nameMap_, _o3_prm_, and _solver_.

Referenced by _checkO3Interfaces_().

Here is the caller graph for this function:

◆ _addInterface2Dag_()

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

Definition at line 129 of file O3InterfaceFactory_tpl.h.

129 {
130 // Adding nodes to the type inheritance graph
131 for (auto& i: _o3_prm_->interfaces()) {
132 auto id = _dag_.addNode();
133 try {
134 _nameMap_.insert(i->name().label(), id);
135 _interfaceMap_.insert(i->name().label(), i.get());
136 _nodeMap_.insert(id, i.get());
137
138 } catch (DuplicateElement const&) {
139 // Raised if duplicate type names
141 return false;
142 }
143 }
144 return true;
145 }
HashTable< std::string, O3Interface * > _interfaceMap_
HashTable< NodeId, O3Interface * > _nodeMap_

References _dag_, _errors_, _interfaceMap_, _nameMap_, _nodeMap_, and _o3_prm_.

Referenced by _checkO3Interfaces_().

Here is the caller graph for this function:

◆ _checkAttributeOverloadLegality_()

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

Definition at line 245 of file O3InterfaceFactory_tpl.h.

247 {
248 const auto& real_i = _prm_->getInterface(i.name().label());
249 const auto& real_elt = real_i.get(elt.name().label());
250
251 const auto& sub_type = _prm_->type(elt.type().label());
252 const auto& super_type = real_elt.type();
253
254 if (!sub_type.isSubTypeOf(super_type)) {
256 return false;
257 }
258
259 if (sub_type.name() == super_type.name()) {
261 return false;
262 }
263
264 return true;
265 }

References _errors_, _prm_, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Interface::name(), gum::prm::o3prm::O3InterfaceElement::name(), and gum::prm::o3prm::O3InterfaceElement::type().

Referenced by _checkOverloadLegality_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkCyclicReference_()

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

Definition at line 299 of file O3InterfaceFactory_tpl.h.

300 {
301 if (_prm_->isInterface(elt.type().label()) || _prm_->isClass(elt.type().label())) {
303
304 if (_prm_->isInterface(elt.type().label())) {
305 ref_type = &(_prm_->getInterface(elt.type().label()));
306 } else {
307 ref_type = &(_prm_->getClass(elt.type().label()));
308 }
309
310 const auto& real_i = _prm_->getInterface(i.name().label());
311
312 if (&real_i == ref_type) {
314 return false;
315 }
316
317 if (ref_type->isSubTypeOf(real_i)) {
319 return false;
320 }
321 }
322
323 return true;
324 }

References _errors_, _prm_, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Interface::name(), and gum::prm::o3prm::O3InterfaceElement::type().

Referenced by _checkInterfaceElement_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkInterfaceElement_()

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

Definition at line 207 of file O3InterfaceFactory_tpl.h.

208 {
209 if (!_solver_->resolveClassElement(elt.type())) { return false; }
210
211 if (_prm_->isType(elt.type().label()) && elt.isArray()) {
213 return false;
214 }
215
216 const auto& real_i = _prm_->getInterface(i.name().label());
217
218 if (real_i.exists(elt.name().label())) {
219 if (!_checkOverloadLegality_(i, elt)) { return false; }
220 }
221
222 if (!_checkCyclicReference_(i, elt)) { return false; }
223
224 return true;
225 }
bool _checkOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)
bool _checkCyclicReference_(O3Interface &i, O3InterfaceElement &elt)

References _checkCyclicReference_(), _checkOverloadLegality_(), _errors_, _prm_, _solver_, gum::prm::o3prm::O3InterfaceElement::isArray(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Interface::name(), gum::prm::o3prm::O3InterfaceElement::name(), and gum::prm::o3prm::O3InterfaceElement::type().

Referenced by buildElements().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkO3Interfaces_()

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

Definition at line 124 of file O3InterfaceFactory_tpl.h.

References _addArcs2Dag_(), and _addInterface2Dag_().

Referenced by buildInterfaces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkOverloadLegality_()

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

Definition at line 228 of file O3InterfaceFactory_tpl.h.

229 {
230 const auto& real_i = _prm_->getInterface(i.name().label());
231 const auto& real_elt = real_i.get(elt.name().label());
232
235 }
236
239 }
240
241 return false;
242 }
bool _checkAttributeOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)
bool _checkReferenceOverloadLegality_(O3Interface &i, O3InterfaceElement &elt)

References _checkAttributeOverloadLegality_(), _checkReferenceOverloadLegality_(), _prm_, gum::prm::PRMClassElement< GUM_SCALAR >::isAttribute(), gum::prm::PRMClassElement< GUM_SCALAR >::isReferenceSlot(), gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Interface::name(), and gum::prm::o3prm::O3InterfaceElement::name().

Referenced by _checkInterfaceElement_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _checkReferenceOverloadLegality_()

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

Definition at line 268 of file O3InterfaceFactory_tpl.h.

270 {
271 const auto& real_i = _prm_->getInterface(i.name().label());
272 const auto& real_elt
273 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(real_i.get(elt.name().label()));
274
276
277 if (_prm_->isClass(elt.type().label())) {
278 sub_type = &(_prm_->getClass(elt.type().label()));
279 } else {
280 sub_type = &(_prm_->getInterface(elt.type().label()));
281 }
282
283 auto super_type = &(real_elt.slotType());
284
285 if (!sub_type->isSubTypeOf(*super_type)) {
287 return false;
288 }
289
290 if (sub_type->name() == super_type->name()) {
292 return false;
293 }
294
295 return true;
296 }

References _errors_, _prm_, gum::prm::o3prm::O3Label::label(), gum::prm::o3prm::O3Interface::name(), gum::prm::o3prm::O3InterfaceElement::name(), and gum::prm::o3prm::O3InterfaceElement::type().

Referenced by _checkOverloadLegality_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setO3InterfaceCreationOrder_()

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

Definition at line 171 of file O3InterfaceFactory_tpl.h.

171 {
172 auto topo_order = _dag_.topologicalOrder();
173 for (auto id = topo_order.rbegin(); id != topo_order.rend(); --id) {
174 _o3Interface_.push_back(_nodeMap_[*id]);
175 }
176 }
std::vector< O3Interface * > _o3Interface_

References _dag_, _nodeMap_, and _o3Interface_.

Referenced by buildInterfaces().

Here is the caller graph for this function:

◆ buildElements()

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

Definition at line 179 of file O3InterfaceFactory_tpl.h.

179 {
181
182 for (auto i: _o3Interface_) {
183 _prm_->getInterface(i->name().label()).inheritInterface();
184
185 factory.continueInterface(i->name().label());
186
187 for (auto& elt: i->elements()) {
189 try {
190 if (_prm_->isType(elt.type().label())) {
191 factory.addAttribute(elt.type().label(), elt.name().label());
192 } else {
193 factory.addReferenceSlot(elt.type().label(), elt.name().label(), elt.isArray());
194 }
195
196 } catch (OperationNotAllowed const&) {
197 // Duplicate or Wrong overload
199 }
200 }
201 }
202 factory.endInterface();
203 }
204 }
bool _checkInterfaceElement_(O3Interface &i, O3InterfaceElement &elt)

References _checkInterfaceElement_(), _errors_, _o3Interface_, _prm_, gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot(), gum::prm::PRMFactory< GUM_SCALAR >::continueInterface(), and gum::prm::PRMFactory< GUM_SCALAR >::endInterface().

Here is the call graph for this function:

◆ buildInterfaces()

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

Definition at line 109 of file O3InterfaceFactory_tpl.h.

109 {
111 if (_checkO3Interfaces_()) {
113
114 for (auto i: _o3Interface_) {
115 if (_solver_->resolveInterface(i->superLabel())) {
116 factory.startInterface(i->name().label(), i->superLabel().label(), true);
117 factory.endInterface();
118 }
119 }
120 }
121 }

References _checkO3Interfaces_(), _o3Interface_, _prm_, _setO3InterfaceCreationOrder_(), _solver_, gum::prm::PRMFactory< GUM_SCALAR >::endInterface(), and gum::prm::PRMFactory< GUM_SCALAR >::startInterface().

Here is the call graph for this function:

◆ operator=() [1/2]

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

Definition at line 88 of file O3InterfaceFactory_tpl.h.

88 {
89 if (this == &src) { return *this; }
90 _prm_ = src._prm_;
94 return *this;
95 }

References O3InterfaceFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 99 of file O3InterfaceFactory_tpl.h.

99 {
100 if (this == &src) { return *this; }
105 return *this;
106 }

References O3InterfaceFactory(), _errors_, _o3_prm_, _prm_, and _solver_.

Here is the call graph for this function:

Member Data Documentation

◆ _dag_

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

◆ _eltName_

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

Definition at line 95 of file O3InterfaceFactory.h.

◆ _errors_

◆ _interfaceMap_

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

Definition at line 97 of file O3InterfaceFactory.h.

Referenced by _addInterface2Dag_().

◆ _nameMap_

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

Definition at line 96 of file O3InterfaceFactory.h.

Referenced by _addArcs2Dag_(), and _addInterface2Dag_().

◆ _nodeMap_

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

Definition at line 98 of file O3InterfaceFactory.h.

Referenced by _addInterface2Dag_(), and _setO3InterfaceCreationOrder_().

◆ _o3_prm_

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

◆ _o3Interface_

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

◆ _prm_

◆ _solver_

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

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