33 template <
typename GUM_SCALAR >
39 template <
typename GUM_SCALAR >
42 bool delayInheritance) :
44 __superInterface(&super) {
46 if (!delayInheritance) { __inheritInterface(super); }
49 template <
typename GUM_SCALAR >
53 __dag(source.__dag), __superInterface(source.__superInterface) {
58 template <
typename GUM_SCALAR >
62 for (
const auto& elt : __nodeIdMap) {
67 template <
typename GUM_SCALAR >
69 if (__superInterface !=
nullptr) { __inheritInterface(*__superInterface); }
72 template <
typename GUM_SCALAR >
79 attr->
setId(i_attr->id());
80 __nodeIdMap.insert(attr->id(), attr);
81 __attributes.insert(attr);
84 __nameMap.insert(attr->name(), attr);
87 __nameMap.insert(attr->safeName(), attr);
88 __dag.addNodeWithId(attr->id());
99 ref->
setId(i_ref->id());
100 __nodeIdMap.insert(ref->id(), ref);
101 __referenceSlots.insert(ref);
104 __nameMap.insert(ref->name(), ref);
107 __nameMap.insert(ref->safeName(), ref);
108 __dag.addNodeWithId(ref->id());
112 template <
typename GUM_SCALAR >
114 if (__nameMap.exists(elt->
name())) {
116 "name '" << elt->
name()
117 <<
"' is already used by another ClassElement");
123 __nameMap.insert(attr->
name(), attr);
127 __dag.addNodeWithId(attr->
id());
128 __nodeIdMap.insert(attr->
id(), attr);
129 __nameMap.insert(attr->
safeName(), attr);
130 __attributes.insert(attr);
132 if (attr->
type().isSubType()) {
140 __dag.addNodeWithId(elt->
id());
141 __nodeIdMap.insert(elt->
id(), elt);
142 __referenceSlots.insert(
144 __nameMap.insert(elt->
name(), elt);
145 __nameMap.insert(elt->
safeName(), elt);
148 "illegal ClassElement<GUM_SCALAR> for an Interface");
154 template <
typename GUM_SCALAR >
158 if (!super().exists(overloader->
name())) {
160 "found no ClassElement<GUM_SCALAR> to overload");
164 "overload is possible only with sub interfaces");
168 if (overloaded == overloader) {
170 "duplicate ClassElement '" << overloader->
name() <<
"'");
172 if (!__checkOverloadLegality(overloaded, overloader)) {
178 auto attr_overloader =
180 auto attr_overloaded =
182 __overloadAttribute(attr_overloader, attr_overloaded);
187 auto ref_overloader =
189 auto ref_overloaded =
191 __overloadReferenceSlot(ref_overloader, ref_overloaded);
197 auto msg =
"element can ! be overloaded";
207 return overloader->
id();
210 template <
typename GUM_SCALAR >
214 if (overloader->
type() != overloaded->
type()) {
216 __dag.addNodeWithId(overloader->
id());
217 __nodeIdMap.insert(overloader->
id(), overloader);
218 __nameMap[overloader->
name()] = overloader;
219 __nameMap.insert(overloader->
safeName(), overloader);
220 __attributes.insert(overloader);
221 __addCastDescendants(overloader, overloaded);
223 overloader->
setId(overloaded->
id());
224 __nodeIdMap[overloader->
id()] = overloader;
225 __nameMap[overloader->
name()] = overloader;
226 __nameMap[overloader->
safeName()] = overloader;
227 __attributes.erase(overloaded);
228 __attributes.insert(overloader);
237 template <
typename GUM_SCALAR >
242 overloader->
setId(overloaded->
id());
243 __nodeIdMap[overloader->
id()] = overloader;
244 __nameMap[overloader->
name()] = overloader;
245 __nameMap.insert(overloader->
safeName(), overloader);
246 __referenceSlots.insert(overloader);
248 __referenceSlots.erase(overloaded);
249 __nameMap.erase(overloaded->
safeName());
253 template <
typename GUM_SCALAR >
259 while (parent->
type().superType() != end->
type()) {
262 __dag.addNodeWithId(child->
id());
263 __nodeIdMap.insert(child->
id(), child);
265 __nameMap.insert(child->
safeName(), child);
266 __attributes.insert(child);
275 template <
typename GUM_SCALAR >
282 if (!overloader->
type().isSubTypeOf(overloaded->
type())) {
return false; }
285 auto ref_overloader =
287 auto ref_overloaded =
289 if (!ref_overloader->slotType().isSubTypeOf(ref_overloaded->
slotType())) {
298 template <
typename GUM_SCALAR >
309 while (current != 0) {
310 if (current == &(cec))
return true;
324 template <
typename GUM_SCALAR >
339 template <
typename GUM_SCALAR >
342 return __nodeIdMap.
begin();
345 template <
typename GUM_SCALAR >
348 return __nodeIdMap.
end();
351 template <
typename GUM_SCALAR >
354 return __nodeIdMap.
begin();
357 template <
typename GUM_SCALAR >
360 return __nodeIdMap.
end();
363 template <
typename GUM_SCALAR >
365 const std::string& head) {
369 template <
typename GUM_SCALAR >
371 if (__superInterface)
372 return *__superInterface;
377 template <
typename GUM_SCALAR >
380 if (__superInterface)
381 return *__superInterface;
386 template <
typename GUM_SCALAR >
389 __implementations.insert(c);
392 template <
typename GUM_SCALAR >
395 __extensions.insert(i);
398 template <
typename GUM_SCALAR >
404 template <
typename GUM_SCALAR >
410 template <
typename GUM_SCALAR >
416 template <
typename GUM_SCALAR >
422 template <
typename GUM_SCALAR >
425 return PRMObject::prm_type::PRM_INTERFACE;
428 template <
typename GUM_SCALAR >
433 template <
typename GUM_SCALAR >
438 template <
typename GUM_SCALAR >
442 return *(__nodeIdMap[id]);
448 template <
typename GUM_SCALAR >
452 return *(__nodeIdMap[id]);
458 template <
typename GUM_SCALAR >
462 return *(__nameMap[name]);
468 template <
typename GUM_SCALAR >
472 return *(__nameMap[name]);
478 template <
typename GUM_SCALAR >
484 template <
typename GUM_SCALAR >
487 return __referenceSlots;
490 template <
typename GUM_SCALAR >
493 return __implementations;
496 template <
typename GUM_SCALAR >
499 return __implementations;
502 template <
typename GUM_SCALAR >
505 for (
const auto impl : __implementations) {
510 for (
const auto ext : __extensions) {
512 ext->_findAllSubtypes(
set);
516 template <
typename GUM_SCALAR >
520 if (!this->_getIOFlag(elt).second) {
521 for (
auto i : __implementations) {
522 if (i->isOutputNode(elt)) {
return true; }
525 if (__superInterface && __superInterface->isOutputNode(elt)) {
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const =0
Returns a proper cast descendant of this PRMAttribute.
const std::string & name() const
Returns the name of this object.
virtual PRMType & type()=0
See gum::PRMClassElement::type().
Headers of gum::prm::Class<GUM_SCALAR>.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
virtual prm_type obj_type() const =0
Returns the type of this object.
Abstract class representing an element of PRM class.
void _findAllSubtypes(Set< PRMClassElementContainer< GUM_SCALAR > * > &set)
Fills set with all the subtypes of this PRMInterface, this includes extensions and implementations...
gum is the global namespace for all aGrUM entities
Headers of gum::prm::PRMInterface.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject)...
Representation of a setA Set is a structure that contains arbitrary elements.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
prm_type
Enumeration of the different types of objects handled by a PRM.
HashTable< std::string, PRMClassElement< GUM_SCALAR > *> __nameMap
Mapping between a member's name and itself. Used for fast access to a member given it's name...
virtual void overload(PRMAttribute< GUM_SCALAR > *source)
Set this as overload of source (necessayr to preserver internal pointers for MultiDims).
PRMInterface(const std::string &name)
Default constructor.
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
NodeId nextNodeId()
Returns the next value of an unique counter for PRM's node id.
<agrum/PRM/classElementContainer.h>
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual void setId(NodeId id)
Used to assign the id of this element.
Set< PRMAttribute< GUM_SCALAR > *> __attributes
The sequence of PRMAttribute<GUM_SCALAR>s.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
virtual void setAsCastDescendant(PRMAttribute< GUM_SCALAR > *attr)=0
Define attr as a cast descendant of this PRMAttribute.
const ClassEltIterator & end()
PRMInterface< GUM_SCALAR > * __superInterface
The alternate PRMClassElementContainer<GUM_SCALAR> searched for elements defined in this...
Set< PRMReferenceSlot< GUM_SCALAR > *> __referenceSlots
The sequence of PRMReferenceSlot<GUM_SCALAR>.
PRMAttribute is a member of a Class in a PRM.
<agrum/PRM/elements/scalarAttribute.h>
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)