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

Private Member Functions

Private methods for type checking and exception handling.
std::string _addPrefix_ (std::string_view 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_ (std::string_view 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_ (std::string_view 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_ (std::string_view 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, std::string_view 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, std::string_view name)
 Add a parent to an attribute.
void _addParent_ (PRMClass< GUM_SCALAR > *c, PRMAggregate< GUM_SCALAR > *agg, std::string_view name)
 Add a parent to an aggregate.
Private methods handling PRMSystem<GUM_SCALAR> and
void _addInstance_ (PRMClass< GUM_SCALAR > *type, std::string_view name)
 Adds an 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<GUM_Numeric 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 90 of file PRMFactory.h.

Constructor & Destructor Documentation

◆ PRMFactory() [1/3]

template<GUM_Numeric GUM_SCALAR>
gum::prm::PRMFactory< GUM_SCALAR >::PRMFactory ( )

Default constructor.

Definition at line 1304 of file PRMFactory_tpl.h.

1304 {
1306 _prm_ = new PRM< GUM_SCALAR >();
1307 }
Factory which builds a PRM<GUM_SCALAR>.
Definition PRMFactory.h:90
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<GUM_Numeric GUM_SCALAR>
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 1310 of file PRMFactory_tpl.h.

1310 : IPRMFactory(), _prm_(prm) {
1312 }
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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
gum::prm::PRMFactory< GUM_SCALAR >::~PRMFactory ( )
override

Destructor.

Definition at line 1315 of file PRMFactory_tpl.h.

1315 {
1317 while (!_namespaces_.empty()) {
1318 auto ns = _namespaces_.back();
1319 _namespaces_.pop_back();
1320 delete ns;
1321 }
1322 }
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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::_addInstance_ ( PRMClass< GUM_SCALAR > * type,
std::string_view name )
private

Adds an instance to the current model.

Definition at line 1664 of file PRMFactory_tpl.h.

1665 {
1666 PRMInstance< GUM_SCALAR >* i = nullptr;
1667 try {
1668 auto s
1671 s->add(i);
1672
1673 } catch (OperationNotAllowed const&) {
1674 if (i) { delete i; }
1675 throw;
1676 }
1677 }
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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::_addParent_ ( PRMClass< GUM_SCALAR > * c,
PRMAggregate< GUM_SCALAR > * agg,
std::string_view name )
private

Add a parent to an aggregate.

Definition at line 602 of file PRMFactory_tpl.h.

604 {
608
609 switch (agg->agg_type()) {
612 if (inputs.front()->type() != *(_retrieveType_("boolean"))) {
613 GUM_ERROR(TypeError, "expected booleans")
614 }
615
616 break;
617 }
618
622 if (!agg->hasLabel()) {
623 auto param = agg->labelValue();
624 Idx label_idx = 0;
625
626 while (label_idx < inputs.front()->type()->domainSize()) {
627 if (inputs.front()->type()->label(label_idx) == param) { break; }
628
629 ++label_idx;
630 }
631
632 if (label_idx == inputs.front()->type()->domainSize()) {
633 GUM_ERROR(NotFound, "could not find label")
634 }
635
636 agg->setLabel(label_idx);
637 }
638
639 break;
640 }
641
647 break;
648 }
649
650 default : {
651 GUM_ERROR(FatalError, "Unknown aggregator.")
652 }
653 }
654
655 c->addArc(inputs.front()->safeName(), agg->safeName());
656 }
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_(std::string_view 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:76

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::_addParent_ ( PRMClassElementContainer< GUM_SCALAR > * c,
PRMAttribute< GUM_SCALAR > * agg,
std::string_view name )
private

Add a parent to an attribute.

Definition at line 252 of file PRMFactory_tpl.h.

254 {
255 if (c->exists(name)) {
257
258 switch (elt.elt_type()) {
261 "can not add a reference slot as a parent of an attribute")
262 break;
263 }
264
266 if (static_cast< PRMSlotChain< GUM_SCALAR >& >(elt).isMultiple()) {
267 GUM_ERROR(OperationNotAllowed, "can not add a multiple slot chain to an attribute")
268 }
269
270 c->addArc(name, a->name());
271
272 break;
273 }
274
277 c->addArc(name, a->name());
278 break;
279 }
280
281 default : {
282 GUM_ERROR(FatalError, "unknown ClassElement<GUM_SCALAR>")
283 }
284 }
285 } else {
286 // Check if name is a slot chain
288
289 if (sc == nullptr) {
290 GUM_ERROR(NotFound, "found no ClassElement<GUM_SCALAR> with the given name " << name)
291 } else if (!sc->isMultiple()) {
292 c->add(sc);
293 c->addArc(sc->name(), a->name());
294 } else {
295 delete sc;
297 "Impossible to add a multiple reference slot as"
298 " direct parent of an PRMAttribute<GUM_SCALAR>.");
299 }
300 }
301 }
PRMSlotChain< GUM_SCALAR > * _buildSlotChain_(PRMClassElementContainer< GUM_SCALAR > *start, std::string_view 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 >::exists(), 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<GUM_Numeric GUM_SCALAR>
std::string gum::prm::PRMFactory< GUM_SCALAR >::_addPrefix_ ( std::string_view str) const
private

Adds prefix to str iff prefix != "".

Definition at line 1680 of file PRMFactory_tpl.h.

1680 {
1681 if (!_packages_.empty()) {
1683 full_name.append(".");
1684 full_name.append(str);
1685 return full_name;
1686 } else {
1687 return std::string(str);
1688 }
1689 }
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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
PRMSlotChain< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_buildSlotChain_ ( PRMClassElementContainer< GUM_SCALAR > * start,
std::string_view 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 if (!current->exists(v[i])) return nullptr;
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 }
965
966 GUM_ASSERT(v.size() == elts.size());
967
968 current->setOutputNode(*(elts.back()), true);
969
971 }

