aGrUM  0.16.0
gum::prm::PRMFactory< GUM_SCALAR > Class Template Reference

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

#include <PRMType.h>

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

Public Member Functions

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

Detailed Description

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

Factory which builds a PRM<GUM_SCALAR>.

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

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

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

See also
PRM<GUM_SCALAR> PRMObject

Definition at line 50 of file PRMType.h.

Constructor & Destructor Documentation

◆ PRMFactory() [1/3]

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

Default constructor.

Definition at line 1359 of file PRMFactory_tpl.h.

1359  {
1360  GUM_CONSTRUCTOR(PRMFactory);
1361  __prm = new PRM< GUM_SCALAR >();
1362  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
PRMFactory()
Default constructor.

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

1365  :
1366  IPRMFactory(), __prm(prm) {
1367  GUM_CONSTRUCTOR(PRMFactory);
1368  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
PRMFactory()
Default constructor.
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 1371 of file PRMFactory_tpl.h.

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

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

Member Function Documentation

◆ __addInstance()

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

Adds a instance to the current model.

Definition at line 1749 of file PRMFactory_tpl.h.

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

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

1750  {
1751  PRMInstance< GUM_SCALAR >* i = nullptr;
1752  try {
1753  auto s = static_cast< PRMSystem< GUM_SCALAR >* >(
1755  i = new PRMInstance< GUM_SCALAR >(name, *type);
1756  s->add(i);
1757 
1758  } catch (OperationNotAllowed&) {
1759  if (i) { delete i; }
1760  throw;
1761  }
1762  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __addParent() [1/2]

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

Add a parent to an attribute.

Definition at line 251 of file PRMFactory_tpl.h.

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

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

◆ __addParent() [2/2]

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

Add a parent to an aggregate.

Definition at line 620 of file PRMFactory_tpl.h.

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

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

◆ __addPrefix()

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

Adds __prefix to str iff __prefix != "".

Definition at line 1766 of file PRMFactory_tpl.h.

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

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

1766  {
1767  if (!__packages.empty()) {
1768  std::string full_name = __packages.back();
1769  full_name.append(".");
1770  full_name.append(str);
1771  return full_name;
1772  } else {
1773  return str;
1774  }
1775  }
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:1043
+ Here is the caller graph for this function:

◆ __buildAggregateCPF()

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

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

◆ __buildSlotChain()

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

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

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

Definition at line 958 of file PRMFactory_tpl.h.

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

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

◆ __buildSlotChains()

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

Builds all PRMSlotChain<GUM_SCALAR><PRMInstance<GUM_SCALAR>> in the given model.

Exceptions
OperationNotAllowedIf reference slots are left un affected

◆ __checkInterfaceImplementation()

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

Check if c implements correctly all his interfaces.

Definition at line 106 of file PRMFactory_tpl.h.

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

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

◆ __checkStack() [1/2]

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

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

Exceptions
FactoryInvalidStateRaised if the stack isn't consistent with the

Definition at line 1779 of file PRMFactory_tpl.h.

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

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

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

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

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

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

◆ __checkStackContainter()

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

Adds __prefix to str iff __prefix != "".

Definition at line 1797 of file PRMFactory_tpl.h.

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

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

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

◆ __fill_sc_in_vector()

template<typename GUM_SCALAR>
void gum::prm::PRMFactory< GUM_SCALAR >::__fill_sc_in_vector ( std::vector< std::string > &  v,
const std::string &  str 
)
private

Decompose a string in v using dots ('.') as delimiters.

◆ __instantiateSlotChain()

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

Instantiate a slot chain in the given instance.

◆ __retrieveClass()

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

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

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

Definition at line 1255 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

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

◆ __retrieveCommonType()

template<typename GUM_SCALAR >
INLINE PRMType * gum::prm::PRMFactory< GUM_SCALAR >::__retrieveCommonType ( const std::vector< PRMClassElement< GUM_SCALAR > * > &  elts)
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 1062 of file PRMFactory_tpl.h.

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

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

1063  {
1064  const PRMType* current = nullptr;
1066  // Finding all types and super types
1067 
1068  for (const auto& elt : elts) {
1069  try {
1070  current = &((*elt).type());
1071 
1072  while (current != 0) {
1073  // Filling counters
1074  if (counters.exists(current->name())) {
1075  ++(counters[current->name()]);
1076  } else {
1077  counters.insert(current->name(), 1);
1078  }
1079 
1080  // Loop guard
1081  if (current->isSubType()) {
1082  current = &(current->superType());
1083  } else {
1084  current = nullptr;
1085  }
1086  }
1087  } catch (OperationNotAllowed&) {
1088  GUM_ERROR(WrongClassElement,
1089  "found a ClassElement<GUM_SCALAR> without a type");
1090  }
1091  }
1092 
1093  // We need to find the most specialized (i.e. max depth) common type
1094  current = nullptr;
1095 
1096  int max_depth = -1;
1097 
1098  int current_depth = 0;
1099 
1100  for (const auto& elt : counters) {
1101  if ((elt.second) == elts.size()) {
1102  current_depth = __typeDepth(__retrieveType(elt.first));
1103 
1104  if (current_depth > max_depth) {
1105  max_depth = current_depth;
1106  current = __retrieveType(elt.first);
1107  }
1108  }
1109  }
1110 
1111  if (current) { return const_cast< PRMType* >(current); }
1112 
1113  GUM_ERROR(NotFound, "could not find a common type");
1114  }
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...
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.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __retrieveInputs()

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

Retrieve inputs for an PRMAggregate.

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

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

Definition at line 1002 of file PRMFactory_tpl.h.

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

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

◆ __retrieveInstanceSequence()

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

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

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

◆ __retrieveInterface()

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

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

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

Definition at line 1305 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

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

◆ __retrieveType()

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

References GUM_ERROR.

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

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

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

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

◆ addAggregator()

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

Add an aggregator in the current declared class.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 682 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMAggregate< GUM_SCALAR >::buildImpl(), gum::prm::PRMObject::CLASS, GUM_ERROR, gum::prm::PRMAggregate< GUM_SCALAR >::label(), gum::prm::PRMObject::name(), gum::prm::PRMClass< GUM_SCALAR >::overload(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAggregate< GUM_SCALAR >::str2enum(), and gum::prm::PRMAggregate< GUM_SCALAR >::type().

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster().

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(WrongType, "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(WrongType, "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 
772  if (params.size() != 0) {
773  GUM_ERROR(OperationNotAllowed, "invalid number of parameters");
774  }
775 
776  auto output_type = __retrieveType(type);
777 
778  // Creating and adding the PRMAggregate<GUM_SCALAR>
779  agg = new PRMAggregate< GUM_SCALAR >(
780  name, PRMAggregate< GUM_SCALAR >::str2enum(agg_type), *output_type);
781 
782  break;
783  }
784 
786  if (params.size() != 1) {
787  GUM_ERROR(OperationNotAllowed, "invalid number of parameters");
788  }
789 
790  Idx label_idx = 0;
791 
792  while (label_idx < inputs.front()->type()->domainSize()) {
793  if (inputs.front()->type()->label(label_idx) == params.front()) {
794  break;
795  }
796 
797  ++label_idx;
798  }
799 
800  if (label_idx == inputs.front()->type()->domainSize()) {
801  GUM_ERROR(NotFound, "could not find label");
802  }
803 
804  auto output_type = __retrieveType(type);
805 
806  // Creating and adding the PRMAggregate<GUM_SCALAR>
807  agg = new PRMAggregate< GUM_SCALAR >(
808  name,
810  *output_type,
811  label_idx);
812 
813  break;
814  }
815 
816  default: {
817  GUM_ERROR(FatalError, "Unknown aggregator.");
818  }
819  }
820 
821  std::string safe_name = agg->safeName();
822 
823  try {
824  if (hasSC) {
825  try {
826  c->add(agg);
827  } catch (DuplicateElement&) { c->overload(agg); }
828  } else {
829  // Inner aggregators can be directly used as attributes
830  auto attr = new PRMScalarAttribute< GUM_SCALAR >(
831  agg->name(), agg->type(), agg->buildImpl());
832 
833  try {
834  c->add(attr);
835  } catch (DuplicateElement&) { c->overload(attr); }
836 
837  delete agg;
838  }
839  } catch (DuplicateElement&) {
840  delete agg;
841  throw;
842  }
843 
844  for (const auto& elt : inputs) {
845  c->addArc(elt->safeName(), safe_name);
846  }
847  }
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:100
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...
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
bool __retrieveInputs(PRMClass< GUM_SCALAR > *c, const std::vector< std::string > &chains, std::vector< PRMClassElement< GUM_SCALAR > * > &inputs)
Retrieve inputs for an PRMAggregate.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addArray()

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 875 of file PRMFactory_tpl.h.

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

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

877  {
878  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
880  PRMClass< GUM_SCALAR >* c = __retrieveClass(type);
881  PRMInstance< GUM_SCALAR >* inst = 0;
882 
883  try {
884  model->addArray(name, *c);
885 
886  for (Size i = 0; i < size; ++i) {
887  std::stringstream elt_name;
888  elt_name << name << "[" << i << "]";
889  inst = new PRMInstance< GUM_SCALAR >(elt_name.str(), *c);
890  model->add(name, inst);
891  }
892  } catch (TypeError&) {
893  delete inst;
894  throw;
895  } catch (NotFound&) {
896  delete inst;
897  throw;
898  }
899  }
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 ...
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAttribute() [1/2]

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

Add an attribute to an interface.

Implements gum::prm::IPRMFactory.

Definition at line 1589 of file PRMFactory_tpl.h.

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

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

1590  {
1592  startAttribute(type, name);
1593  endAttribute();
1594  }
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.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addAttribute() [2/2]

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

Add an already created attribute to the current class.

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

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

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

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

Definition at line 225 of file PRMFactory_tpl.h.

References gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMClass< GUM_SCALAR >::addArc(), gum::prm::PRMObject::CLASS, gum::prm::PRMClassElementContainer< GUM_SCALAR >::containerDag(), gum::prm::PRMAttribute< GUM_SCALAR >::cpf(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), GUM_ERROR, gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAttribute< GUM_SCALAR >::type(), and gum::prm::PRMType::variable().

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

◆ addImport()

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

Add an import for namespace lookup.

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

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

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1874 of file PRMFactory_tpl.h.

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

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

◆ addInstance() [1/2]

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

Add an instance to the model.

Implements gum::prm::IPRMFactory.

Definition at line 1667 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::__addInstance(), and gum::prm::PRMFactory< GUM_SCALAR >::__retrieveClass().

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

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

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

References gum::prm::PRMFactory< GUM_SCALAR >::__addInstance(), gum::prm::PRMFactory< GUM_SCALAR >::__packages, gum::prm::PRMFactory< GUM_SCALAR >::__retrieveClass(), gum::prm::PRMFactory< GUM_SCALAR >::addParameter(), gum::HashTable< Key, Val, Alloc >::empty(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

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

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::LabelizedVariable::addLabel(), gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::DiscreteVariable::label(), and gum::prm::PRMObject::TYPE.

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

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

◆ addNoisyOrCompound()

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1117 of file PRMFactory_tpl.h.

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

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

◆ addParameter()

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 547 of file PRMFactory_tpl.h.

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

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

549  {
550  auto c = static_cast< PRMClass< GUM_SCALAR >* >(
552 
553  PRMParameter< GUM_SCALAR >* p = nullptr;
554  if (type == "int") {
555  p = new PRMParameter< GUM_SCALAR >(
556  name,
557  PRMParameter< GUM_SCALAR >::ParameterType::INT,
558  (GUM_SCALAR)value);
559  } else if (type == "real") {
560  p = new PRMParameter< GUM_SCALAR >(
561  name,
562  PRMParameter< GUM_SCALAR >::ParameterType::REAL,
563  (GUM_SCALAR)value);
564  }
565 
566  try {
567  c->add(p);
568  } catch (DuplicateElement&) { c->overload(p); }
569  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the caller graph for this function:

◆ addParent()

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

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

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

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 308 of file PRMFactory_tpl.h.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAttribute(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster().

308  {
309  PRMClassElementContainer< GUM_SCALAR >* c = __checkStackContainter(2);
310  try {
311  // Retrieving pointers
312  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
314  __addParent(c, a, name);
315  } catch (FactoryInvalidState&) {
316  auto agg = static_cast< PRMAggregate< GUM_SCALAR >* >(
318  __addParent(static_cast< PRMClass< GUM_SCALAR >* >(c), agg, name);
319  }
320  }
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
void __addParent(PRMClassElementContainer< GUM_SCALAR > *c, PRMAttribute< GUM_SCALAR > *agg, const std::string &name)
Add a parent to an attribute.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the caller graph for this function:

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

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

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

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

◆ addReferenceSlot()

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

Tells the factory that we started declaring a slot.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 850 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateInterfaces(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateInterfaces(), and gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::buildElements().

852  {
853  PRMClassElementContainer< GUM_SCALAR >* owner = __checkStackContainter(1);
854  PRMClassElementContainer< GUM_SCALAR >* slotType = 0;
855 
856  try {
857  slotType = __retrieveClass(type);
858  } catch (NotFound&) {
859  try {
860  slotType = __retrieveInterface(type);
861  } catch (NotFound&) {
862  GUM_ERROR(NotFound, "unknown ReferenceSlot<GUM_SCALAR> slot type");
863  }
864  }
865 
866  PRMReferenceSlot< GUM_SCALAR >* ref =
867  new PRMReferenceSlot< GUM_SCALAR >(name, *slotType, isArray);
868 
869  try {
870  owner->add(ref);
871  } catch (DuplicateElement&) { owner->overload(ref); }
872  }
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
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...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addTick()

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

Add a tick to the current discretized type.

Parameters
tickThe tick value.

Implements gum::prm::IPRMFactory.

Definition at line 1525 of file PRMFactory_tpl.h.

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

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

1525  {
1526  PRMType* t =
1527  static_cast< PRMType* >(__checkStack(1, PRMObject::prm_type::TYPE));
1528  DiscretizedVariable< double >* var =
1529  dynamic_cast< DiscretizedVariable< double >* >(t->__var);
1530 
1531  if (!var) {
1532  GUM_ERROR(FatalError,
1533  "the current type's variable is not a LabelizedVariable.");
1534  }
1535 
1536  try {
1537  var->addTick(tick);
1538  } catch (DefaultInLabel&) {
1539  GUM_ERROR(OperationNotAllowed, "tick already in used for this variable");
1540  }
1541  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

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

◆ continueAggregator()

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

Conitnues an aggregator declaration.

Definition at line 608 of file PRMFactory_tpl.h.

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

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

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

◆ continueAttribute()

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

Continues the declaration of an attribute.

Implements gum::prm::IPRMFactory.

Definition at line 1628 of file PRMFactory_tpl.h.

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

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

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

◆ continueClass()

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

Continue the declaration of a class.

Implements gum::prm::IPRMFactory.

Definition at line 85 of file PRMFactory_tpl.h.

References GUM_ERROR.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes().

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

◆ continueInterface()

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

Continue the declaration of an interface.

Implements gum::prm::IPRMFactory.

Definition at line 213 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

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

◆ currentPackage()

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

Implements gum::prm::IPRMFactory.

Definition at line 1418 of file PRMFactory_tpl.h.

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

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

1418  {
1419  return (__packages.empty()) ? "" : __packages.back();
1420  }
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:1043
+ Here is the caller graph for this function:

◆ currentType()

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

Implements gum::prm::IPRMFactory.

Definition at line 1386 of file PRMFactory_tpl.h.

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

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

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

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAggregates(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates().

676  {
678  __stack.pop_back();
679  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), and gum::prm::PRMFactory< GUM_SCALAR >::__stack.

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__completeAttribute(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), and gum::prm::PRMFactory< GUM_SCALAR >::addAttribute().

1639  {
1641  __stack.pop_back();
1642  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endClass()

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

Tells the factory that we finished a class declaration.

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

Implements gum::prm::IPRMFactory.

Definition at line 96 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__addReferenceSlots(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAggregates(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildParameters(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAggregates(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::completeAttributes().

96  {
97  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
99 
100  if (checkImplementations) { __checkInterfaceImplementation(c); }
101 
102  __stack.pop_back();
103  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
void __checkInterfaceImplementation(PRMClass< GUM_SCALAR > *c)
Check if c implements correctly all his interfaces.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__stack, gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), and gum::prm::PRMObject::TYPE.

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

1495  {
1496  PRMType* t =
1497  static_cast< PRMType* >(__checkStack(1, PRMObject::prm_type::TYPE));
1498 
1499  if (!t->__isValid()) {
1500  GUM_ERROR(OperationNotAllowed, "current type is not a valid subtype");
1501  } else if (t->variable().domainSize() < 2) {
1502  GUM_ERROR(OperationNotAllowed,
1503  "current type is not a valid discrete type");
1504  }
1505 
1506  __prm->__typeMap.insert(t->name(), t);
1507 
1508  __prm->__types.insert(t);
1509  __stack.pop_back();
1510  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__stack, gum::DiscreteVariable::domainSize(), GUM_ERROR, gum::Variable::name(), and gum::prm::PRMObject::TYPE.

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

1544  {
1545  PRMType* t =
1546  static_cast< PRMType* >(__checkStack(1, PRMObject::prm_type::TYPE));
1547 
1548  if (t->variable().domainSize() < 2) {
1549  GUM_ERROR(OperationNotAllowed,
1550  "current type is not a valid discrete type");
1551  }
1552 
1553  __prm->__typeMap.insert(t->name(), t);
1554 
1555  __prm->__types.insert(t);
1556  __stack.pop_back();
1557  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::prm::PRMFactory< GUM_SCALAR >::__stack, and gum::prm::PRMObject::PRM_INTERFACE.

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

1583  {
1585  __stack.pop_back();
1586  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

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

1657  {
1658  try {
1659  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
1661  __stack.pop_back();
1662  model->instantiate();
1663  } catch (Exception&) { GUM_ERROR(FatalError, "could not create system"); }
1664  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

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

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

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

◆ getCurrent() [2/2]

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1400 of file PRMFactory_tpl.h.

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

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

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

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

903  {
904  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
906 
907  if (model->isArray(l_i)) {
908  if (model->isInstance(r_i)) {
909  model->add(l_i, model->get(r_i));
910  } else {
911  GUM_ERROR(NotFound, "right value is not an instance");
912  }
913  } else {
914  GUM_ERROR(NotFound, "left value is no an array");
915  }
916  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

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

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

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

◆ isClassOrInterface()

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

Implements gum::prm::IPRMFactory.

Definition at line 1918 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::__retrieveClass(), and gum::prm::PRMFactory< GUM_SCALAR >::__retrieveInterface().

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

◆ operator=()

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

Copy operator. Don't use it.

◆ popPackage()

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

Pop the current package from the package stack.

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

Implements gum::prm::IPRMFactory.

Definition at line 1856 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::__namespaces, gum::prm::PRMFactory< GUM_SCALAR >::__packages, and gum::prm::PRMFactory< GUM_SCALAR >::currentPackage().

1856  {
1857  std::string plop = currentPackage();
1858 
1859  if (!__packages.empty()) {
1860  std::string s = __packages.back();
1861  __packages.pop_back();
1862 
1863  if (__namespaces.size() > 0) {
1864  delete __namespaces.back();
1865  __namespaces.pop_back();
1866  }
1867  return s;
1868  }
1869 
1870  return plop;
1871  }
virtual std::string currentPackage() const override
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:1043
std::vector< List< std::string > *> __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1046
+ Here is the call graph for this function:

◆ prm()

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

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

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

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

Definition at line 1381 of file PRMFactory_tpl.h.

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

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

1381  {
1382  return __prm;
1383  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
+ Here is the caller graph for this function:

◆ pushPackage()

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

Define the current package.

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

Parameters
nameThe name of the package for all further objects.

Implements gum::prm::IPRMFactory.

Definition at line 1850 of file PRMFactory_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::__namespaces, and gum::prm::PRMFactory< GUM_SCALAR >::__packages.

1850  {
1851  __packages.push_back(name);
1852  __namespaces.push_back(new List< std::string >());
1853  }
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:1043
std::vector< List< std::string > *> __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1046

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

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

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster().

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

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

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

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

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

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

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

◆ setCPFByFloatRule()

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

Fills the CPF using a rule.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 398 of file PRMFactory_tpl.h.

References GUM_ERROR.

400  {
401  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(
403 
404  if ((parents.size() + 1) != a->cpf().variablesSequence().size()) {
405  GUM_ERROR(OperationNotAllowed, "wrong number of parents");
406  }
407 
408  if (values.size() != a->type().variable().domainSize()) {
409  GUM_ERROR(OperationNotAllowed, "wrong number of values");
410  }
411 
412  std::vector< GUM_SCALAR > values2(values.begin(), values.end());
413  setCPFByRule(parents, values2);
414  }
virtual void setCPFByRule(const std::vector< std::string > &labels, const std::vector< GUM_SCALAR > &values)
Fills the CPF using a rule.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ setCPFByRule() [1/2]

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

Fills the CPF using a rule.

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

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

Definition at line 417 of file PRMFactory_tpl.h.

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

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

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

◆ setCPFByRule() [2/2]

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 482 of file PRMFactory_tpl.h.

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

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

◆ setRawCPFByColumns() [1/2]

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Definition at line 365 of file PRMFactory_tpl.h.

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

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

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

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

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

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

◆ setRawCPFByFloatColumns()

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 351 of file PRMFactory_tpl.h.

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

352  {
353  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
355 
356  if (a->cpf().domainSize() != array.size()) {
357  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
358  }
359 
360  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
361  setRawCPFByColumns(array2);
362  }
void setRawCPFByColumns(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByFloatLines()

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

Gives the factory the CPF in its raw form.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 323 of file PRMFactory_tpl.h.

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

324  {
325  PRMAttribute< GUM_SCALAR >* a = static_cast< PRMAttribute< GUM_SCALAR >* >(
328 
329  if (a->cpf().domainSize() != array.size())
330  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
331 
332  std::vector< GUM_SCALAR > array2(array.begin(), array.end());
333  a->cpf().fillWith(array2);
334  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setRawCPFByLines() [1/2]

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

Gives the factory the CPF in its raw form.

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

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

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

Definition at line 337 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

338  {
340  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(elt);
342 
343  if (a->cpf().domainSize() != array.size()) {
344  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
345  }
346 
347  a->cpf().fillWith(array);
348  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ setRawCPFByLines() [2/2]

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

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 1984 of file PRMFactory_tpl.h.

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

1985  {
1987 
1988  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1990 
1991  if (a->formulas().domainSize() != array.size()) {
1992  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1993  }
1994 
1995  a->formulas().populate(array);
1996 
1998  a->cpf();
1999  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ setReferenceSlot() [1/2]

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

Instantiate a reference in the current model.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 919 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addAssignments(), gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::__addIncrements(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateSystem(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateSystem(), and gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot().

920  {
921  auto model = static_cast< PRMSystem< GUM_SCALAR >* >(
923  std::vector< PRMInstance< GUM_SCALAR >* > lefts;
924  std::vector< PRMInstance< GUM_SCALAR >* > rights;
925 
926  if (model->isInstance(l_i)) {
927  lefts.push_back(&(model->get(l_i)));
928  } else if (model->isArray(l_i)) {
929  for (const auto& elt : model->getArray(l_i))
930  lefts.push_back(elt);
931  } else {
932  GUM_ERROR(NotFound, "left value does not name an instance or an array");
933  }
934 
935  if (model->isInstance(r_i)) {
936  rights.push_back(&(model->get(r_i)));
937  } else if (model->isArray(r_i)) {
938  for (const auto& elt : model->getArray(r_i))
939  rights.push_back(elt);
940  } else {
941  GUM_ERROR(NotFound, "left value does not name an instance or an array");
942  }
943 
944  for (const auto l : lefts) {
945  for (const auto r : rights) {
946  auto& elt = l->type().get(l_ref);
948  l->add(elt.id(), *r);
949 
950  } else {
951  GUM_ERROR(NotFound, "unfound reference slot");
952  }
953  }
954  }
955  }
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

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

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

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

◆ startAggregator()

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

Start an aggregator declaration.

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

Definition at line 572 of file PRMFactory_tpl.h.

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

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

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

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStackContainter(), gum::prm::PRMFactory< GUM_SCALAR >::__retrieveType(), gum::prm::PRMFactory< GUM_SCALAR >::__stack, gum::prm::PRMClassElementContainer< GUM_SCALAR >::add(), gum::prm::PRMClassElementContainer< GUM_SCALAR >::exists(), gum::prm::PRMClassElement< GUM_SCALAR >::id(), gum::prm::PRMObject::isClass(), and gum::prm::PRMClassElementContainer< GUM_SCALAR >::overload().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__declareAttribute(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), and gum::prm::PRMFactory< GUM_SCALAR >::addAttribute().

1599  {
1600  PRMClassElementContainer< GUM_SCALAR >* c = __checkStackContainter(1);
1601  PRMAttribute< GUM_SCALAR >* a = nullptr;
1602 
1603  if (PRMObject::isClass(*c) && (!scalar_attr)) {
1604  a = new PRMFormAttribute< GUM_SCALAR >(
1605  static_cast< PRMClass< GUM_SCALAR >& >(*c),
1606  name,
1607  *__retrieveType(type));
1608 
1609  } else {
1610  a = new PRMScalarAttribute< GUM_SCALAR >(name, *__retrieveType(type));
1611  }
1612 
1613  std::string dot = ".";
1614 
1615  try {
1616  try {
1617  c->add(a);
1618  } catch (DuplicateElement&) { c->overload(a); }
1619  } catch (Exception&) {
1620  if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1621  }
1622 
1623  __stack.push_back(a);
1624  }
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
Definition: PRMObject.h:102
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...
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startClass()

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

Tells the factory that we start a class declaration.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 48 of file PRMFactory_tpl.h.

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

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::buildClasses().

51  {
52  std::string real_name = __addPrefix(name);
53  if (__prm->__classMap.exists(real_name)
54  || __prm->__interfaceMap.exists(real_name)) {
55  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
56  }
57  PRMClass< GUM_SCALAR >* c = nullptr;
58  PRMClass< GUM_SCALAR >* mother = nullptr;
59  Set< PRMInterface< GUM_SCALAR >* > impl;
60 
61  if (implements != 0) {
62  for (const auto& imp : *implements) {
63  impl.insert(__retrieveInterface(imp));
64  }
65  }
66 
67  if (extends != "") { mother = __retrieveClass(extends); }
68 
69  if ((extends == "") && impl.empty()) {
70  c = new PRMClass< GUM_SCALAR >(real_name);
71  } else if ((extends != "") && impl.empty()) {
72  c = new PRMClass< GUM_SCALAR >(real_name, *mother, delayInheritance);
73  } else if ((extends == "") && (!impl.empty())) {
74  c = new PRMClass< GUM_SCALAR >(real_name, impl, delayInheritance);
75  } else if ((extends != "") && (!impl.empty())) {
76  c = new PRMClass< GUM_SCALAR >(real_name, *mother, impl, delayInheritance);
77  }
78 
79  __prm->__classMap.insert(c->name(), c);
80  __prm->__classes.insert(c);
81  __stack.push_back(c);
82  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
std::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
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...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__addPrefix(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__retrieveType(), gum::prm::PRMFactory< GUM_SCALAR >::__stack, and GUM_ERROR.

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

1425  {
1426  std::string real_name = __addPrefix(name);
1427  if (__prm->__typeMap.exists(real_name)) {
1428  GUM_ERROR(DuplicateElement, "'" << real_name << "' is already used.");
1429  }
1430  if (super == "") {
1431  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1432  __stack.push_back(t);
1433  } else {
1434  auto t = new PRMType(LabelizedVariable(real_name, "", 0));
1435  t->__superType = __retrieveType(super);
1436  t->__label_map = new std::vector< Idx >();
1437  __stack.push_back(t);
1438  }
1439  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
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::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__addPrefix(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__stack, and GUM_ERROR.

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

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

◆ startInterface()

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

Tells the factory that we start an interface declaration.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 187 of file PRMFactory_tpl.h.

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

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

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

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

References gum::prm::PRMFactory< GUM_SCALAR >::__addPrefix(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__stack, GUM_ERROR, and gum::prm::PRMObject::name().

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

1645  {
1646  if (__prm->__systemMap.exists(name)) {
1647  GUM_ERROR(DuplicateElement, "'" << name << "' is already used.");
1648  }
1649  PRMSystem< GUM_SCALAR >* model =
1650  new PRMSystem< GUM_SCALAR >(__addPrefix(name));
1651  __stack.push_back(model);
1652  __prm->__systemMap.insert(model->name(), model);
1653  __prm->__systems.insert(model);
1654  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1049
std::vector< PRMObject *> __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1052
std::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

◆ __namespaces

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

◆ __packages

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

◆ __prm

◆ __stack


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