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

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

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

Detailed Description

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

Factory which builds a PRM<GUM_SCALAR>.

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

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

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

See also
PRM<GUM_SCALAR> PRMObject

Definition at line 50 of file PRMType.h.

Constructor & Destructor Documentation

◆ PRMFactory() [1/3]

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

Default constructor.

Definition at line 1361 of file PRMFactory_tpl.h.

1361  {
1362  GUM_CONSTRUCTOR(PRMFactory);
1363  prm__ = new PRM< GUM_SCALAR >();
1364  }
PRMFactory()
Default constructor.
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048

◆ PRMFactory() [2/3]

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

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

Definition at line 1367 of file PRMFactory_tpl.h.

1367  :
1368  IPRMFactory(), prm__(prm) {
1369  GUM_CONSTRUCTOR(PRMFactory);
1370  }
PRMFactory()
Default constructor.
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.

◆ PRMFactory() [3/3]

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

Copy constructor. Don't use it.

◆ ~PRMFactory()

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

Destructor.

Definition at line 1373 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::namespaces__.

1373  {
1374  GUM_DESTRUCTOR(PRMFactory);
1375  while (!namespaces__.empty()) {
1376  auto ns = namespaces__.back();
1377  namespaces__.pop_back();
1378  delete ns;
1379  }
1380  }
PRMFactory()
Default constructor.
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045

Member Function Documentation

◆ addAggregator()

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

Add an aggregator in the current declared class.

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

Parameters
nameThe name of this aggregator.
agg_typeThe name of the aggregator type of this aggregator.
chainsThe set of chains on which this aggregate applies.
paramsThe list of parameters for this aggregator.
typeSome aggregators have a user defined type, use this parameter to define it.
Exceptions
OperationNotAllowedRaised if one or more parameters misses or are not correct.
WrongTypeRaised 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 683 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMAggregate< GUM_SCALAR >::buildImpl(), gum::prm::PRMObject::CLASS, GUM_ERROR, gum::prm::PRMAggregate< GUM_SCALAR >::label(), gum::prm::PRMObject::name(), gum::prm::PRMClass< GUM_SCALAR >::overload(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAggregate< GUM_SCALAR >::str2enum(), 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__().

688  {
689  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
691  // Checking call legality
692 
693  if (chains.size() == 0) {
694  GUM_ERROR(OperationNotAllowed,
695  "a PRMAggregate<GUM_SCALAR> requires at least one parent");
696  }
697 
698  // Retrieving the parents of the aggregate
699  std::vector< PRMClassElement< GUM_SCALAR >* > inputs;
700 
701  // This helps knowing if the aggregate has parents outside the current
702  // class
703  // (see below)
704  bool hasSC = retrieveInputs__(c, chains, inputs);
705 
706  // Checking that all inputs shares the same PRMType (trivial
707  // if
708  // inputs.size() == 1)
709  if (inputs.size() > 1) {
710  for (auto iter = inputs.begin() + 1; iter != inputs.end(); ++iter) {
711  if ((**(iter - 1)).type() != (**iter).type()) {
712  GUM_ERROR(WrongType, "found different types");
713  }
714  }
715  }
716 
717  // Different treatments for different types of aggregate.
718  PRMAggregate< GUM_SCALAR >* agg = nullptr;
719 
720  switch (PRMAggregate< GUM_SCALAR >::str2enum(agg_type)) {
723  if (inputs.front()->type() != *(retrieveType__("boolean"))) {
724  GUM_ERROR(WrongType, "expected booleans");
725  }
726  if (params.size() != 0) {
727  GUM_ERROR(OperationNotAllowed, "invalid number of paramaters");
728  }
729 
730  agg = new PRMAggregate< GUM_SCALAR >(
731  name,
733  inputs.front()->type());
734 
735  break;
736  }
737 
740  if (params.size() != 1) {
741  GUM_ERROR(OperationNotAllowed, "invalid number of parameters");
742  }
743 
744  Idx label_idx = 0;
745 
746  while (label_idx < inputs.front()->type()->domainSize()) {
747  if (inputs.front()->type()->label(label_idx) == params.front()) {
748  break;
749  }
750 
751  ++label_idx;
752  }
753 
754  if (label_idx == inputs.front()->type()->domainSize()) {
755  GUM_ERROR(NotFound, "could not find label");
756  }
757 
758  // Creating and adding the PRMAggregate<GUM_SCALAR>
759  agg = new PRMAggregate< GUM_SCALAR >(
760  name,
762  *(retrieveType__("boolean")),
763  label_idx);
764  agg->label();
765 
766  break;
767  }
768 
774  if (params.size() != 0) {
775  GUM_ERROR(OperationNotAllowed, "invalid number of parameters");
776  }
777 
778  auto output_type = retrieveType__(type);
779 
780  // Creating and adding the PRMAggregate<GUM_SCALAR>
781  agg = new PRMAggregate< GUM_SCALAR >(
782  name, PRMAggregate< GUM_SCALAR >::str2enum(agg_type), *output_type);
783 
784  break;
785  }
786 
788  if (params.size() != 1) {
789  GUM_ERROR(OperationNotAllowed, "invalid number of parameters");
790  }
791 
792  Idx label_idx = 0;
793 
794  while (label_idx < inputs.front()->type()->domainSize()) {
795  if (inputs.front()->type()->label(label_idx) == params.front()) {
796  break;
797  }
798 
799  ++label_idx;
800  }
801 
802  if (label_idx == inputs.front()->type()->domainSize()) {
803  GUM_ERROR(NotFound, "could not find label");
804  }
805 
806  auto output_type = retrieveType__(type);
807 
808  // Creating and adding the PRMAggregate<GUM_SCALAR>
809  agg = new PRMAggregate< GUM_SCALAR >(
810  name,
812  *output_type,
813  label_idx);
814 
815  break;
816  }
817 
818  default: {
819  GUM_ERROR(FatalError, "Unknown aggregator.");
820  }
821  }
822 
823  std::string safe_name = agg->safeName();
824 
825  try {
826  if (hasSC) {
827  try {
828  c->add(agg);
829  } catch (DuplicateElement&) { c->overload(agg); }
830  } else {
831  // Inner aggregators can be directly used as attributes
832  auto attr = new PRMScalarAttribute< GUM_SCALAR >(
833  agg->name(), agg->type(), agg->buildImpl());
834 
835  try {
836  c->add(attr);
837  } catch (DuplicateElement&) { c->overload(attr); }
838 
839  delete agg;
840  }
841  } catch (DuplicateElement&) {
842  delete agg;
843  throw;
844  }
845 
846  for (const auto& elt: inputs) {
847  c->addArc(elt->safeName(), safe_name);
848  }
849  }
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 ...
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:101
bool retrieveInputs__(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addArray()

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 877 of file PRMFactory_tpl.h.

References 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__().

879  {
880  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
882  PRMClass< GUM_SCALAR >* c = retrieveClass__(type);
883  PRMInstance< GUM_SCALAR >* inst = 0;
884 
885  try {
886  model->addArray(name, *c);
887 
888  for (Size i = 0; i < size; ++i) {
889  std::stringstream elt_name;
890  elt_name << name << "[" << i << "]";
891  inst = new PRMInstance< GUM_SCALAR >(elt_name.str(), *c);
892  model->add(name, inst);
893  }
894  } catch (TypeError&) {
895  delete inst;
896  throw;
897  } catch (NotFound&) {
898  delete inst;
899  throw;
900  }
901  }
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 ...
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAttribute() [1/2]

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

Add an attribute to an interface.

Implements gum::prm::IPRMFactory.

Definition at line 1591 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMObject::PRM_INTERFACE, and gum::prm::PRMFactory< GUM_SCALAR >::startAttribute().

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

1592  {
1594  startAttribute(type, name);
1595  endAttribute();
1596  }
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 ...
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAttribute() [2/2]

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

Add an already created attribute to the current class.

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

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

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

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

Definition at line 225 of file PRMFactory_tpl.h.

References 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, Alloc, std::is_scalar< Key >::value >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAttribute< GUM_SCALAR >::type(), and gum::prm::PRMType::variable().

225  {
226  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
228  c->add(attr);
229  Size count = 0;
230  const Sequence< const DiscreteVariable* >& vars =
231  attr->cpf().variablesSequence();
232 
233  for (const auto& node: c->containerDag().nodes()) {
234  try {
235  if (vars.exists(&(c->get(node).type().variable()))) {
236  ++count;
237 
238  if (&(attr->type().variable()) != &(c->get(node).type().variable())) {
239  c->addArc(c->get(node).safeName(), attr->safeName());
240  }
241  }
242  } catch (OperationNotAllowed&) {}
243  }
244 
245  if (count != attr->cpf().variablesSequence().size()) {
246  GUM_ERROR(NotFound, "unable to found all parents of this attribute");
247  }
248  }
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 ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ addImport()

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

Add an import for namespace lookup.

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

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

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1876 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::namespaces__.

1876  {
1877  if (name.size() == 0) {
1878  GUM_ERROR(OperationNotAllowed, "illegal import name");
1879  }
1880  if (namespaces__.empty()) {
1881  namespaces__.push_back(new List< std::string >());
1882  }
1883  namespaces__.back()->push_back(name);
1884  }
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ addInstance() [1/2]

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

Add an instance to the model.

Implements gum::prm::IPRMFactory.

Definition at line 1669 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addInstance__(), and gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass__().

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

1670  {
1671  auto c = retrieveClass__(type);
1672 
1673  // If class contains parameters, calls the proper addIsntance method
1674  if (c->parameters().size() > 0) {
1676  addInstance(type, name, params);
1677 
1678  } else {
1679  addInstance__(c, name);
1680  }
1681  }
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
void addInstance__(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addInstance() [2/2]

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1684 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addInstance__(), gum::prm::PRMFactory< GUM_SCALAR >::addParameter(), gum::HashTable< Key, Val, Alloc >::empty(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::PRMFactory< GUM_SCALAR >::packages__, gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass__(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

1687  {
1688  auto c = retrieveClass__(type);
1689 
1690  if (c->parameters().empty()) {
1691  if (params.empty()) {
1692  addInstance__(c, name);
1693  } else {
1694  GUM_ERROR(OperationNotAllowed,
1695  "Class " + type + " does not have parameters");
1696  }
1697 
1698  } else {
1699  auto my_params = params;
1700  // Adding all parameters to my_params
1701  for (const auto& p: c->parameters()) {
1702  if (!my_params.exists(p->name())) {
1703  my_params.insert(p->name(), p->value());
1704  }
1705  }
1706 
1707  // Building sub class name using my_params
1708  std::stringstream sBuff;
1709  sBuff << c->name() << "<";
1710 
1711  for (const auto& p: my_params) {
1712  sBuff << p.first << "=" << p.second << ",";
1713  }
1714 
1715  // Removing last , and adding closing >
1716  std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) + ">";
1717 
1718  // Adding class in current package
1719  try {
1720  auto pck_cpy = packages__;
1721  packages__.clear();
1722 
1723  startClass(sub_c, c->name());
1724 
1725  // Update inherited parameters
1726  for (auto p: my_params) {
1727  auto type = static_cast< PRMParameter< GUM_SCALAR >& >(c->get(p.first))
1728  .valueType();
1729  if (type == PRMParameter< GUM_SCALAR >::ParameterType::INT) {
1730  addParameter("int", p.first, p.second);
1731 
1732  } else {
1733  addParameter("real", p.first, p.second);
1734  }
1735  }
1736 
1737  endClass();
1738 
1739  packages__ = pck_cpy;
1740 
1741  } catch (DuplicateElement&) {
1742  // Sub Class already exists in this system
1743  }
1744  c = retrieveClass__(sub_c);
1745  addInstance__(c, name);
1746  }
1747  }
std::vector< std::string > packages__
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1042
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
void addInstance__(PRMClass< GUM_SCALAR > *type, const std::string &name)
Adds a instance to the current model.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool empty() const noexcept
Indicates whether the hash table is empty.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ addInstance__()

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

Adds a instance to the current model.

Definition at line 1751 of file PRMFactory_tpl.h.

References gum::prm::PRMInstance< GUM_SCALAR >::add(), gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), and gum::prm::PRMObject::SYSTEM.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addInstance().

1752  {
1753  PRMInstance< GUM_SCALAR >* i = nullptr;
1754  try {
1755  auto s = static_cast< PRMSystem< GUM_SCALAR >* >(
1757  i = new PRMInstance< GUM_SCALAR >(name, *type);
1758  s->add(i);
1759 
1760  } catch (OperationNotAllowed&) {
1761  if (i) { delete i; }
1762  throw;
1763  }
1764  }
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 ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addLabel()

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

Add a label to the current discrete type.

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

Implements gum::prm::IPRMFactory.

Definition at line 1444 of file PRMFactory_tpl.h.

References gum::LabelizedVariable::addLabel(), gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), 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__().

1445  {
1446  if (extends == "") {
1447  PRMType* t =
1448  static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1449  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->var__);
1450 
1451  if (!var) {
1452  GUM_ERROR(FatalError,
1453  "the current type's variable is not a LabelizedVariable.");
1454  } else if (t->superType__) {
1455  GUM_ERROR(OperationNotAllowed, "current type is a subtype.");
1456  }
1457 
1458  try {
1459  var->addLabel(l);
1460  } catch (DuplicateElement&) {
1461  GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists");
1462  }
1463  } else {
1464  PRMType* t =
1465  static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1466  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->var__);
1467 
1468  if (!var) {
1469  GUM_ERROR(FatalError,
1470  "the current type's variable is not a LabelizedVariable.");
1471  } else if (!t->superType__) {
1472  GUM_ERROR(OperationNotAllowed, "current type is not a subtype.");
1473  }
1474 
1475  bool found = false;
1476 
1477  for (Idx i = 0; i < t->superType__->var__->domainSize(); ++i) {
1478  if (t->superType__->var__->label(i) == extends) {
1479  try {
1480  var->addLabel(l);
1481  } catch (DuplicateElement&) {
1482  GUM_ERROR(DuplicateElement, "a label '" << l << "' already exists");
1483  }
1484 
1485  t->label_map__->push_back(i);
1486 
1487  found = true;
1488  break;
1489  }
1490  }
1491 
1492  if (!found) { GUM_ERROR(NotFound, "inexistent label in super type."); }
1493  }
1494  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addNoisyOrCompound()

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1119 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClassElement< GUM_SCALAR >::cast(), gum::MultiDimICIModel< GUM_SCALAR >::causalWeight(), gum::prm::PRMObject::CLASS, gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), and GUM_ERROR.

