aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
PRMSlotChain.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of gum::PRMSlotChain.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_SLOT_CHAIN_H
30 #define GUM_SLOT_CHAIN_H
31 
32 #include <string>
33 
34 #include <agrum/tools/core/sequence.h>
35 
36 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h>
37 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORNet.h>
38 #include <agrum/tools/multidim/implementations/multiDimBijArray.h>
39 #include <agrum/tools/multidim/potential.h>
40 
41 #include <agrum/PRM/elements/PRMType.h>
42 #include <agrum/PRM/elements/PRMClassElement.h>
43 #include <agrum/PRM/elements/PRMClassElementContainer.h>
44 #include <agrum/PRM/elements/PRMAttribute.h>
45 #include <agrum/PRM/elements/PRMAggregate.h>
46 #include <agrum/PRM/elements/PRMReferenceSlot.h>
47 
48 namespace gum {
49  namespace prm {
50 
51  template < typename GUM_SCALAR >
52  class PRMClass;
53  template < typename GUM_SCALAR >
54  class PRMAttribute;
55 
56  /**
57  * @class PRMSlotChain
58  * @headerfile slotChain.h <agrum/PRM/slotChain.h>
59  *
60  * @brief A PRMSlotChain represents a sequence of
61  *gum::prm::PRMClassElement<GUM_SCALAR>
62  *where
63  * the n-1 first gum::prm::PRMClassElement<GUM_SCALAR> are
64  *gum::prm::PRMReferenceSlot and
65  * the last gum::prm::PRMClassElement<GUM_SCALAR> an
66  *gum::prm::PRMAttribute
67  *or
68  *an
69  * gum::prm::PRMAggregate.
70  *
71  * A PRMSlotChain behaves as an gum::prm::PRMAttribute or an
72  *gum::prm::PRMAggregate
73  * (depending the gum::prm::PRMClassElement<GUM_SCALAR> type of it's last
74  *element)
75  *regarding
76  * the following methods: gum::prm::PRMClassElement<GUM_SCALAR>::type() and
77  * gum::prm::PRMClassElement<GUM_SCALAR>::cpf().
78  *
79  */
80  // ==========================================================================
81  template < typename GUM_SCALAR >
82  class PRMSlotChain: public PRMClassElement< GUM_SCALAR > {
83  public:
84  // ========================================================================
85  /// @name Constructors & destructor
86  // ========================================================================
87  /// @{
88 
89  /** @brief Default constructor.
90  *
91  * Chain's n-1 first elements must be PRMReferenceSlot and the last
92  *element
93  * must either be an PRMAttribute or an PRMAggregate.
94  *
95  * Warning: the last element in chain is copied !
96  *
97  * @param name The name of this PRMSlotChain.
98  * @param chain The chain of gum::prm::PRMClassElement<GUM_SCALAR> in this
99  *PRMSlotChain.
100  *
101  * @throw OperationNotAllowed Raised if the chain contains less than two
102  * PRMClassElement<GUM_SCALAR>.
103  * @throw WrongClassElement<GUM_SCALAR> Raised contains invalid
104  *PRMClassElement<GUM_SCALAR>.
105  */
106  PRMSlotChain(const std::string& name,
107  const Sequence< PRMClassElement< GUM_SCALAR >* >& chain);
108 
109  /** @brief Tweak constructor.
110  *
111  * Chain's n-1 first elements must be PRMReferenceSlot and the last
112  *element
113  * must either be an PRMAttribute or an PRMAggregate.
114  *
115  * Warning: the last element in chain is copied !
116  *
117  * @param name The name of this PRMSlotChain.
118  * @param chain The chain given to this PRMSlotChain, it is deleted
119  * when PRMSlotChain::~PRMSlotChain() is called.
120  *
121  * @throw OperationNotAllowed Raised if the chain contains less than two
122  * PRMClassElement<GUM_SCALAR>.
123  * @throw WrongClassElement<GUM_SCALAR> Raised contains invalid
124  *PRMClassElement<GUM_SCALAR>.
125  */
127  const std::string& name);
128 
129  /**
130  * Copy constructor.
131  *
132  * This creates a copy of the slot chain.
133  */
134  PRMSlotChain(const PRMSlotChain< GUM_SCALAR >& source);
135 
136  /// Destructor.
137  virtual ~PRMSlotChain();
138 
139  /// @}
140  // ========================================================================
141  /// @name Getters & setters
142  // ========================================================================
143  /// @{
144 
145  /// See gum::PRMClassElement<GUM_SCALAR>::elt_type().
146  virtual typename PRMClassElement< GUM_SCALAR >::ClassElementType
147  elt_type() const;
148 
149  /// This is similar to the following call: this->lastElt().type()
150  virtual PRMType& type();
151 
152  /// This is similar to the following call: this->lastElt().type()
153  virtual const PRMType& type() const;
154 
155  // /// This is similar to the following call: this->lastElt().cpf()
156  // virtual Potential<GUM_SCALAR>& cpf();
157 
158  /// This is similar to the following call: this->lastElt().cpf()
159  virtual const Potential< GUM_SCALAR >& cpf() const;
160 
161  /// Return true if this slot chain contains at least one multiple
162  /// reference slot.
163  bool isMultiple() const;
164 
165  /// Returns the PRMClassElement<GUM_SCALAR>Container over which this slot
166  /// chain ends.
168 
169  /// Returns the PRMClassElement<GUM_SCALAR>Container over which this slot
170  /// chain ends.
171  const PRMClassElementContainer< GUM_SCALAR >& end() const;
172 
173  /// Returns the last element of the slot chain, typically this is an
174  /// gum::PRMAttribute or a gum::PRMAggregate.
176 
177  /// Returns the last element of the slot chain, typically this is an
178  /// gum::PRMAttribute or a gum::PRMAggregate.
179  const PRMClassElement< GUM_SCALAR >& lastElt() const;
180 
181  /// Return the sequence representing the chain of elements in this
182  /// PRMSlotChain.
184 
185  /// Return the sequence representing the chain of elements in this
186  /// PRMSlotChain.
187  const Sequence< PRMClassElement< GUM_SCALAR >* >& chain() const;
188 
189  /// See gum::PRMClassElement<GUM_SCALAR>::addParent_().
190  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
191 
192  /// See gum::PRMClassElement<GUM_SCALAR>::addChild_().
193  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
194 
195  /// @brief Raise a gum::OperationNotAllowed exception
196  /// See gum::PRMClassElement<GUM_SCALAR>::getCastDescendant()
197  virtual PRMAttribute< GUM_SCALAR >* getCastDescendant() const;
198  /// @}
199  private:
200  /// Copy operator. Don't use it.
201  PRMSlotChain& operator=(const PRMSlotChain& source);
202 
203  // ========================================================================
204  /// @name Private members of PRMSlotChain.
205  // ========================================================================
206  /// @{
207 
208  /// The sequence of PRMClassElement<GUM_SCALAR> composing the slot chain
210 
211  /// Flag indicating if this slot chain is multiple or not.
213 
214  /// Copy the last element, this prevents unwanted DuplicateElement
215  /// exceptions.
216  void copyLastElt__();
217 
218  /// @}
219  };
220 
221 
222 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
223  extern template class PRMSlotChain< double >;
224 #endif
225 
226 
227  } /* namespace prm */
228 } // namespace gum
229 
230 #include <agrum/PRM/elements/PRMSlotChain_tpl.h>
231 
232 #endif /* GUM_SLOT_CHAIN_H */
PRMSlotChain(const PRMSlotChain< GUM_SCALAR > &source)
Copy constructor.
virtual const PRMType & type() const
This is similar to the following call: this->lastElt().type()
PRMSlotChain & operator=(const PRMSlotChain &source)
Copy operator. Don&#39;t use it.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement<GUM_SCALAR>::addParent_().
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
const Set< PRMSlotChain< GUM_SCALAR > *> & slotChains() const
Returns the set of PRMSlotChain<GUM_SCALAR> of this Class<GUM_SCALAR>.
PRMSlotChain(Sequence< PRMClassElement< GUM_SCALAR > * > *chain, const std::string &name)
Tweak constructor.
const Sequence< PRMClassElement< GUM_SCALAR > *> & chain() const
Return the sequence representing the chain of elements in this PRMSlotChain.
virtual PRMType & type()
This is similar to the following call: this->lastElt().type()
const PRMClassElement< GUM_SCALAR > & lastElt() const
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
Raise a gum::OperationNotAllowed exception See gum::PRMClassElement<GUM_SCALAR>::getCastDescendant() ...
virtual const Potential< GUM_SCALAR > & cpf() const
This is similar to the following call: this->lastElt().cpf()
bool isMultiple__
Flag indicating if this slot chain is multiple or not.
Definition: PRMSlotChain.h:212
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
void copyLastElt__()
Copy the last element, this prevents unwanted DuplicateElement exceptions.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
const PRMClassElementContainer< GUM_SCALAR > & end() const
Returns the PRMClassElement<GUM_SCALAR>Container over which this slot chain ends. ...
PRMClassElementContainer< GUM_SCALAR > & end()
Returns the PRMClassElement<GUM_SCALAR>Container over which this slot chain ends. ...
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const =0
See gum::PRMClassElement::elt_type().
PRMSlotChain(const std::string &name, const Sequence< PRMClassElement< GUM_SCALAR > * > &chain)
Default constructor.
virtual ~PRMSlotChain()
Destructor.
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement<GUM_SCALAR>::addChild_().
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...