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

Factory which builds a PRM<GUM_SCALAR>. More...

#include <PRMFactory.h>

Inheritance diagram for gum::prm::PRMFactory< GUM_SCALAR >:
Collaboration diagram for gum::prm::PRMFactory< GUM_SCALAR >:

Public Member Functions

Constructors & destructor
 PRMFactory ()
 Default constructor.
 PRMFactory (PRM< GUM_SCALAR > *prm)
 This constructor let you set on which PRM instance the factory works.
 PRMFactory (const PRMFactory &from)=delete
 Copy constructor. Don't use it.
PRMFactoryoperator= (const PRMFactory &from)=delete
 Copy operator. Don't use it.
virtual ~PRMFactory ()
 Destructor.
Getters & Setters
PRM< GUM_SCALAR > * prm () const
 Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
virtual PRMObject::prm_type currentType () const override
virtual PRMObjectgetCurrent () override
virtual const PRMObjectgetCurrent () const override
 Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
virtual PRMObjectcloseCurrent () override
 Close current object being built.
virtual std::string currentPackage () const override
PRMClass< GUM_SCALAR > & retrieveClass (const std::string &name)
 Returns a reference over a Class<GUM_SCALAR> given its name.
PRMTyperetrieveType (const std::string &name)
 Returns a reference over a PRMType given its name.
