31 #include <agrum/tools/variables/rangeVariable.h> 37 INLINE RangeVariable* RangeVariable::clone()
const {
38 return new RangeVariable(*
this);
42 INLINE Size RangeVariable::domainSize()
const {
43 return (maxBound__ < minBound__) ? Size(0) : Size(maxBound__ + 1 - minBound__);
49 INLINE std::string RangeVariable::label(Idx indice)
const {
50 long target =
static_cast<
long >(indice) + minBound__;
51 if (belongs(target)) {
52 std::stringstream strBuff;
56 GUM_ERROR(OutOfBounds,
"Indice out of bounds.");
61 double RangeVariable::numerical(Idx indice)
const {
62 return double(minBound__ +
static_cast<
long >(indice));
66 INLINE Idx RangeVariable::index(
const std::string& label)
const {
67 std::istringstream i(label);
71 GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this);
74 if (!belongs(target)) {
75 GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this);
78 return static_cast< Idx >(target - minBound__);
82 INLINE
long RangeVariable::minVal()
const {
return minBound__; }
85 INLINE
void RangeVariable::setMinVal(
long minVal) { minBound__ = minVal; }
88 INLINE
long RangeVariable::maxVal()
const {
return maxBound__; }
91 INLINE
void RangeVariable::setMaxVal(
long maxVal) { maxBound__ = maxVal; }
94 INLINE
bool RangeVariable::belongs(
long val)
const {
95 return ((minBound__ <= val) && (val <= maxBound__));
101 INLINE RangeVariable& RangeVariable::operator=(
const RangeVariable& aRV) {
102 minBound__ = aRV.minBound__;
103 maxBound__ = aRV.maxBound__;
107 INLINE VarType RangeVariable::varType()
const {
return VarType::Range; }