aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
PRMObject.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 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) { return obj.obj_type() == prm_type::CLASS; }
110 
111  /// Returns true if obj_ptr is of type PRMInterface.
112  static INLINE bool isInterface(const PRMObject& obj) {
113  return obj.obj_type() == prm_type::PRM_INTERFACE;
114  }
115 
116  /// Returns true if obj_ptr is of type PRMInstance.
117  static INLINE bool isInstance(const PRMObject& obj) {
118  return obj.obj_type() == prm_type::INSTANCE;
119  }
120 
121  /// @}
122  // ==========================================================================
123  /// @name Constructor & destructor.
124  // ==========================================================================
125  /// @{
126 
127  /**
128  * Constructor.
129  * @param name The name of this object.
130  */
131  explicit PRMObject(const std::string& name);
132 
133  /**
134  * Copy constructor.
135  */
136  PRMObject(const PRMObject& source);
137 
138  /**
139  * Move constructor.
140  */
141  PRMObject(PRMObject&& source);
142 
143  /**
144  * Destructor.
145  */
146  virtual ~PRMObject();
147 
148  /// @}
149  // ==========================================================================
150  /// @name Getters & setters.
151  // ==========================================================================
152  /// @{
153 
154  /**
155  * Returns the name of this object.
156  */
157  const std::string& name() const;
158 
159  /**
160  * @brief Change the name of the PRM Object.
161  * @warning Don't do this unless you know what you are doing !
162  */
163  void name(const std::string& name);
164 
165  /**
166  * Returns the type of this object.
167  */
168  virtual prm_type obj_type() const = 0;
169 
170  /// @}
171  // ==========================================================================
172  /// @name Operators
173  // ==========================================================================
174  /// @{
175 
176  /**
177  * To PRMObject are equal if they have the same name (which is unique).
178  */
179  bool operator==(const PRMObject& obj) const;
180 
181  /**
182  * To PRMObject are equal if they have the same name (which is unique).
183  */
184  bool operator!=(const PRMObject& obj) const;
185 
186  /**
187  * Copy operator.
188  */
189  PRMObject& operator=(const PRMObject& source);
190 
191  /**
192  * Move operator.
193  */
194  PRMObject& operator=(PRMObject&& source);
195 
196  /// @}
197  private:
198  // ==========================================================================
199  /// @name Private members.
200  // ==========================================================================
201  /// @{
202 
203  // The name of this object
204  // ======================================================================
205  std::string _name_;
206 
207  /// @}
208  };
209 
210  /// For printing PRMType easily.
211  std::ostream& operator<<(std::ostream& out, PRMObject::prm_type obj_type);
212 
213  // list of declarations of PRMObjects
214  class PRMType;
215  template < typename GUM_SCALAR >
216  class PRMClassElement;
217  template < typename GUM_SCALAR >
219  template < typename GUM_SCALAR >
220  class PRMAggregate;
221  template < typename GUM_SCALAR >
222  class PRMInterface;
223  template < typename GUM_SCALAR >
224  class PRMAttribute;
225  template < typename GUM_SCALAR >
227  template < typename GUM_SCALAR >
229  template < typename GUM_SCALAR >
230  class PRMClass;
231  template < typename GUM_SCALAR >
232  class PRMInstance;
233  template < typename GUM_SCALAR >
234  class PRMSystem;
235 
236  } /* namespace prm */
237 } /* namespace gum */
238 
239 #ifndef GUM_NO_INLINE
240 # include <agrum/PRM/elements/PRMObject_inl.h>
241 #endif // GUM_NO_INLINE
242 
243 #endif /* GUM_PRM_OBJECT_H */
PRMObject & operator=(const PRMObject &source)
Copy operator.
Definition: PRMObject.cpp:64
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
HashTable< std::string, std::pair< bool, bool > > _IOFlags_
input / output flags, useful when inheriting or copying.
PRMObject(PRMObject &&source)
Move constructor.
Definition: PRMObject.cpp:52
bool operator!=(const PRMObject &obj) const
To PRMObject are equal if they have the same name (which is unique).
Definition: PRMObject_inl.h:46
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:46
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>.
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:58
std::string _name_
Definition: PRMObject.h:205
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:70
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
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
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
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:80