aGrUM  0.20.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 49 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 1368 of file PRMFactory_tpl.h.

1368  {
1369  GUM_CONSTRUCTOR(PRMFactory);
1370  prm__ = new PRM< GUM_SCALAR >();
1371  }
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 1374 of file PRMFactory_tpl.h.

1374  :
1375  IPRMFactory(), prm__(prm) {
1376  GUM_CONSTRUCTOR(PRMFactory);
1377  }
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 1380 of file PRMFactory_tpl.h.

1380  {
1381  GUM_DESTRUCTOR(PRMFactory);
1382  while (!namespaces__.empty()) {
1383  auto ns = namespaces__.back();
1384  namespaces__.pop_back();
1385  delete ns;
1386  }
1387  }
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.
TypeErrorRaised if the aggregator's type or one or more of the chains are not of the good type.

Implements gum::prm::IPRMFactory.

Definition at line 682 of file PRMFactory_tpl.h.

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

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

881  {
882  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
884  PRMClass< GUM_SCALAR >* c = retrieveClass__(type);
885  PRMInstance< GUM_SCALAR >* inst = 0;
886 
887  try {
888  model->addArray(name, *c);
889 
890  for (Size i = 0; i < size; ++i) {
891  std::stringstream elt_name;
892  elt_name << name << "[" << i << "]";
893  inst = new PRMInstance< GUM_SCALAR >(elt_name.str(), *c);
894  model->add(name, inst);
895  }
896  } catch (PRMTypeError&) {
897  delete inst;
898  throw;
899  } catch (NotFound&) {
900  delete inst;
901  throw;
902  }
903  }
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:47

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

1599  {
1601  startAttribute(type, name);
1602  endAttribute();
1603  }
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.

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

224  {
225  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
227  c->add(attr);
228  Size count = 0;
229  const Sequence< const DiscreteVariable* >& vars
230  = attr->cpf().variablesSequence();
231 
232  for (const auto& node: c->containerDag().nodes()) {
233  try {
234  if (vars.exists(&(c->get(node).type().variable()))) {
235  ++count;
236 
237  if (&(attr->type().variable()) != &(c->get(node).type().variable())) {
238  c->addArc(c->get(node).safeName(), attr->safeName());
239  }
240  }
241  } catch (OperationNotAllowed&) {}
242  }
243 
244  if (count != attr->cpf().variablesSequence().size()) {
245  GUM_ERROR(NotFound, "unable to found all parents of this attribute");
246  }
247  }
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:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1884  {
1885  if (name.size() == 0) {
1886  GUM_ERROR(OperationNotAllowed, "illegal import name");
1887  }
1888  if (namespaces__.empty()) {
1889  namespaces__.push_back(new List< std::string >());
1890  }
1891  namespaces__.back()->push_back(name);
1892  }
std::vector< List< std::string > *> namespaces__
Set of all declared namespaces.
Definition: PRMFactory.h:1045
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1677  {
1678  auto c = retrieveClass__(type);
1679 
1680  // If class contains parameters, calls the proper addIsntance method
1681  if (c->parameters().size() > 0) {
1683  addInstance(type, name, params);
1684 
1685  } else {
1686  addInstance__(c, name);
1687  }
1688  }
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.

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

1694  {
1695  auto c = retrieveClass__(type);
1696 
1697  if (c->parameters().empty()) {
1698  if (params.empty()) {
1699  addInstance__(c, name);
1700  } else {
1701  GUM_ERROR(OperationNotAllowed,
1702  "Class " + type + " does not have parameters");
1703  }
1704 
1705  } else {
1706  auto my_params = params;
1707  // Adding all parameters to my_params
1708  for (const auto& p: c->parameters()) {
1709  if (!my_params.exists(p->name())) {
1710  my_params.insert(p->name(), p->value());
1711  }
1712  }
1713 
1714  // Building sub class name using my_params
1715  std::stringstream sBuff;
1716  sBuff << c->name() << "<";
1717 
1718  for (const auto& p: my_params) {
1719  sBuff << p.first << "=" << p.second << ",";
1720  }
1721 
1722  // Removing last , and adding closing >
1723  std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) + ">";
1724 
1725  // Adding class in current package
1726  try {
1727  auto pck_cpy = packages__;
1728  packages__.clear();
1729 
1730  startClass(sub_c, c->name());
1731 
1732  // Update inherited parameters
1733  for (auto p: my_params) {
1734  auto type = static_cast< PRMParameter< GUM_SCALAR >& >(c->get(p.first))
1735  .valueType();
1736  if (type == PRMParameter< GUM_SCALAR >::ParameterType::INT) {
1737  addParameter("int", p.first, p.second);
1738 
1739  } else {
1740  addParameter("real", p.first, p.second);
1741  }
1742  }
1743 
1744  endClass();
1745 
1746  packages__ = pck_cpy;
1747 
1748  } catch (DuplicateElement&) {
1749  // Sub Class already exists in this system
1750  }
1751  c = retrieveClass__(sub_c);
1752  addInstance__(c, name);
1753  }
1754  }
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:54

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

