aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRM.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 PRM.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_PRM_H
30 #define GUM_PRM_H
31 
32 #include <string>
33 
34 #include <agrum/tools/core/hashTable.h>
35 #include <agrum/tools/core/sequence.h>
36 
37 #include <agrum/PRM/elements/PRMAggregate.h>
38 #include <agrum/PRM/elements/PRMAttribute.h>
39 #include <agrum/PRM/elements/PRMClass.h>
40 #include <agrum/PRM/elements/PRMFuncAttribute.h>
41 #include <agrum/PRM/elements/PRMInstance.h>
42 #include <agrum/PRM/elements/PRMObject.h>
43 #include <agrum/PRM/elements/PRMReferenceSlot.h>
44 #include <agrum/PRM/elements/PRMSlotChain.h>
45 #include <agrum/PRM/elements/PRMType.h>
46 
47 #include <agrum/PRM/elements/PRMSystem.h>
48 
49 namespace gum {
50  namespace prm {
51 
52  template < typename GUM_SCALAR >
53  class PRMSystem;
54  template < typename GUM_SCALAR >
55  class PRMFactory;
56  /**
57  * @class PRM
58  * @headerfile PRM.h <agrum/PRM/PRM.h>
59  * @brief This class represents a Probabilistic Relational
60  *PRMSystem<GUM_SCALAR>.
61  *
62  * @ingroup prm_group
63  */
64  template < typename GUM_SCALAR >
65  class PRM {
66  public:
67  friend class PRMFactory< GUM_SCALAR >;
68 
69  // ========================================================================
70  /// @name Destructor.
71  // ========================================================================
72  /// @{
73 
74  /**
75  * Default constructor.
76  */
77  PRM();
78 
79  /**
80  * Destructor.
81  */
82  ~PRM();
83 
84  /// @}
85  // ========================================================================
86  /// @name Getters and setters.
87  // ========================================================================
88  /// @{
89 
90  /**
91  * @param name The name of a possible PRMType in this PRM.
92  * @return Returns true if name names a PRMType in this PRM.
93  */
94  bool isType(const std::string& name) const;
95 
96  /**
97  * @param name The name of a possible Class<GUM_SCALAR> in this PRM.
98  * @return Returns true if name names a Class<GUM_SCALAR> in this PRM.
99  */
100  bool isClass(const std::string& name) const;
101 
102  /**
103  * @param name The name of a possible PRMInterface<GUM_SCALAR> in this
104  * PRM.
105  * @return Returns true if name names a PRMInterface<GUM_SCALAR> in this
106  * PRM.
107  */
108  bool isInterface(const std::string& name) const;
109 
110  /**
111  * @param name The name of a possible PRMSystem<GUM_SCALAR> in this PRM.
112  * @return Returns true if name names a PRMSystem<GUM_SCALAR> in this PRM.
113  */
114  bool isSystem(const std::string& name) const;
115 
116  /**
117  * Returns a constant reference on a PRMType given it's name.
118  * @throw NotFound Raised if no type is found with the given name.
119  */
120  PRMType& type(const std::string& name);
121 
122  /**
123  * Returns a constant reference on a PRMType given it's name.
124  * @throw NotFound Raised if no type is found with the given name.
125  */
126  const PRMType& type(const std::string& name) const;
127 
128  /**
129  * Returns the Set of all PRMType in this PRM.
130  */
131  const Set< PRMType* >& types() const;
132 
133  /**
134  * Returns a constant reference on a Class<GUM_SCALAR> given it's name.
135  * @throw NotFound Raised if no class is found with the given name.
136  */
137  PRMClass< GUM_SCALAR >& getClass(const std::string& name);
138 
139  /**
140  * Returns a constant reference on a Class<GUM_SCALAR> given it's name.
141  * @throw NotFound Raised if no class is found with the given name.
142  */
143  const PRMClass< GUM_SCALAR >& getClass(const std::string& name) const;
144 
145  /**
146  * Returns the Set of all Class<GUM_SCALAR> in this PRM.
147  */
148  const Set< PRMClass< GUM_SCALAR >* >& classes() const;
149 
150  /**
151  * Returns a constant reference on a Class<GUM_SCALAR> given it's name.
152  * @throw NotFound Raised if no class is found with the given name.
153  */
155 
156  /**
157  * Returns a constant reference on a Class<GUM_SCALAR> given it's name.
158  * @throw NotFound Raised if no class is found with the given name.
159  */
160  const PRMInterface< GUM_SCALAR >& getInterface(const std::string& name) const;
161 
162  /**
163  * Returns the Set of all Class<GUM_SCALAR> in this PRM.
164  */
165  const Set< PRMInterface< GUM_SCALAR >* >& interfaces() const;
166 
167  /**
168  * Returns a constant reference on a PRMSystem<GUM_SCALAR> given it's
169  * name.
170  * @throw NotFound Raised if no model is found with the given name.
171  */
172  PRMSystem< GUM_SCALAR >& getSystem(const std::string& name);
173 
174  /**
175  * Returns a constant reference on a PRMSystem<GUM_SCALAR> given it's
176  * name.
177  * @throw NotFound Raised if no model is found with the given name.
178  */
179  const PRMSystem< GUM_SCALAR >& getSystem(const std::string& name) const;
180 
181  /**
182  * Returns the Set of all Systems in this PRM.
183  */
184  const Set< PRMSystem< GUM_SCALAR >* >& systems() const;
185 
186  /// @}
187  private:
188  // ========================================================================
189  /// @name Private methods.
190  // ========================================================================
191  /// @{
192 
193  /**
194  * Copy constructor. Not Implemented.
195  */
196  PRM(const PRM< GUM_SCALAR >& source);
197 
198  /**
199  * Copy operator. Not Implemented.
200  */
201  PRM< GUM_SCALAR >& operator=(const PRM< GUM_SCALAR >& source);
202 
203  /// Add the built-in types in the PRM
204  void _addBuiltInTypes_();
205 
206  /// @}
207  // ========================================================================
208  /// @name Private members.
209  // ========================================================================
210  /// @{
211 
212  /// Mapping of all Class<GUM_SCALAR> given their name.
214 
215  /// Set of all Class<GUM_SCALAR> in this PRM.
217 
218  /// Mapping of all Class<GUM_SCALAR> given their name.
220 
221  /// Set of all Class<GUM_SCALAR> in this PRM.
223 
224  /// Mapping of all PRMType given their name.
226 
227  /// Set of all PRMType in this PRM.
229 
230  /// Mapping of all Systems given their name.
232 
233  /// Set of all Systems in this PRM.
235 
236  /// @}
237  };
238 
239 
240 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
241  extern template class PRM< double >;
242 #endif
243 
244 
245  } /* namespace prm */
246 } /* namespace gum */
247 
248 #include <agrum/PRM/PRM_tpl.h>
249 
250 #endif /* GUM_PRM_H */
PRMInterface< GUM_SCALAR > & getInterface(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:124
const Set< PRMType *> & types() const
Returns the Set of all PRMType in this PRM.
Definition: PRM_tpl.h:103
void _addBuiltInTypes_()
Add the built-in types in the PRM.
Definition: PRM_tpl.h:63
const PRMType & type(const std::string &name) const
Returns a constant reference on a PRMType given it&#39;s name.
Definition: PRM_tpl.h:98
bool isClass(const std::string &name) const
Definition: PRM_tpl.h:78
PRM()
Default constructor.
Definition: PRM_tpl.h:35
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
const Set< PRMSystem< GUM_SCALAR > *> & systems() const
Returns the Set of all Systems in this PRM.
Definition: PRM_tpl.h:151
HashTable< std::string, PRMSystem< GUM_SCALAR > *> _systemMap_
Mapping of all Systems given their name.
Definition: PRM.h:231
const PRMSystem< GUM_SCALAR > & getSystem(const std::string &name) const
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:146
const Set< PRMInterface< GUM_SCALAR > *> & interfaces() const
Returns the Set of all Class<GUM_SCALAR> in this PRM.
Definition: PRM_tpl.h:135
HashTable< std::string, PRMType *> _typeMap_
Mapping of all PRMType given their name.
Definition: PRM.h:225
bool isType(const std::string &name) const
Definition: PRM_tpl.h:73
~PRM()
Destructor.
Definition: PRM_tpl.h:42
PRMType & type(const std::string &name)
Returns a constant reference on a PRMType given it&#39;s name.
Definition: PRM_tpl.h:93
bool isSystem(const std::string &name) const
Definition: PRM_tpl.h:88
PRMSystem< GUM_SCALAR > & getSystem(const std::string &name)
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:140
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
const PRMClass< GUM_SCALAR > & getClass(const std::string &name) const
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:114
const PRMInterface< GUM_SCALAR > & getInterface(const std::string &name) const
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:130
PRM(const PRM< GUM_SCALAR > &source)
Copy constructor.
Set< PRMSystem< GUM_SCALAR > *> _systems_
Set of all Systems in this PRM.
Definition: PRM.h:234
Set< PRMType *> _types_
Set of all PRMType in this PRM.
Definition: PRM.h:228
PRMClass< GUM_SCALAR > & getClass(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it&#39;s name.
Definition: PRM_tpl.h:108
const Sequence< PRMInstance< GUM_SCALAR > *> & getArray(const std::string &name) const
Returns the sequence of instances of a given array.
PRM< GUM_SCALAR > & operator=(const PRM< GUM_SCALAR > &source)
Copy operator.
bool isInterface(const std::string &name) const
Definition: PRM_tpl.h:83