PRMTyperetrieveCommonType (const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
 Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
Package construction methods.
virtual void pushPackage (const std::string &name) override
 Define the current package.
virtual std::string popPackage () override
 Pop the current package from the package stack.
virtual void addImport (const std::string &name) override
 Add an import for namespace lookup.
PRMType construction methods.
virtual void startDiscreteType (const std::string &name, std::string super="") override
 Start a discrete subtype declaration.
virtual void addLabel (const std::string &l, std::string ext="") override
 Add a label to the current discrete type.
virtual void endDiscreteType () override
 End the current discrete type declaration.
virtual void startDiscretizedType (const std::string &name) override
 Start a discretized type declaration.
virtual void addTick (double tick) override
 Add a tick to the current discretized type.
virtual void endDiscretizedType () override
 End the current discretized type declaration.
virtual void addRangeType (const std::string &name, long minVal, long maxVal) override
 Add a range variable type declaration.
several checks for parsers
virtual bool isClassOrInterface (const std::string &type) const override
virtual bool isArrayInCurrentSystem (const std::string &name) const override
Class<GUM_SCALAR> construction models.
virtual void startClass (const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
 Tells the factory that we start a class declaration.
virtual void continueClass (const std::string &c) override
 Continue the declaration of a class.
virtual void endClass (bool checkImplementations=true) override
 Tells the factory that we finished a class declaration.
PRMInterface<GUM_SCALAR> construction models.
virtual void startInterface (const std::string &i, const std::string &ext="", bool delayInheritance=false) override
 Tells the factory that we start an interface declaration.
virtual void continueInterface (const std::string &name) override
 Continue the declaration of an interface.
virtual void addAttribute (const std::string &type, const std::string &name) override
 Add an attribute to an interface.
virtual void endInterface () override
 Tells the factory that we finished an interface declaration.
Attributes construction methods.
virtual void addAttribute (PRMAttribute< GUM_SCALAR > *attr)
 Add an already created attribute to the current class.
virtual void startAttribute (const std::string &type, const std::string &name, bool scalar_atttr=false) override
 Tells the factory that we start an attribute declaration.
virtual void continueAttribute (const std::string &name) override
 Continues the declaration of an attribute.
virtual void addParent (const std::string &name) override
 Tells the factory that we add a parent to the current declared attribute.
void setRawCPFByLines (const std::vector< GUM_SCALAR > &array)
 Gives the factory the CPF in its raw form.
void setRawCPFByColumns (const std::vector< GUM_SCALAR > &array)
 Gives the factory the CPF in its raw form.
virtual void setCPFByRule (const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
 Fills the CPF using a rule.
virtual void setCPFByRule (const std::vector< std::string > &labels, const std::vector< std::string > &values) override
 Fills the CPF using a rule and gum::Formula.
virtual void setRawCPFByFloatLines (const std::vector< float > &array) override
 Gives the factory the CPF in its raw form.
virtual void setRawCPFByFloatColumns (const std::vector< float > &array) override
 Gives the factory the CPF in its raw form.
virtual void setRawCPFByColumns (const std::vector< std::string > &array) override
 Gives the factory the CPF in its raw form use gum::Formula.
virtual void setRawCPFByLines (const std::vector< std::string > &array) override
 Gives the factory the CPF in its raw form using gum::Formula.
virtual void setCPFByFloatRule (const std::vector< std::string > &labels, const std::vector< float > &values) override
 Fills the CPF using a rule.
virtual void endAttribute () override
 Tells the factory that we finished declaring an attribute.
Parameters construction methods.
void addParameter (const std::string &type, const std::string &name, double value) override
 Add a parameter to the current class with a default value.
Aggregator and function construction methods.
virtual void addAggregator (const std::string &name, const std::string &agg_type, const std::vector< std::string > &chains, const std::vector< std::string > &params, std::string type="") override
 Add an aggregator in the current declared class.
void startAggregator (const std::string &name, const std::string &agg_type, const std::string &rv_type, const std::vector< std::string > &params)
 Start an aggregator declaration.
void continueAggregator (const std::string &name)
 Conitnues an aggregator declaration.
void endAggregator ()
 Finishes an aggregate declaration.
virtual void addNoisyOrCompound (const std::string &name, const std::vector< std::string > &chains, const std::vector< float > &numbers, float leak, const std::vector< std::string > &label) override
 Add a compound noisy-or as an PRMAttribute<GUM_SCALAR> to the current Class<GUM_SCALAR>.
PRMReferenceSlot<GUM_SCALAR> construction methods.
virtual void addReferenceSlot (const std::string &type, const std::string &name, bool isArray) override
 Tells the factory that we started declaring a slot.
Systems constructions methods.
virtual void startSystem (const std::string &name) override
 Tells the factory that we started declaring a model.
virtual void endSystem () override
 Tells the factory that we finished declaring a model.
virtual void addInstance (const std::string &type, const std::string &name) override
 Add an instance to the model.
void addInstance (const std::string &type, const std::string &name, const HashTable< std::string, double > &params) override
 Add an instance with params as values of type's parameters.
virtual void addArray (const std::string &type, const std::string &name, Size size) override
 Creates an array with the given number of instances of the given type.
virtual void incArray (const std::string &l_i, const std::string &r_i) override
 Add an instance to an array.
virtual void setReferenceSlot (const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
 Instantiate a reference in the current model.
virtual void setReferenceSlot (const std::string &l_i, const std::string &r_i) override
 Instantiate a reference in the current model.

Private Member Functions

Private methods for type checking and exception handling.
std::string _addPrefix_ (const std::string &str) const
 Adds prefix to str iff prefix != "".
PRMObject_checkStack_ (Idx i, PRMObject::prm_type obj_type)
 Return a pointer on a PRMObject at stack.size() - i position after checking the type of the object given obj_type.
PRMClassElement< GUM_SCALAR > * _checkStack_ (Idx i, typename PRMClassElement< GUM_SCALAR >::ClassElementType obj_type)
 Adds prefix to str iff prefix != "".
PRMClassElementContainer< GUM_SCALAR > * _checkStackContainter_ (Idx i)
 Adds prefix to str iff prefix != "".
Private getters
PRMType_retrieveType_ (const std::string &name) const
 Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local name (without the prefix), full name (with the prefix) or can come from an import unit, or maybe one day with a using declaration we need some processing to find it.
PRMClass< GUM_SCALAR > * _retrieveClass_ (const std::string &name) const
 Returns a pointer on a class given it's name. Used when building models, meaning that the class name can either be local (need to add the current prefix) or global (no prefix needed).
PRMInterface< GUM_SCALAR > * _retrieveInterface_ (const std::string &name) const
 Returns a pointer on an interface given it's name. Used when building models, meaning that the interface name can either be local (need to add the current prefix) or global (no prefix needed).
Private methods handling Class<GUM_SCALAR> and
PRMSlotChain< GUM_SCALAR > * _buildSlotChain_ (PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
 This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
bool _retrieveInputs_ (PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
 Retrieve inputs for an PRMAggregate.
PRMType_retrieveCommonType_ (const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
 Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
int _typeDepth_ (const PRMType *t)
 Returns the inheritance depth of a PRMType.
void _checkInterfaceImplementation_ (PRMClass< GUM_SCALAR > *c)
 Check if c implements correctly all his interfaces.
void _addParent_ (PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
 Add a parent to an attribute.
void _addParent_ (PRMClass< GUM_SCALAR > *c, PRMAggregate< GUM_SCALAR > *agg, const std::string &name)
 Add a parent to an aggregate.
Private methods handling PRMSystem<GUM_SCALAR> and
void _addInstance_ (PRMClass< GUM_SCALAR > *type, const std::string &name)
 Adds a instance to the current model.
void _buildAggregateCPF_ (PRMSystem< GUM_SCALAR > *model)
 Builds all Aggregates CPF in the given model. This must be called after all the slot chains have been generated.
void _instantiateSlotChain_ (PRMSystem< GUM_SCALAR > *model, PRMInstance< GUM_SCALAR > *inst, PRMReferenceSlot< GUM_SCALAR > *ref, PRMSlotChain< GUM_SCALAR > *sc)
 Instantiate a slot chain in the given instance.
std::string _retrieveInstanceSequence_ (PRMInstance< GUM_SCALAR > *inst, Sequence< PRMInstance< GUM_SCALAR > * > &seq, PRMSlotChain< GUM_SCALAR > *sc)
 Fill seq with the sequence of instance build using inst as the instantiation of sc-> class and seeking each instantiation of reference in sc.

Private Attributes

Private members.
std::vector< std::string > _packages_
 The prefix used for classes and types names. It is normally the namespace of the corresponding compilation unit.
std::vector< List< std::string > * > _namespaces_
 Set of all declared namespaces.
PRM< GUM_SCALAR > * _prm_
 The pointer on the PRM<GUM_SCALAR> built by this factory.
std::vector< PRMObject * > _stack_
 A stack used to keep track of created PRMObject.
HashTable< PRMAggregate< GUM_SCALAR > *, std::vector< std::string > > _agg_params_
 A mapping between aggregators and their parameters.

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::PRMFactory< GUM_SCALAR >

Factory which builds a PRM<GUM_SCALAR>.

The Factory always create one PRM<GUM_SCALAR> which is not deleted with the factory, so be very careful to delete the PRM<GUM_SCALAR> built by this factory.

The factory does not allow any sequence of calls, if you call a method when the factory is in an incoherent state it will raise a FactoryInvalidState exception.

Keep in mind that most methods could raise gum::FatalError if something unexpected happens, since the framework is meant to evolve it is possible.

See also
PRM<GUM_SCALAR> PRMObject

Definition at line 88 of file PRMFactory.h.

Constructor & Destructor Documentation

◆ PRMFactory() [1/3]

template<typename GUM_SCALAR>
INLINE gum::prm::PRMFactory< GUM_SCALAR >::PRMFactory ( )

Default constructor.

Definition at line 1309 of file PRMFactory_tpl.h.

1309 {
1311 _prm_ = new PRM< GUM_SCALAR >();
1312 }
Factory which builds a PRM<GUM_SCALAR>.
Definition PRMFactory.h:88
PRMFactory()
Default constructor.
PRM< GUM_SCALAR > * _prm_
The pointer on the PRM<GUM_SCALAR> built by this factory.

References PRMFactory(), and _prm_.

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

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

◆ PRMFactory() [2/3]

template<typename GUM_SCALAR>
INLINE gum::prm::PRMFactory< GUM_SCALAR >::PRMFactory ( PRM< GUM_SCALAR > * prm)

This constructor let you set on which PRM instance the factory works.

Definition at line 1315 of file PRMFactory_tpl.h.

1315 :
1316 IPRMFactory(), _prm_(prm) {
1318 }
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.

References PRMFactory(), _prm_, and prm().

Here is the call graph for this function:

◆ PRMFactory() [3/3]

template<typename GUM_SCALAR>
gum::prm::PRMFactory< GUM_SCALAR >::PRMFactory ( const PRMFactory< GUM_SCALAR > & from)
delete

Copy constructor. Don't use it.

References PRMFactory().

Here is the call graph for this function:

◆ ~PRMFactory()

template<typename GUM_SCALAR>
INLINE gum::prm::PRMFactory< GUM_SCALAR >::~PRMFactory ( )
virtual

Destructor.

Definition at line 1321 of file PRMFactory_tpl.h.

1321 {
1323 while (!_namespaces_.empty()) {
1324 auto ns = _namespaces_.back();
1325 _namespaces_.pop_back();
1326 delete ns;
1327 }
1328 }
std::vector< List< std::string > * > _namespaces_
Set of all declared namespaces.

References PRMFactory(), and _namespaces_.

Here is the call graph for this function:

Member Function Documentation

◆ _addInstance_()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::_addInstance_ ( PRMClass< GUM_SCALAR > * type,
const std::string & name )
private

Adds a instance to the current model.

Definition at line 1676 of file PRMFactory_tpl.h.

1677 {
1678 PRMInstance< GUM_SCALAR >* i = nullptr;
1679 try {
1680 auto s
1683 s->add(i);
1684
1685 } catch (OperationNotAllowed const&) {
1686 if (i) { delete i; }
1687 throw;
1688 }
1689 }
PRMObject * _checkStack_(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at stack.size() - i position after checking the type of the object gi...

References _checkStack_(), and gum::prm::PRMObject::SYSTEM.

Referenced by addInstance(), and addInstance().

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

◆ _addParent_() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::_addParent_ ( PRMClass< GUM_SCALAR > * c,
PRMAggregate< GUM_SCALAR > * agg,
const std::string & name )
private

Add a parent to an aggregate.

Definition at line 608 of file PRMFactory_tpl.h.

610 {
614
615 switch (agg->agg_type()) {
618 if (inputs.front()->type() != *(_retrieveType_("boolean"))) {
619 GUM_ERROR(TypeError, "expected booleans")
620 }
621
622 break;
623 }
624
628 if (!agg->hasLabel()) {
629 auto param = agg->labelValue();
630 Idx label_idx = 0;
631
632 while (label_idx < inputs.front()->type()->domainSize()) {
633 if (inputs.front()->type()->label(label_idx) == param) { break; }
634
635 ++label_idx;
636 }
637
638 if (label_idx == inputs.front()->type()->domainSize()) {
639 GUM_ERROR(NotFound, "could not find label")
640 }
641
642 agg->setLabel(label_idx);
643 }
644
645 break;
646 }
647
653 break;
654 }
655
656 default : {
657 GUM_ERROR(FatalError, "Unknown aggregator.")
658 }
659 }
660
661 c->addArc(inputs.front()->safeName(), agg->safeName());
662 }
bool _retrieveInputs_(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
PRMType * _retrieveType_(const std::string &name) const
Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local na...
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _retrieveInputs_(), _retrieveType_(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMAggregate< GUM_SCALAR >::agg_type(), gum::prm::PRMAggregate< GUM_SCALAR >::AMPLITUDE, gum::prm::PRMAggregate< GUM_SCALAR >::AND, gum::prm::PRMAggregate< GUM_SCALAR >::COUNT, gum::prm::PRMAggregate< GUM_SCALAR >::EXISTS, gum::prm::PRMAggregate< GUM_SCALAR >::FORALL, GUM_ERROR, gum::prm::PRMAggregate< GUM_SCALAR >::hasLabel(), gum::prm::PRMAggregate< GUM_SCALAR >::labelValue(), gum::prm::PRMAggregate< GUM_SCALAR >::MAX, gum::prm::PRMAggregate< GUM_SCALAR >::MEDIAN, gum::prm::PRMAggregate< GUM_SCALAR >::MIN, gum::prm::PRMAggregate< GUM_SCALAR >::OR, gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAggregate< GUM_SCALAR >::setLabel(), and gum::prm::PRMAggregate< GUM_SCALAR >::SUM.

Here is the call graph for this function:

◆ _addParent_() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::_addParent_ ( PRMClassElementContainer< GUM_SCALAR > * c,
PRMAttribute< GUM_SCALAR > * agg,
const std::string & name )
private

Add a parent to an attribute.

Definition at line 253 of file PRMFactory_tpl.h.

255 {
256 try {
258
259 switch (elt.elt_type()) {
262 "can not add a reference slot as a parent of an attribute")
263 break;
264 }
265
267 if (static_cast< PRMSlotChain< GUM_SCALAR >& >(elt).isMultiple()) {
268 GUM_ERROR(OperationNotAllowed, "can not add a multiple slot chain to an attribute")
269 }
270
271 c->addArc(name, a->name());
272
273 break;
274 }
275
278 c->addArc(name, a->name());
279 break;
280 }
281
282 default : {
283 GUM_ERROR(FatalError, "unknown ClassElement<GUM_SCALAR>")
284 }
285 }
286 } catch (NotFound const&) {
287 // Check if name is a slot chain
289
290 if (sc == nullptr) {
291 std::string msg = "found no ClassElement<GUM_SCALAR> with the given name ";
293 } else if (!sc->isMultiple()) {
294 c->add(sc);
295 c->addArc(sc->name(), a->name());
296 } else {
297 delete sc;
299 "Impossible to add a multiple reference slot as"
300 " direct parent of an PRMAttribute<GUM_SCALAR>.");
301 }
302 }
303 }
PRMSlotChain< GUM_SCALAR > * _buildSlotChain_(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.

References _buildSlotChain_(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::add(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::addArc(), gum::prm::PRMClassElement< GUM_SCALAR >::elt_type(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMSlotChain< GUM_SCALAR >::isMultiple(), gum::prm::PRMObject::name(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::prm::PRMClassElement< GUM_SCALAR >::prm_refslot, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_slotchain.

Referenced by addParent().

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

◆ _addPrefix_()

template<typename GUM_SCALAR>
INLINE std::string gum::prm::PRMFactory< GUM_SCALAR >::_addPrefix_ ( const std::string & str) const
private

Adds prefix to str iff prefix != "".

Definition at line 1692 of file PRMFactory_tpl.h.

1692 {
1693 if (!_packages_.empty()) {
1695 full_name.append(".");
1696 full_name.append(str);
1697 return full_name;
1698 } else {
1699 return str;
1700 }
1701 }
std::vector< std::string > _packages_
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...

References _packages_.

Referenced by _retrieveClass_(), _retrieveInterface_(), _retrieveType_(), addRangeType(), continueClass(), continueInterface(), startClass(), startDiscreteType(), startDiscretizedType(), startInterface(), and startSystem().

Here is the caller graph for this function:

◆ _buildAggregateCPF_()

template<typename GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::_buildAggregateCPF_ ( PRMSystem< GUM_SCALAR > * model)
private

Builds all Aggregates CPF in the given model. This must be called after all the slot chains have been generated.

◆ _buildSlotChain_()

template<typename GUM_SCALAR>
INLINE PRMSlotChain< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_buildSlotChain_ ( PRMClassElementContainer< GUM_SCALAR > * start,
const std::string & name )
private

This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.

Returns
Return a pointer over a PRMSlotChain<GUM_SCALAR> or 0 if no PRMSlotChain<GUM_SCALAR> could be built.

Definition at line 933 of file PRMFactory_tpl.h.

934 {
940
941 for (size_t i = 0; i < v.size(); ++i) {
942 try {
943 switch (current->get(v[i]).elt_type()) {
945 ref = &(static_cast< PRMReferenceSlot< GUM_SCALAR >& >(current->get(v[i])));
946 elts.insert(ref);
947 current = &(/*const_cast<PRMClassElementContainer<GUM_SCALAR>&>*/ (ref->slotType()));
948 break;
949
952
953 if (i == v.size() - 1) {
954 elts.insert(&(current->get(v[i])));
955 break;
956 } else {
957 return nullptr;
958 }
959
960 default : {
961 return nullptr;
962 }
963 }
964 } catch (NotFound const&) { return nullptr; }
965 }
966
967 GUM_ASSERT(v.size() == elts.size());
968
969 current->setOutputNode(*(elts.back()), true);
970
972 }

References gum::SequenceImplementation< Key, Gen >::back(), gum::prm::decomposePath(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), gum::SequenceImplementation< Key, Gen >::insert(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::prm::PRMClassElement< GUM_SCALAR >::prm_refslot, gum::prm::PRMClassElementContainer< GUM_SCALAR >::setOutputNode(), gum::SequenceImplementation< Key, Gen >::size(), and gum::prm::PRMReferenceSlot< GUM_SCALAR >::slotType().

Referenced by _addParent_(), _retrieveInputs_(), and addNoisyOrCompound().

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

◆ _checkInterfaceImplementation_()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::_checkInterfaceImplementation_ ( PRMClass< GUM_SCALAR > * c)
private

Check if c implements correctly all his interfaces.

Definition at line 121 of file PRMFactory_tpl.h.

121 {
122 try {
123 for (const auto& i: c->implements()) {
124 try {
125 for (const auto& node: i->containerDag().nodes()) {
126 std::string name = i->get(node).name();
127
128 switch (i->get(node).elt_type()) {
131 if ((c->get(name).elt_type() == PRMClassElement< GUM_SCALAR >::prm_attribute)
132 || (c->get(name).elt_type()
134 if (!c->get(name).type().isSubTypeOf(i->get(name).type())) {
136 msg << "class " << c->name() << " does not respect interface ";
137 GUM_ERROR(PRMTypeError, msg.str() + i->name())
138 }
139 } else {
141 msg << "class " << c->name() << " does not respect interface ";
142 GUM_ERROR(PRMTypeError, msg.str() + i->name())
143 }
144
145 break;
146 }
147
149 if (c->get(name).elt_type() == PRMClassElement< GUM_SCALAR >::prm_refslot) {
151 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(i->get(name));
153 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(c->get(name));
154
155 if (!ref_this.slotType().isSubTypeOf(ref_i.slotType())) {
157 msg << "class " << c->name() << " does not respect interface ";
158 GUM_ERROR(PRMTypeError, msg.str() + i->name())
159 }
160 } else {
162 msg << "class " << c->name() << " does not respect interface ";
163 GUM_ERROR(PRMTypeError, msg.str() + i->name())
164 }
165
166 break;
167 }
168
170 // Nothing to check: they are automatically inherited
171 break;
172 }
173
174 default : {
175 std::string msg = "unexpected ClassElement<GUM_SCALAR> in interface ";
176 GUM_ERROR(FatalError, msg + i->name())
177 }
178 }
179 }
180 } catch (NotFound const&) {
182 msg << "class " << c->name() << " does not respect interface ";
183 GUM_ERROR(PRMTypeError, msg.str() + i->name())
184 }
185 }
186 } catch (NotFound const&) {
187 // this Class<GUM_SCALAR> does not implement any
188 // PRMInterface<GUM_SCALAR>
189 }
190 }

References gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMClass< GUM_SCALAR >::implements(), gum::prm::PRMObject::name(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::prm::PRMClassElement< GUM_SCALAR >::prm_refslot, gum::prm::PRMClassElement< GUM_SCALAR >::prm_slotchain, and gum::prm::PRMReferenceSlot< GUM_SCALAR >::slotType().

Referenced by endClass().

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

◆ _checkStack_() [1/2]

template<typename GUM_SCALAR>
INLINE PRMObject * gum::prm::PRMFactory< GUM_SCALAR >::_checkStack_ ( Idx i,
PRMObject::prm_type obj_type )
private

Return a pointer on a PRMObject at stack.size() - i position after checking the type of the object given obj_type.

Exceptions
FactoryInvalidStateRaised if the stack isn't consistent with the

Definition at line 1704 of file PRMFactory_tpl.h.

1704 {
1705 // Don't forget that Idx are unsigned int
1706 if (_stack_.size() - i > _stack_.size()) {
1707 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1708 }
1709
1710 PRMObject* obj = _stack_[_stack_.size() - i];
1711
1712 if (obj->obj_type() != obj_type) {
1713 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1714 }
1715
1716 return obj;
1717 }
std::vector< PRMObject * > _stack_
A stack used to keep track of created PRMObject.

References _stack_, GUM_ERROR, and gum::prm::PRMObject::obj_type().

Referenced by _addInstance_(), addAggregator(), addArray(), addAttribute(), addAttribute(), addLabel(), addParameter(), addParent(), addTick(), endAggregator(), endAttribute(), endClass(), endDiscreteType(), endDiscretizedType(), endInterface(), endSystem(), incArray(), setCPFByFloatRule(), setCPFByRule(), setCPFByRule(), setRawCPFByColumns(), setRawCPFByColumns(), setRawCPFByFloatColumns(), setRawCPFByFloatLines(), setRawCPFByLines(), setRawCPFByLines(), setReferenceSlot(), and startAggregator().

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

◆ _checkStack_() [2/2]

template<typename GUM_SCALAR>
INLINE PRMClassElement< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_checkStack_ ( Idx i,
typename PRMClassElement< GUM_SCALAR >::ClassElementType obj_type )
private

Adds prefix to str iff prefix != "".

Definition at line 1738 of file PRMFactory_tpl.h.

1740 {
1741 // Don't forget that Idx are unsigned int
1742 if (_stack_.size() - i > _stack_.size()) {
1743 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1744 }
1745
1747 = dynamic_cast< PRMClassElement< GUM_SCALAR >* >(_stack_[_stack_.size() - i]);
1748
1749 if (obj == 0) { GUM_ERROR(FactoryInvalidState, "illegal sequence of calls") }
1750
1751 if (obj->elt_type() != elt_type) {
1752 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1753 }
1754
1755 return obj;
1756 }

References _stack_, gum::prm::PRMClassElement< GUM_SCALAR >::elt_type(), and GUM_ERROR.

Here is the call graph for this function:

◆ _checkStackContainter_()

template<typename GUM_SCALAR>
INLINE PRMClassElementContainer< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_checkStackContainter_ ( Idx i)
private

Adds prefix to str iff prefix != "".

Definition at line 1721 of file PRMFactory_tpl.h.

1721 {
1722 // Don't forget that Idx are unsigned int
1723 if (_stack_.size() - i > _stack_.size()) {
1724 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1725 }
1726
1727 PRMObject* obj = _stack_[_stack_.size() - i];
1728
1729 if ((obj->obj_type() == PRMObject::prm_type::CLASS)
1730 || (obj->obj_type() == PRMObject::prm_type::PRM_INTERFACE)) {
1731 return static_cast< PRMClassElementContainer< GUM_SCALAR >* >(obj);
1732 } else {
1733 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1734 }
1735 }

References _stack_, gum::prm::PRMObject::CLASS, GUM_ERROR, gum::prm::PRMObject::obj_type(), and gum::prm::PRMObject::PRM_INTERFACE.

Referenced by addParent(), addReferenceSlot(), continueAggregator(), continueAttribute(), and startAttribute().

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

◆ _instantiateSlotChain_()

template<typename GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::_instantiateSlotChain_ ( PRMSystem< GUM_SCALAR > * model,
PRMInstance< GUM_SCALAR > * inst,
PRMReferenceSlot< GUM_SCALAR > * ref,
PRMSlotChain< GUM_SCALAR > * sc )
private

Instantiate a slot chain in the given instance.

◆ _retrieveClass_()

template<typename GUM_SCALAR>
PRMClass< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveClass_ ( const std::string & name) const
private

Returns a pointer on a class given it's name. Used when building models, meaning that the class name can either be local (need to add the current prefix) or global (no prefix needed).

Exceptions
NotFoundIf no class matching the name is found.
See also
PRMFactory:: retrieveType

Definition at line 1212 of file PRMFactory_tpl.h.

1212 {
1215
1216 // Looking for the type using its name
1217 if (_prm_->_classMap_.exists(name)) {
1218 a_class = _prm_->_classMap_[name];
1219 full_name = name;
1220 }
1221
1222 // Looking for the type using current package
1224 if (_prm_->_classMap_.exists(prefixed)) {
1225 if (a_class == nullptr) {
1226 a_class = _prm_->_classMap_[prefixed];
1228 } else if (full_name != prefixed) {
1230 "Class name '" << name << "' is ambiguous: specify full name.");
1231 }
1232 }
1233
1234 // Looking for the class using all declared namespaces
1235 if (!_namespaces_.empty()) {
1236 auto ns_list = _namespaces_.back();
1237 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1238 std::string ns = (*ns_list)[i];
1239 std::string ns_name = ns + "." + name;
1240 if (_prm_->_classMap_.exists(ns_name)) {
1241 if (a_class == 0) {
1242 a_class = _prm_->_classMap_[ns_name];
1244 } else if (full_name != ns_name) {
1246 "Class name '" << name << "' is ambiguous: specify full name.");
1247 }
1248 }
1249 }
1250 }
1251
1252 if (a_class == 0) { GUM_ERROR(NotFound, "Class '" << name << "' not found, check imports.") }
1253
1254 return a_class;
1255 }
std::string _addPrefix_(const std::string &str) const
Adds prefix to str iff prefix != "".

References _addPrefix_(), _namespaces_, _prm_, and GUM_ERROR.

Referenced by addArray(), addInstance(), addInstance(), addReferenceSlot(), isClassOrInterface(), retrieveClass(), and startClass().

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

◆ _retrieveCommonType_()

template<typename GUM_SCALAR>
INLINE PRMType * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_ ( const std::vector< PRMClassElement< GUM_SCALAR > * > & elts)
private

Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.

The vector elts must only contains PRMClassElement<GUM_SCALAR> with a PRMType, i.e. PRMAttribute<GUM_SCALAR>, PRMAggregate and PRMSlotChain<GUM_SCALAR>. If not a WrongClassElement is raised.

A common PRMType is PRMType t such as t.isSuperTypeOf(elts[i]) for 0 < i < elts.size(), where elts is a PRMType container.

Parameters
eltsA vector of PRMClassElement<GUM_SCALAR>.
Returns
Returns the common super PRMType of all PRMClassElement<GUM_SCALAR> un elts.
Exceptions
WrongClassElementRaised if elts contains a PRMClassElement<GUM_SCALAR> without a PRMType.
NotFoundRaised if there exists no common super type of all PRMClassElement<GUM_SCALAR> in elts.

Definition at line 1031 of file PRMFactory_tpl.h.

1032 {
1033 const PRMType* current = nullptr;
1035 // Finding all types and super types
1036
1037 for (const auto& elt: elts) {
1038 try {
1039 current = &((*elt).type());
1040
1041 while (current != 0) {
1042 // Filling counters
1043 if (counters.exists(current->name())) {
1044 ++(counters[current->name()]);
1045 } else {
1046 counters.insert(current->name(), 1);
1047 }
1048
1049 // Loop guard
1050 if (current->isSubType()) {
1051 current = &(current->superType());
1052 } else {
1053 current = nullptr;
1054 }
1055 }
1056 } catch (OperationNotAllowed const&) {
1057 GUM_ERROR(WrongClassElement, "found a ClassElement<GUM_SCALAR> without a type")
1058 }
1059 }
1060
1061 // We need to find the most specialized (i.e. max depth) common type
1062 current = nullptr;
1063
1064 int max_depth = -1;
1065
1066 int current_depth = 0;
1067
1068 for (const auto& elt: counters) {
1069 if ((elt.second) == elts.size()) {
1071
1072 if (current_depth > max_depth) {
1074 current = _retrieveType_(elt.first);
1075 }
1076 }
1077 }
1078
1079 if (current) { return const_cast< PRMType* >(current); }
1080
1081 GUM_ERROR(NotFound, "could not find a common type")
1082 }
int _typeDepth_(const PRMType *t)
Returns the inheritance depth of a PRMType.

References _retrieveType_(), _typeDepth_(), gum::HashTable< Key, Val >::exists(), GUM_ERROR, gum::HashTable< Key, Val >::insert(), and gum::Variable::name().

Referenced by _retrieveInputs_(), addNoisyOrCompound(), and retrieveCommonType().

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

◆ _retrieveInputs_()

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMFactory< GUM_SCALAR >::_retrieveInputs_ ( PRMClass< GUM_SCALAR > * c,
const std::vector< std::string > & chains,
std::vector< PRMClassElement< GUM_SCALAR > * > & inputs )
private

Retrieve inputs for an PRMAggregate.

The vector chains contains names of the PRMAggregate inputs. If a name does not match an existing PRMClassElement<GUM_SCALAR> in c, then a call to PRMFactory:: buildSlotChains() is made. Such created PRMSlotChain<GUM_SCALAR> are added to c.

Parameters
cThe class in which the PRMAggregate is defined.
chainsVector of the PRMAggregate inputs names.
inputsVector filled with the PRMClassElement<GUM_SCALAR> matching the names in chains.
Returns
true if there was at least one slotchain in chains.
Exceptions
NotFoundRaised if a name in chains does not match a legal PRMSlotChain<GUM_SCALAR> or an existing PRMClassElement<GUM_SCALAR> in c.

Definition at line 975 of file PRMFactory_tpl.h.

978 {
979 bool retVal = false;
980
981 for (size_t i = 0; i < chains.size(); ++i) {
982 try {
983 inputs.push_back(&(c->get(chains[i])));
985 } catch (NotFound const&) {
986 inputs.push_back(_buildSlotChain_(c, chains[i]));
987 retVal = true;
988
989 if (inputs.back()) {
990 c->add(inputs.back());
991 } else {
992 GUM_ERROR(NotFound, "unknown slot chain")
993 }
994 }
995 }
996
998
1000 toAdd;
1001
1002 for (const auto& elt: inputs) {
1003 if ((*elt).type() != (*t)) {
1007
1008 for (Size idx = 0; idx < sc->chain().size() - 1; ++idx) {
1009 name << sc->chain().atPos(idx)->name() << ".";
1010 }
1011
1012 name << ".(" << t->name() << ")" << sc->lastElt().name();
1013
1014 try {
1015 toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1016 } catch (NotFound const&) {
1017 toAdd.push_back(std::make_pair(elt, _buildSlotChain_(c, name.str())));
1018 }
1019 } else {
1021 name << "(" << t->name() << ")" << elt->name();
1022 toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1023 }
1024 }
1025 }
1026
1027 return retVal;
1028 }
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
PRMType * _retrieveCommonType_(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.

References _buildSlotChain_(), _retrieveCommonType_(), gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMSlotChain< GUM_SCALAR >::chain(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::isSlotChain(), gum::prm::PRMSlotChain< GUM_SCALAR >::lastElt(), and gum::Variable::name().

Referenced by _addParent_(), and addAggregator().

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

◆ _retrieveInstanceSequence_()

template<typename GUM_SCALAR>
std::string gum::prm::PRMFactory< GUM_SCALAR >::_retrieveInstanceSequence_ ( PRMInstance< GUM_SCALAR > * inst,
Sequence< PRMInstance< GUM_SCALAR > * > & seq,
PRMSlotChain< GUM_SCALAR > * sc )
private

Fill seq with the sequence of instance build using inst as the instantiation of sc-> class and seeking each instantiation of reference in sc.

Returns
Returns the name of the corresponding PRMSlotChain<GUM_SCALAR>.

◆ _retrieveInterface_()

template<typename GUM_SCALAR>
PRMInterface< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveInterface_ ( const std::string & name) const
private

Returns a pointer on an interface given it's name. Used when building models, meaning that the interface name can either be local (need to add the current prefix) or global (no prefix needed).

Exceptions
NotFoundIf no class matching the name is found.
See also
PRMFactory:: retrieveType

Definition at line 1259 of file PRMFactory_tpl.h.

1259 {
1262
1263 // Looking for the type using its name
1264 if (_prm_->_interfaceMap_.exists(name)) {
1265 interface = _prm_->_interfaceMap_[name];
1266 full_name = name;
1267 }
1268
1269 // Looking for the type using current package
1271 if (_prm_->_interfaceMap_.exists(prefixed)) {
1272 if (interface == nullptr) {
1273 interface = _prm_->_interfaceMap_[prefixed];
1275 } else if (full_name != prefixed) {
1277 "Interface name '" << name << "' is ambiguous: specify full name.");
1278 }
1279 }
1280
1281 // Looking for the interf using all declared namespaces
1282 if (!_namespaces_.empty()) {
1283 auto ns_list = _namespaces_.back();
1284 // for( const auto & ns : *( _namespaces_.top()) ) {
1285 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1286 std::string ns = (*ns_list)[i];
1287 std::string ns_name = ns + "." + name;
1288
1289 if (_prm_->_interfaceMap_.exists(ns_name)) {
1290 if (interface == nullptr) {
1291 interface = _prm_->_interfaceMap_[ns_name];
1293 } else if (full_name != ns_name) {
1295 "Interface name '" << name << "' is ambiguous: specify full name.");
1296 }
1297 }
1298 }
1299 }
1300
1301 if (interface == nullptr) {
1302 GUM_ERROR(NotFound, "Interface '" << name << "' not found, check imports.")
1303 }
1304
1305 return interface;
1306 }

References _addPrefix_(), _namespaces_, _prm_, and GUM_ERROR.

Referenced by addReferenceSlot(), continueInterface(), isClassOrInterface(), startClass(), and startInterface().

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

◆ _retrieveType_()

template<typename GUM_SCALAR>
INLINE PRMType * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveType_ ( const std::string & name) const
private

Returns a pointer on a PRMType given it's name. Since the type can be given either with it's local name (without the prefix), full name (with the prefix) or can come from an import unit, or maybe one day with a using declaration we need some processing to find it.

The following precedences on finding the name is used:

  • name
  • prefix.name
  • import_1.name
  • import_2.name
  • ...
  • import_N.name In the case a local name is used multiple time, it's preferable to use it's full name.
    Exceptions
    OperationNotAllowedIf the type is undeclared.

Definition at line 1149 of file PRMFactory_tpl.h.

1149 {
1150 PRMType* type = nullptr;
1152
1153 // Looking for the type using its name
1154 if (_prm_->_typeMap_.exists(name)) {
1155 type = _prm_->_typeMap_[name];
1156 full_name = name;
1157 }
1158
1159 // Looking for the type in current package
1161 if (_prm_->_typeMap_.exists(prefixed)) {
1162 if (type == 0) {
1163 type = _prm_->_typeMap_[prefixed];
1165 } else if (full_name != prefixed) {
1166 GUM_ERROR(DuplicateElement, "Type name '" << name << "' is ambiguous: specify full name.")
1167 }
1168 }
1169
1170 // Looking for the type relatively to current package
1172 size_t last_dot = relatif_ns.find_last_of('.');
1173 if (last_dot != std::string::npos) {
1174 relatif_ns = relatif_ns.substr(0, last_dot) + '.' + name;
1175 if (_prm_->_typeMap_.exists(relatif_ns)) {
1176 if (type == 0) {
1177 type = _prm_->_typeMap_[relatif_ns];
1179 } else if (full_name != relatif_ns) {
1181 "Type name '" << name << "' is ambiguous: specify full name.");
1182 }
1183 }
1184 }
1185
1186
1187 // Looking for the type using all declared namespaces
1188 if (!_namespaces_.empty()) {
1189 auto ns_list = _namespaces_.back();
1190 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1191 std::string ns = (*ns_list)[i];
1192 std::string ns_name = ns + "." + name;
1193 if (_prm_->_typeMap_.exists(ns_name)) {
1194 if (type == 0) {
1195 type = _prm_->_typeMap_[ns_name];
1197 } else if (full_name != ns_name) {
1199 "Type name '" << name << "' is ambiguous: specify full name.");
1200 }
1201 }
1202 }
1203 }
1204
1205 if (type == 0) { GUM_ERROR(NotFound, "Type '" << name << "' not found, check imports.") }
1206
1207 return type;
1208 }
virtual std::string currentPackage() const override

