aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
variable.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 /** @file
23  * @brief Base class for random variable.
24  *
25  * Basically wrapper for a string name and description.
26  * This class is used as an interface. So the constructor/destructor is
27  *protected.
28  * @author Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 #ifndef GUM_VARIABLE_H
31 #define GUM_VARIABLE_H
32 
33 #include <iostream>
34 #include <string>
35 
36 #include <agrum/agrum.h>
37 
38 namespace gum {
39 
40  enum class VarType : char
41  {
42  Discretized,
43  Labelized,
44  Range,
45  Continuous
46  };
47 
48  class Variable;
49 
50  /// for friendly displaying the content of the variable
51 
52  std::ostream& operator<<(std::ostream& s, const Variable& LDRV);
53 
54  /* ===========================================================================
55  */
56  /* ===========================================================================
57  */
58  /* === GUM_VARIABLE ===
59  */
60  /* ===========================================================================
61  */
62  /* ===========================================================================
63  */
64  /** @class Variable
65  * @brief Base class for every random variable.
66  * @ingroup multidim_group
67  */
68  /* ===========================================================================
69  */
70 
71  class Variable {
72  public:
73  // ############################################################################
74  /// @name Constructors / Destructors
75  // ############################################################################
76  /// @{
77 
78  /// destructor
79 
80  virtual ~Variable();
81 
82  /// Copy Factory.
83  /// @return Returns a pointer on a new copy of this.
84 
85  virtual Variable* clone() const = 0;
86 
87  /// @}
88 
89  // ############################################################################
90  /// @name Operators
91  // ############################################################################
92  /// @{
93 
94  /// Copy operator
95  /** @param aRV to be copied
96  * @return a const ref to *this */
97 
98  Variable& operator=(const Variable& aRV);
99 
100  /// equality operator
101 
102  virtual bool operator==(const Variable& aRV) const;
103 
104  /// inequality operator
105 
106  virtual bool operator!=(const Variable& aRV) const;
107 
108  /// @}
109 
110  // ############################################################################
111  /// @name Accessors / Modifiers
112  // ############################################################################
113  /// @{
114 
115  /// sets the name of the variable
116  /** @param theValue */
117 
118  void setName(const std::string& theValue);
119 
120  /// returns the name of the variable
121 
122  const std::string& name() const;
123 
124  /// sets the description of the variable
125  /// @warning since _description_ is mutable, setDescription() is const
126  /** @param theValue */
127 
128  void setDescription(const std::string& theValue) const;
129 
130  /// returns the description of the variable
131 
132  const std::string& description() const;
133 
134  /// returns the type of variable
135 
136  virtual VarType varType() const = 0;
137 
138  /// string represent the domain of the variable
139  virtual const std::string domain() const = 0;
140 
141  /// @}
142 
143  protected:
144  /// (protected) Default constructor
145  Variable() {
146  GUM_CONSTRUCTOR(Variable);
147  ;
148  }
149 
150  /// protected copy
151  /** @param aRV to be copied */
152 
153  void copy_(const Variable& aRV);
154 
155  /// constructor
156  /** @param aName name of the variable
157  * @param aDesc description of the variable */
158 
159  Variable(const std::string& aName, const std::string& aDesc);
160 
161  /// copy constructor
162  /** @param aRV the variable we copy */
163 
164  Variable(const Variable& aRV);
165 
166  private:
167  /// the name of the variable
168  std::string _name_;
169 
170  /// the description of the variable
171  /// since description is not a characteristic of a variable, we allow the
172  /// description to be changed even in a const reference.
173  mutable std::string _description_;
174  };
175 
176 } /* namespace gum */
177 
178 #ifndef GUM_NO_INLINE
179 # include <agrum/tools/variables/variable_inl.h>
180 #endif /* GUM_NO_INLINE */
181 
182 #endif /* GUM_VARIABLE_H */