aGrUM  0.14.2
PRMSlotChain_tpl.h
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 
28 namespace gum {
29  namespace prm {
30 
31  template < typename GUM_SCALAR >
33  const std::string& name,
34  const Sequence< PRMClassElement< GUM_SCALAR >* >& chain) :
35  PRMClassElement< GUM_SCALAR >(name),
36  __chain(new Sequence< PRMClassElement< GUM_SCALAR >* >(chain)),
37  __isMultiple(false) {
38  GUM_CONSTRUCTOR(PRMSlotChain);
39 
40  if (__chain->size() < 2) {
42  "chain must contain at least two ClassElement");
43  }
44 
45  for (Size i = 0; i < __chain->size() - 1; ++i) {
46  if (__chain->atPos(i)->elt_type()
48  GUM_ERROR(WrongClassElement, "illegal ClassElement in chain");
49  } else {
50  __isMultiple =
51  __isMultiple
52  || static_cast< PRMReferenceSlot< GUM_SCALAR >* >(__chain->atPos(i))
53  ->isArray();
54  }
55  }
56 
57  __copyLastElt();
58 
59  this->_safeName = PRMObject::LEFT_CAST() + lastElt().type().name()
60  + PRMObject::RIGHT_CAST() + name;
61  this->lastElt().type().variable().setName(name);
62  }
63 
64  // Parameters are inverse to prevent unwanted constructors calls (it
65  // happened)
66  template < typename GUM_SCALAR >
69  const std::string& name) :
70  PRMSlotChain(name, *chain) {
71  // No need to
72  // GUM_CONSTRUCTOR(PRMSlotChain);
73 
74  // if (__chain->size() < 2) {
75  // GUM_ERROR(OperationNotAllowed,
76  // "chain must containt at least two PRMClassElement");
77  //}
78 
79  // for (Size i = 0; i < __chain->size() - 1; ++i) {
80  // if (not(__chain->atPos(i)->elt_type() !=
81  // PRMClassElement<GUM_SCALAR>::prm_refslot)) {
82  // GUM_ERROR(WrongClassElement, "illegal PRMClassElement in chain");
83  // } else {
84  // __isMultiple =
85  // __isMultiple or
86  // static_cast<PRMReferenceSlot<GUM_SCALAR>
87  // *>(__chain->atPos(i))->isArray();
88  // }
89  //}
90 
91  //__copyLastElt();
92  // this->_safeName = PRMObject::LEFT_CAST() + lastElt().type().name() +
93  // PRMObject::RIGHT_CAST() + name;
94  }
95 
96  template < typename GUM_SCALAR >
98  PRMClassElement< GUM_SCALAR >* new_elt = nullptr;
99 
100  switch (__chain->back()->elt_type()) {
102  auto old_attr =
103  static_cast< const PRMAttribute< GUM_SCALAR >* >(__chain->back());
104 
106  for (auto var : old_attr->cpf().variablesSequence()) {
107  if (var != &(old_attr->type().variable())) { bij.insert(var, var); }
108  }
109 
110  new_elt = old_attr->copy(bij);
111  break;
112  }
113 
115  const PRMAggregate< GUM_SCALAR >* c_agg =
116  static_cast< const PRMAggregate< GUM_SCALAR >* >(__chain->back());
118  c_agg->name(), c_agg->agg_type(), c_agg->type(), c_agg->id());
119  new_elt = agg;
120  break;
121  }
122 
123  default: {
124  GUM_ERROR(WrongClassElement, "last element of chain is not valid");
125  }
126  }
127 
128  new_elt->setId(__chain->back()->id());
129  __chain->setAtPos(__chain->size() - 1, new_elt);
130  }
131 
132  template < typename GUM_SCALAR >
134  GUM_DESTRUCTOR(PRMSlotChain);
135  delete __chain->back();
136  delete __chain;
137  }
138 
139  template < typename GUM_SCALAR >
141  const PRMSlotChain< GUM_SCALAR >& source) :
142  PRMClassElement< GUM_SCALAR >(source.name()),
143  __chain(new Sequence< PRMClassElement< GUM_SCALAR >* >(source.chain())),
144  __isMultiple(source.isMultiple()) {
145  GUM_CONS_CPY(PRMSlotChain);
146  __copyLastElt();
147  }
148 
149  template < typename GUM_SCALAR >
153  "Illegal call to gum::SlotChain<GUM_SCALAR> copy constructor.");
154  }
155 
156  template < typename GUM_SCALAR >
159  return this->prm_slotchain;
160  }
161 
162  template < typename GUM_SCALAR >
164  return __chain->back()->type();
165  }
166 
167  template < typename GUM_SCALAR >
169  return __chain->back()->type();
170  }
171 
172  template < typename GUM_SCALAR >
174  return __chain->back()->cpf();
175  }
176 
177  template < typename GUM_SCALAR >
180  return static_cast< PRMReferenceSlot< GUM_SCALAR >* >(
181  __chain->atPos(__chain->size() - 2))
182  ->slotType();
183  }
184 
185  template < typename GUM_SCALAR >
188  return static_cast< PRMReferenceSlot< GUM_SCALAR >* >(
189  __chain->atPos(__chain->size() - 2))
190  ->slotType();
191  }
192 
193  template < typename GUM_SCALAR >
195  return *(__chain->back());
196  }
197 
198  template < typename GUM_SCALAR >
199  INLINE const PRMClassElement< GUM_SCALAR >&
201  return *(__chain->back());
202  }
203 
204  template < typename GUM_SCALAR >
207  return *__chain;
208  }
209 
210  template < typename GUM_SCALAR >
213  return *__chain;
214  }
215 
216  template < typename GUM_SCALAR >
218  const PRMClassElement< GUM_SCALAR >& elt) {}
219 
220  template < typename GUM_SCALAR >
222  const PRMClassElement< GUM_SCALAR >& elt) {}
223 
224  template < typename GUM_SCALAR >
226  return __isMultiple;
227  }
228 
229  template < typename GUM_SCALAR >
232  GUM_ERROR(OperationNotAllowed, "This is a slotchain");
233  }
234 
235  } /* namespace prm */
236 } /* namespace gum */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
Headers of gum::PRMSlotChain.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
Abstract class representing an element of PRM class.
virtual PRMType & type()
This is similar to the following call: this->lastElt().type()
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
Definition: PRMObject.h:220
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:1803
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:60
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Definition: PRMObject.h:218
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:58
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.