1759  {
1760  PRMInstance< GUM_SCALAR >* i = nullptr;
1761  try {
1762  auto s = static_cast< PRMSystem< GUM_SCALAR >* >(
1764  i = new PRMInstance< GUM_SCALAR >(name, *type);
1765  s->add(i);
1766 
1767  } catch (OperationNotAllowed&) {
1768  if (i) { delete i; }
1769  throw;
1770  }
1771  }
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 ...

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

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

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

1129  {
1131  GUM_ERROR(gum::FactoryInvalidState, "invalid state to add a noisy-or");
1132  }
1133 
1134  PRMClass< GUM_SCALAR >* c
1135  = dynamic_cast< gum::prm::PRMClass< GUM_SCALAR >* >(getCurrent());
1136 
1137  std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1138 
1139  for (const auto& elt: chains)
1140  parents.push_back(&(c->get(elt)));
1141 
1142  PRMType* common_type = retrieveCommonType__(parents);
1143 
1144  for (size_t idx = 0; idx < parents.size(); ++idx) {
1145  if (parents[idx]->type() != (*common_type)) {
1146  PRMClassElement< GUM_SCALAR >* parent = parents[idx];
1147  // Either safe_name is an non existing slot chain or an existing cast
1148  // descendant
1149  std::string safe_name = parent->cast(*common_type);
1150 
1151  if (!c->exists(safe_name)) {
1153  parents[idx] = buildSlotChain__(c, safe_name);
1154  c->add(parents[idx]);
1155  } else {
1156  GUM_ERROR(NotFound, "unable to find parent");
1157  }
1158  } else {
1159  parents[idx] = &(c->get(safe_name));
1160  }
1161  }
1162  }
1163 
1164  if (numbers.size() == 1) {
1165  auto impl
1166  = new gum::MultiDimNoisyORCompound< GUM_SCALAR >(leak, numbers.front());
1167  auto attr = new PRMScalarAttribute< GUM_SCALAR >(name,
1168  retrieveType("boolean"),
1169  impl);
1170  addAttribute(attr);
1171  } else if (numbers.size() == parents.size()) {
1176  retrieveType("boolean"),
1177  noisy);
1178 
1179  for (size_t idx = 0; idx < numbers.size(); ++idx) {
1180  noisy->causalWeight(parents[idx]->type().variable(), numbers[idx]);
1181  }
1182 
1183  addAttribute(attr);
1184  } else {
1185  GUM_ERROR(OperationNotAllowed, "invalid parameters for a noisy or");
1186  }
1187 
1188  if (!labels.empty()) {
1189  GUM_ERROR(OperationNotAllowed,
1190  "labels definitions not handle for noisy-or");
1191  }
1192  }
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:65
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:54
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.

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

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

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

307  {
308  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(2);
309  try {
310  // Retrieving pointers
311  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
313  addParent__(c, a, name);
314  } catch (FactoryInvalidState&) {
315  auto agg = static_cast< PRMAggregate< GUM_SCALAR >* >(
317  addParent__(static_cast< PRMClass< GUM_SCALAR >* >(c), agg, name);
318  }
319  }
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__ != "".

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

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

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

621  {
622  auto chains = std::vector< std::string >{name};
623  auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
624  retrieveInputs__(c, chains, inputs);
625 
626  switch (agg->agg_type()) {
629  if (inputs.front()->type() != *(retrieveType__("boolean"))) {
630  GUM_ERROR(TypeError, "expected booleans");
631  }
632 
633  break;
634  }
635 
639  if (!agg->hasLabel()) {
640  auto param = agg->labelValue();
641  Idx label_idx = 0;
642 
643  while (label_idx < inputs.front()->type()->domainSize()) {
644  if (inputs.front()->type()->label(label_idx) == param) { break; }
645 
646  ++label_idx;
647  }
648 
649  if (label_idx == inputs.front()->type()->domainSize()) {
650  GUM_ERROR(NotFound, "could not find label");
651  }
652 
653  agg->setLabel(label_idx);
654  }
655 
656  break;
657  }
658 
664  break;
665  }
666 
667  default: {
668  GUM_ERROR(FatalError, "Unknown aggregator.");
669  }
670  }
671 
672  c->addArc(inputs.front()->safeName(), agg->safeName());
673  }
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:54

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

1775  {
1776  if (!packages__.empty()) {
1777  std::string full_name = packages__.back();
1778  full_name.append(".");
1779  full_name.append(str);
1780  return full_name;
1781  } else {
1782  return str;
1783  }
1784  }
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

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