References _addPrefix_(), _namespaces_, _prm_, currentPackage(), and GUM_ERROR.

Referenced by _addParent_(), _retrieveCommonType_(), addAggregator(), retrieveType(), startAggregator(), startAttribute(), and startDiscreteType().

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

◆ _typeDepth_()

template<typename GUM_SCALAR>
INLINE int gum::prm::PRMFactory< GUM_SCALAR >::_typeDepth_ ( const PRMType * t)
private

Returns the inheritance depth of a PRMType.

This used by PRMFactory:: retrieveCommonType. This returns 0 if t does not have a super type.

Parameters
tThe PRMType for which we compute its depth.
Returns
Returns the depth of t.

Definition at line 1759 of file PRMFactory_tpl.h.

1759 {
1760 int depth = 0;
1761 const PRMType* current = t;
1762
1763 while (current->isSubType()) {
1764 ++depth;
1765 current = &(current->superType());
1766 }
1767
1768 return depth;
1769 }

Referenced by _retrieveCommonType_().

Here is the caller graph for this function:

◆ addAggregator()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addAggregator ( const std::string & name,
const std::string & agg_type,
const std::vector< std::string > & chains,
const std::vector< std::string > & params,
std::string type = "" )
overridevirtual

Add an aggregator in the current declared class.

