aGrUM  0.16.0
PRMClassElement.h
Go to the documentation of this file.
1 
30 #ifndef GUM_CLASS_ELEMENT_H
31 #define GUM_CLASS_ELEMENT_H
32 
33 #include <sstream>
34 
35 #include <agrum/agrum.h>
36 
38 
40 
42 #include <agrum/PRM/utils_prm.h>
43 
44 namespace gum {
45  namespace prm {
46  template < typename GUM_SCALAR >
47  class PRMAttribute;
48 
60  template < typename GUM_SCALAR >
61  class PRMClassElement : public PRMObject {
62  public:
63  // ========================================================================
65  // ========================================================================
67 
77  explicit PRMClassElement(const std::string& name);
78 
83 
87  virtual ~PRMClassElement();
88 
90  // ========================================================================
92  // ========================================================================
94 
101  };
102 
103  static std::string enum2str(ClassElementType type) {
104  switch (type) {
105  case prm_attribute: return "prm_attribute";
106 
107  case prm_aggregate: return "prm_aggregate";
108 
109  case prm_refslot: return "prm_refslot";
110 
111  case prm_slotchain: return "prm_slotchain";
112 
113  case prm_parameter: return "prm_parameter";
114 
115  default: return "unknown";
116  }
117  }
118 
120  static INLINE bool
122  return elt.elt_type() == prm_refslot;
123  }
124 
126  static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR >& elt) {
127  return elt.elt_type() == prm_attribute;
128  }
129 
131  static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR >& elt) {
132  return elt.elt_type() == prm_aggregate;
133  }
134 
136  static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR >& elt) {
137  return elt.elt_type() == prm_slotchain;
138  }
139 
141  static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR >& elt) {
142  return elt.elt_type() == prm_parameter;
143  }
144 
146  // ========================================================================
148  // ========================================================================
150 
152  NodeId id() const;
153 
155  virtual void setId(NodeId id);
156 
163  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt) = 0;
164 
171  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt) = 0;
172 
174  virtual typename PRMObject::prm_type obj_type() const;
175 
177  virtual ClassElementType elt_type() const = 0;
178 
180  // ========================================================================
182  // ========================================================================
184 
191  virtual PRMType& type() = 0;
192 
200  virtual const PRMType& type() const = 0;
201 
218  virtual PRMAttribute< GUM_SCALAR >* getCastDescendant() const = 0;
219 
230  const std::string& safeName() const;
231 
238  virtual std::string cast(const PRMType& t) const;
239 
240  // /**
241  // * Return a reference over the gum::Potential of this class element.
242  // * @throw OperationNotAllowed Raised if this class element doesn't have
243  // * any gum::Potential (like a
244  // gum::PRMReferenceSlot).
245  // */
246  // virtual Potential<GUM_SCALAR>& cpf() = 0;
247 
255  virtual const Potential< GUM_SCALAR >& cpf() const = 0;
256 
258  protected:
260  std::string _safeName;
261 
262  private:
265  };
266 
267 
268 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
269  extern template class PRMClassElement< double >;
270 #endif
271 
272  } /* namespace prm */
273 } // namespace gum
274 
276 
277 #endif /* GUM_CLASS_ELEMENT_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:35
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:69
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:63
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:56
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:61
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
std::string _safeName
The safe name of this PRMClassElement.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.