1571  {
1572  std::string real_name = addPrefix__(name);
1573  if (prm__->typeMap__.exists(real_name)) {
1574  std::stringstream msg;
1575  msg << "\"" << real_name << "' is already used.";
1576  GUM_ERROR(DuplicateElement, msg.str());
1577  }
1578 
1579  auto var = RangeVariable(real_name, "", minVal, maxVal);
1580  auto t = new PRMType(var);
1581 
1582  if (t->variable().domainSize() < 2) {
1583  GUM_ERROR(OperationNotAllowed,
1584  "current type is not a valid discrete type");
1585  }
1586 
1587  prm__->typeMap__.insert(t->name(), t);
1588  prm__->types__.insert(t);
1589  }
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:54

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

856  {
857  PRMClassElementContainer< GUM_SCALAR >* owner = checkStackContainter__(1);
858  PRMClassElementContainer< GUM_SCALAR >* slotType = 0;
859 
860  try {
861  slotType = retrieveClass__(type);
862  } catch (NotFound&) {
863  try {
864  slotType = retrieveInterface__(type);
865  } catch (NotFound&) {
866  GUM_ERROR(NotFound, "unknown ReferenceSlot<GUM_SCALAR> slot type");
867  }
868  }
869 
870  PRMReferenceSlot< GUM_SCALAR >* ref
871  = new PRMReferenceSlot< GUM_SCALAR >(name, *slotType, isArray);
872 
873  try {
874  owner->add(ref);
875  } catch (DuplicateElement&) { owner->overload(ref); }
876  }
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:54

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

1534  {
1535  PRMType* t
1536  = static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1537  DiscretizedVariable< double >* var
1538  = dynamic_cast< DiscretizedVariable< double >* >(t->var__);
1539 
1540  if (!var) {
1541  GUM_ERROR(FatalError,
1542  "the current type's variable is not a LabelizedVariable.");
1543  }
1544 
1545  try {
1546  var->addTick(tick);
1547  } catch (DefaultInLabel&) {
1548  GUM_ERROR(OperationNotAllowed, "tick already in used for this variable");
1549  }
1550  }
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:54

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

966  {
967  std::vector< std::string > v;
968  decomposePath(name, v);
969  PRMClassElementContainer< GUM_SCALAR >* current = start;
970  PRMReferenceSlot< GUM_SCALAR >* ref = nullptr;
971  Sequence< PRMClassElement< GUM_SCALAR >* > elts;
972 
973  for (size_t i = 0; i < v.size(); ++i) {
974  try {
975  switch (current->get(v[i]).elt_type()) {
977  ref = &(static_cast< PRMReferenceSlot< GUM_SCALAR >& >(
978  current->get(v[i])));
979  elts.insert(ref);
980  current = &(/*const_cast<PRMClassElementContainer<GUM_SCALAR>&>*/ (
981  ref->slotType()));
982  break;
983 
986 
987  if (i == v.size() - 1) {
988  elts.insert(&(current->get(v[i])));
989  break;
990  } else {
991  return nullptr;
992  }
993 
994  default: {
995  return nullptr;
996  }
997  }
998  } catch (NotFound&) { return nullptr; }
999  }
1000 
1001  GUM_ASSERT(v.size() == elts.size());
1002 
1003  current->setOutputNode(*(elts.back()), true);
1004 
1005  return new PRMSlotChain< GUM_SCALAR >(name, elts);
1006  }
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:28

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

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

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