If at least one parent of an aggregator is a PRMSlotChain<GUM_SCALAR>, then all of it's parents must be PRMSlotChain<GUM_SCALAR>. When an aggregator parents are only composed of PRMAttribute<GUM_SCALAR> and PRMAggregate, then it is directly added as an PRMAttribute<GUM_SCALAR> to it's Class<GUM_SCALAR>.

Parameters
nameThe name of this aggregator.
agg_typeThe name of the aggregator type of this aggregator.
chainsThe set of chains on which this aggregate applies.
paramsThe list of parameters for this aggregator.
typeSome aggregators have a user defined type, use this parameter to define it.
Exceptions
OperationNotAllowedRaised if one or more parameters misses or are not correct.
TypeErrorRaised if the aggregator's type or one or more of the chains are not of the good type.

Implements gum::prm::IPRMFactory.

Definition at line 671 of file PRMFactory_tpl.h.

675 {
678 // Checking call legality
679
680 if (chains.size() == 0) {
681 GUM_ERROR(OperationNotAllowed, "a PRMAggregate<GUM_SCALAR> requires at least one parent")
682 }
683
684 // Retrieving the parents of the aggregate
686
687 // This helps knowing if the aggregate has parents outside the current
688 // class
689 // (see below)
691
692 // Checking that all inputs shares the same PRMType (trivial
693 // if
694 // inputs.size() == 1)
695 if (inputs.size() > 1) {
696 for (auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
697 if ((**(iter - 1)).type() != (**iter).type()) {
698 GUM_ERROR(TypeError, "found different types")
699 }
700 }
701 }
702
703 // Different treatments for different types of aggregate.
705
709 if (inputs.front()->type() != *(_retrieveType_("boolean"))) {
710 GUM_ERROR(TypeError, "expected booleans")
711 }
712 if (params.size() != 0) { GUM_ERROR(OperationNotAllowed, "invalid number of paramaters") }
713
716 inputs.front()->type());
717
718 break;
719 }
720
723 if (params.size() != 1) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
724
725 Idx label_idx = 0;
726
727 while (label_idx < inputs.front()->type()->domainSize()) {
728 if (inputs.front()->type()->label(label_idx) == params.front()) { break; }
729
730 ++label_idx;
731 }
732
733 if (label_idx == inputs.front()->type()->domainSize()) {
734 GUM_ERROR(NotFound, "could not find label")
735 }
736
737 // Creating and adding the PRMAggregate<GUM_SCALAR>
740 *(_retrieveType_("boolean")),
741 label_idx);
742 agg->label();
743
744 break;
745 }
746
752 if (params.size() != 0) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
753
755
756 // Creating and adding the PRMAggregate<GUM_SCALAR>
759 *output_type);
760
761 break;
762 }
763
765 if (params.size() != 1) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
766
767 Idx label_idx = 0;
768
769 while (label_idx < inputs.front()->type()->domainSize()) {
770 if (inputs.front()->type()->label(label_idx) == params.front()) { break; }
771
772 ++label_idx;
773 }
774
775 if (label_idx == inputs.front()->type()->domainSize()) {
776 GUM_ERROR(NotFound, "could not find label")
777 }
778
780
781 // Creating and adding the PRMAggregate<GUM_SCALAR>
785 label_idx);
786
787 break;
788 }
789
790 default : {
791 GUM_ERROR(FatalError, "Unknown aggregator.")
792 }
793 }
794
795 std::string safe_name = agg->safeName();
796
797 try {
798 if (hasSC) {
799 try {
800 c->add(agg);
801 } catch (DuplicateElement const&) { c->overload(agg); }
802 } else {
803 // Inner aggregators can be directly used as attributes
804 auto attr
805 = new PRMScalarAttribute< GUM_SCALAR >(agg->name(), agg->type(), agg->buildImpl());
806
807 try {
808 c->add(attr);
809 } catch (DuplicateElement const&) { c->overload(attr); }
810
811 delete agg;
812 }
813 } catch (DuplicateElement const&) {
814 delete agg;
815 throw;
816 }
817
818 for (const auto& elt: inputs) {
819 c->addArc(elt->safeName(), safe_name);
820 }
821 }

References _checkStack_(), _retrieveInputs_(), _retrieveType_(), gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMAggregate< GUM_SCALAR >::AMPLITUDE, gum::prm::PRMAggregate< GUM_SCALAR >::AND, gum::prm::PRMAggregate< GUM_SCALAR >::buildImpl(), gum::prm::PRMObject::CLASS, gum::prm::PRMAggregate< GUM_SCALAR >::COUNT, gum::prm::PRMAggregate< GUM_SCALAR >::EXISTS, gum::prm::PRMAggregate< GUM_SCALAR >::FORALL, GUM_ERROR, gum::prm::PRMAggregate< GUM_SCALAR >::label(), gum::prm::PRMAggregate< GUM_SCALAR >::MAX, gum::prm::PRMAggregate< GUM_SCALAR >::MEDIAN, gum::prm::PRMAggregate< GUM_SCALAR >::MIN, gum::prm::PRMObject::name(), gum::prm::PRMAggregate< GUM_SCALAR >::OR, gum::prm::PRMClass< GUM_SCALAR >::overload(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAggregate< GUM_SCALAR >::str2enum(), gum::prm::PRMAggregate< GUM_SCALAR >::SUM, and gum::prm::PRMAggregate< GUM_SCALAR >::type().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_().

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

◆ addArray()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addArray ( const std::string & type,
const std::string & name,
Size size )
overridevirtual

Creates an array with the given number of instances of the given type.

PRMInstance<GUM_SCALAR> are name using "name" as prefix and adding the suffix "[i]", with "i" being the position of the instance in the array.

Implements gum::prm::IPRMFactory.

Definition at line 849 of file PRMFactory_tpl.h.

851 {
856
857 try {
858 model->addArray(name, *c);
859
860 for (Size i = 0; i < size; ++i) {
862 elt_name << name << "[" << i << "]";
864 model->add(name, inst);
865 }
866 } catch (PRMTypeError const&) {
867 delete inst;
868 throw;
869 } catch (NotFound const&) {
870 delete inst;
871 throw;
872 }
873 }
virtual void addArray(const std::string &type, const std::string &name, Size size) override
Creates an array with the given number of instances of the given type.
PRMClass< GUM_SCALAR > * _retrieveClass_(const std::string &name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...

References _checkStack_(), _retrieveClass_(), gum::prm::PRMSystem< GUM_SCALAR >::add(), gum::prm::PRMSystem< GUM_SCALAR >::addArray(), and gum::prm::PRMObject::SYSTEM.

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addInstances_().

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

◆ addAttribute() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addAttribute ( const std::string & type,
const std::string & name )
overridevirtual

Add an attribute to an interface.

Implements gum::prm::IPRMFactory.

Definition at line 1521 of file PRMFactory_tpl.h.

1522 {
1525 endAttribute();
1526 }
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.

References _checkStack_(), endAttribute(), gum::prm::PRMObject::PRM_INTERFACE, and startAttribute().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateInterfaces_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateInterfaces_(), addNoisyOrCompound(), and gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements().

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

◆ addAttribute() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addAttribute ( PRMAttribute< GUM_SCALAR > * attr)
virtual

Add an already created attribute to the current class.

Use this method when you must add functions, such as Noisy-Or.

Use this method when you need to add functions, such as Noisy-Or. The attribute CPT is checked for parents and arcs will be added using the DiscreteVariable pointers, thus be careful to use those of the attributes, aggregates and slotchains of the current class. gum::prm::Class<GUM_SCALAR>::insertArc() will be called for each found parent of attr, so you should overload gum::prm::PRMAttribute<GUM_SCALAR>::addParent() to prevent duplication errors. Such class exists: gum::prm::PRMFuncAttribute .

The pointer is given to the class, so do not worry about deleting it.

Parameters
attrThe attribute added to the current class.
Exceptions
NotFoundRaised if one of the DiscreteVariable in attr CPT does not match any PRMClassElement<GUM_SCALAR> in this.

Definition at line 228 of file PRMFactory_tpl.h.

228 {
231 c->add(attr);
232 Size count = 0;
233 const Sequence< const DiscreteVariable* >& vars = attr->cpf().variablesSequence();
234
235 for (const auto& node: c->containerDag().nodes()) {
236 try {
237 if (vars.exists(&(c->get(node).type().variable()))) {
238 ++count;
239
240 if (&(attr->type().variable()) != &(c->get(node).type().variable())) {
241 c->addArc(c->get(node).safeName(), attr->safeName());
242 }
243 }
244 } catch (OperationNotAllowed const&) {}
245 }
246
247 if (count != attr->cpf().variablesSequence().size()) {
248 GUM_ERROR(NotFound, "unable to found all parents of this attribute")
249 }
250 }

References _checkStack_(), gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMObject::CLASS, gum::prm::PRMClassElementContainer< GUM_SCALAR >::containerDag(), gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), gum::SequenceImplementation< Key, Gen >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::NodeGraphPart::nodes(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAttribute< GUM_SCALAR >::type(), and gum::prm::PRMType::variable().

Here is the call graph for this function:

◆ addImport()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addImport ( const std::string & name)
overridevirtual

Add an import for namespace lookup.

When loading a module, you should push all import declarations using this method. The order in which you add imports will impact name resolution (first found, first used).

Imports are sync with packages: when you push a new package a new empty list of imports is added. When you pop a package the current list of imports is discarded and the previous one is restored.

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1796 of file PRMFactory_tpl.h.

1796 {
1797 if (name.size() == 0) { GUM_ERROR(OperationNotAllowed, "illegal import name") }
1798 if (_namespaces_.empty()) { _namespaces_.push_back(new List< std::string >()); }
1799 _namespaces_.back()->push_back(name);
1800 }

References _namespaces_, and GUM_ERROR.

◆ addInstance() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addInstance ( const std::string & type,
const std::string & name )
overridevirtual

Add an instance to the model.

Implements gum::prm::IPRMFactory.

Definition at line 1599 of file PRMFactory_tpl.h.

1600 {
1601 auto c = _retrieveClass_(type);
1602
1603 // If class contains parameters, calls the proper addIsntance method
1604 if (c->parameters().size() > 0) {
1607
1608 } else {
1610 }
1611 }
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
void _addInstance_(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.

References _addInstance_(), _retrieveClass_(), and addInstance().

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addInstances_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), and addInstance().

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

◆ addInstance() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addInstance ( const std::string & type,
const std::string & name,
const HashTable< std::string, double > & params )
overridevirtual

Add an instance with params as values of type's parameters.

Implements gum::prm::IPRMFactory.

Definition at line 1615 of file PRMFactory_tpl.h.

1617 {
1618 auto c = _retrieveClass_(type);
1619
1620 if (c->parameters().empty()) {
1621 if (params.empty()) {
1623 } else {
1624 GUM_ERROR(OperationNotAllowed, "Class " + type + " does not have parameters")
1625 }
1626
1627 } else {
1628 auto my_params = params;
1629 // Adding all parameters to my_params
1630 for (const auto& p: c->parameters()) {
1631 if (!my_params.exists(p->name())) { my_params.insert(p->name(), p->value()); }
1632 }
1633
1634 // Building sub class name using my_params
1636 sBuff << c->name() << "<";
1637
1638 for (const auto& p: my_params) {
1639 sBuff << p.first << "=" << p.second << ",";
1640 }
1641
1642 // Removing last , and adding closing >
1643 std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) + ">";
1644
1645 // Adding class in current package
1646 try {
1647 auto pck_cpy = _packages_;
1648 _packages_.clear();
1649
1650 startClass(sub_c, c->name());
1651
1652 // Update inherited parameters
1653 for (auto p: my_params) {
1654 auto type = static_cast< PRMParameter< GUM_SCALAR >& >(c->get(p.first)).valueType();
1656 addParameter("int", p.first, p.second);
1657
1658 } else {
1659 addParameter("real", p.first, p.second);
1660 }
1661 }
1662
1663 endClass();
1664
1666
1667 } catch (DuplicateElement const&) {
1668 // Sub Class already exists in this system
1669 }
1672 }
1673 }
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.

