aGrUM  0.14.2
PRMClassElement.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_CLASS_ELEMENT_H
28 #define GUM_CLASS_ELEMENT_H
29 
30 #include <sstream>
31 
32 #include <agrum/agrum.h>
33 
35 
37 
39 #include <agrum/PRM/utils_prm.h>
40 
41 namespace gum {
42  namespace prm {
43  template < typename GUM_SCALAR >
44  class PRMAttribute;
45 
57  template < typename GUM_SCALAR >
58  class PRMClassElement : public PRMObject {
59  public:
60  // ========================================================================
62  // ========================================================================
64 
74  explicit PRMClassElement(const std::string& name);
75 
80 
84  virtual ~PRMClassElement();
85 
87  // ========================================================================
89  // ========================================================================
91 
98  };
99 
100  static std::string enum2str(ClassElementType type) {
101  switch (type) {
102  case prm_attribute: return "prm_attribute";
103 
104  case prm_aggregate: return "prm_aggregate";
105 
106  case prm_refslot: return "prm_refslot";
107 
108  case prm_slotchain: return "prm_slotchain";
109 
110  case prm_parameter: return "prm_parameter";
111 
112  default: return "unknown";
113  }
114  }
115 
117  static INLINE bool
119  return elt.elt_type() == prm_refslot;
120  }
121 
123  static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR >& elt) {
124  return elt.elt_type() == prm_attribute;
125  }
126 
128  static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR >& elt) {
129  return elt.elt_type() == prm_aggregate;
130  }
131 
133  static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR >& elt) {
134  return elt.elt_type() == prm_slotchain;
135  }
136 
138  static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR >& elt) {
139  return elt.elt_type() == prm_parameter;
140  }
141 
143  // ========================================================================
145  // ========================================================================
147 
149  NodeId id() const;
150 
152  virtual void setId(NodeId id);
153 
160  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt) = 0;
161 
168  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt) = 0;
169 
171  virtual typename PRMObject::prm_type obj_type() const;
172 
174  virtual ClassElementType elt_type() const = 0;
175 
177  // ========================================================================
179  // ========================================================================
181 
188  virtual PRMType& type() = 0;
189 
197  virtual const PRMType& type() const = 0;
198 
215  virtual PRMAttribute< GUM_SCALAR >* getCastDescendant() const = 0;
216 
227  const std::string& safeName() const;
228 
235  virtual std::string cast(const PRMType& t) const;
236 
237  // /**
238  // * Return a reference over the gum::Potential of this class element.
239  // * @throw OperationNotAllowed Raised if this class element doesn't have
240  // * any gum::Potential (like a
241  // gum::PRMReferenceSlot).
242  // */
243  // virtual Potential<GUM_SCALAR>& cpf() = 0;
244 
252  virtual const Potential< GUM_SCALAR >& cpf() const = 0;
253 
255  protected:
257  std::string _safeName;
258 
259  private:
262  };
263 
264 
265 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
266  extern template class PRMClassElement< double >;
267 #endif
268 
269  } /* namespace prm */
270 } // namespace gum
271 
273 
274 #endif /* GUM_CLASS_ELEMENT_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
virtual const Potential< GUM_SCALAR > & cpf() const =0
Return a reference over the gum::Potential of this class element.
static std::string enum2str(ClassElementType type)
Returns true if obj_ptr is of type PRMReferenceSlot.
Inline implementation of gum::PRMClassElement.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a child to this element.
Abstract class representing an element of PRM class.
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:66
Header of the Potential class.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const =0
Returns a proper cast descendant of this PRMAttribute.
virtual ~PRMClassElement()
Destructor of this class.
virtual PRMObject::prm_type obj_type() const
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:60
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:53
NodeId id() const
Returns the NodeId of this element in it&#39;s class DAG.
virtual void setId(NodeId id)
Used to assign the id of this element.
PRMClassElement(const std::string &name)
Default constructor of a PRMClassElement.
NodeId __id
The node&#39;s id of this element.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:58
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a parent to this element.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
Headers of PRMObject.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
std::string _safeName
The safe name of this PRMClassElement.
some utils for topology : NodeId, Edge, Arc and consorts ...