1789  {
1790  // Don't forget that Idx are unsigned int
1791  if (stack__.size() - i > stack__.size()) {
1792  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1793  }
1794 
1795  PRMObject* obj = stack__[stack__.size() - i];
1796 
1797  if (obj->obj_type() != obj_type) {
1798  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1799  }
1800 
1801  return obj;
1802  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1825  {
1826  // Don't forget that Idx are unsigned int
1827  if (stack__.size() - i > stack__.size()) {
1828  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1829  }
1830 
1831  PRMClassElement< GUM_SCALAR >* obj
1832  = dynamic_cast< PRMClassElement< GUM_SCALAR >* >(
1833  stack__[stack__.size() - i]);
1834 
1835  if (obj == 0) {
1836  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1837  }
1838 
1839  if (obj->elt_type() != elt_type) {
1840  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1841  }
1842 
1843  return obj;
1844  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1806  {
1807  // Don't forget that Idx are unsigned int
1808  if (stack__.size() - i > stack__.size()) {
1809  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1810  }
1811 
1812  PRMObject* obj = stack__[stack__.size() - i];
1813 
1814  if ((obj->obj_type() == PRMObject::prm_type::CLASS)
1815  || (obj->obj_type() == PRMObject::prm_type::PRM_INTERFACE)) {
1816  return static_cast< PRMClassElementContainer< GUM_SCALAR >* >(obj);
1817  } else {
1818  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1819  }
1820  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1416  {
1417  if (stack__.size() > 0) {
1418  PRMObject* obj = stack__.back();
1419  stack__.pop_back();
1420  return obj;
1421  } else {
1422  return 0;
1423  }
1424  }
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 607 of file PRMFactory_tpl.h.

607  {
608  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
609  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
610  auto& agg = c->get(name);
612  GUM_ERROR(OperationNotAllowed, name << " not an aggregate");
613  }
614  stack__.push_back(&agg);
615  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1637  {
1638  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
1639  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
1640  auto& a = c->get(name);
1642  GUM_ERROR(OperationNotAllowed, name << " not an attribute");
1643  }
1644  stack__.push_back(&a);
1645  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

84  {
85  std::string real_name = addPrefix__(name);
86  if (!(prm__->classMap__.exists(real_name))) {
87  std::stringstream msg;
88  msg << "'" << real_name << "' not found";
89  GUM_ERROR(NotFound, msg.str());
90  }
91  stack__.push_back(&(prm__->getClass(real_name)));
92  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

212  {
213  std::string real_name = addPrefix__(name);
214  if (!prm__->interfaceMap__.exists(real_name)) {
215  GUM_ERROR(DuplicateElement, "'" << real_name << "' not found.");
216  }
217 
218  PRMInterface< GUM_SCALAR >* i = retrieveInterface__(real_name);
219  stack__.push_back(i);
220  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1427  {
1428  return (packages__.empty()) ? "" : packages__.back();
1429  }
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

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

1395  {
1396  if (stack__.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1397 
1398  return stack__.back()->obj_type();
1399  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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 676 of file PRMFactory_tpl.h.

676  {
678  stack__.pop_back();
679  }
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

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

1648  {
1650  stack__.pop_back();
1651  }
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

◆ endClass()

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

Tells the factory that we finished a class declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 95 of file PRMFactory_tpl.h.

95  {
96  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
98 
99  if (checkImplementations) { checkInterfaceImplementation__(c); }
100 
101  stack__.pop_back();
102  }
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

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

1504  {
1505  PRMType* t
1506  = static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1507 
1508  if (!t->isValid__()) {
1509  GUM_ERROR(OperationNotAllowed, "current type is not a valid subtype");
1510  } else if (t->variable().domainSize() < 2) {
1511  GUM_ERROR(OperationNotAllowed,
1512  "current type is not a valid discrete type");
1513  }
1514 
1515  prm__->typeMap__.insert(t->name(), t);
1516 
1517  prm__->types__.insert(t);
1518  stack__.pop_back();
1519  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1553  {
1554  PRMType* t
1555  = static_cast< PRMType* >(checkStack__(1, PRMObject::prm_type::TYPE));
1556 
1557  if (t->variable().domainSize() < 2) {
1558  GUM_ERROR(OperationNotAllowed,
1559  "current type is not a valid discrete type");
1560  }
1561 
1562  prm__->typeMap__.insert(t->name(), t);
1563 
1564  prm__->types__.insert(t);
1565  stack__.pop_back();
1566  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1592  {
1594  stack__.pop_back();
1595  }
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

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

1666  {
1667  try {
1668  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
1670  stack__.pop_back();
1671  model->instantiate();
1672  } catch (Exception&) { GUM_ERROR(FatalError, "could not create system"); }
1673  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1409  {
1410  if (stack__.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1411 
1412  return stack__.back();
1413  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
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 906 of file PRMFactory_tpl.h.

907  {
908  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
910 
911  if (model->isArray(l_i)) {
912  if (model->isInstance(r_i)) {
913  model->add(l_i, model->get(r_i));
914  } else {
915  GUM_ERROR(NotFound, "right value is not an instance");
916  }
917  } else {
918  GUM_ERROR(NotFound, "left value is no an array");
919  }
920  }
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:54

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

1949  {
1950  const PRMSystem< GUM_SCALAR >* system
1951  = static_cast< const PRMSystem< GUM_SCALAR >* >(getCurrent());
1952  return (system && system->isArray(name));
1953  }
virtual PRMObject * getCurrent() override

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

1929  {
1930  try {
1931  retrieveClass__(type);
1932  return true;
1933 
1934  } catch (NotFound&) {
1935  } catch (DuplicateElement&) {}
1936 
1937  try {
1938  retrieveInterface__(type);
1939  return true;
1940 
1941  } catch (NotFound&) {
1942  } catch (DuplicateElement&) {}
1943 
1944  return false;
1945  }
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...

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

1866  {
1867  std::string plop = currentPackage();
1868 
1869  if (!packages__.empty()) {
1870  std::string s = packages__.back();
1871  packages__.pop_back();
1872 
1873  if (namespaces__.size() > 0) {
1874  delete namespaces__.back();
1875  namespaces__.pop_back();
1876  }
1877  return s;
1878  }
1879 
1880  return plop;
1881  }
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

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

1390  {
1391  return prm__;
1392  }
PRM< GUM_SCALAR > * prm__
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1048

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

1860  {
1861  packages__.push_back(name);
1862  namespaces__.push_back(new List< std::string >());
1863  }
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 1910 of file PRMFactory_tpl.h.

1910  {
1911  return *retrieveClass__(name);
1912  }
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 ...

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

1264  {
1265  PRMClass< GUM_SCALAR >* a_class = nullptr;
1266  std::string full_name;
1267 
1268  // Looking for the type using its name
1269  if (prm__->classMap__.exists(name)) {
1270  a_class = prm__->classMap__[name];
1271  full_name = name;
1272  }
1273 
1274  // Looking for the type using current package
1275  std::string prefixed = addPrefix__(name);
1276  if (prm__->classMap__.exists(prefixed)) {
1277  if (a_class == nullptr) {
1278  a_class = prm__->classMap__[prefixed];
1279  full_name = prefixed;
1280  } else if (full_name != prefixed) {
1281  GUM_ERROR(DuplicateElement,
1282  "Class name '" << name
1283  << "' is ambiguous: specify full name.");
1284  }
1285  }
1286 
1287  // Looking for the class using all declared namespaces
1288  if (!namespaces__.empty()) {
1289  auto ns_list = namespaces__.back();
1290  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1291  std::string ns = (*ns_list)[i];
1292  std::string ns_name = ns + "." + name;
1293  if (prm__->classMap__.exists(ns_name)) {
1294  if (a_class == 0) {
1295  a_class = prm__->classMap__[ns_name];
1296  full_name = ns_name;
1297  } else if (full_name != ns_name) {
1298  GUM_ERROR(DuplicateElement,
1299  "Class name '" << name
1300  << "' is ambiguous: specify full name.");
1301  }
1302  }
1303  }
1304  }
1305 
1306  if (a_class == 0) {
1307  GUM_ERROR(NotFound, "Class '" << name << "' not found, check imports.");
1308  }
1309 
1310  return a_class;
1311  }
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:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1922  {
1923  return *(retrieveCommonType__(elts));
1924  }
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.

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

1070  {
1071  const PRMType* current = nullptr;
1073  // Finding all types and super types
1074 
1075  for (const auto& elt: elts) {
1076  try {
1077  current = &((*elt).type());
1078 
1079  while (current != 0) {
1080  // Filling counters
1081  if (counters.exists(current->name())) {
1082  ++(counters[current->name()]);
1083  } else {
1084  counters.insert(current->name(), 1);
1085  }
1086 
1087  // Loop guard
1088  if (current->isSubType()) {
1089  current = &(current->superType());
1090  } else {
1091  current = nullptr;
1092  }
1093  }
1094  } catch (OperationNotAllowed&) {
1095  GUM_ERROR(WrongClassElement,
1096  "found a ClassElement<GUM_SCALAR> without a type");
1097  }
1098  }
1099 
1100  // We need to find the most specialized (i.e. max depth) common type
1101  current = nullptr;
1102 
1103  int max_depth = -1;
1104 
1105  int current_depth = 0;
1106 
1107  for (const auto& elt: counters) {
1108  if ((elt.second) == elts.size()) {
1109  current_depth = typeDepth__(retrieveType__(elt.first));
1110 
1111  if (current_depth > max_depth) {
1112  max_depth = current_depth;
1113  current = retrieveType__(elt.first);
1114  }
1115  }
1116  }
1117 
1118  if (current) { return const_cast< PRMType* >(current); }
1119 
1120  GUM_ERROR(NotFound, "could not find a common type");
1121  }
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:54

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

1012  {
1013  bool retVal = false;
1014 
1015  for (size_t i = 0; i < chains.size(); ++i) {
1016  try {
1017  inputs.push_back(&(c->get(chains[i])));
1018  retVal = retVal
1019  || PRMClassElement< GUM_SCALAR >::isSlotChain(*(inputs.back()));
1020  } catch (NotFound&) {
1021  inputs.push_back(buildSlotChain__(c, chains[i]));
1022  retVal = true;
1023 
1024  if (inputs.back()) {
1025  c->add(inputs.back());
1026  } else {
1027  GUM_ERROR(NotFound, "unknown slot chain");
1028  }
1029  }
1030  }
1031 
1032  PRMType* t = retrieveCommonType__(inputs);
1033 
1034  std::vector< std::pair< PRMClassElement< GUM_SCALAR >*,
1035  PRMClassElement< GUM_SCALAR >* > >
1036  toAdd;
1037 
1038  for (const auto& elt: inputs) {
1039  if ((*elt).type() != (*t)) {
1041  PRMSlotChain< GUM_SCALAR >* sc
1042  = static_cast< PRMSlotChain< GUM_SCALAR >* >(elt);
1043  std::stringstream name;
1044 
1045  for (Size idx = 0; idx < sc->chain().size() - 1; ++idx) {
1046  name << sc->chain().atPos(idx)->name() << ".";
1047  }
1048 
1049  name << ".(" << t->name() << ")" << sc->lastElt().name();
1050 
1051  try {
1052  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1053  } catch (NotFound&) {
1054  toAdd.push_back(
1055  std::make_pair(elt, buildSlotChain__(c, name.str())));
1056  }
1057  } else {
1058  std::stringstream name;
1059  name << "(" << t->name() << ")" << elt->name();
1060  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1061  }
1062  }
1063  }
1064 
1065  return retVal;
1066  }
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:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
PRMType * retrieveCommonType__(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType of a vector of PRMClassElement<GUM_SCALAR>.

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

1315  {
1316  PRMInterface< GUM_SCALAR >* interface = nullptr;
1317  std::string full_name;
1318 
1319  // Looking for the type using its name
1320  if (prm__->interfaceMap__.exists(name)) {
1321  interface = prm__->interfaceMap__[name];
1322  full_name = name;
1323  }
1324 
1325  // Looking for the type using current package
1326  std::string prefixed = addPrefix__(name);
1327  if (prm__->interfaceMap__.exists(prefixed)) {
1328  if (interface == nullptr) {
1329  interface = prm__->interfaceMap__[prefixed];
1330  full_name = prefixed;
1331  } else if (full_name != prefixed) {
1332  GUM_ERROR(DuplicateElement,
1333  "Interface name '" << name
1334  << "' is ambiguous: specify full name.");
1335  }
1336  }
1337 
1338  // Looking for the interf using all declared namespaces
1339  if (!namespaces__.empty()) {
1340  auto ns_list = namespaces__.back();
1341  // for( const auto & ns : *(namespaces__.top()) ) {
1342  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1343  std::string ns = (*ns_list)[i];
1344  std::string ns_name = ns + "." + name;
1345 
1346  if (prm__->interfaceMap__.exists(ns_name)) {
1347  if (interface == nullptr) {
1348  interface = prm__->interfaceMap__[ns_name];
1349  full_name = ns_name;
1350  } else if (full_name != ns_name) {
1351  GUM_ERROR(DuplicateElement,
1352  "Interface name '"
1353  << name << "' is ambiguous: specify full name.");
1354  }
1355  }
1356  }
1357  }
1358 
1359  if (interface == nullptr) {
1360  GUM_ERROR(NotFound,
1361  "Interface '" << name << "' not found, check imports.");
1362  }
1363 
1364  return interface;
1365  }
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:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

1916  {
1917  return *retrieveType__(name);
1918  }
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...

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

1196  {
1197  PRMType* type = nullptr;
1198  std::string full_name;
1199 
1200  // Looking for the type using its name
1201  if (prm__->typeMap__.exists(name)) {
1202  type = prm__->typeMap__[name];
1203  full_name = name;
1204  }
1205 
1206  // Looking for the type in current package
1207  std::string prefixed = addPrefix__(name);
1208  if (prm__->typeMap__.exists(prefixed)) {
1209  if (type == 0) {
1210  type = prm__->typeMap__[prefixed];
1211  full_name = prefixed;
1212  } else if (full_name != prefixed) {
1213  GUM_ERROR(DuplicateElement,
1214  "Type name '" << name << "' is ambiguous: specify full name.");
1215  }
1216  }
1217 
1218  // Looking for the type relatively to current package
1219  std::string relatif_ns = currentPackage();
1220  size_t last_dot = relatif_ns.find_last_of('.');
1221  if (last_dot != std::string::npos) {
1222  relatif_ns = relatif_ns.substr(0, last_dot) + '.' + name;
1223  if (prm__->typeMap__.exists(relatif_ns)) {
1224  if (type == 0) {
1225  type = prm__->typeMap__[relatif_ns];
1226  full_name = relatif_ns;
1227  } else if (full_name != relatif_ns) {
1228  GUM_ERROR(DuplicateElement,
1229  "Type name '" << name
1230  << "' is ambiguous: specify full name.");
1231  }
1232  }
1233  }
1234 
1235 
1236  // Looking for the type using all declared namespaces
1237  if (!namespaces__.empty()) {
1238  auto ns_list = namespaces__.back();
1239  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1240  std::string ns = (*ns_list)[i];
1241  std::string ns_name = ns + "." + name;
1242  if (prm__->typeMap__.exists(ns_name)) {
1243  if (type == 0) {
1244  type = prm__->typeMap__[ns_name];
1245  full_name = ns_name;
1246  } else if (full_name != ns_name) {
1247  GUM_ERROR(DuplicateElement,
1248  "Type name '" << name
1249  << "' is ambiguous: specify full name.");
1250  }
1251  }
1252  }
1253  }
1254 
1255  if (type == 0) {
1256  GUM_ERROR(NotFound, "Type '" << name << "' not found, check imports.");
1257  }
1258 
1259  return type;
1260  }
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:47
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

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

399  {
400  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
402 
403  if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
404  GUM_ERROR(OperationNotAllowed, "wrong number of parents");
405  }
406 
407  if (values.size() != a->type().variable().domainSize()) {
408  GUM_ERROR(OperationNotAllowed, "wrong number of values");
409  }
410 
411  std::vector< GUM_SCALAR > values2(values.begin(), values.end());
412  setCPFByRule(parents, values2);
413  }
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:54

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

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

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

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

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

365  {
366  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
368 
369  if (a->cpf().domainSize() != array.size()) {
370  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
371  }
372 
373  if (a->cpf().nbrDim() == 1) {
374  setRawCPFByLines(array);
375 
376  } else {
377  Instantiation inst(a->cpf());
378  Instantiation jnst;
379  for (auto idx = inst.variablesSequence().rbegin();
380  idx != inst.variablesSequence().rend();
381  --idx) {
382  jnst.add(**idx);
383  }
384 
385  jnst.setFirst();
386  auto idx = (std::size_t)0;
387  while ((!jnst.end()) && idx < array.size()) {
388  inst.setVals(jnst);
389  a->cpf().set(inst, array[idx]);
390  jnst.inc();
391  ++idx;
392  }
393  }
394  }
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:54

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

1957  {
1959 
1960  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1962 
1963  if (a->formulas().domainSize() != array.size()) {
1964  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1965  }
1966 
1967  if (a->formulas().nbrDim() == 1) {
1968  setRawCPFByLines(array);
1969 
1970  } else {
1971  Instantiation inst(a->formulas());
1972  Instantiation jnst;
1973  for (auto idx = inst.variablesSequence().rbegin();
1974  idx != inst.variablesSequence().rend();
1975  --idx) {
1976  jnst.add(**idx);
1977  }
1978 
1979  jnst.setFirst();
1980  auto idx = (std::size_t)0;
1981  while ((!jnst.end()) && idx < array.size()) {
1982  inst.setVals(jnst);
1983  a->formulas().set(inst, array[idx]);
1984  jnst.inc();
1985  ++idx;
1986  }
1987 
1988  // Generate cpf by calling it
1989  a->cpf();
1990  }
1991  }
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:54

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

351  {
352  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
354 
355  if (a->cpf().domainSize() != array.size()) {
356  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
357  }
358 
359  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
360  setRawCPFByColumns(array2);
361  }
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:54

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

323  {
324  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
327 
328  if (a->cpf().domainSize() != array.size())
329  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
330 
331  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
332  a->cpf().fillWith(array2);
333  }
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:54

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

337  {
339  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(elt);
341 
342  if (a->cpf().domainSize() != array.size()) {
343  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
344  }
345 
346  a->cpf().fillWith(array);
347  }
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:54

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

1995  {
1997 
1998  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
2000 
2001  if (a->formulas().domainSize() != array.size()) {
2002  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
2003  }
2004 
2005  a->formulas().populate(array);
2006 
2008  a->cpf();
2009  }
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:54

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

926  {
927  auto model = static_cast< PRMSystem< GUM_SCALAR >* >(
929  std::vector< PRMInstance< GUM_SCALAR >* > lefts;
930  std::vector< PRMInstance< GUM_SCALAR >* > rights;
931 
932  if (model->isInstance(l_i)) {
933  lefts.push_back(&(model->get(l_i)));
934  } else if (model->isArray(l_i)) {
935  for (const auto& elt: model->getArray(l_i))
936  lefts.push_back(elt);
937  } else {
938  GUM_ERROR(NotFound, "left value does not name an instance or an array");
939  }
940 
941  if (model->isInstance(r_i)) {
942  rights.push_back(&(model->get(r_i)));
943  } else if (model->isArray(r_i)) {
944  for (const auto& elt: model->getArray(r_i))
945  rights.push_back(elt);
946  } else {
947  GUM_ERROR(NotFound, "left value does not name an instance or an array");
948  }
949 
950  for (const auto l: lefts) {
951  for (const auto r: rights) {
952  auto& elt = l->type().get(l_ref);
954  l->add(elt.id(), *r);
955 
956  } else {
957  GUM_ERROR(NotFound, "unfound reference slot");
958  }
959  }
960  }
961  }
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:54

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

1897  {
1898  size_t pos = l_i.find_last_of('.');
1899 
1900  if (pos != std::string::npos) {
1901  std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1902  setReferenceSlot(l_i.substr(0, pos), l_ref, r_i);
1903  } else {
1904  GUM_ERROR(NotFound, "left value does not name an instance or an array");
1905  }
1906  }
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:54

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

575  {
576  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
578 
579  auto agg = new PRMAggregate< GUM_SCALAR >(
580  name,
582  *retrieveType__(rv_type));
583 
584  try {
585  c->add(agg);
586  } catch (DuplicateElement&) { c->overload(agg); }
587 
588  switch (agg->agg_type()) {
592  if (params.size() != 1) {
593  GUM_ERROR(OperationNotAllowed, "aggregate requires a parameter");
594  }
595  agg->setLabel(params.front());
596  break;
597  }
598  default: {
599  // Nothing to do
600  }
601  }
602  stack__.push_back(agg);
603  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1608  {
1609  PRMClassElementContainer< GUM_SCALAR >* c = checkStackContainter__(1);
1610  PRMAttribute< GUM_SCALAR >* a = nullptr;
1611 
1612  if (PRMObject::isClass(*c) && (!scalar_attr)) {
1613  a = new PRMFormAttribute< GUM_SCALAR >(
1614  static_cast< PRMClass< GUM_SCALAR >& >(*c),
1615  name,
1616  *retrieveType__(type));
1617 
1618  } else {
1619  a = new PRMScalarAttribute< GUM_SCALAR >(name, *retrieveType__(type));
1620  }
1621 
1622  std::string dot = ".";
1623 
1624  try {
1625  try {
1626  c->add(a);
1627  } catch (DuplicateElement&) { c->overload(a); }
1628  } catch (Exception&) {
1629  if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1630  }
1631 
1632  stack__.push_back(a);
1633  }
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
Definition: PRMObject.h:109
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

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

50  {
51  std::string real_name = addPrefix__(name);
52  if (prm__->classMap__.exists(real_name)
53  || prm__->interfaceMap__.exists(real_name)) {
54  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
55  }
56  PRMClass< GUM_SCALAR >* c = nullptr;
57  PRMClass< GUM_SCALAR >* mother = nullptr;
58  Set< PRMInterface< GUM_SCALAR >* > impl;
59 
60  if (implements != 0) {
61  for (const auto& imp: *implements) {
62  impl.insert(retrieveInterface__(imp));
63  }
64  }
65 
66  if (extends != "") { mother = retrieveClass__(extends); }
67 
68  if ((extends == "") && impl.empty()) {
69  c = new PRMClass< GUM_SCALAR >(real_name);
70  } else if ((extends != "") && impl.empty()) {
71  c = new PRMClass< GUM_SCALAR >(real_name, *mother, delayInheritance);
72  } else if ((extends == "") && (!impl.empty())) {
73  c = new PRMClass< GUM_SCALAR >(real_name, impl, delayInheritance);
74  } else if ((extends != "") && (!impl.empty())) {
75  c = new PRMClass< GUM_SCALAR >(real_name, *mother, impl, delayInheritance);
76  }
77 
78  prm__->classMap__.insert(c->name(), c);
79  prm__->classes__.insert(c);
80  stack__.push_back(c);
81  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1434  {
1435  std::string real_name = addPrefix__(name);
1436  if (prm__->typeMap__.exists(real_name)) {
1437  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
1438  }
1439  if (super == "") {
1440  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1441  stack__.push_back(t);
1442  } else {
1443  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1444  t->superType__ = retrieveType__(super);
1445  t->label_map__ = new std::vector< Idx >();
1446  stack__.push_back(t);
1447  }
1448  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1523  {
1524  std::string real_name = addPrefix__(name);
1525  if (prm__->typeMap__.exists(real_name)) {
1526  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
1527  }
1528  auto var = DiscretizedVariable< double >(real_name, "");
1529  auto t = new PRMType(var);
1530  stack__.push_back(t);
1531  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

188  {
189  std::string real_name = addPrefix__(name);
190  if (prm__->classMap__.exists(real_name)
191  || prm__->interfaceMap__.exists(real_name)) {
192  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
193  }
194  PRMInterface< GUM_SCALAR >* i = nullptr;
195  PRMInterface< GUM_SCALAR >* super = nullptr;
196 
197  if (extends != "") { super = retrieveInterface__(extends); }
198 
199  if (super != nullptr) {
200  i = new PRMInterface< GUM_SCALAR >(real_name, *super, delayInheritance);
201  } else {
202  i = new PRMInterface< GUM_SCALAR >(real_name);
203  }
204 
205  prm__->interfaceMap__.insert(i->name(), i);
206  prm__->interfaces__.insert(i);
207  stack__.push_back(i);
208  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1654  {
1655  if (prm__->systemMap__.exists(name)) {
1656  GUM_ERROR(DuplicateElement, "'" << name << "' is already used.");
1657  }
1658  PRMSystem< GUM_SCALAR >* model
1659  = new PRMSystem< GUM_SCALAR >(addPrefix__(name));
1660  stack__.push_back(model);
1661  prm__->systemMap__.insert(model->name(), model);
1662  prm__->systems__.insert(model);
1663  }
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:54
std::vector< PRMObject *> stack__
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1051

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

1847  {
1848  int depth = 0;
1849  const PRMType* current = t;
1850 
1851  while (current->isSubType()) {
1852  ++depth;
1853  current = &(current->superType());
1854  }
1855 
1856  return depth;
1857  }

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

Set of all declared namespaces.

Definition at line 1045 of file PRMFactory.h.

◆ packages__

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

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

Definition at line 1042 of file PRMFactory.h.

◆ prm__

template<typename GUM_SCALAR >
PRM< GUM_SCALAR >* gum::prm::PRMFactory< GUM_SCALAR >::prm__
private

The pointer on the PRM<GUM_SCALAR> built by this factory.

Definition at line 1048 of file PRMFactory.h.

◆ stack__

template<typename GUM_SCALAR >
std::vector< PRMObject* > gum::prm::PRMFactory< GUM_SCALAR >::stack__
private

A stack used to keep track of created PRMObject.

Definition at line 1051 of file PRMFactory.h.


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