References gum::SequenceImplementation< Key, Gen >::back(), gum::prm::decomposePath(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), 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<GUM_Numeric GUM_SCALAR>
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 // c->implements() throws NotFound if no interface is implemented
124 const auto& interfaces = c->implements();
125 for (const auto& i: interfaces) {
126 for (const auto& node: i->containerDag().nodes()) {
127 std::string name = i->get(node).name();
128
129 if (!c->exists(name)) {
131 std::format("class {} does not respect interface {}", c->name(), i->name()))
132 }
133
134 switch (i->get(node).elt_type()) {
137 if ((c->get(name).elt_type() == PRMClassElement< GUM_SCALAR >::prm_attribute)
138 || (c->get(name).elt_type() == PRMClassElement< GUM_SCALAR >::prm_aggregate)) {
139 if (!c->get(name).type().isSubTypeOf(i->get(name).type())) {
140 GUM_ERROR(
142 std::format("class {} does not respect interface {}", c->name(), i->name()))
143 }
144 } else {
145 GUM_ERROR(
147 std::format("class {} does not respect interface {}", c->name(), i->name()))
148 }
149
150 break;
151 }
152
154 if (c->get(name).elt_type() == PRMClassElement< GUM_SCALAR >::prm_refslot) {
156 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(i->get(name));
158 = static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(c->get(name));
159
160 if (!ref_this.slotType().isSubTypeOf(ref_i.slotType())) {
161 GUM_ERROR(
163 std::format("class {} does not respect interface {}", c->name(), i->name()))
164 }
165 } else {
166 GUM_ERROR(
168 std::format("class {} does not respect interface {}", c->name(), i->name()))
169 }
170
171 break;
172 }
173
175 // Nothing to check: they are automatically inherited
176 break;
177 }
178
179 default : {
180 std::string msg = "unexpected ClassElement<GUM_SCALAR> in interface ";
181 GUM_ERROR(FatalError, msg + i->name())
182 }
183 }
184 }
185 }
186 } catch (NotFound const&) {
187 // this Class does not implement any Interface
188 }
189 }

References gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), 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<GUM_Numeric GUM_SCALAR>
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 1692 of file PRMFactory_tpl.h.

1692 {
1693 // Don't forget that Idx are unsigned int
1694 if (_stack_.size() - i > _stack_.size()) {
1695 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1696 }
1697
1698 PRMObject* obj = _stack_[_stack_.size() - i];
1699
1700 if (obj->obj_type() != obj_type) {
1701 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1702 }
1703
1704 return obj;
1705 }
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<GUM_Numeric GUM_SCALAR>
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 1726 of file PRMFactory_tpl.h.

1728 {
1729 // Don't forget that Idx are unsigned int
1730 if (_stack_.size() - i > _stack_.size()) {
1731 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1732 }
1733
1735 = dynamic_cast< PRMClassElement< GUM_SCALAR >* >(_stack_[_stack_.size() - i]);
1736
1737 if (obj == 0) { GUM_ERROR(FactoryInvalidState, "illegal sequence of calls") }
1738
1739 if (obj->elt_type() != elt_type) {
1740 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1741 }
1742
1743 return obj;
1744 }

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

Here is the call graph for this function:

◆ _checkStackContainter_()

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

Adds prefix to str iff prefix != "".

Definition at line 1709 of file PRMFactory_tpl.h.

