aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
PRMClassElement.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48
49#ifndef GUM_CLASS_ELEMENT_H
50#define GUM_CLASS_ELEMENT_H
51
52#include <sstream>
53
54#include <agrum/agrum.h>
55
56#include <agrum/PRM/utils_prm.h>
57
58namespace gum {
59 namespace prm {
60 template < GUM_Numeric GUM_SCALAR >
61 class PRMAttribute;
62
74 template < GUM_Numeric GUM_SCALAR >
75 class PRMClassElement: public PRMObject {
76 public:
77 // ========================================================================
79 // ========================================================================
81
91 explicit PRMClassElement(std::string_view name);
92
97
101 ~PRMClassElement() override;
102
104 // ========================================================================
106 // ========================================================================
108
116
117 static std::string enum2str(ClassElementType type);
118
120 static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR >& elt);
121
123 static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR >& elt);
124
126 static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR >& elt);
127
129 static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR >& elt);
130
132 static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR >& elt);
133
135 // ========================================================================
137 // ========================================================================
139
141 NodeId id() const;
142
144 virtual void setId(NodeId id);
145
152 virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt) = 0;
153
160 virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt) = 0;
161
163 typename PRMObject::prm_type obj_type() const override;
164
166 virtual ClassElementType elt_type() const = 0;
167
169 // ========================================================================
171 // ========================================================================
173
180 virtual PRMType& type() = 0;
181
189 virtual const PRMType& type() const = 0;
190
208
219 const std::string& safeName() const;
220
227 virtual std::string cast(const PRMType& t) const;
228
229 // /**
230 // * Return a reference over the gum::Tensor of this class element.
231 // * @throw OperationNotAllowed Raised if this class element doesn't have
232 // * any gum::Tensor (like a
233 // gum::PRMReferenceSlot).
234 // */
235 // virtual Tensor<GUM_SCALAR>& cpf() = 0;
236
244 virtual const Tensor< GUM_SCALAR >& cpf() const = 0;
245
247
248 protected:
250 std::string safeName_;
251
252 private:
255 };
256
257
258#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
259 extern template class PRMClassElement< double >;
260#endif
261
262 } /* namespace prm */
263} // namespace gum
264
266
267#endif /* GUM_CLASS_ELEMENT_H */
Inline implementation of gum::PRMClassElement.
PRMAttribute is a member of a Class in a PRM.
Abstract class representing an element of PRM class.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a parent to this element.
~PRMClassElement() override
Destructor of this class.
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a child to this element.
PRMClassElement(std::string_view name)
Default constructor of a PRMClassElement.
virtual const Tensor< GUM_SCALAR > & cpf() const =0
Return a constant reference over the gum::Tensor of this class element.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
NodeId _id_
The node's id of this element.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
static std::string enum2str(ClassElementType type)
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const =0
Returns a proper cast descendant of this PRMAttribute.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
virtual const PRMType & type() const =0
Return a constant reference over the gum::PRMType of this class element.
PRMObject::prm_type obj_type() const override
virtual void setId(NodeId id)
Used to assign the id of this element.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
std::string safeName_
The safe name of this PRMClassElement.
PRMObject(std::string_view name)
Constructor.
Definition PRMObject.cpp:62
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition PRMObject.h:90
This is a decoration of the DiscreteVariable class.
Definition PRMType.h:78
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46