aGrUM  0.13.2
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...
 
PRMType< GUM_SCALAR > & retrieveType (const std::string &name)
 Returns a reference over a PRMType<GUM_SCALAR> given its name. More...
 
PRMType< GUM_SCALAR > & retrieveCommonType (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<GUM_SCALAR> 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 45 of file PRMType.h.

Constructor & Destructor Documentation

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

Default constructor.

Definition at line 1350 of file PRMFactory_tpl.h.

1350  {
1351  GUM_CONSTRUCTOR(PRMFactory);
1352  __prm = new PRM< GUM_SCALAR >();
1353  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
PRMFactory()
Default constructor.
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 1356 of file PRMFactory_tpl.h.

1356  :
1357  IPRMFactory(), __prm(prm) {
1358  GUM_CONSTRUCTOR(PRMFactory);
1359  }
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
PRMFactory()
Default constructor.
template<typename GUM_SCALAR>
gum::prm::PRMFactory< GUM_SCALAR >::PRMFactory ( const PRMFactory< GUM_SCALAR > &  from)
delete

Copy constructor. Don't use it.

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

Destructor.

Definition at line 1362 of file PRMFactory_tpl.h.

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

1362  {
1363  GUM_DESTRUCTOR(PRMFactory);
1364  while (!__namespaces.empty()) {
1365  auto ns = __namespaces.back();
1366  __namespaces.pop_back();
1367  delete ns;
1368  }
1369  }
PRMFactory()
Default constructor.
std::vector< List< std::string > * > __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1043

Member Function Documentation

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

1747  {
1748  PRMInstance< GUM_SCALAR >* i = nullptr;
1749  try {
1750  auto s = static_cast< PRMSystem< GUM_SCALAR >* >(
1752  i = new PRMInstance< GUM_SCALAR >(name, *type);
1753  s->add(i);
1754 
1755  } catch (OperationNotAllowed&) {
1756  if (i) { delete i; }
1757  throw;
1758  }
1759  }
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:

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

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

+ Here is the call graph for this function:

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

619  {
620  auto chains = std::vector< std::string >{name};
621  auto inputs = std::vector< PRMClassElement< GUM_SCALAR >* >();
622  __retrieveInputs(c, chains, inputs);
623 
624  switch (agg->agg_type()) {
627  if (inputs.front()->type() != *(__retrieveType("boolean"))) {
628  GUM_ERROR(WrongType, "expected booleans");
629  }
630 
631  break;
632  }
633 
637  if (!agg->hasLabel()) {
638  auto param = agg->labelValue();
639  Idx label_idx = 0;
640 
641  while (label_idx < inputs.front()->type()->domainSize()) {
642  if (inputs.front()->type()->label(label_idx) == param) { break; }
643 
644  ++label_idx;
645  }
646 
647  if (label_idx == inputs.front()->type()->domainSize()) {
648  GUM_ERROR(NotFound, "could not find label");
649  }
650 
651  agg->setLabel(label_idx);
652  }
653 
654  break;
655  }
656 
661  break;
662  }
663 
664  default: { GUM_ERROR(FatalError, "Unknown aggregator."); }
665  }
666 
667  c->addArc(inputs.front()->safeName(), agg->safeName());
668  }
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...
unsigned long Idx
Type for indexes.
Definition: types.h:43
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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:

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

1763  {
1764  if (!__packages.empty()) {
1765  std::string full_name = __packages.back();
1766  full_name.append(".");
1767  full_name.append(str);
1768  return full_name;
1769  } else {
1770  return str;
1771  }
1772  }
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:1040

+ Here is the caller graph for this function:

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.

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

952  {
953  std::vector< std::string > v;
954  decomposePath(name, v);
955  PRMClassElementContainer< GUM_SCALAR >* current = start;
956  PRMReferenceSlot< GUM_SCALAR >* ref = nullptr;
957  Sequence< PRMClassElement< GUM_SCALAR >* > elts;
958 
959  for (size_t i = 0; i < v.size(); ++i) {
960  try {
961  switch (current->get(v[i]).elt_type()) {
963  ref = &(static_cast< PRMReferenceSlot< GUM_SCALAR >& >(
964  current->get(v[i])));
965  elts.insert(ref);
966  current = &(/*const_cast<PRMClassElementContainer<GUM_SCALAR>&>*/ (
967  ref->slotType()));
968  break;
969 
972 
973  if (i == v.size() - 1) {
974  elts.insert(&(current->get(v[i])));
975  break;
976  } else {
977  return nullptr;
978  }
979 
980  default: { return nullptr; }
981  }
982  } catch (NotFound&) { return nullptr; }
983  }
984 
985  GUM_ASSERT(v.size() == elts.size());
986 
987  current->setOutputNode(*(elts.back()), true);
988 
989  return new PRMSlotChain< GUM_SCALAR >(name, elts);
990  }
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:27

+ Here is the call graph for this function:

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
template<typename GUM_SCALAR >
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::__checkInterfaceImplementation ( PRMClass< GUM_SCALAR > *  c)
private

Check if c implements correctly all his interfaces.

Definition at line 105 of file PRMFactory_tpl.h.

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

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

+ Here is the call graph for this function:

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

