aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
variable.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
50#ifndef GUM_VARIABLE_H
51#define GUM_VARIABLE_H
52
53#include <iostream>
54#include <string>
55
56#include <agrum/agrum.h>
57
58#include <string_view>
59
60namespace gum {
61
63
64 /* ===========================================================================
65 */
66 /* ===========================================================================
67 */
68 /* === GUM_VARIABLE ===
69 */
70 /* ===========================================================================
71 */
72 /* ===========================================================================
73 */
78 /* ===========================================================================
79 */
80
81 class Variable {
82 public:
83 // ############################################################################
85 // ############################################################################
87
89
90 virtual ~Variable();
91
94 [[nodiscard]] virtual Variable* clone() const = 0;
95
97
98 // ############################################################################
100 // ############################################################################
102
104
106
108
110 bool operator==(const Variable& aRV) const;
111
112
114
115 // ############################################################################
117 // ############################################################################
119
121
122 void setName(std::string_view theValue);
123
125 const std::string& name() const;
126
129
130 void setDescription(std::string_view theValue) const;
131
133 const std::string& description() const;
134
136 virtual VarType varType() const = 0;
137
139 virtual std::string domain() const = 0;
140
142
143 protected:
145 Variable() { GUM_CONSTRUCTOR(Variable); }
146
148
149 void copy_(const Variable& aRV);
150
152
154 Variable(std::string_view aName, std::string_view aDesc);
155
157
158 Variable(const Variable& aRV);
159
160 private:
162 std::string _name_;
163
167 mutable std::string _description_;
168
170
173 virtual bool _checkSameDomain_(const Variable& aRV) const = 0;
174 };
175
176} /* namespace gum */
177
179std::ostream& operator<<(std::ostream& s, const gum::Variable& LDRV);
180
181#ifndef GUM_NO_INLINE
183#endif /* GUM_NO_INLINE */
184
185#endif /* GUM_VARIABLE_H */
Base class for every random variable.
Definition variable.h:81
void setDescription(std::string_view theValue) const
sets the description of the variable
virtual Variable * clone() const =0
Copy Factory.
std::string _name_
the name of the variable
Definition variable.h:162
Variable(std::string_view aName, std::string_view aDesc)
constructor
virtual bool _checkSameDomain_(const Variable &aRV) const =0
check the domain
void copy_(const Variable &aRV)
protected copy
Variable()
(protected) Default constructor
Definition variable.h:145
const std::string & name() const
returns the name of the variable
virtual VarType varType() const =0
returns the type of variable
std::string _description_
the description of the variable since description is not a characteristic of a variable,...
Definition variable.h:167
Variable(const Variable &aRV)
copy constructor
const std::string & description() const
returns the description of the variable
virtual std::string domain() const =0
string represent the domain of the variable
Variable & operator=(const Variable &aRV)
Copy operator.
void setName(std::string_view theValue)
sets the name of the variable
virtual ~Variable()
destructor
bool operator==(const Variable &aRV) const
equality operator
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:62
std::ostream & operator<<(std::ostream &s, const gum::Variable &LDRV)
for friendly displaying the content of the variable