1 /**
2  *
3  *   Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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(_at_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     Integer,
45     Range,
46     Continuous
47   };
48 
49   class Variable;
50 
51   /// for friendly displaying the content of the variable
52 
53   std::ostream& operator<<(std::ostream& s, const Variable& LDRV);
54 
55   /* ===========================================================================
56    */
57   /* ===========================================================================
58    */
59   /* ===                            GUM_VARIABLE                             ===
60    */
61   /* ===========================================================================
62    */
63   /* ===========================================================================
64    */
65   /** @class Variable
66    * @brief Base class for every random variable.
67    * @ingroup multidim_group
68    */
69   /* ===========================================================================
70    */
71 
72   class Variable {
73     public:
74     // ############################################################################
75     /// @name Constructors / Destructors
76     // ############################################################################
77     /// @{
78 
79     /// destructor
80 
81     virtual ~Variable();
82 
83     /// Copy Factory.
84     /// @return Returns a pointer on a new copy of this.
85 
86     virtual Variable* clone() const = 0;
87 
88     /// @}
89 
90     // ############################################################################
91     /// @name Operators
92     // ############################################################################
93     /// @{
94 
95     /// Copy operator
96     /** @param aRV to be copied
97      * @return a const ref to *this */
98 
99     Variable& operator=(const Variable& aRV);
100 
101     /// equality operator
102 
103     virtual bool operator==(const Variable& aRV) const;
104 
105     /// inequality operator
106 
107     virtual bool operator!=(const Variable& aRV) const;
108 
109     /// @}
110 
111     // ############################################################################
112     /// @name Accessors / Modifiers
113     // ############################################################################
114     /// @{
115 
116     /// sets the name of the variable
117     /** @param theValue */
118     void setName(const std::string& theValue);
119 
120     /// returns the name of the variable
121     const std::string& name() const;
122 
123     /// sets the description of the variable
124     /// @warning since  _description_ is mutable, setDescription() is const
125     /** @param theValue */
126     void setDescription(const std::string& theValue) const;
127 
128     /// returns the description of the variable
129     const std::string& description() const;
130 
131     /// returns the type of variable
132     virtual VarType varType() const = 0;
133 
134     /// string represent the domain of the variable
135     virtual const std::string domain() const = 0;
136 
137     /// @}
138 
139     protected:
140     /// (protected) Default constructor
Variable()141     Variable() { GUM_CONSTRUCTOR(Variable); }
142 
143     /// protected copy
144     /** @param aRV to be copied */
145     void copy_(const Variable& aRV);
146 
147     /// constructor
148     /** @param aName name of the variable
149      * @param aDesc description of the variable */
150     Variable(const std::string& aName, const std::string& aDesc);
151 
152     /// copy constructor
153     /** @param aRV the variable we copy */
154     Variable(const Variable& aRV);
155 
156     private:
157     /// the name of the variable
158     std::string _name_;
159 
160     /// the description of the variable
161     /// since description is not a characteristic of a variable, we allow the
162     /// description to be changed even in a const reference.
163     mutable std::string _description_;
164   };
165 
166 } /* namespace gum */
167 
168 #ifndef GUM_NO_INLINE
169 #  include <agrum/tools/variables/variable_inl.h>
170 #endif /* GUM_NO_INLINE */
171 
172 #endif /* GUM_VARIABLE_H */
173