1776  {
1777  // Don't forget that Idx are unsigned int
1778  if (__stack.size() - i > __stack.size()) {
1779  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1780  }
1781 
1782  PRMObject* obj = __stack[__stack.size() - i];
1783 
1784  if (obj->obj_type() != obj_type) {
1785  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1786  }
1787 
1788  return obj;
1789  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

1811  {
1812  // Don't forget that Idx are unsigned int
1813  if (__stack.size() - i > __stack.size()) {
1814  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1815  }
1816 
1817  PRMClassElement< GUM_SCALAR >* obj =
1818  dynamic_cast< PRMClassElement< GUM_SCALAR >* >(
1819  __stack[__stack.size() - i]);
1820 
1821  if (obj == 0) {
1822  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1823  }
1824 
1825  if (obj->elt_type() != elt_type) {
1826  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1827  }
1828 
1829  return obj;
1830  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

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

1793  {
1794  // Don't forget that Idx are unsigned int
1795  if (__stack.size() - i > __stack.size()) {
1796  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1797  }
1798 
1799  PRMObject* obj = __stack[__stack.size() - i];
1800 
1801  if ((obj->obj_type() == PRMObject::prm_type::CLASS)
1802  || (obj->obj_type() == PRMObject::prm_type::PRM_INTERFACE)) {
1803  return static_cast< PRMClassElementContainer< GUM_SCALAR >* >(obj);
1804  } else {
1805  GUM_ERROR(FactoryInvalidState, "illegal sequence of calls");
1806  }
1807  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

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.

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

1246  {
1247  PRMClass< GUM_SCALAR >* a_class = nullptr;
1248  std::string full_name;
1249 
1250  // Looking for the type using its name
1251  if (__prm->__classMap.exists(name)) {
1252  a_class = __prm->__classMap[name];
1253  full_name = name;
1254  }
1255 
1256  // Looking for the type using current package
1257  std::string prefixed = __addPrefix(name);
1258  if (__prm->__classMap.exists(prefixed)) {
1259  if (a_class == nullptr) {
1260  a_class = __prm->__classMap[prefixed];
1261  full_name = prefixed;
1262  } else if (full_name != prefixed) {
1263  GUM_ERROR(DuplicateElement,
1264  "Class name '" << name
1265  << "' is ambiguous: specify full name.");
1266  }
1267  }
1268 
1269  // Looking for the class using all declared namespaces
1270  if (!__namespaces.empty()) {
1271  auto ns_list = __namespaces.back();
1272  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1273  std::string ns = (*ns_list)[i];
1274  std::string ns_name = ns + "." + name;
1275  if (__prm->__classMap.exists(ns_name)) {
1276  if (a_class == 0) {
1277  a_class = __prm->__classMap[ns_name];
1278  full_name = ns_name;
1279  } else if (full_name != ns_name) {
1280  GUM_ERROR(DuplicateElement,
1281  "Class name '" << name
1282  << "' is ambiguous: specify full name.");
1283  }
1284  }
1285  }
1286  }
1287 
1288  if (a_class == 0) {
1289  GUM_ERROR(NotFound, "Class '" << name << "' not found, check imports.");
1290  }
1291 
1292  return a_class;
1293  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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:1043
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

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

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

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

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

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

Definition at line 1053 of file PRMFactory_tpl.h.

References gum::HashTable< Key, Val, Alloc >::exists(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::prm::PRMType< GUM_SCALAR >::isSubType(), gum::prm::PRMType< GUM_SCALAR >::name(), and gum::prm::PRMType< GUM_SCALAR >::superType().

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

1054  {
1055  const PRMType< GUM_SCALAR >* current = nullptr;
1057  // Finding all types and super types
1058 
1059  for (const auto& elt : elts) {
1060  try {
1061  current = &((*elt).type());
1062 
1063  while (current != 0) {
1064  // Filling counters
1065  if (counters.exists(current->name())) {
1066  ++(counters[current->name()]);
1067  } else {
1068  counters.insert(current->name(), 1);
1069  }
1070 
1071  // Loop guard
1072  if (current->isSubType()) {
1073  current = &(current->superType());
1074  } else {
1075  current = nullptr;
1076  }
1077  }
1078  } catch (OperationNotAllowed&) {
1079  GUM_ERROR(WrongClassElement,
1080  "found a ClassElement<GUM_SCALAR> without a type");
1081  }
1082  }
1083 
1084  // We need to find the most specialized (i.e. max depth) common type
1085  current = nullptr;
1086 
1087  int max_depth = -1;
1088 
1089  int current_depth = 0;
1090 
1091  for (const auto& elt : counters) {
1092  if ((elt.second) == elts.size()) {
1093  current_depth = __typeDepth(__retrieveType(elt.first));
1094 
1095  if (current_depth > max_depth) {
1096  max_depth = current_depth;
1097  current = __retrieveType(elt.first);
1098  }
1099  }
1100  }
1101 
1102  if (current) { return const_cast< PRMType< GUM_SCALAR >* >(current); }
1103 
1104  GUM_ERROR(NotFound, "could not find a common type");
1105  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
int __typeDepth(const PRMType< GUM_SCALAR > *t)
Returns the inheritance depth of a PRMType<GUM_SCALAR>.
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 993 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::prm::PRMType< GUM_SCALAR >::name().

996  {
997  bool retVal = false;
998 
999  for (size_t i = 0; i < chains.size(); ++i) {
1000  try {
1001  inputs.push_back(&(c->get(chains[i])));
1002  retVal =
1003  retVal || PRMClassElement< GUM_SCALAR >::isSlotChain(*(inputs.back()));
1004  } catch (NotFound&) {
1005  inputs.push_back(__buildSlotChain(c, chains[i]));
1006  retVal = true;
1007 
1008  if (inputs.back()) {
1009  c->add(inputs.back());
1010  } else {
1011  GUM_ERROR(NotFound, "unknown slot chain");
1012  }
1013  }
1014  }
1015 
1016  PRMType< GUM_SCALAR >* t = __retrieveCommonType(inputs);
1017 
1018  std::vector< std::pair< PRMClassElement< GUM_SCALAR >*,
1019  PRMClassElement< GUM_SCALAR >* > >
1020  toAdd;
1021 
1022  for (const auto& elt : inputs) {
1023  if ((*elt).type() != (*t)) {
1025  PRMSlotChain< GUM_SCALAR >* sc =
1026  static_cast< PRMSlotChain< GUM_SCALAR >* >(elt);
1027  std::stringstream name;
1028 
1029  for (Size idx = 0; idx < sc->chain().size() - 1; ++idx) {
1030  name << sc->chain().atPos(idx)->name() << ".";
1031  }
1032 
1033  name << ".(" << t->name() << ")" << sc->lastElt().name();
1034 
1035  try {
1036  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1037  } catch (NotFound&) {
1038  toAdd.push_back(
1039  std::make_pair(elt, __buildSlotChain(c, name.str())));
1040  }
1041  } else {
1042  std::stringstream name;
1043  name << "(" << t->name() << ")" << elt->name();
1044  toAdd.push_back(std::make_pair(elt, &(c->get(name.str()))));
1045  }
1046  }
1047  }
1048 
1049  return retVal;
1050  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
PRMType< GUM_SCALAR > * __retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType<GUM_SCALAR> 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 &elt)
Return true if obj is of type PRMSlotChain.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

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

References GUM_ERROR.

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

1297  {
1298  PRMInterface< GUM_SCALAR >* interface = nullptr;
1299  std::string full_name;
1300 
1301  // Looking for the type using its name
1302  if (__prm->__interfaceMap.exists(name)) {
1303  interface = __prm->__interfaceMap[name];
1304  full_name = name;
1305  }
1306 
1307  // Looking for the type using current package
1308  std::string prefixed = __addPrefix(name);
1309  if (__prm->__interfaceMap.exists(prefixed)) {
1310  if (interface == nullptr) {
1311  interface = __prm->__interfaceMap[prefixed];
1312  full_name = prefixed;
1313  } else if (full_name != prefixed) {
1314  GUM_ERROR(DuplicateElement,
1315  "Interface name '" << name
1316  << "' is ambiguous: specify full name.");
1317  }
1318  }
1319 
1320  // Looking for the interf using all declared namespaces
1321  if (!__namespaces.empty()) {
1322  auto ns_list = __namespaces.back();
1323  // for( const auto & ns : *(__namespaces.top()) ) {
1324  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1325  std::string ns = (*ns_list)[i];
1326  std::string ns_name = ns + "." + name;
1327 
1328  if (__prm->__interfaceMap.exists(ns_name)) {
1329  if (interface == nullptr) {
1330  interface = __prm->__interfaceMap[ns_name];
1331  full_name = ns_name;
1332  } else if (full_name != ns_name) {
1333  GUM_ERROR(DuplicateElement,
1334  "Interface name '"
1335  << name << "' is ambiguous: specify full name.");
1336  }
1337  }
1338  }
1339  }
1340 
1341  if (interface == nullptr) {
1342  GUM_ERROR(NotFound,
1343  "Interface '" << name << "' not found, check imports.");
1344  }
1345 
1346  return interface;
1347  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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:1043
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

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

Returns a pointer on a PRMType<GUM_SCALAR> 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 1178 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().

1178  {
1179  PRMType< GUM_SCALAR >* type = nullptr;
1180  std::string full_name;
1181 
1182  // Looking for the type using its name
1183  if (__prm->__typeMap.exists(name)) {
1184  type = __prm->__typeMap[name];
1185  full_name = name;
1186  }
1187 
1188  // Looking for the type in current package
1189  std::string prefixed = __addPrefix(name);
1190  if (__prm->__typeMap.exists(prefixed)) {
1191  if (type == 0) {
1192  type = __prm->__typeMap[prefixed];
1193  full_name = prefixed;
1194  } else if (full_name != prefixed) {
1195  GUM_ERROR(DuplicateElement,
1196  "Type name '" << name << "' is ambiguous: specify full name.");
1197  }
1198  }
1199 
1200  // Looking for the type relatively to current package
1201  std::string relatif_ns = currentPackage();
1202  size_t last_dot = relatif_ns.find_last_of('.');
1203  if (last_dot != std::string::npos) {
1204  relatif_ns = relatif_ns.substr(0, last_dot) + '.' + name;
1205  if (__prm->__typeMap.exists(relatif_ns)) {
1206  if (type == 0) {
1207  type = __prm->__typeMap[relatif_ns];
1208  full_name = relatif_ns;
1209  } else if (full_name != relatif_ns) {
1210  GUM_ERROR(DuplicateElement,
1211  "Type name '" << name
1212  << "' is ambiguous: specify full name.");
1213  }
1214  }
1215  }
1216 
1217 
1218  // Looking for the type using all declared namespaces
1219  if (!__namespaces.empty()) {
1220  auto ns_list = __namespaces.back();
1221  for (gum::Size i = 0; i < ns_list->size(); ++i) {
1222  std::string ns = (*ns_list)[i];
1223  std::string ns_name = ns + "." + name;
1224  if (__prm->__typeMap.exists(ns_name)) {
1225  if (type == 0) {
1226  type = __prm->__typeMap[ns_name];
1227  full_name = ns_name;
1228  } else if (full_name != ns_name) {
1229  GUM_ERROR(DuplicateElement,
1230  "Type name '" << name
1231  << "' is ambiguous: specify full name.");
1232  }
1233  }
1234  }
1235  }
1236 
1237  if (type == 0) {
1238  GUM_ERROR(NotFound, "Type '" << name << "' not found, check imports.");
1239  }
1240 
1241  return type;
1242  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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:1043
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

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

Returns the inheritance depth of a PRMType<GUM_SCALAR>.

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

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

Definition at line 1834 of file PRMFactory_tpl.h.

References gum::prm::PRMType< GUM_SCALAR >::isSubType(), and gum::prm::PRMType< GUM_SCALAR >::superType().

1834  {
1835  int depth = 0;
1836  const PRMType< GUM_SCALAR >* current = t;
1837 
1838  while (current->isSubType()) {
1839  ++depth;
1840  current = &(current->superType());
1841  }
1842 
1843  return depth;
1844  }

+ Here is the call graph for this function:

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

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

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

870  {
871  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
873  PRMClass< GUM_SCALAR >* c = __retrieveClass(type);
874  PRMInstance< GUM_SCALAR >* inst = 0;
875 
876  try {
877  model->addArray(name, *c);
878 
879  for (Size i = 0; i < size; ++i) {
880  std::stringstream elt_name;
881  elt_name << name << "[" << i << "]";
882  inst = new PRMInstance< GUM_SCALAR >(elt_name.str(), *c);
883  model->add(name, inst);
884  }
885  } catch (TypeError&) {
886  delete inst;
887  throw;
888  } catch (NotFound&) {
889  delete inst;
890  throw;
891  }
892  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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 ...

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1587  {
1589  startAttribute(type, name);
1590  endAttribute();
1591  }
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:

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 226 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(), and gum::prm::PRMAttribute< GUM_SCALAR >::type().

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

+ Here is the call graph for this function:

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

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

1871  {
1872  if (name.size() == 0) {
1873  GUM_ERROR(OperationNotAllowed, "illegal import name");
1874  }
1875  if (__namespaces.empty()) {
1876  __namespaces.push_back(new List< std::string >());
1877  }
1878  __namespaces.back()->push_back(name);
1879  }
std::vector< List< std::string > * > __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1043
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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 1664 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().

1665  {
1666  auto c = __retrieveClass(type);
1667 
1668  // If class contains parameters, calls the proper addIsntance method
1669  if (c->parameters().size() > 0) {
1671  addInstance(type, name, params);
1672 
1673  } else {
1674  __addInstance(c, name);
1675  }
1676  }
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:

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

1682  {
1683  auto c = __retrieveClass(type);
1684 
1685  if (c->parameters().empty()) {
1686  if (params.empty()) {
1687  __addInstance(c, name);
1688  } else {
1689  GUM_ERROR(OperationNotAllowed,
1690  "Class " + type + " does not have parameters");
1691  }
1692 
1693  } else {
1694  auto my_params = params;
1695  // Adding all parameters to my_params
1696  for (const auto& p : c->parameters()) {
1697  if (!my_params.exists(p->name())) {
1698  my_params.insert(p->name(), p->value());
1699  }
1700  }
1701 
1702  // Building sub class name using my_params
1703  std::stringstream sBuff;
1704  sBuff << c->name() << "<";
1705 
1706  for (const auto& p : my_params) {
1707  sBuff << p.first << "=" << p.second << ",";
1708  }
1709 
1710  // Removing last , and adding closing >
1711  std::string sub_c = sBuff.str().substr(0, sBuff.str().size() - 1) + ">";
1712 
1713  // Adding class in current package
1714  try {
1715  auto pck_cpy = __packages;
1716  __packages.clear();
1717 
1718  startClass(sub_c, c->name());
1719 
1720  // Update inherited parameters
1721  for (auto p : my_params) {
1722  auto type = static_cast< PRMParameter< GUM_SCALAR >& >(c->get(p.first))
1723  .valueType();
1724  if (type == PRMParameter< GUM_SCALAR >::ParameterType::INT) {
1725  addParameter("int", p.first, p.second);
1726 
1727  } else {
1728  addParameter("real", p.first, p.second);
1729  }
1730  }
1731 
1732  endClass();
1733 
1734  __packages = pck_cpy;
1735 
1736  } catch (DuplicateElement&) {
1737  // Sub Class already exists in this system
1738  }
1739  c = __retrieveClass(sub_c);
1740  __addInstance(c, name);
1741  }
1742  }
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.
PRMClass< GUM_SCALAR > * __retrieveClass(const std::string &name) const
Returns a pointer on a class given it&#39;s name. Used when building models, meaning that the class name ...
std::vector< std::string > __packages
The prefix used for classes and types names. It is normally the namespace of the corresponding compil...
Definition: PRMFactory.h:1040
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
void addParameter(const std::string &type, const std::string &name, double value) override
Add a parameter to the current class with a default value.
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:66

+ Here is the call graph for this function:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::prm::PRMType< GUM_SCALAR >::__label_map, gum::prm::PRMType< GUM_SCALAR >::__superType, gum::prm::PRMType< GUM_SCALAR >::__var, GUM_ERROR, 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().

1436  {
1437  if (extends == "") {
1438  PRMType< GUM_SCALAR >* t = static_cast< PRMType< GUM_SCALAR >* >(
1440  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->__var);
1441 
1442  if (!var) {
1443  GUM_ERROR(FatalError,
1444  "the current type's variable is not a LabelizedVariable.");
1445  } else if (t->__superType) {
1446  GUM_ERROR(OperationNotAllowed, "current type is a subtype.");
1447  }
1448 
1449  try {
1450  var->addLabel(l);
1451  } catch (DuplicateElement&) {
1452  GUM_ERROR(DuplicateElement,
1453  "a label with the same value already exists");
1454  }
1455  } else {
1456  PRMType< GUM_SCALAR >* t = static_cast< PRMType< GUM_SCALAR >* >(
1458  LabelizedVariable* var = dynamic_cast< LabelizedVariable* >(t->__var);
1459 
1460  if (!var) {
1461  GUM_ERROR(FatalError,
1462  "the current type's variable is not a LabelizedVariable.");
1463  } else if (!t->__superType) {
1464  GUM_ERROR(OperationNotAllowed, "current type is not a subtype.");
1465  }
1466 
1467  bool found = false;
1468 
1469  for (Idx i = 0; i < t->__superType->__var->domainSize(); ++i) {
1470  if (t->__superType->__var->label(i) == extends) {
1471  try {
1472  var->addLabel(l);
1473  } catch (DuplicateElement&) {
1474  GUM_ERROR(DuplicateElement,
1475  "a label with the same value already exists");
1476  }
1477 
1478  t->__label_map->push_back(i);
1479 
1480  found = true;
1481  break;
1482  }
1483  }
1484 
1485  if (!found) { GUM_ERROR(NotFound, "inexistent label in super type."); }
1486  }
1487  }
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 ...
unsigned long Idx
Type for indexes.
Definition: types.h:43
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1113  {
1115  GUM_ERROR(gum::FactoryInvalidState, "invalid state to add a noisy-or");
1116  }
1117 
1118  PRMClass< GUM_SCALAR >* c =
1119  dynamic_cast< gum::prm::PRMClass< GUM_SCALAR >* >(getCurrent());
1120 
1121  std::vector< PRMClassElement< GUM_SCALAR >* > parents;
1122 
1123  for (const auto& elt : chains)
1124  parents.push_back(&(c->get(elt)));
1125 
1126  PRMType< GUM_SCALAR >* common_type = __retrieveCommonType(parents);
1127 
1128  for (size_t idx = 0; idx < parents.size(); ++idx) {
1129  if (parents[idx]->type() != (*common_type)) {
1130  PRMClassElement< GUM_SCALAR >* parent = parents[idx];
1131  // Either safe_name is an non existing slot chain or an existing cast
1132  // descendant
1133  std::string safe_name = parent->cast(*common_type);
1134 
1135  if (!c->exists(safe_name)) {
1137  parents[idx] = __buildSlotChain(c, safe_name);
1138  c->add(parents[idx]);
1139  } else {
1140  GUM_ERROR(NotFound, "unable to find parent");
1141  }
1142  } else {
1143  parents[idx] = &(c->get(safe_name));
1144  }
1145  }
1146  }
1147 
1148  if (numbers.size() == 1) {
1149  auto impl =
1150  new gum::MultiDimNoisyORCompound< GUM_SCALAR >(leak, numbers.front());
1151  auto attr = new PRMScalarAttribute< GUM_SCALAR >(
1152  name, retrieveType("boolean"), impl);
1153  addAttribute(attr);
1154  } else if (numbers.size() == parents.size()) {
1159  name, retrieveType("boolean"), noisy);
1160 
1161  for (size_t idx = 0; idx < numbers.size(); ++idx) {
1162  noisy->causalWeight(parents[idx]->type().variable(), numbers[idx]);
1163  }
1164 
1165  addAttribute(attr);
1166  } else {
1167  GUM_ERROR(OperationNotAllowed, "invalid parameters for a noisy or");
1168  }
1169 
1170  if (!labels.empty()) {
1171  GUM_ERROR(OperationNotAllowed,
1172  "labels definitions not handle for noisy-or");
1173  }
1174  }
PRMType< GUM_SCALAR > * __retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType<GUM_SCALAR> of a vector of PRMClassElement<GUM_SCALAR>.
PRMType< GUM_SCALAR > & retrieveType(const std::string &name)
Returns a reference over a PRMType<GUM_SCALAR> given its name.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
virtual PRMObject::prm_type currentType() const override
<agrum/PRM/elements/funcAttribute.h>
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:58
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
static INLINE bool isSlotChain(const PRMClassElement &elt)
Return true if obj is of type PRMSlotChain.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 546 of file PRMFactory_tpl.h.

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

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

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

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

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

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

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 307 of file PRMFactory_tpl.h.

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

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

845  {
846  PRMClassElementContainer< GUM_SCALAR >* owner = __checkStackContainter(1);
847  PRMClassElementContainer< GUM_SCALAR >* slotType = 0;
848 
849  try {
850  slotType = __retrieveClass(type);
851  } catch (NotFound&) {
852  try {
853  slotType = __retrieveInterface(type);
854  } catch (NotFound&) {
855  GUM_ERROR(NotFound, "unknown ReferenceSlot<GUM_SCALAR> slot type");
856  }
857  }
858 
859  PRMReferenceSlot< GUM_SCALAR >* ref =
860  new PRMReferenceSlot< GUM_SCALAR >(name, *slotType, isArray);
861 
862  try {
863  owner->add(ref);
864  } catch (DuplicateElement&) { owner->overload(ref); }
865  }
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 ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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:

+ Here is the caller graph for this function:

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

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

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

1522  {
1523  PRMType< GUM_SCALAR >* t = static_cast< PRMType< GUM_SCALAR >* >(
1525  DiscretizedVariable< double >* var =
1526  dynamic_cast< DiscretizedVariable< double >* >(t->__var);
1527 
1528  if (!var) {
1529  GUM_ERROR(FatalError,
1530  "the current type's variable is not a LabelizedVariable.");
1531  }
1532 
1533  try {
1534  var->addTick(tick);
1535  } catch (DefaultInLabel& e) {
1536  GUM_ERROR(OperationNotAllowed, "tick already in used for this variable");
1537  }
1538  }
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

1398  {
1399  if (__stack.size() > 0) {
1400  PRMObject* obj = __stack.back();
1401  __stack.pop_back();
1402  return obj;
1403  } else {
1404  return 0;
1405  }
1406  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
template<typename GUM_SCALAR >
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::continueAggregator ( const std::string &  name)

Conitnues an aggregator declaration.

Definition at line 605 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().

605  {
606  PRMClassElementContainer< GUM_SCALAR >* c = __checkStackContainter(1);
607  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
608  auto& agg = c->get(name);
610  GUM_ERROR(OperationNotAllowed, name << " not an aggregate");
611  }
612  __stack.push_back(&agg);
613  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
static INLINE bool isAggregate(const PRMClassElement &elt)
Return true if obj is of type PRMAggregate.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1623  {
1624  PRMClassElementContainer< GUM_SCALAR >* c = __checkStackContainter(1);
1625  if (!c->exists(name)) { GUM_ERROR(NotFound, name << "not found"); }
1626  auto& a = c->get(name);
1628  GUM_ERROR(OperationNotAllowed, name << " not an attribute");
1629  }
1630  __stack.push_back(&a);
1631  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
static INLINE bool isAttribute(const PRMClassElement &elt)
Returns true if obj_ptr is of type PRMAttribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Continue the declaration of a class.

Implements gum::prm::IPRMFactory.

Definition at line 84 of file PRMFactory_tpl.h.

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

84  {
85  std::string real_name = __addPrefix(name);
86  if (!(__prm->__classMap.exists(real_name))) {
87  std::stringstream msg;
88  msg << "\"" << real_name << "\" not found";
89  GUM_ERROR(NotFound, msg.str());
90  }
91  __stack.push_back(&(__prm->getClass(real_name)));
92  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
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:66

+ Here is the caller graph for this function:

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

Continue the declaration of an interface.

Implements gum::prm::IPRMFactory.

Definition at line 212 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

212  {
213  std::string real_name = __addPrefix(name);
214  if (!__prm->__interfaceMap.exists(real_name)) {
215  std::stringstream msg;
216  msg << "\"" << real_name << "\" not found.";
217  GUM_ERROR(DuplicateElement, msg.str());
218  }
219 
220  PRMInterface< GUM_SCALAR >* i = __retrieveInterface(real_name);
221  __stack.push_back(i);
222  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
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:66
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 caller graph for this function:

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

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

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

1409  {
1410  return (__packages.empty()) ? "" : __packages.back();
1411  }
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:1040

+ Here is the caller graph for this function:

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

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

1377  {
1378  if (__stack.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1379 
1380  return __stack.back()->obj_type();
1381  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
template<typename GUM_SCALAR >
INLINE void gum::prm::PRMFactory< GUM_SCALAR >::endAggregator ( )

Finishes an aggregate declaration.

Definition at line 671 of file PRMFactory_tpl.h.

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

671  {
673  __stack.pop_back();
674  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:

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

1634  {
1636  __stack.pop_back();
1637  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:

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

95  {
96  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
98 
99  if (checkImplementations) { __checkInterfaceImplementation(c); }
100 
101  __stack.pop_back();
102  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:

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

References gum::prm::PRMFactory< GUM_SCALAR >::__checkStack(), gum::prm::PRMType< GUM_SCALAR >::__isValid(), gum::prm::PRMFactory< GUM_SCALAR >::__prm, gum::prm::PRMFactory< GUM_SCALAR >::__stack, GUM_ERROR, gum::prm::PRMType< GUM_SCALAR >::name(), gum::prm::PRMObject::TYPE, and gum::prm::PRMType< GUM_SCALAR >::variable().

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

1490  {
1491  PRMType< GUM_SCALAR >* t = static_cast< PRMType< GUM_SCALAR >* >(
1493 
1494  if (!t->__isValid()) {
1495  GUM_ERROR(OperationNotAllowed, "current type is not a valid subtype");
1496  } else if (t->variable().domainSize() < 2) {
1497  GUM_ERROR(OperationNotAllowed,
1498  "current type is not a valid discrete type");
1499  }
1500 
1501  __prm->__typeMap.insert(t->name(), t);
1502 
1503  __prm->__types.insert(t);
1504  __stack.pop_back();
1505  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 1541 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_ERROR, gum::prm::PRMType< GUM_SCALAR >::name(), gum::prm::PRMObject::TYPE, and gum::prm::PRMType< GUM_SCALAR >::variable().

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

1541  {
1542  PRMType< GUM_SCALAR >* t = static_cast< PRMType< GUM_SCALAR >* >(
1544 
1545  if (t->variable().domainSize() < 2) {
1546  GUM_ERROR(OperationNotAllowed,
1547  "current type is not a valid discrete type");
1548  }
1549 
1550  __prm->__typeMap.insert(t->name(), t);
1551 
1552  __prm->__types.insert(t);
1553  __stack.pop_back();
1554  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1580  {
1582  __stack.pop_back();
1583  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:

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

1654  {
1655  try {
1656  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
1658  __stack.pop_back();
1659  model->instantiate();
1660  } catch (Exception&) { GUM_ERROR(FatalError, "could not create system"); }
1661  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

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

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

+ Here is the caller graph for this function:

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

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

1391  {
1392  if (__stack.size() == 0) { GUM_ERROR(NotFound, "no object being built"); }
1393 
1394  return __stack.back();
1395  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
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 895 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.

896  {
897  PRMSystem< GUM_SCALAR >* model = static_cast< PRMSystem< GUM_SCALAR >* >(
899 
900  if (model->isArray(l_i)) {
901  if (model->isInstance(r_i)) {
902  model->add(l_i, model->get(r_i));
903  } else {
904  GUM_ERROR(NotFound, "right value is not an instance");
905  }
906  } else {
907  GUM_ERROR(NotFound, "left value is no an array");
908  }
909  }
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:66

+ Here is the call graph for this function:

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

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

1936  {
1937  const PRMSystem< GUM_SCALAR >* system =
1938  static_cast< const PRMSystem< GUM_SCALAR >* >(getCurrent());
1939  return (system && system->isArray(name));
1940  }
virtual PRMObject * getCurrent() override

+ Here is the call graph for this function:

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

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

1916  {
1917  try {
1918  __retrieveClass(type);
1919  return true;
1920 
1921  } catch (NotFound&) {
1922  } catch (DuplicateElement&) {}
1923 
1924  try {
1925  __retrieveInterface(type);
1926  return true;
1927 
1928  } catch (NotFound&) {
1929  } catch (DuplicateElement&) {}
1930 
1931  return false;
1932  }
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:

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

Copy operator. Don't use it.

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

1853  {
1854  std::string plop = currentPackage();
1855 
1856  if (!__packages.empty()) {
1857  std::string s = __packages.back();
1858  __packages.pop_back();
1859 
1860  if (__namespaces.size() > 0) {
1861  delete __namespaces.back();
1862  __namespaces.pop_back();
1863  }
1864  return s;
1865  }
1866 
1867  return plop;
1868  }
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:1040
std::vector< List< std::string > * > __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1043

+ Here is the call graph for this function:

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

1372  {
1373  return __prm;
1374  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046

+ Here is the caller graph for this function:

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

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

1847  {
1848  __packages.push_back(name);
1849  __namespaces.push_back(new List< std::string >());
1850  }
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:1040
std::vector< List< std::string > * > __namespaces
Set of all declared namespaces.
Definition: PRMFactory.h:1043
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 1897 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().

1897  {
1898  return *__retrieveClass(name);
1899  }
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:

template<typename GUM_SCALAR >
INLINE PRMType< GUM_SCALAR > & 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 1908 of file PRMFactory_tpl.h.

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

1909  {
1910  return *(__retrieveCommonType(elts));
1911  }
PRMType< GUM_SCALAR > * __retrieveCommonType(const std::vector< PRMClassElement< GUM_SCALAR > * > &elts)
Retrieve the common PRMType<GUM_SCALAR> of a vector of PRMClassElement<GUM_SCALAR>.

+ Here is the call graph for this function:

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

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

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

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

Definition at line 1903 of file PRMFactory_tpl.h.

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

1903  {
1904  return *__retrieveType(name);
1905  }
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...

+ Here is the call graph for this function:

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

Fills the CPF using a rule.

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

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

Implements gum::prm::IPRMFactory.

Definition at line 397 of file PRMFactory_tpl.h.

References GUM_ERROR.

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

Fills the CPF using a rule.

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

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

Definition at line 416 of file PRMFactory_tpl.h.

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 481 of file PRMFactory_tpl.h.

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

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

+ Here is the call graph for this function:

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Definition at line 364 of file PRMFactory_tpl.h.

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

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1944  {
1946 
1947  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1949 
1950  if (a->formulas().domainSize() != array.size()) {
1951  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1952  }
1953 
1954  if (a->formulas().nbrDim() == 1) {
1955  setRawCPFByLines(array);
1956 
1957  } else {
1958  Instantiation inst(a->formulas());
1959  Instantiation jnst;
1960  for (auto idx = inst.variablesSequence().rbegin();
1961  idx != inst.variablesSequence().rend();
1962  --idx) {
1963  jnst.add(**idx);
1964  }
1965 
1966  jnst.setFirst();
1967  auto idx = (std::size_t)0;
1968  while ((!jnst.end()) && idx < array.size()) {
1969  inst.setVals(jnst);
1970  a->formulas().set(inst, array[idx]);
1971  jnst.inc();
1972  ++idx;
1973  }
1974 
1975  // Generate cpf by calling it
1976  a->cpf();
1977  }
1978  }
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:66

+ Here is the call graph for this function:

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

Gives the factory the CPF in its raw form.

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

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

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

See PRMFactory::setRawCPFByLines() for more details.

Exceptions
OperationNotAllowedRaised if the given operation is illegal.

Implements gum::prm::IPRMFactory.

Definition at line 350 of file PRMFactory_tpl.h.

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

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

+ Here is the call graph for this function:

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

Gives the factory the CPF in its raw form.

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

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

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

Implements gum::prm::IPRMFactory.

Definition at line 322 of file PRMFactory_tpl.h.

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

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

+ Here is the call graph for this function:

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

Gives the factory the CPF in its raw form.

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

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

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

Definition at line 336 of file PRMFactory_tpl.h.

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

337  {
339  auto a = static_cast< PRMAttribute< GUM_SCALAR >* >(elt);
341 
342  if (a->cpf().domainSize() != array.size()) {
343  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
344  }
345 
346  a->cpf().fillWith(array);
347  }
PRMObject * __checkStack(Idx i, PRMObject::prm_type obj_type)
Return a pointer on a PRMObject at __stack.size() - i position after checking the type of the object ...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the caller graph for this function:

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

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

1982  {
1984 
1985  auto a = static_cast< PRMFormAttribute< GUM_SCALAR >* >(
1987 
1988  if (a->formulas().domainSize() != array.size()) {
1989  GUM_ERROR(OperationNotAllowed, "illegal CPF size");
1990  }
1991 
1992  a->formulas().populate(array);
1993 
1995  a->cpf();
1996  }
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:66

+ Here is the call graph for this function:

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

913  {
914  auto model = static_cast< PRMSystem< GUM_SCALAR >* >(
916  std::vector< PRMInstance< GUM_SCALAR >* > lefts;
917  std::vector< PRMInstance< GUM_SCALAR >* > rights;
918 
919  if (model->isInstance(l_i)) {
920  lefts.push_back(&(model->get(l_i)));
921  } else if (model->isArray(l_i)) {
922  for (const auto& elt : model->getArray(l_i))
923  lefts.push_back(elt);
924  } else {
925  GUM_ERROR(NotFound, "left value does not name an instance or an array");
926  }
927 
928  if (model->isInstance(r_i)) {
929  rights.push_back(&(model->get(r_i)));
930  } else if (model->isArray(r_i)) {
931  for (const auto& elt : model->getArray(r_i))
932  rights.push_back(elt);
933  } else {
934  GUM_ERROR(NotFound, "left value does not name an instance or an array");
935  }
936 
937  for (const auto l : lefts) {
938  for (const auto r : rights) {
939  auto& elt = l->type().get(l_ref);
941  l->add(elt.id(), *r);
942 
943  } else {
944  GUM_ERROR(NotFound, "unfound reference slot");
945  }
946  }
947  }
948  }
static INLINE bool isReferenceSlot(const PRMClassElement &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:66

+ Here is the caller graph for this function:

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

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

1884  {
1885  size_t pos = l_i.find_last_of('.');
1886 
1887  if (pos != std::string::npos) {
1888  std::string l_ref = l_i.substr(pos + 1, std::string::npos);
1889  setReferenceSlot(l_i.substr(0, pos), l_ref, r_i);
1890  } else {
1891  GUM_ERROR(NotFound, "left value does not name an instance or an array");
1892  }
1893  }
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:66

+ Here is the call graph for this function:

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

573  {
574  PRMClass< GUM_SCALAR >* c = static_cast< PRMClass< GUM_SCALAR >* >(
576 
577  auto agg = new PRMAggregate< GUM_SCALAR >(
578  name,
580  *__retrieveType(rv_type));
581 
582  try {
583  c->add(agg);
584  } catch (DuplicateElement&) { c->overload(agg); }
585 
586  switch (agg->agg_type()) {
590  if (params.size() != 1) {
591  GUM_ERROR(OperationNotAllowed, "aggregate requires a parameter");
592  }
593  agg->setLabel(params.front());
594  break;
595  }
596  default: {
597  // Nothing to do
598  }
599  }
600  __stack.push_back(agg);
601  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:88
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 ...
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1596  {
1597  PRMClassElementContainer< GUM_SCALAR >* c = __checkStackContainter(1);
1598  PRMAttribute< GUM_SCALAR >* a = nullptr;
1599 
1600  if (PRMObject::isClass(*c) && (!scalar_attr)) {
1601  a = new PRMFormAttribute< GUM_SCALAR >(
1602  static_cast< PRMClass< GUM_SCALAR >& >(*c), name, *__retrieveType(type));
1603 
1604  } else {
1605  a = new PRMScalarAttribute< GUM_SCALAR >(name, *__retrieveType(type));
1606  }
1607 
1608  std::string dot = ".";
1609 
1610  try {
1611  try {
1612  c->add(a);
1613  } catch (DuplicateElement&) { c->overload(a); }
1614  } catch (Exception&) {
1615  if (a != nullptr && (!c->exists(a->id()))) { delete a; }
1616  }
1617 
1618  __stack.push_back(a);
1619  }
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
Definition: PRMObject.h:99
PRMClassElementContainer< GUM_SCALAR > * __checkStackContainter(Idx i)
Adds __prefix to str iff __prefix != "".
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

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

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

+ Here is the caller graph for this function:

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

1416  {
1417  std::string real_name = __addPrefix(name);
1418  if (__prm->__typeMap.exists(real_name)) {
1419  std::stringstream msg;
1420  msg << "\"" << real_name << "\" is already used.";
1421  GUM_ERROR(DuplicateElement, msg.str());
1422  }
1423  if (super == "") {
1424  auto t = new PRMType< GUM_SCALAR >(LabelizedVariable(real_name, "", 0));
1425  __stack.push_back(t);
1426  } else {
1427  auto t = new PRMType< GUM_SCALAR >(LabelizedVariable(real_name, "", 0));
1428  t->__superType = __retrieveType(super);
1429  t->__label_map = new std::vector< Idx >();
1430  __stack.push_back(t);
1431  }
1432  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
Definition: PRMFactory.h:1049
std::string __addPrefix(const std::string &str) const
Adds __prefix to str iff __prefix != "".
PRMType< GUM_SCALAR > * __retrieveType(const std::string &name) const
Returns a pointer on a PRMType<GUM_SCALAR> given it&#39;s name. Since the type can be given either with i...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1509  {
1510  std::string real_name = __addPrefix(name);
1511  if (__prm->__typeMap.exists(real_name)) {
1512  std::stringstream msg;
1513  msg << "\"" << real_name << "\" is already used.";
1514  GUM_ERROR(DuplicateElement, msg.str());
1515  }
1516  auto var = DiscretizedVariable< double >(real_name, "");
1517  auto t = new PRMType< GUM_SCALAR >(var);
1518  __stack.push_back(t);
1519  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References GUM_ERROR.

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

186  {
187  std::string real_name = __addPrefix(name);
188  if (__prm->__classMap.exists(real_name)
189  || __prm->__interfaceMap.exists(real_name)) {
190  std::stringstream msg;
191  msg << "\"" << real_name << "\" is already used.";
192  GUM_ERROR(DuplicateElement, msg.str());
193  }
194  PRMInterface< GUM_SCALAR >* i = nullptr;
195  PRMInterface< GUM_SCALAR >* super = nullptr;
196 
197  if (extends != "") { super = __retrieveInterface(extends); }
198 
199  if (super != nullptr) {
200  i = new PRMInterface< GUM_SCALAR >(real_name, *super, delayInheritance);
201  } else {
202  i = new PRMInterface< GUM_SCALAR >(real_name);
203  }
204 
205  __prm->__interfaceMap.insert(i->name(), i);
206  __prm->__interfaces.insert(i);
207  __stack.push_back(i);
208  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
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:66
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 caller graph for this function:

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 1640 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::LayerGenerator< GUM_SCALAR >::__generateSystem(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateSystem(), and gum::prm::o3prm::O3SystemFactory< GUM_SCALAR >::build().

1640  {
1641  if (__prm->__systemMap.exists(name)) {
1642  std::stringstream msg;
1643  msg << "\"" << name << "\" is already used.";
1644  GUM_ERROR(DuplicateElement, msg.str());
1645  }
1646  PRMSystem< GUM_SCALAR >* model =
1647  new PRMSystem< GUM_SCALAR >(__addPrefix(name));
1648  __stack.push_back(model);
1649  __prm->__systemMap.insert(model->name(), model);
1650  __prm->__systems.insert(model);
1651  }
PRM< GUM_SCALAR > * __prm
The pointer on the PRM<GUM_SCALAR> built by this factory.
Definition: PRMFactory.h:1046
std::vector< PRMObject * > __stack
A stack used to keep track of created PRMObject.
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:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

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

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