1124  {
1126  GUM_ERROR(gum::FactoryInvalidState, "invalid state to add a noisy-or");
1127  }
1128 
1129  PRMClass< GUM_SCALAR >* c =
1130  dynamic_cast< gum::prm::PRMClass< GUM_SCALAR >* >(getCurrent());
1131 
1132  std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1133 
1134  for (const auto& elt: chains)
1135  parents.push_back(&(c->get(elt)));
1136 
1137  PRMType* common_type = retrieveCommonType__(parents);
1138 
1139  for (size_t idx = 0; idx < parents.size(); ++idx) {
1140  if (parents[idx]->type() != (*common_type)) {
1141  PRMClassElement< GUM_SCALAR >* parent = parents[idx];
1142  // Either safe_name is an non existing slot chain or an existing cast
1143  // descendant
1144  std::string safe_name = parent->cast(*common_type);
1145 
1146  if (!c->exists(safe_name)) {
1148  parents[idx] = buildSlotChain__(c, safe_name);
1149  c->add(parents[idx]);
1150  } else {
1151  GUM_ERROR(NotFound, "unable to find parent");
1152  }
1153  } else {
1154  parents[idx] = &(c->get(safe_name));
1155  }
1156  }
1157  }
1158 
1159  if (numbers.size() == 1) {
1160  auto impl =
1161  new gum::MultiDimNoisyORCompound< GUM_SCALAR >(leak, numbers.front());
1162  auto attr = new PRMScalarAttribute< GUM_SCALAR >(
1163  name, retrieveType("boolean"), impl);
1164  addAttribute(attr);
1165  } else if (numbers.size() == parents.size()) {
1170  name, retrieveType("boolean"), noisy);
1171 
1172  for (size_t idx = 0; idx < numbers.size(); ++idx) {
1173  noisy->causalWeight(parents[idx]->type().variable(), numbers[idx]);
1174  }
1175 
1176  addAttribute(attr);
1177  } else {
1178  GUM_ERROR(OperationNotAllowed, "invalid parameters for a noisy or");
1179  }
1180 
1181  if (!labels.empty()) {
1182  GUM_ERROR(OperationNotAllowed,
1183  "labels definitions not handle for noisy-or");
1184  }
1185  }
PRMSlotChain< GUM_SCALAR > * buildSlotChain__(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
PRMType & retrieveType(const std::string &name)
Returns a reference over a PRMType given its name.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
virtual PRMObject::prm_type currentType() const override
<agrum/PRM/elements/funcAttribute.h>
virtual PRMObject * getCurrent() override
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:66
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
+ Here is the call graph for this function:

◆ addParameter()

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 547 of file PRMFactory_tpl.h.

References gum::prm::PRMObject::CLASS.

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

549  {
550  auto c = static_cast< PRMClass< GUM_SCALAR >* >(
552 
553  PRMParameter< GUM_SCALAR >* p = nullptr;
554  if (type == "int") {
555  p = new PRMParameter< GUM_SCALAR >(
556  name,
557  PRMParameter< GUM_SCALAR >::ParameterType::INT,
558  (GUM_SCALAR)value);
559  } else if (type == "real") {
560  p = new PRMParameter< GUM_SCALAR >(
561  name,
562  PRMParameter< GUM_SCALAR >::ParameterType::REAL,
563  (GUM_SCALAR)value);
564  }
565 
566  try {
567  c->add(p);
568  } catch (DuplicateElement&) { c->overload(p); }
569  }
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 ...
+ Here is the caller graph for this function:

◆ addParent()

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

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

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

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 308 of file PRMFactory_tpl.h.

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__().

308  {
309  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(2);
310  try {
311  // Retrieving pointers
312  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
314  addParent__(c, a, name);
315  } catch (FactoryInvalidState&) {
316  auto agg = static_cast< PRMAggregate< GUM_SCALAR >* >(
318  addParent__(static_cast< PRMClass< GUM_SCALAR >* >(c), agg, name);
319  }
320  }
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 ...
void addParent__(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
PRMClassElementContainer< GUM_SCALAR > * checkStackContainter__(Idx i)
Adds prefix__ to str iff prefix__ != "".
+ Here is the caller graph for this function:

◆ addParent__() [1/2]

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

Add a parent to an attribute.

Definition at line 251 of file PRMFactory_tpl.h.

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

254  {
255  try {
256  PRMClassElement< GUM_SCALAR >& elt = c->get(name);
257 
258  switch (elt.elt_type()) {
260  GUM_ERROR(OperationNotAllowed,
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,
268  "can not add a multiple slot chain to an attribute");
269  }
270 
271  c->addArc(name, a->name());
272 
273  break;
274  }
275 
278  c->addArc(name, a->name());
279  break;
280  }
281 
282  default: {
283  GUM_ERROR(FatalError, "unknown ClassElement<GUM_SCALAR>");
284  }
285  }
286  } catch (NotFound&) {
287  // Check if name is a slot chain
288  PRMSlotChain< GUM_SCALAR >* sc = buildSlotChain__(c, name);
289 
290  if (sc == nullptr) {
291  std::string msg =
292  "found no ClassElement<GUM_SCALAR> with the given name ";
293  GUM_ERROR(NotFound, msg + name);
294  } else if (!sc->isMultiple()) {
295  c->add(sc);
296  c->addArc(sc->name(), a->name());
297  } else {
298  delete sc;
299  GUM_ERROR(OperationNotAllowed,
300  "Impossible to add a multiple reference slot as"
301  " direct parent of an PRMAttribute<GUM_SCALAR>.");
302  }
303  }
304  }
PRMSlotChain< GUM_SCALAR > * buildSlotChain__(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ addParent__() [2/2]

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

Add a parent to an aggregate.

Definition at line 620 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMAggregate< GUM_SCALAR >::agg_type(), GUM_ERROR, gum::prm::PRMAggregate< GUM_SCALAR >::hasLabel(), gum::prm::PRMAggregate< GUM_SCALAR >::labelValue(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), and gum::prm::PRMAggregate< GUM_SCALAR >::setLabel().

622  {
623  auto chains = std::vector< std::string >{name};
624  auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
625  retrieveInputs__(c, chains, inputs);
626 
627  switch (agg->agg_type()) {
630  if (inputs.front()->type() != *(retrieveType__("boolean"))) {
631  GUM_ERROR(WrongType, "expected booleans");
632  }
633 
634  break;
635  }
636 
640  if (!agg->hasLabel()) {
641  auto param = agg->labelValue();
642  Idx label_idx = 0;
643 
644  while (label_idx < inputs.front()->type()->domainSize()) {
645  if (inputs.front()->type()->label(label_idx) == param) { break; }
646 
647  ++label_idx;
648  }
649 
650  if (label_idx == inputs.front()->type()->domainSize()) {
651  GUM_ERROR(NotFound, "could not find label");
652  }
653 
654  agg->setLabel(label_idx);
655  }
656 
657  break;
658  }
659 
665  break;
666  }
667 
668  default: {
669  GUM_ERROR(FatalError, "Unknown aggregator.");
670  }
671  }
672 
673  c->addArc(inputs.front()->safeName(), agg->safeName());
674  }
bool retrieveInputs__(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ addPrefix__()

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

Adds prefix__ to str iff prefix__ != "".

Definition at line 1768 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::packages__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addRangeType(), gum::prm::PRMFactory< GUM_SCALAR >::startDiscreteType(), gum::prm::PRMFactory< GUM_SCALAR >::startDiscretizedType(), and gum::prm::PRMFactory< GUM_SCALAR >::startSystem().

1768  {
1769  if (!packages__.empty()) {
1770  std::string full_name = packages__.back();
1771  full_name.append(".");
1772  full_name.append(str);
1773  return full_name;
1774  } else {
1775  return str;
1776  }
1777  }
std::vector< std::string > packages__
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1042
+ Here is the caller graph for this function:

◆ addRangeType()

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

Add a range variable type declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 1562 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addPrefix__(), GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::prm__.

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

1564  {
1565  std::string real_name = addPrefix__(name);
1566  if (prm__->typeMap__.exists(real_name)) {
1567  std::stringstream msg;
1568  msg << "\"" << real_name << "' is already used.";
1569  GUM_ERROR(DuplicateElement, msg.str());
1570  }
1571 
1572  auto var = RangeVariable(real_name, "", minVal, maxVal);
1573  auto t = new PRMType(var);
1574 
1575  if (t->variable().domainSize() < 2) {
1576  GUM_ERROR(OperationNotAllowed,
1577  "current type is not a valid discrete type");
1578  }
1579 
1580  prm__->typeMap__.insert(t->name(), t);
1581  prm__->types__.insert(t);
1582  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addReferenceSlot()

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

Tells the factory that we started declaring a slot.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 852 of file PRMFactory_tpl.h.

References 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::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateClass__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateClasses__(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateInterfaces__(), and gum::prm::LayerGenerator< GUM_SCALAR >::generateInterfaces__().

854  {
855  PRMClassElementContainer< GUM_SCALAR >* owner = checkStackContainter__(1);
856  PRMClassElementContainer< GUM_SCALAR >* slotType = 0;
857 
858  try {
859  slotType = retrieveClass__(type);
860  } catch (NotFound&) {
861  try {
862  slotType = retrieveInterface__(type);
863  } catch (NotFound&) {
864  GUM_ERROR(NotFound, "unknown ReferenceSlot<GUM_SCALAR> slot type");
865  }
866  }
867 
868  PRMReferenceSlot< GUM_SCALAR >* ref =
869  new PRMReferenceSlot< GUM_SCALAR >(name, *slotType, isArray);
870 
871  try {
872  owner->add(ref);
873  } catch (DuplicateElement&) { owner->overload(ref); }
874  }
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
PRMClassElementContainer< GUM_SCALAR > * checkStackContainter__(Idx i)
Adds prefix__ to str iff prefix__ != "".
PRMInterface< GUM_SCALAR > * retrieveInterface__(const std::string &name) const
Returns a pointer on an interface given it&#39;s name. Used when building models, meaning that the interf...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTick()

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

Add a tick to the current discretized type.

Parameters
tickThe tick value.

Implements gum::prm::IPRMFactory.

Definition at line 1527 of file PRMFactory_tpl.h.

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

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

1527  {
1528  PRMType* t =
1529  static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1530  DiscretizedVariable< double >* var =
1531  dynamic_cast< DiscretizedVariable< double >* >(t->var__);
1532 
1533  if (!var) {
1534  GUM_ERROR(FatalError,
1535  "the current type's variable is not a LabelizedVariable.");
1536  }
1537 
1538  try {
1539  var->addTick(tick);
1540  } catch (DefaultInLabel&) {
1541  GUM_ERROR(OperationNotAllowed, "tick already in used for this variable");
1542  }
1543  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildAggregateCPF__()

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

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

◆ buildSlotChain__()

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

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

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

Definition at line 960 of file PRMFactory_tpl.h.

References gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::back(), gum::prm::decomposePath(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::setOutputNode(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::size(), and gum::prm::PRMReferenceSlot< GUM_SCALAR >::slotType().

961  {
962  std::vector< std::string > v;
963  decomposePath(name, v);
964  PRMClassElementContainer< GUM_SCALAR >* current = start;
965  PRMReferenceSlot< GUM_SCALAR >* ref = nullptr;
966  Sequence< PRMClassElement< GUM_SCALAR >* > elts;
967 
968  for (size_t i = 0; i < v.size(); ++i) {
969  try {
970  switch (current->get(v[i]).elt_type()) {
972  ref = &(static_cast< PRMReferenceSlot< GUM_SCALAR >& >(
973  current->get(v[i])));
974  elts.insert(ref);
975  current = &(/*const_cast<PRMClassElementContainer<GUM_SCALAR>&>*/ (
976  ref->slotType()));
977  break;
978 
981 
982  if (i == v.size() - 1) {
983  elts.insert(&(current->get(v[i])));
984  break;
985  } else {
986  return nullptr;
987  }
988 
989  default: {
990  return nullptr;
991  }
992  }
993  } catch (NotFound&) { return nullptr; }
994  }
995 
996  GUM_ASSERT(v.size() == elts.size());
997 
998  current->setOutputNode(*(elts.back()), true);
999 
1000  return new PRMSlotChain< GUM_SCALAR >(name, elts);
1001  }
void decomposePath(const std::string &path, std::vector< std::string > &v)
Decompose a string in a vector of strings using "." as separators.
Definition: utils_prm.cpp:29
+ Here is the call graph for this function:

◆ checkInterfaceImplementation__()

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

Check if c implements correctly all his interfaces.

Definition at line 106 of file PRMFactory_tpl.h.

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

107  {
108  try {
109  for (const auto& i: c->implements()) {
110  try {
111  for (const auto& node: i->containerDag().nodes()) {
112  std::string name = i->get(node).name();
113 
114  switch (i->get(node).elt_type()) {
117  if ((c->get(name).elt_type()
119  || (c->get(name).elt_type()
121  if (!c->get(name).type().isSubTypeOf(i->get(name).type())) {
122  std::stringstream msg;
123  msg << "class " << c->name()
124  << " does not respect interface ";
125  GUM_ERROR(TypeError, msg.str() + i->name());
126  }
127  } else {
128  std::stringstream msg;
129  msg << "class " << c->name() << " does not respect interface ";
130  GUM_ERROR(TypeError, msg.str() + i->name());
131  }
132 
133  break;
134  }
135 
137  if (c->get(name).elt_type()
139  const PRMReferenceSlot< GUM_SCALAR >& ref_i =
140  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(
141  i->get(name));
142  const PRMReferenceSlot< GUM_SCALAR >& ref_this =
143  static_cast< const PRMReferenceSlot< GUM_SCALAR >& >(
144  c->get(name));
145 
146  if (!ref_this.slotType().isSubTypeOf(ref_i.slotType())) {
147  std::stringstream msg;
148  msg << "class " << c->name()
149  << " does not respect interface ";
150  GUM_ERROR(TypeError, msg.str() + i->name());
151  }
152  } else {
153  std::stringstream msg;
154  msg << "class " << c->name() << " does not respect interface ";
155  GUM_ERROR(TypeError, msg.str() + i->name());
156  }
157 
158  break;
159  }
160 
162  // Nothing to check: they are automatically inherited
163  break;
164  }
165 
166  default: {
167  std::string msg =
168  "unexpected ClassElement<GUM_SCALAR> in interface ";
169  GUM_ERROR(FatalError, msg + i->name());
170  }
171  }
172  }
173  } catch (NotFound&) {
174  std::stringstream msg;
175  msg << "class " << c->name() << " does not respect interface ";
176  GUM_ERROR(TypeError, msg.str() + i->name());
177  }
178  }
179  } catch (NotFound&) {
180  // this Class<GUM_SCALAR> does not implement any
181  // PRMInterface<GUM_SCALAR>
182  }
183  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ checkStack__() [1/2]

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

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

Exceptions
FactoryInvalidStateRaised if the stack isn't consistent with the

Definition at line 1781 of file PRMFactory_tpl.h.

References GUM_ERROR, gum::prm::PRMObject::obj_type(), and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance__(), gum::prm::PRMFactory< GUM_SCALAR >::addLabel(), gum::prm::PRMFactory< GUM_SCALAR >::addTick(), gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscreteType(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscretizedType(), gum::prm::PRMFactory< GUM_SCALAR >::endInterface(), gum::prm::PRMFactory< GUM_SCALAR >::endSystem(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines().

1782  {
1783  // Don't forget that Idx are unsigned int
1784  if (stack__.size() - i > stack__.size()) {
1785  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1786  }
1787 
1788  PRMObject* obj = stack__[stack__.size() - i];
1789 
1790  if (obj->obj_type() != obj_type) {
1791  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1792  }
1793 
1794  return obj;
1795  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkStack__() [2/2]

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

Adds prefix__ to str iff prefix__ != "".

Definition at line 1816 of file PRMFactory_tpl.h.

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

1817  {
1818  // Don't forget that Idx are unsigned int
1819  if (stack__.size() - i > stack__.size()) {
1820  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1821  }
1822 
1823  PRMClassElement< GUM_SCALAR >* obj =
1824  dynamic_cast< PRMClassElement< GUM_SCALAR >* >(
1825  stack__[stack__.size() - i]);
1826 
1827  if (obj == 0) {
1828  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1829  }
1830 
1831  if (obj->elt_type() != elt_type) {
1832  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1833  }
1834 
1835  return obj;
1836  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:

◆ checkStackContainter__()

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

Adds prefix__ to str iff prefix__ != "".

Definition at line 1799 of file PRMFactory_tpl.h.

References gum::prm::PRMObject::CLASS, GUM_ERROR, gum::prm::PRMObject::obj_type(), gum::prm::PRMObject::PRM_INTERFACE, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::continueAttribute(), and gum::prm::PRMFactory< GUM_SCALAR >::startAttribute().

1799  {
1800  // Don't forget that Idx are unsigned int
1801  if (stack__.size() - i > stack__.size()) {
1802  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1803  }
1804 
1805  PRMObject* obj = stack__[stack__.size() - i];
1806 
1807  if ((obj->obj_type() == PRMObject::prm_type::CLASS)
1808  || (obj->obj_type() == PRMObject::prm_type::PRM_INTERFACE)) {
1809  return static_cast< PRMClassElementContainer< GUM_SCALAR >* >(obj);
1810  } else {
1811  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1812  }
1813  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ closeCurrent()

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

Close current object being built.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1409 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::stack__.

1409  {
1410  if (stack__.size() > 0) {
1411  PRMObject* obj = stack__.back();
1412  stack__.pop_back();
1413  return obj;
1414  } else {
1415  return 0;
1416  }
1417  }
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

◆ continueAggregator()

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

Conitnues an aggregator declaration.

Definition at line 608 of file PRMFactory_tpl.h.

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

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

608  {
609  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
610  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
611  auto& agg = c->get(name);
613  GUM_ERROR(OperationNotAllowed, name << " not an aggregate");
614  }
615  stack__.push_back(&agg);
616  }
PRMClassElementContainer< GUM_SCALAR > * checkStackContainter__(Idx i)
Adds prefix__ to str iff prefix__ != "".
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ continueAttribute()

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

Continues the declaration of an attribute.

Implements gum::prm::IPRMFactory.

Definition at line 1630 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStackContainter__(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::get(), GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

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

1630  {
1631  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
1632  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
1633  auto& a = c->get(name);
1635  GUM_ERROR(OperationNotAllowed, name << " not an attribute");
1636  }
1637  stack__.push_back(&a);
1638  }
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
PRMClassElementContainer< GUM_SCALAR > * checkStackContainter__(Idx i)
Adds prefix__ to str iff prefix__ != "".
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ continueClass()

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

Continue the declaration of a class.

Implements gum::prm::IPRMFactory.

Definition at line 85 of file PRMFactory_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::addReferenceSlots__(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAggregates__(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAttribute__().

85  {
86  std::string real_name = addPrefix__(name);
87  if (!(prm__->classMap__.exists(real_name))) {
88  std::stringstream msg;
89  msg << "'" << real_name << "' not found";
90  GUM_ERROR(NotFound, msg.str());
91  }
92  stack__.push_back(&(prm__->getClass(real_name)));
93  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the caller graph for this function:

◆ continueInterface()

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

Continue the declaration of an interface.

Implements gum::prm::IPRMFactory.

Definition at line 213 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

213  {
214  std::string real_name = addPrefix__(name);
215  if (!prm__->interfaceMap__.exists(real_name)) {
216  GUM_ERROR(DuplicateElement, "'" << real_name << "' not found.");
217  }
218 
219  PRMInterface< GUM_SCALAR >* i = retrieveInterface__(real_name);
220  stack__.push_back(i);
221  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
PRMInterface< GUM_SCALAR > * retrieveInterface__(const std::string &name) const
Returns a pointer on an interface given it&#39;s name. Used when building models, meaning that the interf...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the caller graph for this function:

◆ currentPackage()

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

Implements gum::prm::IPRMFactory.

Definition at line 1420 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::packages__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::popPackage().

1420  {
1421  return (packages__.empty()) ? "" : packages__.back();
1422  }
std::vector< std::string > packages__
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1042
+ Here is the caller graph for this function:

◆ currentType()

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

Implements gum::prm::IPRMFactory.

Definition at line 1388 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

1388  {
1389  if (stack__.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1390 
1391  return stack__.back()->obj_type();
1392  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

◆ endAggregator()

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

Finishes an aggregate declaration.

Definition at line 677 of file PRMFactory_tpl.h.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates__(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAggregates__().

677  {
679  stack__.pop_back();
680  }
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 ...
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the caller graph for this function:

◆ endAttribute()

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

Tells the factory that we finished declaring an attribute.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1641 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), 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__(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__().

1641  {
1643  stack__.pop_back();
1644  }
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 ...
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endClass()

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

Tells the factory that we finished a class declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 96 of file PRMFactory_tpl.h.

References gum::prm::PRMObject::CLASS.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::addReferenceSlots__(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes(), 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__(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__().

96  {
97  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
99 
100  if (checkImplementations) { checkInterfaceImplementation__(c); }
101 
102  stack__.pop_back();
103  }
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 ...
void checkInterfaceImplementation__(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the caller graph for this function:

◆ endDiscreteType()

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

End the current discrete type declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 1497 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), gum::prm::PRMFactory< GUM_SCALAR >::prm__, gum::prm::PRMFactory< GUM_SCALAR >::stack__, 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__().

1497  {
1498  PRMType* t =
1499  static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1500 
1501  if (!t->isValid__()) {
1502  GUM_ERROR(OperationNotAllowed, "current type is not a valid subtype");
1503  } else if (t->variable().domainSize() < 2) {
1504  GUM_ERROR(OperationNotAllowed,
1505  "current type is not a valid discrete type");
1506  }
1507 
1508  prm__->typeMap__.insert(t->name(), t);
1509 
1510  prm__->types__.insert(t);
1511  stack__.pop_back();
1512  }
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 ...
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endDiscretizedType()

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

End the current discretized type declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 1546 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), gum::prm::PRMFactory< GUM_SCALAR >::prm__, gum::prm::PRMFactory< GUM_SCALAR >::stack__, and gum::prm::PRMObject::TYPE.

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

1546  {
1547  PRMType* t =
1548  static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1549 
1550  if (t->variable().domainSize() < 2) {
1551  GUM_ERROR(OperationNotAllowed,
1552  "current type is not a valid discrete type");
1553  }
1554 
1555  prm__->typeMap__.insert(t->name(), t);
1556 
1557  prm__->types__.insert(t);
1558  stack__.pop_back();
1559  }
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 ...
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endInterface()

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

Tells the factory that we finished an interface declaration.

Implements gum::prm::IPRMFactory.

Definition at line 1585 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::prm::PRMObject::PRM_INTERFACE, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

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

1585  {
1587  stack__.pop_back();
1588  }
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 ...
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endSystem()

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

Tells the factory that we finished declaring a model.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1659 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), GUM_ERROR, gum::prm::PRMSystem< GUM_SCALAR >::instantiate(), gum::prm::PRMFactory< GUM_SCALAR >::stack__, and gum::prm::PRMObject::SYSTEM.

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

1659  {
1660  try {
1661  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
1663  stack__.pop_back();
1664  model->instantiate();
1665  } catch (Exception&) { GUM_ERROR(FatalError, "could not create system"); }
1666  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCurrent() [1/2]

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

Implements gum::prm::IPRMFactory.

Definition at line 1395 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::isArrayInCurrentSystem().

1395  {
1396  if (stack__.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1397 
1398  return stack__.back();
1399  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the caller graph for this function:

◆ getCurrent() [2/2]

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1402 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

1402  {
1403  if (stack__.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1404 
1405  return stack__.back();
1406  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

◆ incArray()

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

Add an instance to an array.

Implements gum::prm::IPRMFactory.

Definition at line 904 of file PRMFactory_tpl.h.

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

905  {
906  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
908 
909  if (model->isArray(l_i)) {
910  if (model->isInstance(r_i)) {
911  model->add(l_i, model->get(r_i));
912  } else {
913  GUM_ERROR(NotFound, "right value is not an instance");
914  }
915  } else {
916  GUM_ERROR(NotFound, "left value is no an array");
917  }
918  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ instantiateSlotChain__()

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

Instantiate a slot chain in the given instance.

◆ isArrayInCurrentSystem()

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

Implements gum::prm::IPRMFactory.

Definition at line 1940 of file PRMFactory_tpl.h.

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

1941  {
1942  const PRMSystem< GUM_SCALAR >* system =
1943  static_cast< const PRMSystem< GUM_SCALAR >* >(getCurrent());
1944  return (system && system->isArray(name));
1945  }
virtual PRMObject * getCurrent() override
+ Here is the call graph for this function:

◆ isClassOrInterface()

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

Implements gum::prm::IPRMFactory.

Definition at line 1920 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass__(), and gum::prm::PRMFactory< GUM_SCALAR >::retrieveInterface__().

1921  {
1922  try {
1923  retrieveClass__(type);
1924  return true;
1925 
1926  } catch (NotFound&) {
1927  } catch (DuplicateElement&) {}
1928 
1929  try {
1930  retrieveInterface__(type);
1931  return true;
1932 
1933  } catch (NotFound&) {
1934  } catch (DuplicateElement&) {}
1935 
1936  return false;
1937  }
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
PRMInterface< GUM_SCALAR > * retrieveInterface__(const std::string &name) const
Returns a pointer on an interface given it&#39;s name. Used when building models, meaning that the interf...
+ Here is the call graph for this function:

◆ operator=()

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

Copy operator. Don't use it.

◆ popPackage()

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

Pop the current package from the package stack.

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

Implements gum::prm::IPRMFactory.

Definition at line 1858 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::currentPackage(), gum::prm::PRMFactory< GUM_SCALAR >::namespaces__, and gum::prm::PRMFactory< GUM_SCALAR >::packages__.

1858  {
1859  std::string plop = currentPackage();
1860 
1861  if (!packages__.empty()) {
1862  std::string s = packages__.back();
1863  packages__.pop_back();
1864 
1865  if (namespaces__.size() > 0) {
1866  delete namespaces__.back();
1867  namespaces__.pop_back();
1868  }
1869  return s;
1870  }
1871 
1872  return plop;
1873  }
std::vector< std::string > packages__
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1042
virtual std::string currentPackage() const override
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
+ Here is the call graph for this function:

◆ prm()

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

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

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

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

Definition at line 1383 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::prm__.

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

1383  {
1384  return prm__;
1385  }
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
+ Here is the caller graph for this function:

◆ pushPackage()

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

Define the current package.

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

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1852 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::namespaces__, and gum::prm::PRMFactory< GUM_SCALAR >::packages__.

1852  {
1853  packages__.push_back(name);
1854  namespaces__.push_back(new List< std::string >());
1855  }
std::vector< std::string > packages__
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1042
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045

◆ retrieveClass()

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

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

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

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

Definition at line 1902 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass__().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateClass__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateClasses__(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__().

1902  {
1903  return *retrieveClass__(name);
1904  }
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveClass__()

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

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

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

Definition at line 1257 of file PRMFactory_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::prm::PRMFactory< GUM_SCALAR >::isClassOrInterface(), and gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass().

1257  {
1258  PRMClass< GUM_SCALAR >* a_class = nullptr;
1259  std::string full_name;
1260 
1261  // Looking for the type using its name
1262  if (prm__->classMap__.exists(name)) {
1263  a_class = prm__->classMap__[name];
1264  full_name = name;
1265  }
1266 
1267  // Looking for the type using current package
1268  std::string prefixed = addPrefix__(name);
1269  if (prm__->classMap__.exists(prefixed)) {
1270  if (a_class == nullptr) {
1271  a_class = prm__->classMap__[prefixed];
1272  full_name = prefixed;
1273  } else if (full_name != prefixed) {
1274  GUM_ERROR(DuplicateElement,
1275  "Class name '" << name
1276  << "' is ambiguous: specify full name.");
1277  }
1278  }
1279 
1280  // Looking for the class using all declared namespaces
1281  if (!namespaces__.empty()) {
1282  auto ns_list = namespaces__.back();
1283  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1284  std::string ns = (*ns_list)[i];
1285  std::string ns_name = ns + "." + name;
1286  if (prm__->classMap__.exists(ns_name)) {
1287  if (a_class == 0) {
1288  a_class = prm__->classMap__[ns_name];
1289  full_name = ns_name;
1290  } else if (full_name != ns_name) {
1291  GUM_ERROR(DuplicateElement,
1292  "Class name '" << name
1293  << "' is ambiguous: specify full name.");
1294  }
1295  }
1296  }
1297  }
1298 
1299  if (a_class == 0) {
1300  GUM_ERROR(NotFound, "Class '" << name << "' not found, check imports.");
1301  }
1302 
1303  return a_class;
1304  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ retrieveCommonType()

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

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

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

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

Definition at line 1913 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::retrieveCommonType__().

1914  {
1915  return *(retrieveCommonType__(elts));
1916  }
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
+ Here is the call graph for this function:

◆ retrieveCommonType__()

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

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

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

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

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

Definition at line 1064 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::retrieveCommonType().

1065  {
1066  const PRMType* current = nullptr;
1068  // Finding all types and super types
1069 
1070  for (const auto& elt: elts) {
1071  try {
1072  current = &((*elt).type());
1073 
1074  while (current != 0) {
1075  // Filling counters
1076  if (counters.exists(current->name())) {
1077  ++(counters[current->name()]);
1078  } else {
1079  counters.insert(current->name(), 1);
1080  }
1081 
1082  // Loop guard
1083  if (current->isSubType()) {
1084  current = &(current->superType());
1085  } else {
1086  current = nullptr;
1087  }
1088  }
1089  } catch (OperationNotAllowed&) {
1090  GUM_ERROR(WrongClassElement,
1091  "found a ClassElement<GUM_SCALAR> without a type");
1092  }
1093  }
1094 
1095  // We need to find the most specialized (i.e. max depth) common type
1096  current = nullptr;
1097 
1098  int max_depth = -1;
1099 
1100  int current_depth = 0;
1101 
1102  for (const auto& elt: counters) {
1103  if ((elt.second) == elts.size()) {
1104  current_depth = typeDepth__(retrieveType__(elt.first));
1105 
1106  if (current_depth > max_depth) {
1107  max_depth = current_depth;
1108  current = retrieveType__(elt.first);
1109  }
1110  }
1111  }
1112 
1113  if (current) { return const_cast< PRMType* >(current); }
1114 
1115  GUM_ERROR(NotFound, "could not find a common type");
1116  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
int typeDepth__(const PRMType *t)
Returns the inheritance depth of a PRMType.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveInputs__()

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

Retrieve inputs for an PRMAggregate.

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

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

Definition at line 1004 of file PRMFactory_tpl.h.

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

1007  {
1008  bool retVal = false;
1009 
1010  for (size_t i = 0; i < chains.size(); ++i) {
1011  try {
1012  inputs.push_back(&(c->get(chains[i])));
1013  retVal = retVal
1014  || PRMClassElement< GUM_SCALAR >::isSlotChain(*(inputs.back()));
1015  } catch (NotFound&) {
1016  inputs.push_back(buildSlotChain__(c, chains[i]));
1017  retVal = true;
1018 
1019  if (inputs.back()) {
1020  c->add(inputs.back());
1021  } else {
1022  GUM_ERROR(NotFound, "unknown slot chain");
1023  }
1024  }
1025  }
1026 
1027  PRMType* t = retrieveCommonType__(inputs);
1028 
1029  std::vector< std::pair< PRMClassElement< GUM_SCALAR >*,
1030  PRMClassElement< GUM_SCALAR >* > >
1031  toAdd;
1032 
1033  for (const auto& elt: inputs) {
1034  if ((*elt).type() != (*t)) {
1036  PRMSlotChain< GUM_SCALAR >* sc =
1037  static_cast< PRMSlotChain< GUM_SCALAR >* >(elt);
1038  std::stringstream name;
1039 
1040  for (Size idx = 0; idx < sc->chain().size() - 1; ++idx) {
1041  name << sc->chain().atPos(idx)->name() << ".";
1042  }
1043 
1044  name << ".(" << t->name() << ")" << sc->lastElt().name();
1045 
1046  try {
1047  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1048  } catch (NotFound&) {
1049  toAdd.push_back(
1050  std::make_pair(elt, buildSlotChain__(c, name.str())));
1051  }
1052  } else {
1053  std::stringstream name;
1054  name << "(" << t->name() << ")" << elt->name();
1055  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1056  }
1057  }
1058  }
1059 
1060  return retVal;
1061  }
PRMSlotChain< GUM_SCALAR > * buildSlotChain__(PRMClassElementContainer< GUM_SCALAR > *start, const std::string &name)
This methods build a PRMSlotChain<GUM_SCALAR> given a starting element and a string.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.
+ Here is the call graph for this function:

◆ retrieveInstanceSequence__()

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

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

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

◆ retrieveInterface__()

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

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

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

Definition at line 1307 of file PRMFactory_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::isClassOrInterface().

1308  {
1309  PRMInterface< GUM_SCALAR >* interface = nullptr;
1310  std::string full_name;
1311 
1312  // Looking for the type using its name
1313  if (prm__->interfaceMap__.exists(name)) {
1314  interface = prm__->interfaceMap__[name];
1315  full_name = name;
1316  }
1317 
1318  // Looking for the type using current package
1319  std::string prefixed = addPrefix__(name);
1320  if (prm__->interfaceMap__.exists(prefixed)) {
1321  if (interface == nullptr) {
1322  interface = prm__->interfaceMap__[prefixed];
1323  full_name = prefixed;
1324  } else if (full_name != prefixed) {
1325  GUM_ERROR(DuplicateElement,
1326  "Interface name '" << name
1327  << "' is ambiguous: specify full name.");
1328  }
1329  }
1330 
1331  // Looking for the interf using all declared namespaces
1332  if (!namespaces__.empty()) {
1333  auto ns_list = namespaces__.back();
1334  // for( const auto & ns : *(namespaces__.top()) ) {
1335  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1336  std::string ns = (*ns_list)[i];
1337  std::string ns_name = ns + "." + name;
1338 
1339  if (prm__->interfaceMap__.exists(ns_name)) {
1340  if (interface == nullptr) {
1341  interface = prm__->interfaceMap__[ns_name];
1342  full_name = ns_name;
1343  } else if (full_name != ns_name) {
1344  GUM_ERROR(DuplicateElement,
1345  "Interface name '"
1346  << name << "' is ambiguous: specify full name.");
1347  }
1348  }
1349  }
1350  }
1351 
1352  if (interface == nullptr) {
1353  GUM_ERROR(NotFound,
1354  "Interface '" << name << "' not found, check imports.");
1355  }
1356 
1357  return interface;
1358  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ retrieveType()

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

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 1908 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::retrieveType__().

1908  {
1909  return *retrieveType__(name);
1910  }
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
+ Here is the call graph for this function:

◆ retrieveType__()

template<typename GUM_SCALAR >
INLINE PRMType * gum::prm::PRMFactory< GUM_SCALAR >::retrieveType__ ( const std::string &  name) 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 1189 of file PRMFactory_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::retrieveType(), gum::prm::PRMFactory< GUM_SCALAR >::startAttribute(), and gum::prm::PRMFactory< GUM_SCALAR >::startDiscreteType().

1189  {
1190  PRMType* type = nullptr;
1191  std::string full_name;
1192 
1193  // Looking for the type using its name
1194  if (prm__->typeMap__.exists(name)) {
1195  type = prm__->typeMap__[name];
1196  full_name = name;
1197  }
1198 
1199  // Looking for the type in current package
1200  std::string prefixed = addPrefix__(name);
1201  if (prm__->typeMap__.exists(prefixed)) {
1202  if (type == 0) {
1203  type = prm__->typeMap__[prefixed];
1204  full_name = prefixed;
1205  } else if (full_name != prefixed) {
1206  GUM_ERROR(DuplicateElement,
1207  "Type name '" << name << "' is ambiguous: specify full name.");
1208  }
1209  }
1210 
1211  // Looking for the type relatively to current package
1212  std::string relatif_ns = currentPackage();
1213  size_t last_dot = relatif_ns.find_last_of('.');
1214  if (last_dot != std::string::npos) {
1215  relatif_ns = relatif_ns.substr(0, last_dot) + '.' + name;
1216  if (prm__->typeMap__.exists(relatif_ns)) {
1217  if (type == 0) {
1218  type = prm__->typeMap__[relatif_ns];
1219  full_name = relatif_ns;
1220  } else if (full_name != relatif_ns) {
1221  GUM_ERROR(DuplicateElement,
1222  "Type name '" << name
1223  << "' is ambiguous: specify full name.");
1224  }
1225  }
1226  }
1227 
1228 
1229  // Looking for the type 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];
1234  std::string ns_name = ns + "." + name;
1235  if (prm__->typeMap__.exists(ns_name)) {
1236  if (type == 0) {
1237  type = prm__->typeMap__[ns_name];
1238  full_name = ns_name;
1239  } else if (full_name != ns_name) {
1240  GUM_ERROR(DuplicateElement,
1241  "Type name '" << name
1242  << "' is ambiguous: specify full name.");
1243  }
1244  }
1245  }
1246  }
1247 
1248  if (type == 0) {
1249  GUM_ERROR(NotFound, "Type '" << name << "' not found, check imports.");
1250  }
1251 
1252  return type;
1253  }
virtual std::string currentPackage() const override
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setCPFByFloatRule()

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

Fills the CPF using a rule.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 398 of file PRMFactory_tpl.h.

References GUM_ERROR.

400  {
401  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
403 
404  if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
405  GUM_ERROR(OperationNotAllowed, "wrong number of parents");
406  }
407 
408  if (values.size() != a->type().variable().domainSize()) {
409  GUM_ERROR(OperationNotAllowed, "wrong number of values");
410  }
411 
412  std::vector< GUM_SCALAR > values2(values.begin(), values.end());
413  setCPFByRule(parents, values2);
414  }
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 ...
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ setCPFByRule() [1/2]

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

Fills the CPF using a rule.

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

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

Definition at line 417 of file PRMFactory_tpl.h.

References gum::Instantiation::chgVal(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::DiscreteVariable::label(), gum::Instantiation::setVals(), and gum::to_string().

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

419  {
420  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
422 
423  if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
424  GUM_ERROR(OperationNotAllowed, "wrong number of parents");
425  }
426 
427  if (values.size() != a->type().variable().domainSize()) {
428  GUM_ERROR(OperationNotAllowed, "wrong number of values");
429  }
430 
431  if (dynamic_cast< PRMFormAttribute< GUM_SCALAR >* >(a)) {
432  auto form = static_cast< PRMFormAttribute< GUM_SCALAR >* >(a);
433  // jnst holds parents with a specific value (not "*")
434  // knst holds parents without a specific value ("*")
435  Instantiation jnst, knst;
436  const DiscreteVariable* var = 0;
437  // not_used Size pos = 0;
438  bool found = false;
439 
440  for (Idx i = 0; i < parents.size(); ++i) {
441  var = form->formulas().variablesSequence().atPos(1 + i);
442 
443  if (parents[i] == "*") {
444  knst.add(*var);
445  } else {
446  jnst.add(*var);
447  // not_used pos = 0;
448  found = false;
449 
450  for (Size j = 0; j < var->domainSize(); ++j) {
451  if (var->label(j) == parents[i]) {
452  jnst.chgVal(*var, j);
453  found = true;
454  break;
455  }
456  }
457 
458  if (!found) {
459  std::string msg = "could not find label ";
460  GUM_ERROR(NotFound, msg + parents[i]);
461  }
462  }
463  }
464 
465  Instantiation inst(form->formulas());
466  inst.setVals(jnst);
467 
468  for (Size i = 0; i < form->type()->domainSize(); ++i) {
469  inst.chgVal(form->type().variable(), i);
470 
471  for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
472  form->formulas().set(inst, std::to_string(values[i]));
473  }
474  }
475 
476  } else {
477  GUM_ERROR(OperationNotAllowed, "invalide attribute type");
478  }
479  }
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 ...
std::string to_string(const Formula &f)
Definition: formula_inl.h:499
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCPFByRule() [2/2]

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 482 of file PRMFactory_tpl.h.

References gum::Instantiation::chgVal(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::DiscreteVariable::label(), and gum::Instantiation::setVals().

484  {
485  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
487 
488  if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
489  GUM_ERROR(OperationNotAllowed, "wrong number of parents");
490  }
491 
492  if (values.size() != a->type().variable().domainSize()) {
493  GUM_ERROR(OperationNotAllowed, "wrong number of values");
494  }
495 
496  if (dynamic_cast< PRMFormAttribute< GUM_SCALAR >* >(a)) {
497  auto form = static_cast< PRMFormAttribute< GUM_SCALAR >* >(a);
498  // jnst holds parents with a specific value (not "*")
499  // knst holds parents without a specific value ("*")
500  Instantiation jnst, knst;
501  const DiscreteVariable* var = 0;
502  // not_used Size pos = 0;
503  bool found = false;
504 
505  for (Idx i = 0; i < parents.size(); ++i) {
506  var = form->formulas().variablesSequence().atPos(1 + i);
507 
508  if (parents[i] == "*") {
509  knst.add(*var);
510  } else {
511  jnst.add(*var);
512  // not_used pos = 0;
513  found = false;
514 
515  for (Size j = 0; j < var->domainSize(); ++j) {
516  if (var->label(j) == parents[i]) {
517  jnst.chgVal(*var, j);
518  found = true;
519  break;
520  }
521  }
522 
523  if (!found) {
524  std::string msg = "could not find label ";
525  GUM_ERROR(NotFound, msg + parents[i]);
526  }
527  }
528  }
529 
530  Instantiation inst(form->formulas());
531  inst.setVals(jnst);
532 
533  for (Size i = 0; i < form->type()->domainSize(); ++i) {
534  inst.chgVal(form->type().variable(), i);
535 
536  for (inst.setFirstIn(knst); !inst.end(); inst.incIn(knst)) {
537  form->formulas().set(inst, values[i]);
538  }
539  }
540 
541  } else {
542  GUM_ERROR(OperationNotAllowed, "invalide attribute type");
543  }
544  }
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 ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByColumns() [1/2]

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Definition at line 365 of file PRMFactory_tpl.h.

References gum::Instantiation::add(), gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), and GUM_ERROR.

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

366  {
367  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
369 
370  if (a->cpf().domainSize() != array.size()) {
371  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
372  }
373 
374  if (a->cpf().nbrDim() == 1) {
375  setRawCPFByLines(array);
376 
377  } else {
378  Instantiation inst(a->cpf());
379  Instantiation jnst;
380  for (auto idx = inst.variablesSequence().rbegin();
381  idx != inst.variablesSequence().rend();
382  --idx) {
383  jnst.add(**idx);
384  }
385 
386  jnst.setFirst();
387  auto idx = (std::size_t)0;
388  while ((!jnst.end()) && idx < array.size()) {
389  inst.setVals(jnst);
390  a->cpf().set(inst, array[idx]);
391  jnst.inc();
392  ++idx;
393  }
394  }
395  }
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 ...
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRawCPFByColumns() [2/2]

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

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

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1948 of file PRMFactory_tpl.h.

References gum::Instantiation::add(), gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::prm::PRMObject::CLASS, GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines().

1949  {
1951 
1952  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1954 
1955  if (a->formulas().domainSize() != array.size()) {
1956  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1957  }
1958 
1959  if (a->formulas().nbrDim() == 1) {
1960  setRawCPFByLines(array);
1961 
1962  } else {
1963  Instantiation inst(a->formulas());
1964  Instantiation jnst;
1965  for (auto idx = inst.variablesSequence().rbegin();
1966  idx != inst.variablesSequence().rend();
1967  --idx) {
1968  jnst.add(**idx);
1969  }
1970 
1971  jnst.setFirst();
1972  auto idx = (std::size_t)0;
1973  while ((!jnst.end()) && idx < array.size()) {
1974  inst.setVals(jnst);
1975  a->formulas().set(inst, array[idx]);
1976  jnst.inc();
1977  ++idx;
1978  }
1979 
1980  // Generate cpf by calling it
1981  a->cpf();
1982  }
1983  }
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 ...
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByFloatColumns()

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 351 of file PRMFactory_tpl.h.

References gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), and GUM_ERROR.

352  {
353  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
355 
356  if (a->cpf().domainSize() != array.size()) {
357  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
358  }
359 
360  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
361  setRawCPFByColumns(array2);
362  }
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 ...
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByFloatLines()

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

Gives the factory the CPF in its raw form.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 323 of file PRMFactory_tpl.h.

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

324  {
325  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
328 
329  if (a->cpf().domainSize() != array.size())
330  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
331 
332  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
333  a->cpf().fillWith(array2);
334  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByLines() [1/2]

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

Gives the factory the CPF in its raw form.

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

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

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

Definition at line 337 of file PRMFactory_tpl.h.

References gum::prm::PRMObject::CLASS, and GUM_ERROR.

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateClass__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateClasses__(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

338  {
340  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(elt);
342 
343  if (a->cpf().domainSize() != array.size()) {
344  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
345  }
346 
347  a->cpf().fillWith(array);
348  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setRawCPFByLines() [2/2]

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

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1986 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::checkStack__(), gum::prm::PRMObject::CLASS, and GUM_ERROR.

1987  {
1989 
1990  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1992 
1993  if (a->formulas().domainSize() != array.size()) {
1994  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1995  }
1996 
1997  a->formulas().populate(array);
1998 
2000  a->cpf();
2001  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setReferenceSlot() [1/2]

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

Instantiate a reference in the current model.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 921 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMObject::SYSTEM.

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::addAssignments__(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::addIncrements__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateSystem__(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateSystem__(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

922  {
923  auto model = static_cast< PRMSystem< GUM_SCALAR >* >(
925  std::vector< PRMInstance< GUM_SCALAR >* > lefts;
926  std::vector< PRMInstance< GUM_SCALAR >* > rights;
927 
928  if (model->isInstance(l_i)) {
929  lefts.push_back(&(model->get(l_i)));
930  } else if (model->isArray(l_i)) {
931  for (const auto& elt: model->getArray(l_i))
932  lefts.push_back(elt);
933  } else {
934  GUM_ERROR(NotFound, "left value does not name an instance or an array");
935  }
936 
937  if (model->isInstance(r_i)) {
938  rights.push_back(&(model->get(r_i)));
939  } else if (model->isArray(r_i)) {
940  for (const auto& elt: model->getArray(r_i))
941  rights.push_back(elt);
942  } else {
943  GUM_ERROR(NotFound, "left value does not name an instance or an array");
944  }
945 
946  for (const auto l: lefts) {
947  for (const auto r: rights) {
948  auto& elt = l->type().get(l_ref);
950  l->add(elt.id(), *r);
951 
952  } else {
953  GUM_ERROR(NotFound, "unfound reference slot");
954  }
955  }
956  }
957  }
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 ...
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setReferenceSlot() [2/2]

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

Instantiate a reference in the current model.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1888 of file PRMFactory_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

1889  {
1890  size_t pos = l_i.find_last_of('.');
1891 
1892  if (pos != std::string::npos) {
1893  std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1894  setReferenceSlot(l_i.substr(0, pos), l_ref, r_i);
1895  } else {
1896  GUM_ERROR(NotFound, "left value does not name an instance or an array");
1897  }
1898  }
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ startAggregator()

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

Start an aggregator declaration.

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

Definition at line 572 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMObject::CLASS, GUM_ERROR, gum::prm::PRMClass< GUM_SCALAR >::overload(), and gum::prm::PRMAggregate< GUM_SCALAR >::str2enum().

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

576  {
577  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
579 
580  auto agg = new PRMAggregate< GUM_SCALAR >(
581  name,
583  *retrieveType__(rv_type));
584 
585  try {
586  c->add(agg);
587  } catch (DuplicateElement&) { c->overload(agg); }
588 
589  switch (agg->agg_type()) {
593  if (params.size() != 1) {
594  GUM_ERROR(OperationNotAllowed, "aggregate requires a parameter");
595  }
596  agg->setLabel(params.front());
597  break;
598  }
599  default: {
600  // Nothing to do
601  }
602  }
603  stack__.push_back(agg);
604  }
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 ...
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:101
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startAttribute()

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

Tells the factory that we start an attribute declaration.

Exceptions
FatalErrorRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1599 of file PRMFactory_tpl.h.

References gum::prm::PRMClassElementContainer< GUM_SCALAR >::add(), gum::prm::PRMFactory< GUM_SCALAR >::checkStackContainter__(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElement< GUM_SCALAR >::id(), gum::prm::PRMObject::isClass(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::overload(), gum::prm::PRMFactory< GUM_SCALAR >::retrieveType__(), and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::declareAttribute__(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateClass__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateClasses__(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__().

1601  {
1602  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
1603  PRMAttribute< GUM_SCALAR >* a = nullptr;
1604 
1605  if (PRMObject::isClass(*c) && (!scalar_attr)) {
1606  a = new PRMFormAttribute< GUM_SCALAR >(
1607  static_cast< PRMClass< GUM_SCALAR >& >(*c),
1608  name,
1609  *retrieveType__(type));
1610 
1611  } else {
1612  a = new PRMScalarAttribute< GUM_SCALAR >(name, *retrieveType__(type));
1613  }
1614 
1615  std::string dot = ".";
1616 
1617  try {
1618  try {
1619  c->add(a);
1620  } catch (DuplicateElement&) { c->overload(a); }
1621  } catch (Exception&) {
1622  if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1623  }
1624 
1625  stack__.push_back(a);
1626  }
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
Definition: PRMObject.h:102
PRMClassElementContainer< GUM_SCALAR > * checkStackContainter__(Idx i)
Adds prefix__ to str iff prefix__ != "".
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startClass()

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

Tells the factory that we start a class declaration.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 48 of file PRMFactory_tpl.h.

References gum::Set< Key, Alloc >::empty(), GUM_ERROR, gum::Set< Key, Alloc >::insert(), and gum::prm::PRMObject::name().

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateClass__(), gum::prm::LayerGenerator< GUM_SCALAR >::generateClasses__(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generateCluster__().

51  {
52  std::string real_name = addPrefix__(name);
53  if (prm__->classMap__.exists(real_name)
54  || prm__->interfaceMap__.exists(real_name)) {
55  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
56  }
57  PRMClass< GUM_SCALAR >* c = nullptr;
58  PRMClass< GUM_SCALAR >* mother = nullptr;
59  Set< PRMInterface< GUM_SCALAR >* > impl;
60 
61  if (implements != 0) {
62  for (const auto& imp: *implements) {
63  impl.insert(retrieveInterface__(imp));
64  }
65  }
66 
67  if (extends != "") { mother = retrieveClass__(extends); }
68 
69  if ((extends == "") && impl.empty()) {
70  c = new PRMClass< GUM_SCALAR >(real_name);
71  } else if ((extends != "") && impl.empty()) {
72  c = new PRMClass< GUM_SCALAR >(real_name, *mother, delayInheritance);
73  } else if ((extends == "") && (!impl.empty())) {
74  c = new PRMClass< GUM_SCALAR >(real_name, impl, delayInheritance);
75  } else if ((extends != "") && (!impl.empty())) {
76  c = new PRMClass< GUM_SCALAR >(real_name, *mother, impl, delayInheritance);
77  }
78 
79  prm__->classMap__.insert(c->name(), c);
80  prm__->classes__.insert(c);
81  stack__.push_back(c);
82  }
PRMClass< GUM_SCALAR > * retrieveClass__(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
PRMInterface< GUM_SCALAR > * retrieveInterface__(const std::string &name) const
Returns a pointer on an interface given it&#39;s name. Used when building models, meaning that the interf...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startDiscreteType()

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

Start a discrete subtype declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 1426 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addPrefix__(), GUM_ERROR, gum::prm::PRMFactory< GUM_SCALAR >::prm__, gum::prm::PRMFactory< GUM_SCALAR >::retrieveType__(), and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

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

1427  {
1428  std::string real_name = addPrefix__(name);
1429  if (prm__->typeMap__.exists(real_name)) {
1430  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
1431  }
1432  if (super == "") {
1433  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1434  stack__.push_back(t);
1435  } else {
1436  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1437  t->superType__ = retrieveType__(super);
1438  t->label_map__ = new std::vector< Idx >();
1439  stack__.push_back(t);
1440  }
1441  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
PRMType * retrieveType__(const std::string &name) const
Returns a pointer on a PRMType given it&#39;s name. Since the type can be given either with it&#39;s local na...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startDiscretizedType()

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

Start a discretized type declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 1516 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addPrefix__(), GUM_ERROR, gum::prm::PRMFactory< GUM_SCALAR >::prm__, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

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

1516  {
1517  std::string real_name = addPrefix__(name);
1518  if (prm__->typeMap__.exists(real_name)) {
1519  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
1520  }
1521  auto var = DiscretizedVariable< double >(real_name, "");
1522  auto t = new PRMType(var);
1523  stack__.push_back(t);
1524  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startInterface()

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

Tells the factory that we start an interface declaration.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 187 of file PRMFactory_tpl.h.

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

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

189  {
190  std::string real_name = addPrefix__(name);
191  if (prm__->classMap__.exists(real_name)
192  || prm__->interfaceMap__.exists(real_name)) {
193  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
194  }
195  PRMInterface< GUM_SCALAR >* i = nullptr;
196  PRMInterface< GUM_SCALAR >* super = nullptr;
197 
198  if (extends != "") { super = retrieveInterface__(extends); }
199 
200  if (super != nullptr) {
201  i = new PRMInterface< GUM_SCALAR >(real_name, *super, delayInheritance);
202  } else {
203  i = new PRMInterface< GUM_SCALAR >(real_name);
204  }
205 
206  prm__->interfaceMap__.insert(i->name(), i);
207  prm__->interfaces__.insert(i);
208  stack__.push_back(i);
209  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
PRMInterface< GUM_SCALAR > * retrieveInterface__(const std::string &name) const
Returns a pointer on an interface given it&#39;s name. Used when building models, meaning that the interf...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startSystem()

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

Tells the factory that we started declaring a model.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 1647 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addPrefix__(), GUM_ERROR, gum::prm::PRMObject::name(), gum::prm::PRMFactory< GUM_SCALAR >::prm__, and gum::prm::PRMFactory< GUM_SCALAR >::stack__.

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

1647  {
1648  if (prm__->systemMap__.exists(name)) {
1649  GUM_ERROR(DuplicateElement, "'" << name << "' is already used.");
1650  }
1651  PRMSystem< GUM_SCALAR >* model =
1652  new PRMSystem< GUM_SCALAR >(addPrefix__(name));
1653  stack__.push_back(model);
1654  prm__->systemMap__.insert(model->name(), model);
1655  prm__->systems__.insert(model);
1656  }
std::string addPrefix__(const std::string &str) const
Adds prefix__ to str iff prefix__ != "".
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ typeDepth__()

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

Returns the inheritance depth of a PRMType.

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

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

Definition at line 1839 of file PRMFactory_tpl.h.

1839  {
1840  int depth = 0;
1841  const PRMType* current = t;
1842 
1843  while (current->isSubType()) {
1844  ++depth;
1845  current = &(current->superType());
1846  }
1847 
1848  return depth;
1849  }

Member Data Documentation

◆ agg_params__

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

A mapping between aggregators and their parameters.

Definition at line 1055 of file PRMFactory.h.

◆ namespaces__

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

◆ packages__

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

◆ prm__

◆ stack__


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