References _addInstance_(), _packages_, _retrieveClass_(), addParameter(), gum::HashTable< Key, Val >::empty(), endClass(), GUM_ERROR, gum::prm::PRMParameter< GUM_SCALAR >::INT, startClass(), and gum::prm::PRMParameter< GUM_SCALAR >::valueType().

Here is the call graph for this function:

◆ addLabel()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addLabel ( const std::string & l,
std::string ext = "" )
overridevirtual

Add a label to the current discrete type.

Parameters
lThe label value.
extThe super type label for which l is an extension.
Exceptions
OperationNotAllowedRaised if the current type does not have a super type, see PRMFactory::addLabel(const std::string&).
DuplicateElementRaised if a label with the same value already exists.
NotFoundRaised if ext does not match any label in the current type's super type.

Implements gum::prm::IPRMFactory.

Definition at line 1391 of file PRMFactory_tpl.h.

1391 {
1392 if (extends.empty()) {
1393 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1394 LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->_var_);
1395
1396 if (!var) {
1397 GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.")
1398 } else if (t->_superType_) {
1399 GUM_ERROR(OperationNotAllowed, "current type is a subtype.")
1400 }
1401
1402 try {
1403 var->addLabel(l);
1404 } catch (DuplicateElement const&) {
1405 GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists")
1406 }
1407 } else {
1408 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1409 LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->_var_);
1410
1411 if (!var) {
1412 GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.")
1413 } else if (!t->_superType_) {
1414 GUM_ERROR(OperationNotAllowed, "current type is not a subtype.")
1415 }
1416
1417 bool found = false;
1418
1419 for (Idx i = 0; i < t->_superType_->_var_->domainSize(); ++i) {
1420 if (t->_superType_->_var_->label(i) == extends) {
1421 try {
1422 var->addLabel(l);
1423 } catch (DuplicateElement const&) {
1424 GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists")
1425 }
1426
1427 t->_label_map_->push_back(i);
1428
1429 found = true;
1430 break;
1431 }
1432 }
1433
1434 if (!found) { GUM_ERROR(NotFound, "inexistent label in super type.") }
1435 }
1436 }
virtual void addLabel(const std::string &l, std::string ext="") override
Add a label to the current discrete type.

References _checkStack_(), gum::LabelizedVariable::addLabel(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::DiscreteVariable::label(), and gum::prm::PRMObject::TYPE.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildTypes_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateType_(), and gum::prm::LayerGenerator< GUM_SCALAR >::_generateType_().

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

◆ addNoisyOrCompound()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addNoisyOrCompound ( const std::string & name,
const std::vector< std::string > & chains,
const std::vector< float > & numbers,
float leak,
const std::vector< std::string > & label )
overridevirtual

Add a compound noisy-or as an PRMAttribute<GUM_SCALAR> to the current Class<GUM_SCALAR>.

The type of a noisy-or must be a boolean.

Parameters
namethe name of the PRMAttribute<GUM_SCALAR> added as a noisy-or.
chainsthe list of parents of the noisy-or.
numbersthe list of weights for each parent. Can consist of only one value which will be applied to all the parents.
leakthe leak
labelthe label on which the noisy-or applies, can be an empty string (the noisy-or will behave as if chains are all booleans).
Exceptions
NotFoundRaised if one of the chains or the label is not found.
FactoryInvalidStateRaised if a Class<GUM_SCALAR> is not the current declared PRMObject.
OperationNotAllowedRaised if for some reasons the parameters are invalid.

Implements gum::prm::IPRMFactory.

Definition at line 1086 of file PRMFactory_tpl.h.

1090 {
1092 GUM_ERROR(gum::FactoryInvalidState, "invalid state to add a noisy-or")
1093 }
1094
1096
1098
1099 for (const auto& elt: chains)
1100 parents.push_back(&(c->get(elt)));
1101
1103
1104 for (size_t idx = 0; idx < parents.size(); ++idx) {
1105 if (parents[idx]->type() != (*common_type)) {
1107 // Either safe_name is an non existing slot chain or an existing cast
1108 // descendant
1110
1111 if (!c->exists(safe_name)) {
1114 c->add(parents[idx]);
1115 } else {
1116 GUM_ERROR(NotFound, "unable to find parent")
1117 }
1118 } else {
1119 parents[idx] = &(c->get(safe_name));
1120 }
1121 }
1122 }
1123
1124 if (numbers.size() == 1) {
1128 } else if (numbers.size() == parents.size()) {
1133
1134 for (size_t idx = 0; idx < numbers.size(); ++idx) {
1135 noisy->causalWeight(parents[idx]->type().variable(), numbers[idx]);
1136 }
1137
1139 } else {
1140 GUM_ERROR(OperationNotAllowed, "invalid parameters for a noisy or")
1141 }
1142
1143 if (!labels.empty()) {
1144 GUM_ERROR(OperationNotAllowed, "labels definitions not handle for noisy-or")
1145 }
1146 }
PRMType & retrieveType(const std::string &name)
Returns a reference over a PRMType given its name.
virtual PRMObject::prm_type currentType() const override
virtual PRMObject * getCurrent() override
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.

