aGrUM  0.14.2
discreteVariable_inl.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  ***************************************************************************/
20 
21 #ifndef DOXYGEN_SHOULD_SKIP_THIS
22 
23 // to ease parsers in IDE
25 
26 namespace gum {
27  /* =========================================================================*/
28  /* =========================================================================*/
29  /* === GUM_DISCRETE_VARIABLE === */
30  /* =========================================================================*/
31  /* =========================================================================*/
32 
33  // Default constructor
34  INLINE DiscreteVariable::DiscreteVariable(const std::string& aName,
35  const std::string& aDesc) :
36  Variable(aName, aDesc) {
37  GUM_CONSTRUCTOR(DiscreteVariable);
38  }
39 
40  // Copy constructor
42  Variable(aDRV) {
43  GUM_CONSTRUCTOR(DiscreteVariable);
44  }
45 
46  // destructor
48  GUM_DESTRUCTOR(DiscreteVariable);
49  }
50 
51  // Copy operator
53  operator=(const DiscreteVariable& aRV) {
54  if (&aRV != this) { Variable::operator=(aRV); }
55 
56  return *this;
57  }
58 
59  // equality operator
60  INLINE bool DiscreteVariable::operator==(const DiscreteVariable& aRV) const {
61  return (Variable::operator==(aRV) && (domainSize() == aRV.domainSize()));
62  }
63 
64  // inequality operator
65  INLINE bool DiscreteVariable::operator!=(const DiscreteVariable& aRV) const {
66  return (!operator==(aRV));
67  }
68 
69  // empty() <==> domainSize()<2
70  INLINE bool DiscreteVariable::empty() const { return domainSize() < 2; }
71 
72  // vector of labels
73  INLINE std::vector< std::string > DiscreteVariable::labels() const {
74  std::vector< std::string > v;
75  for (Idx i = 0; i < domainSize(); i++)
76  v.push_back(label(i));
77  return v;
78  }
79 } /* namespace gum */
80 
81 #endif // DOXYGEN_SHOULD_SKIP_THIS
std::vector< std::string > labels() const
vector of labels
DiscreteVariable & operator=(const DiscreteVariable &aRV)
Copy operator.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual bool operator==(const DiscreteVariable &aRV) const
equality operator
virtual Size domainSize() const =0
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
virtual bool operator!=(const DiscreteVariable &aRV) const
inequality operator
Variable & operator=(const Variable &aRV)
Copy operator.
virtual ~DiscreteVariable()
destructor
DiscreteVariable()
(protected) Default constructor
Variable()
(protected) Default constructor
Definition: variable.h:137