aGrUM  0.16.0
PRMSlotChain_tpl.h
Go to the documentation of this file.
1 
30 
31 namespace gum {
32  namespace prm {
33 
34  template < typename GUM_SCALAR >
36  const std::string& name,
37  const Sequence< PRMClassElement< GUM_SCALAR >* >& chain) :
38  PRMClassElement< GUM_SCALAR >(name),
39  __chain(new Sequence< PRMClassElement< GUM_SCALAR >* >(chain)),
40  __isMultiple(false) {
41  GUM_CONSTRUCTOR(PRMSlotChain);
42 
43  if (__chain->size() < 2) {
45  "chain must contain at least two ClassElement");
46  }
47 
48  for (Size i = 0; i < __chain->size() - 1; ++i) {
49  if (__chain->atPos(i)->elt_type()
51  GUM_ERROR(WrongClassElement, "illegal ClassElement in chain");
52  } else {
53  __isMultiple =
54  __isMultiple
55  || static_cast< PRMReferenceSlot< GUM_SCALAR >* >(__chain->atPos(i))
56  ->isArray();
57  }
58  }
59 
60  __copyLastElt();
61 
62  this->_safeName = PRMObject::LEFT_CAST() + lastElt().type().name()
63  + PRMObject::RIGHT_CAST() + name;
64  this->lastElt().type().variable().setName(name);
65  }
66 
67  // Parameters are inverse to prevent unwanted constructors calls (it
68  // happened)
69  template < typename GUM_SCALAR >
72  const std::string& name) :
73  PRMSlotChain(name, *chain) {
74  // No need to
75  // GUM_CONSTRUCTOR(PRMSlotChain);
76 
77  // if (__chain->size() < 2) {
78  // GUM_ERROR(OperationNotAllowed,
79  // "chain must containt at least two PRMClassElement");
80  //}
81 
82  // for (Size i = 0; i < __chain->size() - 1; ++i) {
83  // if (not(__chain->atPos(i)->elt_type() !=
84  // PRMClassElement<GUM_SCALAR>::prm_refslot)) {
85  // GUM_ERROR(WrongClassElement, "illegal PRMClassElement in chain");
86  // } else {
87  // __isMultiple =
88  // __isMultiple or
89  // static_cast<PRMReferenceSlot<GUM_SCALAR>
90  // *>(__chain->atPos(i))->isArray();
91  // }
92  //}
93 
94  //__copyLastElt();
95  // this->_safeName = PRMObject::LEFT_CAST() + lastElt().type().name() +
96  // PRMObject::RIGHT_CAST() + name;
97  }
98 
99  template < typename GUM_SCALAR >
101  PRMClassElement< GUM_SCALAR >* new_elt = nullptr;
102 
103  switch (__chain->back()->elt_type()) {
105  auto old_attr =
106  static_cast< const PRMAttribute< GUM_SCALAR >* >(__chain->back());
107 
109  for (auto var : old_attr->cpf().variablesSequence()) {
110  if (var != &(old_attr->type().variable())) { bij.insert(var, var); }
111  }
112 
113  new_elt = old_attr->copy(bij);
114  break;
115  }
116 
118  const PRMAggregate< GUM_SCALAR >* c_agg =
119  static_cast< const PRMAggregate< GUM_SCALAR >* >(__chain->back());
121  c_agg->name(), c_agg->agg_type(), c_agg->type(), c_agg->id());
122  new_elt = agg;
123  break;
124  }
125 
126  default: {
127  GUM_ERROR(WrongClassElement, "last element of chain is not valid");
128  }
129  }
130 
131  new_elt->setId(__chain->back()->id());
132  __chain->setAtPos(__chain->size() - 1, new_elt);
133  }
134 
135  template < typename GUM_SCALAR >
137  GUM_DESTRUCTOR(PRMSlotChain);
138  delete __chain->back();
139  delete __chain;
140  }
141 
142  template < typename GUM_SCALAR >
144  const PRMSlotChain< GUM_SCALAR >& source) :
145  PRMClassElement< GUM_SCALAR >(source.name()),
146  __chain(new Sequence< PRMClassElement< GUM_SCALAR >* >(source.chain())),
147  __isMultiple(source.isMultiple()) {
148  GUM_CONS_CPY(PRMSlotChain);
149  __copyLastElt();
150  }
151 
152  template < typename GUM_SCALAR >
156  "Illegal call to gum::SlotChain<GUM_SCALAR> copy constructor.");
157  }
158 
159  template < typename GUM_SCALAR >
162  return this->prm_slotchain;
163  }
164 
165  template < typename GUM_SCALAR >
167  return __chain->back()->type();
168  }
169 
170  template < typename GUM_SCALAR >
172  return __chain->back()->type();
173  }
174 
175  template < typename GUM_SCALAR >
177  return __chain->back()->cpf();
178  }
179 
180  template < typename GUM_SCALAR >
183  return static_cast< PRMReferenceSlot< GUM_SCALAR >* >(
184  __chain->atPos(__chain->size() - 2))
185  ->slotType();
186  }
187 
188  template < typename GUM_SCALAR >
191  return static_cast< PRMReferenceSlot< GUM_SCALAR >* >(
192  __chain->atPos(__chain->size() - 2))
193  ->slotType();
194  }
195 
196  template < typename GUM_SCALAR >
198  return *(__chain->back());
199  }
200 
201  template < typename GUM_SCALAR >
202  INLINE const PRMClassElement< GUM_SCALAR >&
204  return *(__chain->back());
205  }
206 
207  template < typename GUM_SCALAR >
210  return *__chain;
211  }
212 
213  template < typename GUM_SCALAR >
216  return *__chain;
217  }
218 
219  template < typename GUM_SCALAR >
221  const PRMClassElement< GUM_SCALAR >& elt) {}
222 
223  template < typename GUM_SCALAR >
225  const PRMClassElement< GUM_SCALAR >& elt) {}
226 
227  template < typename GUM_SCALAR >
229  return __isMultiple;
230  }
231 
232  template < typename GUM_SCALAR >
235  GUM_ERROR(OperationNotAllowed, "This is a slotchain");
236  }
237 
238  } /* namespace prm */
239 } /* namespace gum */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:35
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
Abstract class representing an element of PRM class.
virtual PRMType & type()
This is similar to the following call: this->lastElt().type()
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
Definition: PRMObject.h:223
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject)...
virtual const Potential< GUM_SCALAR > & cpf() const
This is similar to the following call: this->lastElt().cpf()
AggregateType agg_type() const
Returns the aggregate of *this.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:63
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Definition: PRMObject.h:221
virtual PRMType & type()
See gum::PRMClassElement::type().
<agrum/PRM/classElementContainer.h>
NodeId id() const
Returns the NodeId of this element in it&#39;s class DAG.
virtual void setId(NodeId id)
Used to assign the id of this element.
PRMSlotChain(const std::string &name, const Sequence< PRMClassElement< GUM_SCALAR > * > &chain)
Default constructor.
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.