aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRMSlotChain.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 
128  /**
129  * Copy constructor.
130  *
131  * This creates a copy of the slot chain.
132  */
133  PRMSlotChain(const PRMSlotChain< GUM_SCALAR >& source);
134 
135  /// Destructor.
136  virtual ~PRMSlotChain();
137 
138  /// @}
139  // ========================================================================
140  /// @name Getters & setters
141  // ========================================================================
142  /// @{
143 
144  /// See gum::PRMClassElement<GUM_SCALAR>::elt_type().
145  virtual typename PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const;
146 
147  /// This is similar to the following call: this->lastElt().type()
148  virtual PRMType& type();
149 
150  /// This is similar to the following call: this->lastElt().type()
151  virtual const PRMType& type() const;
152 
153  // /// This is similar to the following call: this->lastElt().cpf()
154  // virtual Potential<GUM_SCALAR>& cpf();
155 
156  /// This is similar to the following call: this->lastElt().cpf()
157  virtual const Potential< GUM_SCALAR >& cpf() const;
158 
159  /// Return true if this slot chain contains at least one multiple
160  /// reference slot.
161  bool isMultiple() const;
162 
163  /// Returns the PRMClassElement<GUM_SCALAR>Container over which this slot
164  /// chain ends.
166 
167  /// Returns the PRMClassElement<GUM_SCALAR>Container over which this slot
168  /// chain ends.
169  const PRMClassElementContainer< GUM_SCALAR >& end() const;
170 
171  /// Returns the last element of the slot chain, typically this is an
172  /// gum::PRMAttribute or a gum::PRMAggregate.
174 
175  /// Returns the last element of the slot chain, typically this is an
176  /// gum::PRMAttribute or a gum::PRMAggregate.
177  const PRMClassElement< GUM_SCALAR >& lastElt() const;
178 
179  /// Return the sequence representing the chain of elements in this
180  /// PRMSlotChain.
182 
183  /// Return the sequence representing the chain of elements in this
184  /// PRMSlotChain.
185  const Sequence< PRMClassElement< GUM_SCALAR >* >& chain() const;
186 
187  /// See gum::PRMClassElement<GUM_SCALAR>::addParent_().
188  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
189 
190  /// See gum::PRMClassElement<GUM_SCALAR>::addChild_().
191  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
192 
193  /// @brief Raise a gum::OperationNotAllowed exception
194  /// See gum::PRMClassElement<GUM_SCALAR>::getCastDescendant()
195  virtual PRMAttribute< GUM_SCALAR >* getCastDescendant() const;
196  /// @}
197  private:
198  /// Copy operator. Don't use it.
199  PRMSlotChain& operator=(const PRMSlotChain& source);
200 
201  // ========================================================================
202  /// @name Private members of PRMSlotChain.
203  // ========================================================================
204  /// @{
205 
206  /// The sequence of PRMClassElement<GUM_SCALAR> composing the slot chain
208 
209  /// Flag indicating if this slot chain is multiple or not.
211 
212  /// Copy the last element, this prevents unwanted DuplicateElement
213  /// exceptions.
214  void _copyLastElt_();
215 
216  /// @}
217  };
218 
219 
220 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
221  extern template class PRMSlotChain< double >;
222 #endif
223 
224 
225  } /* namespace prm */
226 } // namespace gum
227 
228 #include <agrum/PRM/elements/PRMSlotChain_tpl.h>
229 
230 #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:643
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...
bool _isMultiple_
Flag indicating if this slot chain is multiple or not.
Definition: PRMSlotChain.h:210
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()
void _copyLastElt_()
Copy the last element, this prevents unwanted DuplicateElement exceptions.
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
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...