1709 {
1710 // Don't forget that Idx are unsigned int
1711 if (_stack_.size() - i > _stack_.size()) {
1712 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1713 }
1714
1715 PRMObject* obj = _stack_[_stack_.size() - i];
1716
1717 if ((obj->obj_type() == PRMObject::prm_type::CLASS)
1718 || (obj->obj_type() == PRMObject::prm_type::PRM_INTERFACE)) {
1719 return static_cast< PRMClassElementContainer< GUM_SCALAR >* >(obj);
1720 } else {
1721 GUM_ERROR(FactoryInvalidState, "illegal sequence of calls")
1722 }
1723 }

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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
PRMClass< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveClass_ ( std::string_view 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 1207 of file PRMFactory_tpl.h.

1207 {
1210
1211 // Looking for the type using its name
1212 if (auto p = _prm_->_classMap_.tryGet(name)) {
1213 a_class = *p;
1214 full_name = name;
1215 }
1216
1217 // Looking for the type using current package
1219 if (auto p = _prm_->_classMap_.tryGet(prefixed)) {
1220 if (a_class == nullptr) {
1221 a_class = *p;
1223 } else if (full_name != prefixed) {
1225 "Class name '" << name << "' is ambiguous: specify full name.");
1226 }
1227 }
1228
1229 // Looking for the class using all declared namespaces
1230 if (!_namespaces_.empty()) {
1231 auto ns_list = _namespaces_.back();
1232 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1233 std::string ns = (*ns_list)[i];
1235 if (auto p = _prm_->_classMap_.tryGet(ns_name)) {
1236 if (a_class == 0) {
1237 a_class = *p;
1239 } else if (full_name != ns_name) {
1241 "Class name '" << name << "' is ambiguous: specify full name.");
1242 }
1243 }
1244 }
1245 }
1246
1247 if (a_class == 0) { GUM_ERROR(NotFound, "Class '" << name << "' not found, check imports.") }
1248
1249 return a_class;
1250 }
std::string _addPrefix_(std::string_view 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<GUM_Numeric GUM_SCALAR>
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 1029 of file PRMFactory_tpl.h.

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

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

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

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

◆ _retrieveInputs_()

template<GUM_Numeric GUM_SCALAR>
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 974 of file PRMFactory_tpl.h.

977 {
978 bool retVal = false;
979
980 for (size_t i = 0; i < chains.size(); ++i) {
981 if (c->exists(chains[i])) {
982 inputs.push_back(&(c->get(chains[i])));
984 } else {
985 inputs.push_back(_buildSlotChain_(c, chains[i]));
986 retVal = true;
987
988 if (inputs.back()) {
989 c->add(inputs.back());
990 } else {
991 GUM_ERROR(NotFound, "unknown slot chain")
992 }
993 }
994 }
995
997
999 toAdd;
1000
1001 for (const auto& elt: inputs) {
1002 if ((*elt).type() != (*t)) {
1006
1007 for (Size idx = 0; idx < sc->chain().size() - 1; ++idx) {
1008 name << sc->chain().atPos(idx)->name() << ".";
1009 }
1010
1011 name << ".(" << t->name() << ")" << sc->lastElt().name();
1012
1013 if (c->exists(name.str())) {
1014 toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1015 } else {
1016 toAdd.push_back(std::make_pair(elt, _buildSlotChain_(c, name.str())));
1017 }
1018 } else {
1019 toAdd.push_back(
1020 std::make_pair(elt, &(c->get(std::format("({}){}", t->name(), elt->name())))));
1021 }
1022 }
1023 }
1024
1025 return retVal;
1026 }
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::PRMClassElementContainer< GUM_SCALAR >::exists(), 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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
PRMInterface< GUM_SCALAR > * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveInterface_ ( std::string_view 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 1254 of file PRMFactory_tpl.h.

1254 {
1257
1258 // Looking for the type using its name
1259 if (auto p = _prm_->_interfaceMap_.tryGet(name)) {
1260 a_interface = *p;
1261 full_name = name;
1262 }
1263
1264 // Looking for the type using current package
1266 if (auto p = _prm_->_interfaceMap_.tryGet(prefixed)) {
1267 if (a_interface == nullptr) {
1268 a_interface = *p;
1270 } else if (full_name != prefixed) {
1272 "Interface name '" << name << "' is ambiguous: specify full name.");
1273 }
1274 }
1275
1276 // Looking for the interf using all declared namespaces
1277 if (!_namespaces_.empty()) {
1278 auto ns_list = _namespaces_.back();
1279 // for( const auto & ns : *( _namespaces_.top()) ) {
1280 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1281 std::string ns = (*ns_list)[i];
1283
1284 if (auto p = _prm_->_interfaceMap_.tryGet(ns_name)) {
1285 if (a_interface == nullptr) {
1286 a_interface = *p;
1288 } else if (full_name != ns_name) {
1290 "Interface name '" << name << "' is ambiguous: specify full name.");
1291 }
1292 }
1293 }
1294 }
1295
1296 if (a_interface == nullptr) {
1297 GUM_ERROR(NotFound, "Interface '" << name << "' not found, check imports.")
1298 }
1299
1300 return a_interface;
1301 }

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<GUM_Numeric GUM_SCALAR>
PRMType * gum::prm::PRMFactory< GUM_SCALAR >::_retrieveType_ ( std::string_view 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 1146 of file PRMFactory_tpl.h.

1146 {
1147 PRMType* type = nullptr;
1149
1150 // Looking for the type using its name
1151 if (auto p = _prm_->_typeMap_.tryGet(name)) {
1152 type = *p;
1153 full_name = name;
1154 }
1155
1156 // Looking for the type in current package
1158 if (auto p = _prm_->_typeMap_.tryGet(prefixed)) {
1159 if (type == 0) {
1160 type = *p;
1162 } else if (full_name != prefixed) {
1163 GUM_ERROR(DuplicateElement, "Type name '" << name << "' is ambiguous: specify full name.")
1164 }
1165 }
1166
1167 // Looking for the type relatively to current package
1169 if (auto last_dot = relatif_ns.find_last_of('.'); last_dot != std::string::npos) {
1170 relatif_ns = relatif_ns.substr(0, last_dot) + '.' + std::string(name);
1171 if (auto p = _prm_->_typeMap_.tryGet(relatif_ns)) {
1172 if (type == 0) {
1173 type = *p;
1175 } else if (full_name != relatif_ns) {
1177 "Type name '" << name << "' is ambiguous: specify full name.");
1178 }
1179 }
1180 }
1181
1182
1183 // Looking for the type using all declared namespaces
1184 if (!_namespaces_.empty()) {
1185 auto ns_list = _namespaces_.back();
1186 for (gum::Size i = 0; i < ns_list->size(); ++i) {
1187 std::string ns = (*ns_list)[i];
1189 if (auto p = _prm_->_typeMap_.tryGet(ns_name)) {
1190 if (type == 0) {
1191 type = *p;
1193 } else if (full_name != ns_name) {
1195 "Type name '" << name << "' is ambiguous: specify full name.");
1196 }
1197 }
1198 }
1199 }
1200
1201 if (type == 0) { GUM_ERROR(NotFound, "Type '" << name << "' not found, check imports.") }
1202
1203 return type;
1204 }
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<GUM_Numeric GUM_SCALAR>
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 1747 of file PRMFactory_tpl.h.

