aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
PRMObject.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 PRMObject.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_PRM_OBJECT_H
30 #define GUM_PRM_OBJECT_H
31 
32 #include <string>
33 
34 #include <agrum/agrum.h>
35 
36 namespace gum {
37 
38  namespace prm {
39  /**
40  * @class PRMObject
41  *
42  * @brief Abstract base class for any element defined in a PRM.
43  *
44  * This class is a base class for any element defined in a PRM. Since
45  *objects
46  * in a PRM are differentiated by their names, the only information we need
47  * about them is their name.
48  *
49  * Furthermore we use an enumeration to know the concrete type of a given
50  * PRMObject preventing faster type checking.
51  *
52  * @ingroup prm_group
53  */
54 
55  class PRMObject {
56  public:
57  // ==========================================================================
58  /// @name Built-in types.
59  // ==========================================================================
60  /// @{
61 
62  /**
63  * Enumeration of the different types of objects handled by a PRM.
64  * The "all" type is used to tell that we want any kind of PRMType
65  * (useful with iterators for example). No PRMObject will ever have
66  * "all" as type.
67  */
68  enum class prm_type : char
69  {
70  ALL,
71  CLASS,
73  CLASS_ELT,
74  TYPE,
75  SYSTEM,
76  INSTANCE
77  };
78 
79  static std::string LEFT_CAST() { return "("; }
80  static std::string RIGHT_CAST() { return ")"; }
81 
82  /// Returns the string representation of a PRMObject.
83  static std::string enum2str(prm_type type) {
84  switch (type) {
85  case prm_type::CLASS:
86  return "PRMType::CLASS";
87 
88  case prm_type::CLASS_ELT:
89  return "PRMType::CLASS_ELT";
90 
91  case prm_type::TYPE:
92  return "PRMType::TYPE";
93 
94  case prm_type::SYSTEM:
95  return "PRMType::SYSTEM";
96 
97  case prm_type::INSTANCE:
98  return "PRMType::INSTANCE";
99 
100  case prm_type::PRM_INTERFACE:
101  return "PRMType::PRM_INTERFACE";
102 
103  default:
104  return "unknown";
105  }
106  }
107 
108  /// Returns true if obj_ptr is of type Class.
109  static INLINE bool isClass(const PRMObject& obj) {
110  return obj.obj_type() == prm_type::CLASS;
111  }
112 
113  /// Returns true if obj_ptr is of type PRMInterface.
114  static INLINE bool isInterface(const PRMObject& obj) {
115  return obj.obj_type() == prm_type::PRM_INTERFACE;
116  }
117 
118  /// Returns true if obj_ptr is of type PRMInstance.
119  static INLINE bool isInstance(const PRMObject& obj) {
120  return obj.obj_type() == prm_type::INSTANCE;
121  }
122 
123  /// @}
124  // ==========================================================================
125  /// @name Constructor & destructor.
126  // ==========================================================================
127  /// @{
128 
129  /**
130  * Constructor.
131  * @param name The name of this object.
132  */
133  explicit PRMObject(const std::string& name);
134 
135  /**
136  * Copy constructor.
137  */
138  PRMObject(const PRMObject& source);
139 
140  /**
141  * Move constructor.
142  */
143  PRMObject(PRMObject&& source);
144 
145  /**
146  * Destructor.
147  */
148  virtual ~PRMObject();
149 
150  /// @}
151  // ==========================================================================
152  /// @name Getters & setters.
153  // ==========================================================================
154  /// @{
155 
156  /**
157  * Returns the name of this object.
158  */
159  const std::string& name() const;
160 
161  /**
162  * @brief Change the name of the PRM Object.
163  * @warning Don't do this unless you know what you are doing !
164  */
165  void name(const std::string& name);
166 
167  /**
168  * Returns the type of this object.
169  */
170  virtual prm_type obj_type() const = 0;
171 
172  /// @}
173  // ==========================================================================
174  /// @name Operators
175  // ==========================================================================
176  /// @{
177 
178  /**
179  * To PRMObject are equal if they have the same name (which is unique).
180  */
181  bool operator==(const PRMObject& obj) const;
182 
183  /**
184  * To PRMObject are equal if they have the same name (which is unique).
185  */
186  bool operator!=(const PRMObject& obj) const;
187 
188  /**
189  * Copy operator.
190  */
191  PRMObject& operator=(const PRMObject& source);
192 
193  /**
194  * Move operator.
195  */
196  PRMObject& operator=(PRMObject&& source);
197 
198  /// @}
199  private:
200  // ==========================================================================
201  /// @name Private members.
202  // ==========================================================================
203  /// @{
204 
205  // The name of this object
206  // ======================================================================
207  std::string name__;
208 
209  /// @}
210  };
211 
212  /// For printing PRMType easily.
213  std::ostream& operator<<(std::ostream& out, PRMObject::prm_type obj_type);
214 
215  // list of declarations of PRMObjects
216  class PRMType;
217  template < typename GUM_SCALAR >
218  class PRMClassElement;
219  template < typename GUM_SCALAR >
221  template < typename GUM_SCALAR >
222  class PRMAggregate;
223  template < typename GUM_SCALAR >
224  class PRMInterface;
225  template < typename GUM_SCALAR >
226  class PRMAttribute;
227  template < typename GUM_SCALAR >
229  template < typename GUM_SCALAR >
231  template < typename GUM_SCALAR >
232  class PRMClass;
233  template < typename GUM_SCALAR >
234  class PRMInstance;
235  template < typename GUM_SCALAR >
236  class PRMSystem;
237 
238  } /* namespace prm */
239 } /* namespace gum */
240 
241 #ifndef GUM_NO_INLINE
242 # include <agrum/PRM/elements/PRMObject_inl.h>
243 #endif // GUM_NO_INLINE
244 
245 #endif /* GUM_PRM_OBJECT_H */
PRMObject & operator=(const PRMObject &source)
Copy operator.
Definition: PRMObject.cpp:63
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
NodeProperty< std::vector< pair > *> referingAttr__
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:525
std::string name__
Definition: PRMObject.h:207
PRMObject(PRMObject &&source)
Move constructor.
Definition: PRMObject.cpp:54
bool operator!=(const PRMObject &obj) const
To PRMObject are equal if they have the same name (which is unique).
Definition: PRMObject_inl.h:48
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
PRMObject(const PRMObject &source)
Copy constructor.
Definition: PRMObject.cpp:48
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>.
static std::string enum2str(prm_type type)
Returns the string representation of a PRMObject.
Definition: PRMObject.h:83
virtual prm_type obj_type() const =0
Returns the type of this object.
virtual ~PRMObject()
Destructor.
Definition: PRMObject.cpp:60
const Sequence< PRMClassElement< GUM_SCALAR > *> & chain() const
Return the sequence representing the chain of elements in this PRMSlotChain.
bool operator==(const PRMObject &obj) const
To PRMObject are equal if they have the same name (which is unique).
Definition: PRMObject_inl.h:42
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
Implementation of the pure virtual method of PRMObject.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:68
void name(const std::string &name)
Change the name of the PRM Object.
Definition: PRMObject_inl.h:38
PRMObject & operator=(PRMObject &&source)
Move operator.
Definition: PRMObject.cpp:69
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const =0
See gum::PRMClassElement::elt_type().
const Set< PRMReferenceSlot< GUM_SCALAR > *> & referenceSlots() const
Returns the set of PRMAggregate of this Class<GUM_SCALAR>.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:79
const Sequence< PRMInstance< GUM_SCALAR > *> & getArray(const std::string &name) const
Returns the sequence of instances of a given array.
PRMObject(const std::string &name)
Constructor.
Definition: PRMObject.cpp:42
HashTable< std::string, std::pair< bool, bool > > IOFlags__
input / output flags, useful when inheriting or copying.
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:80