31 #include <agrum/tools/variables/rangeVariable.h> 37 INLINE RangeVariable* RangeVariable::clone()
const {
return new RangeVariable(*
this); }
40 INLINE Size RangeVariable::domainSize()
const {
41 return (_maxBound_ < _minBound_) ? Size(0) : Size(_maxBound_ + 1 - _minBound_);
47 INLINE std::string RangeVariable::label(Idx indice)
const {
48 long target =
static_cast<
long >(indice) + _minBound_;
49 if (belongs(target)) {
50 std::stringstream strBuff;
54 GUM_ERROR(OutOfBounds,
"Indice out of bounds.")
59 double RangeVariable::numerical(Idx indice)
const {
60 return double(_minBound_ +
static_cast<
long >(indice));
64 INLINE Idx RangeVariable::index(
const std::string& label)
const {
65 std::istringstream i(label);
68 if (!(i >> target)) { GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this) }
70 if (!belongs(target)) { GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this) }
72 return static_cast< Idx >(target - _minBound_);
76 INLINE
long RangeVariable::minVal()
const {
return _minBound_; }
79 INLINE
void RangeVariable::setMinVal(
long minVal) { _minBound_ = minVal; }
82 INLINE
long RangeVariable::maxVal()
const {
return _maxBound_; }
85 INLINE
void RangeVariable::setMaxVal(
long maxVal) { _maxBound_ = maxVal; }
88 INLINE
bool RangeVariable::belongs(
long val)
const {
89 return ((_minBound_ <= val) && (val <= _maxBound_));
95 INLINE RangeVariable& RangeVariable::operator=(
const RangeVariable& aRV) {
96 _minBound_ = aRV._minBound_;
97 _maxBound_ = aRV._maxBound_;
101 INLINE VarType RangeVariable::varType()
const {
return VarType::Range; }