References _buildSlotChain_(), _retrieveCommonType_(), gum::prm::PRMClass< GUM_SCALAR >::add(), addAttribute(), gum::prm::PRMClassElement< GUM_SCALAR >::cast(), gum::MultiDimICIModel< GUM_SCALAR >::causalWeight(), gum::prm::PRMObject::CLASS, currentType(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), getCurrent(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::isSlotChain(), and retrieveType().

Here is the call graph for this function:

◆ addParameter()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addParameter ( const std::string & type,
const std::string & name,
double value )
overridevirtual

Add a parameter to the current class with a default value.

A parameter with a default value is an PRMAttribute<GUM_SCALAR> (aka mutable PRMAttribute<GUM_SCALAR>) with no parents and with a CPF filled with 1.

Parameters
typeThe type of this parameter.
nameThe name of this parameter.
valueThe label used as default value for this parameter.

Implements gum::prm::IPRMFactory.

Definition at line 539 of file PRMFactory_tpl.h.

541 {
543
544 PRMParameter< GUM_SCALAR >* p = nullptr;
545 if (type == "int") {
549 } else if (type == "real") {
553 }
554
555 try {
556 c->add(p);
557 } catch (DuplicateElement const&) { c->overload(p); }
558 }

References _checkStack_(), gum::prm::PRMObject::CLASS, gum::prm::PRMParameter< GUM_SCALAR >::INT, and gum::prm::PRMParameter< GUM_SCALAR >::REAL.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_addParameters_(), and addInstance().

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

◆ addParent()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addParent ( const std::string & name)
overridevirtual

Tells the factory that we add a parent to the current declared attribute.

The name can refer to an already declared attribute or aggregate of the same class. It can also be a slot chain only if there is no multiple reference in it.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 306 of file PRMFactory_tpl.h.

306 {
308 try {
309 // Retrieving pointers
312 _addParent_(c, a, name);
313 } catch (FactoryInvalidState const&) {
314 auto agg = static_cast< PRMAggregate< GUM_SCALAR >* >(
316 _addParent_(static_cast< PRMClass< GUM_SCALAR >* >(c), agg, name);
317 }
318 }
PRMClassElementContainer< GUM_SCALAR > * _checkStackContainter_(Idx i)
Adds prefix to str iff prefix != "".
void _addParent_(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.

References _addParent_(), _checkStack_(), _checkStackContainter_(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAggregates_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAttribute_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_().

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

◆ addRangeType()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addRangeType ( const std::string & name,
long minVal,
long maxVal )
overridevirtual

Add a range variable type declaration.

Parameters
nameThe variable's name
minValThe variable's lower bound.
maxValThe variable's upper bound.
Exceptions
DuplicateElementRaised if an object with the same name already exists.
OperationNotAllowedRaised if the range variable is not a valid discrete type.

Implements gum::prm::IPRMFactory.

Definition at line 1495 of file PRMFactory_tpl.h.

1495 {
1497 if (_prm_->_typeMap_.exists(real_name)) {
1499 msg << "\"" << real_name << "' is already used.";
1501 }
1502
1503 auto var = RangeVariable(real_name, "", minVal, maxVal);
1504 auto t = new PRMType(var);
1505
1506 if (t->variable().domainSize() < 2) {
1507 GUM_ERROR(OperationNotAllowed, "current type is not a valid discrete type")
1508 }
1509
1510 _prm_->_typeMap_.insert(t->name(), t);
1511 _prm_->_types_.insert(t);
1512 }

References _addPrefix_(), _prm_, and GUM_ERROR.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildIntTypes_().

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

◆ addReferenceSlot()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot ( const std::string & type,
const std::string & name,
bool isArray )
overridevirtual

Tells the factory that we started declaring a slot.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 824 of file PRMFactory_tpl.h.

826 {
829
830 try {
832 } catch (NotFound const&) {
833 try {
835 } catch (NotFound const&) {
836 GUM_ERROR(NotFound, "unknown ReferenceSlot<GUM_SCALAR> slot type")
837 }
838 }
839
842
843 try {
844 owner->add(ref);
845 } catch (DuplicateElement const&) { owner->overload(ref); }
846 }
PRMInterface< GUM_SCALAR > * _retrieveInterface_(const std::string &name) const
Returns a pointer on an interface given it's name. Used when building models, meaning that the interf...

References _checkStackContainter_(), _retrieveClass_(), _retrieveInterface_(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::add(), GUM_ERROR, and gum::prm::PRMClassElementContainer< GUM_SCALAR >::overload().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_addReferenceSlots_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateInterfaces_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateInterfaces_(), and gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements().

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

◆ addTick()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::addTick ( double tick)
overridevirtual

Add a tick to the current discretized type.

Parameters
tickThe tick value.

Implements gum::prm::IPRMFactory.

Definition at line 1466 of file PRMFactory_tpl.h.

1466 {
1467 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1469
1470 if (!var) { GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.") }
1471
1472 try {
1473 var->addTick(tick);
1474 } catch (DefaultInLabel const&) {
1475 GUM_ERROR(OperationNotAllowed, "tick already in used for this variable")
1476 }
1477 }
virtual void addTick(double tick) override
Add a tick to the current discretized type.

References _checkStack_(), gum::DiscretizedVariable< T_TICKS >::addTick(), GUM_ERROR, and gum::prm::PRMObject::TYPE.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildRealTypes_().

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

◆ closeCurrent()

template<typename GUM_SCALAR>
INLINE PRMObject * gum::prm::PRMFactory< GUM_SCALAR >::closeCurrent ( )
overridevirtual

Close current object being built.

Nothing is done in particular except removing the current object from the factory's stack. If the object was not added to a container it will not be deleted properly, so you might want to delete it yourself (at your own risks!).

Returns
Returns the top most object removed in this factory's stack before. If their is no such object, 0 is returned.

Implements gum::prm::IPRMFactory.

Definition at line 1357 of file PRMFactory_tpl.h.

1357 {
1358 if (_stack_.size() > 0) {
1359 PRMObject* obj = _stack_.back();
1360 _stack_.pop_back();
1361 return obj;
1362 } else {
1363 return 0;
1364 }
1365 }

References _stack_.

◆ continueAggregator()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::continueAggregator ( const std::string & name)

Conitnues an aggregator declaration.

Definition at line 595 of file PRMFactory_tpl.h.

595 {
597
598 if (!c->exists(name)) GUM_ERROR(NotFound, "Element " << name << "not found")
599
600 auto& agg = c->get(name);
602 GUM_ERROR(OperationNotAllowed, "Element " << name << " not an aggregate")
603
605 }

References _checkStackContainter_(), _stack_, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), GUM_ERROR, and gum::prm::PRMClassElement< GUM_SCALAR >::isAggregate().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAggregates_().

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

◆ continueAttribute()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::continueAttribute ( const std::string & name)
overridevirtual

Continues the declaration of an attribute.

Implements gum::prm::IPRMFactory.

Definition at line 1558 of file PRMFactory_tpl.h.

1558 {
1560
1561 if (!c->exists(name)) GUM_ERROR(NotFound, "Attribute " << name << "not found")
1562
1563 auto& a = c->get(name);
1564
1566 GUM_ERROR(OperationNotAllowed, "Element " << name << " not an attribute")
1567
1569 }

References _checkStackContainter_(), _stack_, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), GUM_ERROR, and gum::prm::PRMClassElement< GUM_SCALAR >::isAttribute().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAttribute_().

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

◆ continueClass()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::continueClass ( const std::string & c)
overridevirtual

Continue the declaration of a class.

Implements gum::prm::IPRMFactory.

Definition at line 99 of file PRMFactory_tpl.h.

99 {
101 if (!(_prm_->_classMap_.exists(real_name))) {
103 msg << "'" << real_name << "' not found";
104 GUM_ERROR(NotFound, msg.str())
105 }
106 _stack_.push_back(&(_prm_->getClass(real_name)));
107 }

References _addPrefix_(), _prm_, _stack_, and GUM_ERROR.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_addReferenceSlots_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAggregates_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAttribute_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes().

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

◆ continueInterface()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::continueInterface ( const std::string & name)
overridevirtual

Continue the declaration of an interface.

Implements gum::prm::IPRMFactory.

Definition at line 217 of file PRMFactory_tpl.h.

217 {
219 if (!_prm_->_interfaceMap_.exists(real_name)) {
220 GUM_ERROR(DuplicateElement, "'" << real_name << "' not found.")
221 }
222
224 _stack_.push_back(i);
225 }

References _addPrefix_(), _prm_, _retrieveInterface_(), _stack_, and GUM_ERROR.

Referenced by gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements().

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

◆ currentPackage()

template<typename GUM_SCALAR>
INLINE std::string gum::prm::PRMFactory< GUM_SCALAR >::currentPackage ( ) const
overridevirtual
Returns
Returns the current package name.

Implements gum::prm::IPRMFactory.

Definition at line 1368 of file PRMFactory_tpl.h.

1368 {
1369 return (_packages_.empty()) ? "" : _packages_.back();
1370 }

References _packages_.

Referenced by _retrieveType_(), and popPackage().

Here is the caller graph for this function:

◆ currentType()

template<typename GUM_SCALAR>
INLINE PRMObject::prm_type gum::prm::PRMFactory< GUM_SCALAR >::currentType ( ) const
overridevirtual
Returns
Returns the PRMObject type of the object begin built.
Exceptions
NotFoundif no type is being built.

Implements gum::prm::IPRMFactory.

Definition at line 1336 of file PRMFactory_tpl.h.

1336 {
1337 if (_stack_.size() == 0) { GUM_ERROR(NotFound, "no object being built") }
1338
1339 return _stack_.back()->obj_type();
1340 }

References _stack_, and GUM_ERROR.

Referenced by addNoisyOrCompound().

Here is the caller graph for this function:

◆ endAggregator()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endAggregator ( )

Finishes an aggregate declaration.

Definition at line 665 of file PRMFactory_tpl.h.

References _checkStack_(), _stack_, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAggregates_(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAggregates_().

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

◆ endAttribute()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endAttribute ( )
overridevirtual

Tells the factory that we finished declaring an attribute.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1572 of file PRMFactory_tpl.h.

1572 {
1574 _stack_.pop_back();
1575 }

References _checkStack_(), _stack_, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAttribute_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAttribute_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), and addAttribute().

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

◆ endClass()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endClass ( bool checkImplementations = true)
overridevirtual

Tells the factory that we finished a class declaration.

Exceptions
PRMTypeErrorRaised if the current Class<GUM_SCALAR> does not respect one of it's PRMInterface<GUM_SCALAR>.

Implements gum::prm::IPRMFactory.

Definition at line 110 of file PRMFactory_tpl.h.

110 {
113
115
116 _stack_.pop_back();
117 }
void _checkInterfaceImplementation_(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.

References _checkInterfaceImplementation_(), _checkStack_(), _stack_, and gum::prm::PRMObject::CLASS.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_addReferenceSlots_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAggregates_(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAttribute_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), addInstance(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes().

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

◆ endDiscreteType()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endDiscreteType ( )
overridevirtual

End the current discrete type declaration.

Exceptions
OperationNotAllowedRaised if the current type is not a valid discrete type.

Implements gum::prm::IPRMFactory.

Definition at line 1439 of file PRMFactory_tpl.h.

1439 {
1440 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1441
1442 if (!t->_isValid_()) {
1443 GUM_ERROR(OperationNotAllowed, "current type is not a valid subtype")
1444 } else if (t->variable().domainSize() < 2) {
1445 GUM_ERROR(OperationNotAllowed, "current type is not a valid discrete type")
1446 }
1447
1448 _prm_->_typeMap_.insert(t->name(), t);
1449
1450 _prm_->_types_.insert(t);
1451 _stack_.pop_back();
1452 }

References _checkStack_(), _prm_, _stack_, gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), and gum::prm::PRMObject::TYPE.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildTypes_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateType_(), and gum::prm::LayerGenerator< GUM_SCALAR >::_generateType_().

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

◆ endDiscretizedType()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endDiscretizedType ( )
overridevirtual

End the current discretized type declaration.

Exceptions
OperationNotAllowedRaised if the current type is not a valid discrete type.

Implements gum::prm::IPRMFactory.

Definition at line 1480 of file PRMFactory_tpl.h.

1480 {
1481 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1482
1483 if (t->variable().domainSize() < 2) {
1484 GUM_ERROR(OperationNotAllowed, "current type is not a valid discrete type")
1485 }
1486
1487 _prm_->_typeMap_.insert(t->name(), t);
1488
1489 _prm_->_types_.insert(t);
1490 _stack_.pop_back();
1491 }

References _checkStack_(), _prm_, _stack_, gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), and gum::prm::PRMObject::TYPE.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildRealTypes_().

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

◆ endInterface()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endInterface ( )
overridevirtual

Tells the factory that we finished an interface declaration.

Implements gum::prm::IPRMFactory.

Definition at line 1515 of file PRMFactory_tpl.h.

1515 {
1517 _stack_.pop_back();
1518 }

References _checkStack_(), _stack_, and gum::prm::PRMObject::PRM_INTERFACE.

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateInterfaces_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateInterfaces_(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements(), and gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildInterfaces().

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

◆ endSystem()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endSystem ( )
overridevirtual

Tells the factory that we finished declaring a model.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1589 of file PRMFactory_tpl.h.

1589 {
1590 try {
1593 _stack_.pop_back();
1594 model->instantiate();
1595 } catch (Exception const&) { GUM_ERROR(FatalError, "could not create system") }
1596 }

References _checkStack_(), _stack_, GUM_ERROR, gum::prm::PRMSystem< GUM_SCALAR >::instantiate(), and gum::prm::PRMObject::SYSTEM.

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

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

◆ getCurrent() [1/2]

template<typename GUM_SCALAR>
INLINE const PRMObject * gum::prm::PRMFactory< GUM_SCALAR >::getCurrent ( ) const
overridevirtual

Returns a pointer on the PRM<GUM_SCALAR> created by this factory.

This pointer will not be deleted when the factory is destroyed.

Returns
Returns the PRM<GUM_SCALAR> created by this factory.

Implements gum::prm::IPRMFactory.

Definition at line 1350 of file PRMFactory_tpl.h.

1350 {
1351 if (_stack_.size() == 0) { GUM_ERROR(NotFound, "no object being built") }
1352
1353 return _stack_.back();
1354 }

References _stack_, and GUM_ERROR.

◆ getCurrent() [2/2]

template<typename GUM_SCALAR>
INLINE PRMObject * gum::prm::PRMFactory< GUM_SCALAR >::getCurrent ( )
overridevirtual
Returns
the current PRMObject being built by this factory.
Exceptions
NotFoundif nothing is being built.

Implements gum::prm::IPRMFactory.

Definition at line 1343 of file PRMFactory_tpl.h.

1343 {
1344 if (_stack_.size() == 0) { GUM_ERROR(NotFound, "no object being built") }
1345
1346 return _stack_.back();
1347 }

References _stack_, and GUM_ERROR.

Referenced by addNoisyOrCompound(), and isArrayInCurrentSystem().

Here is the caller graph for this function:

◆ incArray()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::incArray ( const std::string & l_i,
const std::string & r_i )
overridevirtual

Add an instance to an array.

Implements gum::prm::IPRMFactory.

Definition at line 876 of file PRMFactory_tpl.h.

876 {
879
880 if (model->isArray(l_i)) {
881 if (model->isInstance(r_i)) {
882 model->add(l_i, model->get(r_i));
883 } else {
884 GUM_ERROR(NotFound, "right value is not an instance")
885 }
886 } else {
887 GUM_ERROR(NotFound, "left value is no an array")
888 }
889 }

References _checkStack_(), gum::prm::PRMSystem< GUM_SCALAR >::add(), gum::prm::PRMSystem< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMSystem< GUM_SCALAR >::isArray(), gum::prm::PRMSystem< GUM_SCALAR >::isInstance(), and gum::prm::PRMObject::SYSTEM.

Here is the call graph for this function:

◆ isArrayInCurrentSystem()

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMFactory< GUM_SCALAR >::isArrayInCurrentSystem ( const std::string & name) const
overridevirtual

Implements gum::prm::IPRMFactory.

Definition at line 1852 of file PRMFactory_tpl.h.

1852 {
1854 = static_cast< const PRMSystem< GUM_SCALAR >* >(getCurrent());
1855 return (system && system->isArray(name));
1856 }

References getCurrent(), and gum::prm::PRMSystem< GUM_SCALAR >::isArray().

Here is the call graph for this function:

◆ isClassOrInterface()

template<typename GUM_SCALAR>
INLINE bool gum::prm::PRMFactory< GUM_SCALAR >::isClassOrInterface ( const std::string & type) const
overridevirtual

Implements gum::prm::IPRMFactory.

Definition at line 1833 of file PRMFactory_tpl.h.

1833 {
1834 try {
1836 return true;
1837
1838 } catch (NotFound const&) {
1839 } catch (DuplicateElement const&) {}
1840
1841 try {
1843 return true;
1844
1845 } catch (NotFound const&) {
1846 } catch (DuplicateElement const&) {}
1847
1848 return false;
1849 }

References _retrieveClass_(), and _retrieveInterface_().

Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR>
PRMFactory & gum::prm::PRMFactory< GUM_SCALAR >::operator= ( const PRMFactory< GUM_SCALAR > & from)
delete

Copy operator. Don't use it.

References PRMFactory().

Here is the call graph for this function:

◆ popPackage()

template<typename GUM_SCALAR>
INLINE std::string gum::prm::PRMFactory< GUM_SCALAR >::popPackage ( )
overridevirtual

Pop the current package from the package stack.

Returns
the popped package or an empty string if there was nothing to pop.

Implements gum::prm::IPRMFactory.

Definition at line 1778 of file PRMFactory_tpl.h.

1778 {
1780
1781 if (!_packages_.empty()) {
1782 std::string s = _packages_.back();
1783 _packages_.pop_back();
1784
1785 if (_namespaces_.size() > 0) {
1786 delete _namespaces_.back();
1787 _namespaces_.pop_back();
1788 }
1789 return s;
1790 }
1791
1792 return plop;
1793 }

References _namespaces_, _packages_, and currentPackage().

Here is the call graph for this function:

◆ prm()

template<typename GUM_SCALAR>
INLINE PRM< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::prm ( ) const

Returns a pointer on the PRM<GUM_SCALAR> created by this factory.

This pointer will not be deleted when the factory is destroyed.

Returns
Returns the PRM<GUM_SCALAR> created by this factory.

Definition at line 1331 of file PRMFactory_tpl.h.

1331 {
1332 return _prm_;
1333 }

References _prm_.

Referenced by PRMFactory(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generate(), and gum::prm::LayerGenerator< GUM_SCALAR >::generate().

Here is the caller graph for this function:

◆ pushPackage()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::pushPackage ( const std::string & name)
overridevirtual

Define the current package.

A stack is used to keep track of packages given the different imports.

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1772 of file PRMFactory_tpl.h.

1772 {
1773 _packages_.push_back(name);
1774 _namespaces_.push_back(new List< std::string >());
1775 }

References _namespaces_, and _packages_.

◆ retrieveClass()

template<typename GUM_SCALAR>
INLINE PRMClass< GUM_SCALAR > & gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass ( const std::string & name)

Returns a reference over a Class<GUM_SCALAR> given its name.

This methods adds if necessary the current package as a prefix to name.

Parameters
nameThe name of the Class<GUM_SCALAR>.
Returns
the Class<GUM_SCALAR> with the given name.
Exceptions
NotFoundif no Class<GUM_SCALAR> matches the given name.

Definition at line 1817 of file PRMFactory_tpl.h.

1817 {
1818 return *_retrieveClass_(name);
1819 }

References _retrieveClass_().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_().

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

◆ retrieveCommonType()

template<typename GUM_SCALAR>
INLINE PRMType & gum::prm::PRMFactory< GUM_SCALAR >::retrieveCommonType ( const std::vector< PRMClassElement< GUM_SCALAR > * > & elts)

Returns a pointer on the PRM<GUM_SCALAR> created by this factory.

This pointer will not be deleted when the factory is destroyed.

Returns
Returns the PRM<GUM_SCALAR> created by this factory.

Definition at line 1827 of file PRMFactory_tpl.h.

1828 {
1829 return *(_retrieveCommonType_(elts));
1830 }

References _retrieveCommonType_().

Here is the call graph for this function:

◆ retrieveType()

template<typename GUM_SCALAR>
INLINE PRMType & gum::prm::PRMFactory< GUM_SCALAR >::retrieveType ( const std::string & name)

Returns a reference over a PRMType given its name.

This methods adds if necessary the current package as a prefix to name.

Parameters
nameThe name of the PRMType.
Returns
the PRMType with the given name.
Exceptions
NotFoundif no PRMType matches the given name.

Definition at line 1822 of file PRMFactory_tpl.h.

1822 {
1823 return *_retrieveType_(name);
1824 }

References _retrieveType_().

Referenced by addNoisyOrCompound().

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

◆ setCPFByFloatRule()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setCPFByFloatRule ( const std::vector< std::string > & labels,
const std::vector< float > & values )
overridevirtual

Fills the CPF using a rule.

The labels vector is filled with one of each parent's labels or with a wildcard ("*"). If a wildcard is used then all values of the corresponding parents are used. The sequence of parents must be the declaration order used when adding the current attribute's parents.

Parameters
labelsThe value of each parents.
valuesThe probability values of the current attribute given the values in parenst.

Implements gum::prm::IPRMFactory.

Definition at line 393 of file PRMFactory_tpl.h.

394 {
395 auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
397
398 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
399 GUM_ERROR(OperationNotAllowed, "wrong number of parents")
400 }
401
402 if (values.size() != a->type().variable().domainSize()) {
403 GUM_ERROR(OperationNotAllowed, "wrong number of values")
404 }
405
408 }
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.

References _checkStack_(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, and setCPFByRule().

Here is the call graph for this function:

◆ setCPFByRule() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule ( const std::vector< std::string > & labels,
const std::vector< GUM_SCALAR > & values )
virtual

Fills the CPF using a rule.

The labels vector is filled with one of each parent's labels or with a wildcard ("*"). If a wildcard is used then all values of the corresponding parents are used. The sequence of parents must be the declaration order used when adding the current attribute's parents.

Parameters
labelsThe value of each parents.
valuesThe probability values of the current attribute given the values in parents.

Definition at line 411 of file PRMFactory_tpl.h.

412 {
413 auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
415
416 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
417 GUM_ERROR(OperationNotAllowed, "wrong number of parents")
418 }
419
420 if (values.size() != a->type().variable().domainSize()) {
421 GUM_ERROR(OperationNotAllowed, "wrong number of values")
422 }
423
424 if (dynamic_cast< PRMFormAttribute< GUM_SCALAR >* >(a)) {
425 auto form = static_cast< PRMFormAttribute< GUM_SCALAR >* >(a);
426 // jnst holds parents with a specific value (not "*")
427 // knst holds parents without a specific value ("*")
429 const DiscreteVariable* var = 0;
430 // not_used Size pos = 0;
431 bool found = false;
432
433 for (Idx i = 0; i < parents.size(); ++i) {
434 var = form->formulas().variablesSequence().atPos(1 + i);
435
436 if (parents[i] == "*") {
437 knst.add(*var);
438 } else {
439 jnst.add(*var);
440 // not_used pos = 0;
441 found = false;
442
443 for (Size j = 0; j < var->domainSize(); ++j) {
444 if (var->label(j) == parents[i]) {
445 jnst.chgVal(*var, j);
446 found = true;
447 break;
448 }
449 }
450
451 if (!found) {
452 std::string msg = "could not find label ";
454 }
455 }
456 }
457
458 Instantiation inst(form->formulas());
459 inst.setVals(jnst);
460
461 for (Size i = 0; i < form->type()->domainSize(); ++i) {
462 inst.chgVal(form->type().variable(), i);
463
464 for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
465 form->formulas().set(inst, std::to_string(values[i]));
466 }
467 }
468
469 } else {
470 GUM_ERROR(OperationNotAllowed, "invalide attribute type")
471 }
472 }

References _checkStack_(), gum::Instantiation::chgVal(), gum::DiscreteVariable::domainSize(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::incIn(), gum::DiscreteVariable::label(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::Instantiation::setFirstIn(), and gum::Instantiation::setVals().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAttribute_(), and setCPFByFloatRule().

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

◆ setCPFByRule() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule ( const std::vector< std::string > & labels,
const std::vector< std::string > & values )
overridevirtual

Fills the CPF using a rule and gum::Formula.

The labels vector is filled with one of each parent's labels or with a wildcard ("*"). If a wildcard is used then all values of the corresponding parents are used. The sequence of parents must be the declaration order used when adding the current attribute's parents.

Parameters
labelsThe value of each parents.
valuesThe probability values of the current attribute given the values in parents.

Implements gum::prm::IPRMFactory.

Definition at line 475 of file PRMFactory_tpl.h.

476 {
477 auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
479
480 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
481 GUM_ERROR(OperationNotAllowed, "wrong number of parents")
482 }
483
484 if (values.size() != a->type().variable().domainSize()) {
485 GUM_ERROR(OperationNotAllowed, "wrong number of values")
486 }
487
488 if (dynamic_cast< PRMFormAttribute< GUM_SCALAR >* >(a)) {
489 auto form = static_cast< PRMFormAttribute< GUM_SCALAR >* >(a);
490 // jnst holds parents with a specific value (not "*")
491 // knst holds parents without a specific value ("*")
493 const DiscreteVariable* var = 0;
494 // not_used Size pos = 0;
495 bool found = false;
496
497 for (Idx i = 0; i < parents.size(); ++i) {
498 var = form->formulas().variablesSequence().atPos(1 + i);
499
500 if (parents[i] == "*") {
501 knst.add(*var);
502 } else {
503 jnst.add(*var);
504 // not_used pos = 0;
505 found = false;
506
507 for (Size j = 0; j < var->domainSize(); ++j) {
508 if (var->label(j) == parents[i]) {
509 jnst.chgVal(*var, j);
510 found = true;
511 break;
512 }
513 }
514
515 if (!found) {
516 std::string msg = "could not find label ";
518 }
519 }
520 }
521
522 Instantiation inst(form->formulas());
523 inst.setVals(jnst);
524
525 for (Size i = 0; i < form->type()->domainSize(); ++i) {
526 inst.chgVal(form->type().variable(), i);
527
528 for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
529 form->formulas().set(inst, values[i]);
530 }
531 }
532
533 } else {
534 GUM_ERROR(OperationNotAllowed, "invalide attribute type")
535 }
536 }

References _checkStack_(), gum::Instantiation::chgVal(), gum::DiscreteVariable::domainSize(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::incIn(), gum::DiscreteVariable::label(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::Instantiation::setFirstIn(), and gum::Instantiation::setVals().

Here is the call graph for this function:

◆ setRawCPFByColumns() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns ( const std::vector< GUM_SCALAR > & array)

Gives the factory the CPF in its raw form.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

//P(A|f,f),P(A|f,t),P(A|t,f),P(A|t,t)
[ 0.2, 0.7, 0.5, 0.01,
0.8, 0.3, 0.5, 0.99]

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Definition at line 361 of file PRMFactory_tpl.h.

361 {
364
365 if (a->cpf().domainSize() != array.size()) {
366 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
367 }
368
369 if (a->cpf().nbrDim() == 1) {
371
372 } else {
373 Instantiation inst(a->cpf());
375 for (auto idx = inst.variablesSequence().rbegin(); idx != inst.variablesSequence().rend();
376 --idx) {
377 jnst.add(**idx);
378 }
379
380 jnst.setFirst();
381 auto idx = (std::size_t)0;
382 while ((!jnst.end()) && idx < array.size()) {
383 inst.setVals(jnst);
384 a->cpf().set(inst, array[idx]);
385 jnst.inc();
386 ++idx;
387 }
388 }
389 }
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.

References _checkStack_(), gum::Instantiation::add(), gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::inc(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::Instantiation::setFirst(), setRawCPFByLines(), gum::Instantiation::setVals(), and gum::Instantiation::variablesSequence().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_completeAttribute_(), and setRawCPFByFloatColumns().

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

◆ setRawCPFByColumns() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns ( const std::vector< std::string > & array)
overridevirtual

Gives the factory the CPF in its raw form use gum::Formula.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

//P(A|f,f),P(A|f,t),P(A|t,f),P(A|t,t)
[ 0.2, 0.7, 0.5, 0.01,
0.8, 0.3, 0.5, 0.99]

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1860 of file PRMFactory_tpl.h.

1860 {
1862
1863 auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1865
1866 if (a->formulas().domainSize() != array.size()) {
1867 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
1868 }
1869
1870 if (a->formulas().nbrDim() == 1) {
1872
1873 } else {
1874 Instantiation inst(a->formulas());
1876 for (auto idx = inst.variablesSequence().rbegin(); idx != inst.variablesSequence().rend();
1877 --idx) {
1878 jnst.add(**idx);
1879 }
1880
1881 jnst.setFirst();
1882 auto idx = (std::size_t)0;
1883 while ((!jnst.end()) && idx < array.size()) {
1884 inst.setVals(jnst);
1885 a->formulas().set(inst, array[idx]);
1886 jnst.inc();
1887 ++idx;
1888 }
1889
1890 // Generate cpf by calling it
1891 a->cpf();
1892 }
1893 }

References _checkStack_(), gum::Instantiation::add(), gum::prm::PRMObject::CLASS, gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::inc(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::Instantiation::setFirst(), setRawCPFByLines(), gum::Instantiation::setVals(), and gum::Instantiation::variablesSequence().

Here is the call graph for this function:

◆ setRawCPFByFloatColumns()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByFloatColumns ( const std::vector< float > & array)
overridevirtual

Gives the factory the CPF in its raw form.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

//P(A|f,f),P(A|f,t),P(A|t,f),P(A|t,t)
[ 0.2, 0.7, 0.5, 0.01,
0.8, 0.3, 0.5, 0.99]

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 347 of file PRMFactory_tpl.h.

347 {
350
351 if (a->cpf().domainSize() != array.size()) {
352 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
353 }
354
357 }
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.

References _checkStack_(), gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, and setRawCPFByColumns().

Here is the call graph for this function:

◆ setRawCPFByFloatLines()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByFloatLines ( const std::vector< float > & array)
overridevirtual

Gives the factory the CPF in its raw form.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

[0.20, 0.80, // P(f|f, f) = 0.20 and P(t|f, f) = 0.80
0.50, 0.50, // P(f|t, f) = 0.50 and P(t|t, f) = 0.50
0.70, 0.30, // P(f|f, t) = 0.70 and P(t|f, t) = 0.30
0.01, 0.99] // P(f|t, t) = 0.01 and P(t|t, t) = 0.99
Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 321 of file PRMFactory_tpl.h.

321 {
325
326 if (a->cpf().domainSize() != array.size()) GUM_ERROR(OperationNotAllowed, "illegal CPF size")
327
329 a->cpf().fillWith(array2);
330 }

References _checkStack_(), gum::prm::PRMObject::CLASS, gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), GUM_ERROR, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute.

Here is the call graph for this function:

◆ setRawCPFByLines() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines ( const std::vector< GUM_SCALAR > & array)

Gives the factory the CPF in its raw form.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

[0.20, 0.80, // P(f|f, f) = 0.20 and P(t|f, f) = 0.80
0.50, 0.50, // P(f|t, f) = 0.50 and P(t|t, f) = 0.50
0.70, 0.30, // P(f|f, t) = 0.70 and P(t|f, t) = 0.30
0.01, 0.99] // P(f|t, t) = 0.01 and P(t|t, t) = 0.99
Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Definition at line 333 of file PRMFactory_tpl.h.

333 {
335 auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(elt);
337
338 if (a->cpf().domainSize() != array.size()) {
339 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
340 }
341
342 a->cpf().fillWith(array);
343 }

References _checkStack_(), gum::prm::PRMObject::CLASS, GUM_ERROR, and gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute.

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), setRawCPFByColumns(), and setRawCPFByColumns().

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

◆ setRawCPFByLines() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines ( const std::vector< std::string > & array)
overridevirtual

Gives the factory the CPF in its raw form using gum::Formula.

The creation of the CPF is left to the factory because we do not know what level of complexity for CPF implementation can be handled by the PRM<GUM_SCALAR> implementation.

How to fill a CPT? If you want to fill the CPT of P(A|B,C) with A, B and C boolean variables ( {f, t}, the order is important), then the following array is valid:

[0.20, 0.80, // P(f|f, f) = 0.20 and P(t|f, f) = 0.80
0.50, 0.50, // P(f|t, f) = 0.50 and P(t|t, f) = 0.50
0.70, 0.30, // P(f|f, t) = 0.70 and P(t|f, t) = 0.30
0.01, 0.99] // P(f|t, t) = 0.01 and P(t|t, t) = 0.99
Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1897 of file PRMFactory_tpl.h.

1897 {
1899
1900 auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1902
1903 if (a->formulas().domainSize() != array.size()) {
1904 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
1905 }
1906
1907 a->formulas().populate(array);
1908
1910 a->cpf();
1911 }

References _checkStack_(), gum::prm::PRMObject::CLASS, gum::prm::PRMFormAttribute< GUM_SCALAR >::formulas(), GUM_ERROR, gum::MultiDimContainer< GUM_SCALAR >::populate(), and gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute.

Here is the call graph for this function:

◆ setReferenceSlot() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot ( const std::string & l_i,
const std::string & r_i )
overridevirtual

Instantiate a reference in the current model.

This is equivalent to the following SKOOL instruction: left_instance.left_reference = right_instance;

right_instance's type must be compatible with the slot type of left_reference.

Parameters
l_iA slot chain starting from an instance and ending over a reference slot.
r_iThe name of an instance or an array of instances in the model.

Implements gum::prm::IPRMFactory.

Definition at line 1803 of file PRMFactory_tpl.h.

1804 {
1805 size_t pos = l_i.find_last_of('.');
1806
1807 if (pos != std::string::npos) {
1808 std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1809 setReferenceSlot(l_i.substr(0, pos), l_ref, r_i);
1810 } else {
1811 GUM_ERROR(NotFound, "left value does not name an instance or an array")
1812 }
1813 }
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.

References GUM_ERROR, and setReferenceSlot().

Here is the call graph for this function:

◆ setReferenceSlot() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot ( const std::string & left_instance,
const std::string & left_reference,
const std::string & right_instance )
overridevirtual

Instantiate a reference in the current model.

This is equivalent to the following SKOOL instruction: left_instance.left_reference = right_instance;

right_instance's type must be compatible with the slot type of left_reference.

Parameters
left_instanceThe name of an instance in the model.
left_referenceThe name of a reference of left_instance.
right_instanceThe name of an instance or an array of instances in the model.

Implements gum::prm::IPRMFactory.

Definition at line 892 of file PRMFactory_tpl.h.

894 {
895 auto model
899
900 if (model->isInstance(l_i)) {
901 lefts.push_back(&(model->get(l_i)));
902 } else if (model->isArray(l_i)) {
903 for (const auto& elt: model->getArray(l_i))
904 lefts.push_back(elt);
905 } else {
906 GUM_ERROR(NotFound, "left value does not name an instance or an array")
907 }
908
909 if (model->isInstance(r_i)) {
910 rights.push_back(&(model->get(r_i)));
911 } else if (model->isArray(r_i)) {
912 for (const auto& elt: model->getArray(r_i))
913 rights.push_back(elt);
914 } else {
915 GUM_ERROR(NotFound, "left value does not name an instance or an array")
916 }
917
918 for (const auto l: lefts) {
919 for (const auto r: rights) {
920 auto& elt = l->type().get(l_ref);
922 l->add(elt.id(), *r);
923
924 } else {
925 GUM_ERROR(NotFound, "unfound reference slot")
926 }
927 }
928 }
929 }

References _checkStack_(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::isReferenceSlot(), and gum::prm::PRMObject::SYSTEM.

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addAssignments_(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::_addIncrements_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), and setReferenceSlot().

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

◆ startAggregator()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startAggregator ( const std::string & name,
const std::string & agg_type,
const std::string & rv_type,
const std::vector< std::string > & params )

Start an aggregator declaration.

Parameters
nameThe aggregator's name.
agg_typeThe aggregtor's type (
See also
Aggregate::agg_type()).
Parameters
rv_typeThe aggregator's random variable type (
See also
Aggregate::type()).
Parameters
paramsThe aggregator's parameters.

Definition at line 562 of file PRMFactory_tpl.h.

565 {
568
572
573 try {
574 c->add(agg);
575 } catch (DuplicateElement const&) { c->overload(agg); }
576
577 switch (agg->agg_type()) {
581 if (params.size() != 1) {
582 GUM_ERROR(OperationNotAllowed, "aggregate requires a parameter")
583 }
584 agg->setLabel(params.front());
585 break;
586 }
587 default : {
588 // Nothing to do
589 }
590 }
591 _stack_.push_back(agg);
592 }

References _checkStack_(), _retrieveType_(), _stack_, gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMObject::CLASS, gum::prm::PRMAggregate< GUM_SCALAR >::COUNT, gum::prm::PRMAggregate< GUM_SCALAR >::EXISTS, gum::prm::PRMAggregate< GUM_SCALAR >::FORALL, GUM_ERROR, gum::prm::PRMClass< GUM_SCALAR >::overload(), and gum::prm::PRMAggregate< GUM_SCALAR >::str2enum().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAggregates_().

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

◆ startAttribute()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startAttribute ( const std::string & type,
const std::string & name,
bool scalar_atttr = false )
overridevirtual

Tells the factory that we start an attribute declaration.

Exceptions
FatalErrorRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1529 of file PRMFactory_tpl.h.

1531 {
1533 PRMAttribute< GUM_SCALAR >* a = nullptr;
1534
1535 if (PRMObject::isClass(*c) && (!scalar_attr)) {
1537 name,
1539
1540 } else {
1542 }
1543
1544 std::string dot = ".";
1545
1546 try {
1547 try {
1548 c->add(a);
1549 } catch (DuplicateElement const&) { c->overload(a); }
1550 } catch (Exception const&) {
1551 if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1552 }
1553
1554 _stack_.push_back(a);
1555 }

References _checkStackContainter_(), _retrieveType_(), _stack_, gum::prm::PRMClassElementContainer< GUM_SCALAR >::add(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElement< GUM_SCALAR >::id(), gum::prm::PRMObject::isClass(), and gum::prm::PRMClassElementContainer< GUM_SCALAR >::overload().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::_declareAttribute_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), and addAttribute().

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

◆ startClass()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startClass ( const std::string & c,
const std::string & ext = "",
const Set< std::string > * implements = nullptr,
bool delayInheritance = false )
overridevirtual

Tells the factory that we start a class declaration.

Use the default values if you do not want c to be a subclass or to implement interfaces.

Parameters
cThe class name.
extThe name of the super class of c.
implementsThe list of interface implemented by c.
delayInheritanceIf true, the created gum::prm::Class inheritance will be delayed.
Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 63 of file PRMFactory_tpl.h.

66 {
68 if (_prm_->_classMap_.exists(real_name) || _prm_->_interfaceMap_.exists(real_name)) {
69 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
70 }
71 PRMClass< GUM_SCALAR >* c = nullptr;
74
75 if (implements != 0) {
76 for (const auto& imp: *implements) {
78 }
79 }
80
81 if (extends != "") { mother = _retrieveClass_(extends); }
82
83 if ((extends.empty()) && impl.empty()) {
85 } else if ((extends != "") && impl.empty()) {
87 } else if ((extends.empty()) && (!impl.empty())) {
89 } else if ((extends != "") && (!impl.empty())) {
91 }
92
93 _prm_->_classMap_.insert(c->name(), c);
94 _prm_->_classes_.insert(c);
95 _stack_.push_back(c);
96 }

References _addPrefix_(), _prm_, _retrieveClass_(), _retrieveInterface_(), _stack_, gum::Set< Key >::empty(), GUM_ERROR, gum::Set< Key >::insert(), and gum::prm::PRMObject::name().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), addInstance(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses().

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

◆ startDiscreteType()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startDiscreteType ( const std::string & name,
std::string super = "" )
overridevirtual

Start a discrete subtype declaration.

Parameters
nameThe discrete type's name.
superThe super type of the declared discrete type.
Exceptions
DuplicateElementRaised if an object with the same name already exists.

Implements gum::prm::IPRMFactory.

Definition at line 1373 of file PRMFactory_tpl.h.

1374 {
1376 if (_prm_->_typeMap_.exists(real_name)) {
1377 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
1378 }
1379 if (super.empty()) {
1380 auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1381 _stack_.push_back(t);
1382 } else {
1383 auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1384 t->_superType_ = _retrieveType_(super);
1385 t->_label_map_ = new std::vector< Idx >();
1386 _stack_.push_back(t);
1387 }
1388 }

References _addPrefix_(), _prm_, _retrieveType_(), _stack_, and GUM_ERROR.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildTypes_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateType_(), and gum::prm::LayerGenerator< GUM_SCALAR >::_generateType_().

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

◆ startDiscretizedType()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startDiscretizedType ( const std::string & name)
overridevirtual

Start a discretized type declaration.

Parameters
nameThe discretized type's name.
Exceptions
DuplicateElementRaised if an object with the same name already exists.

Implements gum::prm::IPRMFactory.

Definition at line 1455 of file PRMFactory_tpl.h.

1455 {
1457 if (_prm_->_typeMap_.exists(real_name)) {
1458 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
1459 }
1461 auto t = new PRMType(var);
1462 _stack_.push_back(t);
1463 }

References _addPrefix_(), _prm_, _stack_, and GUM_ERROR.

Referenced by gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::_buildRealTypes_().

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

◆ startInterface()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startInterface ( const std::string & i,
const std::string & ext = "",
bool delayInheritance = false )
overridevirtual

Tells the factory that we start an interface declaration.

Use the default values if you do not want c to be a subclass or to implement interfaces.

Parameters
iThe interface name.
extThe name of the super interface of i.
delayInheritanceIf true, the created gum::prm::PRMInterface inheritance will be delayed.
Exceptions
NotFoundRaised if ext does not match any declared PRMInterface<GUM_SCALAR>.

Implements gum::prm::IPRMFactory.

Definition at line 193 of file PRMFactory_tpl.h.

195 {
197 if (_prm_->_classMap_.exists(real_name) || _prm_->_interfaceMap_.exists(real_name)) {
198 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
199 }
200 PRMInterface< GUM_SCALAR >* i = nullptr;
202
203 if (extends != "") { super = _retrieveInterface_(extends); }
204
205 if (super != nullptr) {
207 } else {
209 }
210
211 _prm_->_interfaceMap_.insert(i->name(), i);
212 _prm_->_interfaces_.insert(i);
213 _stack_.push_back(i);
214 }

References _addPrefix_(), _prm_, _retrieveInterface_(), _stack_, GUM_ERROR, and gum::prm::PRMObject::name().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateInterfaces_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateInterfaces_(), and gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildInterfaces().

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

◆ startSystem()

template<typename GUM_SCALAR>
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::startSystem ( const std::string & name)
overridevirtual

Tells the factory that we started declaring a model.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1578 of file PRMFactory_tpl.h.

1578 {
1579 if (_prm_->_systemMap_.exists(name)) {
1580 GUM_ERROR(DuplicateElement, "'" << name << "' is already used.")
1581 }
1583 _stack_.push_back(model);
1584 _prm_->_systemMap_.insert(model->name(), model);
1585 _prm_->_systems_.insert(model);
1586 }

References _addPrefix_(), _prm_, _stack_, GUM_ERROR, and gum::prm::PRMObject::name().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateSystem_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateSystem_(), and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

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

Member Data Documentation

◆ _agg_params_

template<typename GUM_SCALAR>
HashTable< PRMAggregate< GUM_SCALAR >*, std::vector< std::string > > gum::prm::PRMFactory< GUM_SCALAR >::_agg_params_
private

A mapping between aggregators and their parameters.

Definition at line 1046 of file PRMFactory.h.

◆ _namespaces_

template<typename GUM_SCALAR>
std::vector< List< std::string >* > gum::prm::PRMFactory< GUM_SCALAR >::_namespaces_
private

Set of all declared namespaces.

Definition at line 1037 of file PRMFactory.h.

Referenced by ~PRMFactory(), _retrieveClass_(), _retrieveInterface_(), _retrieveType_(), addImport(), popPackage(), and pushPackage().

◆ _packages_

template<typename GUM_SCALAR>
std::vector< std::string > gum::prm::PRMFactory< GUM_SCALAR >::_packages_
private

The prefix used for classes and types names. It is normally the namespace of the corresponding compilation unit.

Definition at line 1034 of file PRMFactory.h.

Referenced by _addPrefix_(), addInstance(), currentPackage(), popPackage(), and pushPackage().

◆ _prm_

◆ _stack_


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