1747 {
1748 int depth = 0;
1749 const PRMType* current = t;
1750
1751 while (current->isSubType()) {
1752 ++depth;
1753 current = &(current->superType());
1754 }
1755
1756 return depth;
1757 }

Referenced by _retrieveCommonType_().

Here is the caller graph for this function:

◆ addAggregator()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addAggregator ( std::string_view name,
std::string_view agg_type,
const std::vector< std::string > & chains,
const std::vector< std::string > & params,
std::string_view 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 665 of file PRMFactory_tpl.h.

669 {
672 // Checking call legality
674
675 if (chains.size() == 0) {
676 GUM_ERROR(OperationNotAllowed, "a PRMAggregate<GUM_SCALAR> requires at least one parent")
677 }
678
679 // Retrieving the parents of the aggregate
681
682 // This helps knowing if the aggregate has parents outside the current
683 // class
684 // (see below)
686
687 // Checking that all inputs shares the same PRMType (trivial
688 // if
689 // inputs.size() == 1)
690 if (inputs.size() > 1) {
691 for (auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
692 if ((**(iter - 1)).type() != (**iter).type()) {
693 GUM_ERROR(TypeError, "found different types")
694 }
695 }
696 }
697
698 // Different treatments for different types of aggregate.
700
704 if (inputs.front()->type() != *(_retrieveType_("boolean"))) {
705 GUM_ERROR(TypeError, "expected booleans")
706 }
707 if (params.size() != 0) { GUM_ERROR(OperationNotAllowed, "invalid number of paramaters") }
708
711 inputs.front()->type());
712
713 break;
714 }
715
718 if (params.size() != 1) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
719
720 Idx label_idx = 0;
721
722 while (label_idx < inputs.front()->type()->domainSize()) {
723 if (inputs.front()->type()->label(label_idx) == params.front()) { break; }
724
725 ++label_idx;
726 }
727
728 if (label_idx == inputs.front()->type()->domainSize()) {
729 GUM_ERROR(NotFound, "could not find label")
730 }
731
732 // Creating and adding the PRMAggregate<GUM_SCALAR>
735 *(_retrieveType_("boolean")),
736 label_idx);
737 agg->label();
738
739 break;
740 }
741
747 if (params.size() != 0) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
748
750
751 // Creating and adding the PRMAggregate<GUM_SCALAR>
754 *output_type);
755
756 break;
757 }
758
760 if (params.size() != 1) { GUM_ERROR(OperationNotAllowed, "invalid number of parameters") }
761
762 Idx label_idx = 0;
763
764 while (label_idx < inputs.front()->type()->domainSize()) {
765 if (inputs.front()->type()->label(label_idx) == params.front()) { break; }
766
767 ++label_idx;
768 }
769
770 if (label_idx == inputs.front()->type()->domainSize()) {
771 GUM_ERROR(NotFound, "could not find label")
772 }
773
775
776 // Creating and adding the PRMAggregate<GUM_SCALAR>
780 label_idx);
781
782 break;
783 }
784
785 default : {
786 GUM_ERROR(FatalError, "Unknown aggregator.")
787 }
788 }
789
790 std::string safe_name = agg->safeName();
791
792 try {
793 if (hasSC) {
794 try {
795 c->add(agg);
796 } catch (DuplicateElement const&) { c->overload(agg); }
797 } else {
798 // Inner aggregators can be directly used as attributes
799 auto attr
800 = new PRMScalarAttribute< GUM_SCALAR >(agg->name(), agg->type(), agg->buildImpl());
801
802 try {
803 try {
804 c->add(attr);
805 } catch (DuplicateElement const&) { c->overload(attr); }
806 } catch (...) {
807 delete attr;
808 throw;
809 }
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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addArray ( std::string_view type,
std::string_view 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 {
860
861 for (Size i = 0; i < size; ++i) {
862 inst = new PRMInstance< GUM_SCALAR >(std::format("{}[{}]", name, i), *c);
863 model->add(name_str, inst);
864 inst = nullptr;
865 }
866 } catch (PRMTypeError const&) {
867 delete inst;
868 throw;
869 } catch (NotFound const&) {
870 delete inst;
871 throw;
872 }
873 }
PRMClass< GUM_SCALAR > * _retrieveClass_(std::string_view name) const
Returns a pointer on a class given it's name. Used when building models, meaning that the class name ...
void addArray(std::string_view type, std::string_view name, Size size) override
Creates an array with the given number of instances of the given type.

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<GUM_Numeric GUM_SCALAR>
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 227 of file PRMFactory_tpl.h.

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

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:

◆ addAttribute() [2/2]

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addAttribute ( std::string_view type,
std::string_view name )
overridevirtual

Add an attribute to an interface.

Implements gum::prm::IPRMFactory.

Definition at line 1512 of file PRMFactory_tpl.h.

1512 {
1515 endAttribute();
1516 }
void startAttribute(std::string_view type, std::string_view name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
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:

◆ addImport()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addImport ( std::string_view 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 1784 of file PRMFactory_tpl.h.

1784 {
1785 if (name.size() == 0) { GUM_ERROR(OperationNotAllowed, "illegal import name") }
1786 if (_namespaces_.empty()) { _namespaces_.push_back(new List< std::string >()); }
1787 _namespaces_.back()->push_back(std::string(name));
1788 }

References _namespaces_, and GUM_ERROR.

◆ addInstance() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addInstance ( std::string_view type,
std::string_view name )
overridevirtual

Add an instance to the model.

Implements gum::prm::IPRMFactory.

Definition at line 1589 of file PRMFactory_tpl.h.

1589 {
1590 auto c = _retrieveClass_(type);
1591
1592 // If class contains parameters, calls the proper addIsntance method
1593 if (c->parameters().size() > 0) {
1596
1597 } else {
1599 }
1600 }
void _addInstance_(PRMClass< GUM_SCALAR > *type, std::string_view name)
Adds an instance to the current model.
void addInstance(std::string_view type, std::string_view name) override
Add an instance to the 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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addInstance ( std::string_view type,
std::string_view 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 1603 of file PRMFactory_tpl.h.

1605 {
1606 auto c = _retrieveClass_(type);
1607
1608 if (c->parameters().empty()) {
1609 if (params.empty()) {
1611 } else {
1612 GUM_ERROR(OperationNotAllowed, "Class " << type << " does not have parameters")
1613 }
1614
1615 } else {
1616 auto my_params = params;
1617 // Adding all parameters to my_params
1618 for (const auto& p: c->parameters()) {
1619 if (!my_params.exists(p->name())) { my_params.insert(p->name(), p->value()); }
1620 }
1621
1622 // Building sub class name using my_params
1624 sBuff << c->name() << "<";
1625
1626 for (const auto& p: my_params) {
1627 sBuff << p.first << "=" << p.second << ",";
1628 }
1629
1630 // Removing last , and adding closing >
1631 std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) + ">";
1632
1633 // Adding class in current package
1634 try {
1635 auto pck_cpy = _packages_;
1636 _packages_.clear();
1637
1638 startClass(sub_c, c->name());
1639
1640 // Update inherited parameters
1641 for (auto p: my_params) {
1642 auto type = static_cast< PRMParameter< GUM_SCALAR >& >(c->get(p.first)).valueType();
1644 addParameter("int", p.first, p.second);
1645
1646 } else {
1647 addParameter("real", p.first, p.second);
1648 }
1649 }
1650
1651 endClass();
1652
1654
1655 } catch (DuplicateElement const&) {
1656 // Sub Class already exists in this system
1657 }
1660 }
1661 }
void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
void addParameter(std::string_view type, std::string_view name, double value) override
Add a parameter to the current class with a default value.
void startClass(std::string_view c, std::string_view ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start 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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addLabel ( std::string_view l,
std::string_view 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 1385 of file PRMFactory_tpl.h.

1385 {
1386 if (extends.empty()) {
1387 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1388 LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->_var_);
1389
1390 if (!var) {
1391 GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.")
1392 } else if (t->_superType_) {
1393 GUM_ERROR(OperationNotAllowed, "current type is a subtype.")
1394 }
1395
1396 try {
1397 var->addLabel(l);
1398 } catch (DuplicateElement const&) {
1399 GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists")
1400 }
1401 } else {
1402 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1403 LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->_var_);
1404
1405 if (!var) {
1406 GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.")
1407 } else if (!t->_superType_) {
1408 GUM_ERROR(OperationNotAllowed, "current type is not a subtype.")
1409 }
1410
1411 bool found = false;
1412
1413 for (Idx i = 0; i < t->_superType_->_var_->domainSize(); ++i) {
1414 if (t->_superType_->_var_->label(i) == extends) {
1415 try {
1416 var->addLabel(l);
1417 } catch (DuplicateElement const&) {
1418 GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists")
1419 }
1420
1421 t->_label_map_->push_back(i);
1422
1423 found = true;
1424 break;
1425 }
1426 }
1427
1428 if (!found) { GUM_ERROR(NotFound, "inexistent label in super type.") }
1429 }
1430 }
void addLabel(std::string_view l, std::string_view 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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addNoisyOrCompound ( std::string_view 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 1083 of file PRMFactory_tpl.h.

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

References _buildSlotChain_(), _retrieveCommonType_(), gum::prm::PRMClass< GUM_SCALAR >::add(), addAttribute(), gum::prm::PRMClassElement< GUM_SCALAR >::cast(), gum::MultiDimICIModel< GUM_ELEMENT >::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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addParameter ( std::string_view type,
std::string_view 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 534 of file PRMFactory_tpl.h.

536 {
538
539 PRMParameter< GUM_SCALAR >* p = nullptr;
540 if (type == "int") {
544 } else if (type == "real") {
548 }
549
550 try {
551 c->add(p);
552 } catch (DuplicateElement const&) { c->overload(p); }
553 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addParent ( std::string_view 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 304 of file PRMFactory_tpl.h.

304 {
306 try {
307 // Retrieving pointers
310 _addParent_(c, a, name);
311 } catch (FactoryInvalidState const&) {
312 auto agg = static_cast< PRMAggregate< GUM_SCALAR >* >(
314 _addParent_(static_cast< PRMClass< GUM_SCALAR >* >(c), agg, name);
315 }
316 }
PRMClassElementContainer< GUM_SCALAR > * _checkStackContainter_(Idx i)
Adds prefix to str iff prefix != "".
void _addParent_(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, std::string_view 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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addRangeType ( std::string_view 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 1488 of file PRMFactory_tpl.h.

1488 {
1490 if (_prm_->_typeMap_.exists(real_name)) {
1491 GUM_ERROR(DuplicateElement, std::format("\"{}' is already used.", real_name))
1492 }
1493
1494 auto var = RangeVariable(real_name, "", minVal, maxVal);
1495 auto t = new PRMType(var);
1496
1497 if (t->variable().domainSize() < 2) {
1498 GUM_ERROR(OperationNotAllowed, "current type is not a valid discrete type")
1499 }
1500
1501 _prm_->_typeMap_.insert(t->name(), t);
1502 _prm_->_types_.insert(t);
1503 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot ( std::string_view type,
std::string_view 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_(std::string_view 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<GUM_Numeric GUM_SCALAR>
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 1460 of file PRMFactory_tpl.h.

1460 {
1461 PRMType* t = static_cast< PRMType* >(_checkStack_(1, PRMObject::prm_type::TYPE));
1463
1464 if (!var) { GUM_ERROR(FatalError, "the current type's variable is not a LabelizedVariable.") }
1465
1466 try {
1467 var->addTick(tick);
1468 } catch (DefaultInLabel const&) {
1469 GUM_ERROR(OperationNotAllowed, "tick already in used for this variable")
1470 }
1471 }
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<GUM_Numeric GUM_SCALAR>
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 1351 of file PRMFactory_tpl.h.

1351 {
1352 if (_stack_.size() > 0) {
1353 PRMObject* obj = _stack_.back();
1354 _stack_.pop_back();
1355 return obj;
1356 } else {
1357 return 0;
1358 }
1359 }

References _stack_.

◆ continueAggregator()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::continueAggregator ( std::string_view name)

Conitnues an aggregator declaration.

Definition at line 589 of file PRMFactory_tpl.h.

589 {
591
592 if (!c->exists(name)) GUM_ERROR(NotFound, "Element " << name << "not found")
593
594 auto& agg = c->get(name);
596 GUM_ERROR(OperationNotAllowed, "Element " << name << " not an aggregate")
597
599 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::continueAttribute ( std::string_view name)
overridevirtual

Continues the declaration of an attribute.

Implements gum::prm::IPRMFactory.

Definition at line 1548 of file PRMFactory_tpl.h.

1548 {
1550
1551 if (!c->exists(name)) GUM_ERROR(NotFound, "Attribute " << name << "not found")
1552
1553 auto& a = c->get(name);
1554
1556 GUM_ERROR(OperationNotAllowed, "Element " << name << " not an attribute")
1557
1559 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::continueClass ( std::string_view c)
overridevirtual

Continue the declaration of a class.

Implements gum::prm::IPRMFactory.

Definition at line 102 of file PRMFactory_tpl.h.

102 {
104 if (!(_prm_->_classMap_.exists(real_name))) {
105 GUM_ERROR(NotFound, std::format("'{}' not found", real_name))
106 }
107 _stack_.push_back(&(_prm_->getClass(real_name)));
108 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::continueInterface ( std::string_view name)
overridevirtual

Continue the declaration of an interface.

Implements gum::prm::IPRMFactory.

Definition at line 216 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
std::string gum::prm::PRMFactory< GUM_SCALAR >::currentPackage ( ) const
overridevirtual
Returns
Returns the current package name.

Implements gum::prm::IPRMFactory.

Definition at line 1362 of file PRMFactory_tpl.h.

1362 {
1363 return (_packages_.empty()) ? "" : _packages_.back();
1364 }

References _packages_.

Referenced by _retrieveType_(), and popPackage().

Here is the caller graph for this function:

◆ currentType()

template<GUM_Numeric GUM_SCALAR>
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 1330 of file PRMFactory_tpl.h.

1330 {
1331 if (_stack_.size() == 0) { GUM_ERROR(NotFound, "no object being built") }
1332
1333 return _stack_.back()->obj_type();
1334 }

References _stack_, and GUM_ERROR.

Referenced by addNoisyOrCompound().

Here is the caller graph for this function:

◆ endAggregator()

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

Finishes an aggregate declaration.

Definition at line 659 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<GUM_Numeric GUM_SCALAR>
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 1562 of file PRMFactory_tpl.h.

1562 {
1564 _stack_.pop_back();
1565 }

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<GUM_Numeric GUM_SCALAR>
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 111 of file PRMFactory_tpl.h.

111 {
114
116
117 _stack_.pop_back();
118 }
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<GUM_Numeric GUM_SCALAR>
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 1433 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
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 1474 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::endInterface ( )
overridevirtual

Tells the factory that we finished an interface declaration.

Implements gum::prm::IPRMFactory.

Definition at line 1506 of file PRMFactory_tpl.h.

1506 {
1508 _stack_.pop_back();
1509 }

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<GUM_Numeric GUM_SCALAR>
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 1579 of file PRMFactory_tpl.h.

1579 {
1580 try {
1583 _stack_.pop_back();
1584 model->instantiate();
1585 } catch (Exception const&) { GUM_ERROR(FatalError, "could not create system") }
1586 }

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<GUM_Numeric GUM_SCALAR>
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 1344 of file PRMFactory_tpl.h.

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

References _stack_, and GUM_ERROR.

◆ getCurrent() [2/2]

template<GUM_Numeric GUM_SCALAR>
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 1337 of file PRMFactory_tpl.h.

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

References _stack_, and GUM_ERROR.

Referenced by addNoisyOrCompound(), and isArrayInCurrentSystem().

Here is the caller graph for this function:

◆ incArray()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::incArray ( std::string_view l_i,
std::string_view 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(std::string(l_i))) {
881 if (model->isInstance(std::string(r_i))) {
882 model->add(std::string(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<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMFactory< GUM_SCALAR >::isArrayInCurrentSystem ( std::string_view name) const
overridevirtual

Implements gum::prm::IPRMFactory.

Definition at line 1836 of file PRMFactory_tpl.h.

1836 {
1838 = static_cast< const PRMSystem< GUM_SCALAR >* >(getCurrent());
1839 return (system && system->isArray(name));
1840 }

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

Here is the call graph for this function:

◆ isClassOrInterface()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMFactory< GUM_SCALAR >::isClassOrInterface ( std::string_view type) const
overridevirtual

Implements gum::prm::IPRMFactory.

Definition at line 1817 of file PRMFactory_tpl.h.

1817 {
1818 try {
1820 return true;
1821
1822 } catch (NotFound const&) {
1823 } catch (DuplicateElement const&) {}
1824
1825 try {
1827 return true;
1828
1829 } catch (NotFound const&) {
1830 } catch (DuplicateElement const&) {}
1831
1832 return false;
1833 }

References _retrieveClass_(), and _retrieveInterface_().

Here is the call graph for this function:

◆ operator=()

template<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
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 1766 of file PRMFactory_tpl.h.

1766 {
1768
1769 if (!_packages_.empty()) {
1770 std::string s = _packages_.back();
1771 _packages_.pop_back();
1772
1773 if (_namespaces_.size() > 0) {
1774 delete _namespaces_.back();
1775 _namespaces_.pop_back();
1776 }
1777 return s;
1778 }
1779
1780 return plop;
1781 }

References _namespaces_, _packages_, and currentPackage().

Here is the call graph for this function:

◆ prm()

template<GUM_Numeric GUM_SCALAR>
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 1325 of file PRMFactory_tpl.h.

1325 {
1326 return _prm_;
1327 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::pushPackage ( std::string_view 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 1760 of file PRMFactory_tpl.h.

1760 {
1761 _packages_.emplace_back(name);
1762 _namespaces_.push_back(new List< std::string >());
1763 }

References _namespaces_, and _packages_.

◆ retrieveClass()

template<GUM_Numeric GUM_SCALAR>
PRMClass< GUM_SCALAR > & gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass ( std::string_view 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 1801 of file PRMFactory_tpl.h.

1801 {
1802 return *_retrieveClass_(name);
1803 }

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<GUM_Numeric GUM_SCALAR>
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 1811 of file PRMFactory_tpl.h.

1812 {
1813 return *(_retrieveCommonType_(elts));
1814 }

References _retrieveCommonType_().

Here is the call graph for this function:

◆ retrieveType()

template<GUM_Numeric GUM_SCALAR>
PRMType & gum::prm::PRMFactory< GUM_SCALAR >::retrieveType ( std::string_view 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 1806 of file PRMFactory_tpl.h.

1806 {
1807 return *_retrieveType_(name);
1808 }

References _retrieveType_().

Referenced by addNoisyOrCompound().

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

◆ setCPFByFloatRule()

template<GUM_Numeric GUM_SCALAR>
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 388 of file PRMFactory_tpl.h.

389 {
390 auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
392
393 if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
394 GUM_ERROR(OperationNotAllowed, "wrong number of parents")
395 }
396
397 if (values.size() != a->type().variable().domainSize()) {
398 GUM_ERROR(OperationNotAllowed, "wrong number of values")
399 }
400
403 }
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<GUM_Numeric GUM_SCALAR>
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 406 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
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 470 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
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 357 of file PRMFactory_tpl.h.

357 {
360
361 if (a->cpf().domainSize() != array.size()) {
362 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
363 }
364
365 if (a->cpf().nbrDim() == 1) {
367
368 } else {
369 Instantiation inst(a->cpf());
371 for (auto idx = inst.variablesSequence().rbegin(); idx != inst.variablesSequence().rend();
372 --idx) {
373 jnst.add(**idx);
374 }
375
376 jnst.setFirst();
377 auto idx = (std::size_t)0;
378 while ((!jnst.end()) && idx < array.size()) {
379 inst.setVals(jnst);
380 a->cpf().set(inst, array[idx]);
381 jnst.inc();
382 ++idx;
383 }
384 }
385 }
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<GUM_Numeric GUM_SCALAR>
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 1843 of file PRMFactory_tpl.h.

1843 {
1845
1846 auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1848
1849 if (a->formulas().domainSize() != array.size()) {
1850 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
1851 }
1852
1853 if (a->formulas().nbrDim() == 1) {
1855
1856 } else {
1857 Instantiation inst(a->formulas());
1859 for (auto idx = inst.variablesSequence().rbegin(); idx != inst.variablesSequence().rend();
1860 --idx) {
1861 jnst.add(**idx);
1862 }
1863
1864 jnst.setFirst();
1865 auto idx = (std::size_t)0;
1866 while ((!jnst.end()) && idx < array.size()) {
1867 inst.setVals(jnst);
1868 a->formulas().set(inst, array[idx]);
1869 jnst.inc();
1870 ++idx;
1871 }
1872
1873 // Generate cpf by calling it
1874 a->cpf();
1875 }
1876 }

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<GUM_Numeric GUM_SCALAR>
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 344 of file PRMFactory_tpl.h.

344 {
347
348 if (a->cpf().domainSize() != array.size()) {
349 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
350 }
351
354 }
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<GUM_Numeric GUM_SCALAR>
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 319 of file PRMFactory_tpl.h.

319 {
323
324 if (a->cpf().domainSize() != array.size()) GUM_ERROR(OperationNotAllowed, "illegal CPF size")
325
327 a->cpf().fillWith(array2);
328 }

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<GUM_Numeric GUM_SCALAR>
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 331 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
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 1879 of file PRMFactory_tpl.h.

1879 {
1881
1882 auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1884
1885 if (a->formulas().domainSize() != array.size()) {
1886 GUM_ERROR(OperationNotAllowed, "illegal CPF size")
1887 }
1888
1889 a->formulas().populate(array);
1890
1892 a->cpf();
1893 }

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

Here is the call graph for this function:

◆ setReferenceSlot() [1/2]

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot ( std::string_view l_i,
std::string_view 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 1791 of file PRMFactory_tpl.h.

1791 {
1792 if (auto pos = l_i.find_last_of('.'); pos != std::string_view::npos) {
1793 std::string_view l_ref = l_i.substr(pos + 1);
1794 setReferenceSlot(l_i.substr(0, pos), l_ref, r_i);
1795 } else {
1796 GUM_ERROR(NotFound, "left value does not name an instance or an array")
1797 }
1798 }
void setReferenceSlot(std::string_view left_instance, std::string_view left_reference, std::string_view 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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot ( std::string_view left_instance,
std::string_view left_reference,
std::string_view 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(std::string(l_i))) {
901 lefts.push_back(&(model->get(l_i)));
902 } else if (model->isArray(std::string(l_i))) {
903 for (const auto& elt: model->getArray(std::string(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(std::string(r_i))) {
910 rights.push_back(&(model->get(r_i)));
911 } else if (model->isArray(std::string(r_i))) {
912 for (const auto& elt: model->getArray(std::string(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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startAggregator ( std::string_view name,
std::string_view agg_type,
std::string_view 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 556 of file PRMFactory_tpl.h.

559 {
562
566
567 try {
568 c->add(agg);
569 } catch (DuplicateElement const&) { c->overload(agg); }
570
571 switch (agg->agg_type()) {
575 if (params.size() != 1) {
576 GUM_ERROR(OperationNotAllowed, "aggregate requires a parameter")
577 }
578 agg->setLabel(params.front());
579 break;
580 }
581 default : {
582 // Nothing to do
583 }
584 }
585 _stack_.push_back(agg);
586 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startAttribute ( std::string_view type,
std::string_view 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 1519 of file PRMFactory_tpl.h.

1521 {
1523 PRMAttribute< GUM_SCALAR >* a = nullptr;
1524
1525 if (PRMObject::isClass(*c) && (!scalar_attr)) {
1527 name,
1529
1530 } else {
1532 }
1533
1534 std::string dot = ".";
1535
1536 try {
1537 try {
1538 c->add(a);
1539 } catch (DuplicateElement const&) { c->overload(a); }
1540 } catch (Exception const&) {
1541 if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1542 }
1543
1544 _stack_.push_back(a);
1545 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startClass ( std::string_view c,
std::string_view 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 66 of file PRMFactory_tpl.h.

69 {
71 if (_prm_->_classMap_.exists(real_name) || _prm_->_interfaceMap_.exists(real_name)) {
72 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
73 }
74 PRMClass< GUM_SCALAR >* c = nullptr;
77
78 if (implements != 0) {
79 for (const auto& imp: *implements) {
81 }
82 }
83
84 if (extends != "") { mother = _retrieveClass_(extends); }
85
86 if ((extends.empty()) && impl.empty()) {
88 } else if ((extends != "") && impl.empty()) {
90 } else if ((extends.empty()) && (!impl.empty())) {
92 } else if ((extends != "") && (!impl.empty())) {
94 }
95
96 _prm_->_classMap_.insert(c->name(), c);
97 _prm_->_classes_.insert(c);
98 _stack_.push_back(c);
99 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startDiscreteType ( std::string_view name,
std::string_view 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 1367 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startDiscretizedType ( std::string_view 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 1449 of file PRMFactory_tpl.h.

1449 {
1451 if (_prm_->_typeMap_.exists(real_name)) {
1452 GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.")
1453 }
1455 auto t = new PRMType(var);
1456 _stack_.push_back(t);
1457 }

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startInterface ( std::string_view i,
std::string_view 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 192 of file PRMFactory_tpl.h.

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

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<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::startSystem ( std::string_view 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 1568 of file PRMFactory_tpl.h.

1568 {
1569 if (_prm_->_systemMap_.exists(name)) {
1570 GUM_ERROR(DuplicateElement, "'" << name << "' is already used.")
1571 }
1573 _stack_.push_back(model);
1574 _prm_->_systemMap_.insert(model->name(), model);
1575 _prm_->_systems_.insert(model);
1576 }

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<GUM_Numeric 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 1047 of file PRMFactory.h.

◆ _namespaces_

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

Set of all declared namespaces.

Definition at line 1038 of file PRMFactory.h.

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

◆ _packages_

template<GUM_Numeric 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 1035 of file PRMFactory.h.

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

◆ _prm_

template<GUM_Numeric GUM_SCALAR>
PRM< GUM_SCALAR >* gum::prm::PRMFactory< GUM_SCALAR >::_prm_
private

◆ _stack_


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