aGrUM  0.14.2
labelizedVariable.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_LABELIZED_DISCRETE_VARIABLE_H
26 #define GUM_LABELIZED_DISCRETE_VARIABLE_H
27 
28 #include <iostream>
29 #include <sstream>
30 #include <string>
31 
32 #include <agrum/agrum.h>
33 
34 #include <agrum/core/sequence.h>
36 
37 namespace gum {
38  /* =========================================================================*/
39  /* =========================================================================*/
40  /* === GUM_LABELIZED_VARIABLE === */
41  /* =========================================================================*/
42  /* =========================================================================*/
47  /* =========================================================================*/
48 
50  public:
51  // ############################################################################
53  // ############################################################################
55 
62  LabelizedVariable(const std::string& aName,
63  const std::string& aDesc = "",
64  const Size nbrLabel = 2);
65 
72  LabelizedVariable(const std::string& aName,
73  const std::string& aDesc,
74  const std::vector< std::string >& labels);
75 
77 
82 
84 
85  virtual ~LabelizedVariable();
86 
88  virtual LabelizedVariable* clone() const;
89 
91 
92  // ############################################################################
94  // ############################################################################
96 
98 
100 
101 
103 
106  virtual Idx index(const std::string& label) const;
107 
109 
110  // ############################################################################
112  // ############################################################################
114 
120  bool isLabel(const std::string& aLabel) const;
121 
124 
129  LabelizedVariable& addLabel(const std::string& aLabel);
130 
132 
141  void changeLabel(Idx pos, const std::string& aLabel) const;
142 
144  void eraseLabels();
145 
147 
149  virtual std::string label(Idx i) const;
150 
152  Idx posLabel(const std::string& label) const;
153 
155  virtual double numerical(Idx indice) const;
156 
158  virtual Size domainSize() const;
159 
161  virtual VarType varType() const;
162 
164  virtual const std::string domain() const;
165 
167 
168  protected:
170  LabelizedVariable() { GUM_CONSTRUCTOR(LabelizedVariable); };
171 
173 
174  void _copy(const LabelizedVariable& aLDRV);
175 
176  private:
179  };
180 
181 } /* namespace gum */
182 
183 /* ==============================================================================
184  */
185 /* ==============================================================================
186  */
187 /* === LabelizedVariable IMPLEMENTATION === */
188 /* ==============================================================================
189  */
190 /* ==============================================================================
191  */
192 #ifndef GUM_NO_INLINE
194 #endif /* GUM_NO_INLINE */
195 
196 #endif /* GUM_LABELIZED_DISCRETE_VARIABLE_H */
virtual double numerical(Idx indice) const
get a numerical representation of he indice-the value.
std::vector< std::string > labels() const
vector of labels
virtual const std::string domain() const
Returns the domain.
void changeLabel(Idx pos, const std::string &aLabel) const
change a label for this index
Base class for discrete random variable.
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
Base class for labelized discrete random variables.
class LabelizedVariable
virtual std::string label(Idx i) const
returns the ith label
virtual VarType varType() const
returns the type of variable
void eraseLabels()
erase all the labels
virtual Size domainSize() const
returns the size of the random discrete variable domain
Base class for discrete random variable.
virtual ~LabelizedVariable()
destructor
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool isLabel(const std::string &aLabel) const
indicates whether the variable already has the label passed in argument
void _copy(const LabelizedVariable &aLDRV)
copies the content of aLDRV
Sequence< std::string > __labels
the set of labels contained in the variable
VarType
Definition: variable.h:38
Idx posLabel(const std::string &label) const
return the pos from label
virtual LabelizedVariable * clone() const
a virtual clone ...
LabelizedVariable & operator=(const LabelizedVariable &aLDRV)
copy operator
LabelizedVariable()
(protected) Default constructor
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
virtual Idx index(const std::string &label) const
returns the index of a given label