20 #ifndef DOXYGEN_SHOULD_SKIP_THIS 26 template <
typename T_TICKS >
28 const DiscretizedVariable< T_TICKS >& aDRV) {
32 for (
Idx i = 0; i < aDRV.__ticks_size; ++i) {
33 addTick((T_TICKS)aDRV.__ticks[i]);
37 template <
typename T_TICKS >
47 mid = (max + min) / 2;
48 T_TICKS val = __ticks[mid];
52 else if (target < val)
53 res = _dichotomy(target, min, mid);
54 else if (target > val)
55 res = _dichotomy(target, mid, max);
63 template <
typename T_TICKS >
65 if (__ticks_size < 2) {
GUM_ERROR(OutOfBounds,
"not enough ticks"); }
67 if (target < __ticks[0]) {
68 GUM_ERROR(OutOfLowerBound,
"less than first range");
71 if (target > __ticks[__ticks_size - 1]) {
72 GUM_ERROR(OutOfUpperBound,
"more than last range");
75 if (target == __ticks[__ticks_size - 1])
77 return __ticks_size - 2;
79 return _dichotomy(target, 0, __ticks_size - 1);
82 template <
typename T_TICKS >
84 const std::string& aName,
const std::string& aDesc) :
85 IDiscretizedVariable(aName, aDesc),
86 __ticks_size((
Size)0) {
91 template <
typename T_TICKS >
93 const std::string& aName,
94 const std::string& aDesc,
95 const std::vector< T_TICKS >&
ticks) :
100 for (
const auto t : ticks)
104 template <
typename T_TICKS >
106 const DiscretizedVariable< T_TICKS >& aDRV) :
113 template <
typename T_TICKS >
118 template <
typename T_TICKS >
120 return new DiscretizedVariable< T_TICKS >(*this);
123 template <
typename T_TICKS >
125 operator=(
const DiscretizedVariable< T_TICKS >& aDRV) {
130 template <
typename T_TICKS >
140 return (
__ticks[zeIdx] == aTick);
142 return ((
__ticks[zeIdx] == aTick) || (
__ticks[zeIdx + 1] == aTick));
143 }
catch (OutOfBounds&) {
return false; }
146 template <
typename T_TICKS >
147 DiscretizedVariable< T_TICKS >&
151 "Tick '" << aTick <<
"' already used for variable " <<
name());
177 }
catch (OutOfUpperBound&) {
179 }
catch (OutOfLowerBound&) {
193 template <
typename T_TICKS >
198 template <
typename T_TICKS >
200 std::stringstream ss;
203 GUM_ERROR(OutOfBounds,
"inexisting label index");
214 template <
typename T_TICKS >
217 GUM_ERROR(OutOfBounds,
"inexisting label index");
223 template <
typename T_TICKS >
228 std::istringstream i(label);
231 if (!(i >> target)) {
232 GUM_ERROR(NotFound,
"Bad label : " << label <<
" for " << *
this);
242 template <
typename T_TICKS >
247 template <
typename T_TICKS >
252 template <
typename T_TICKS >
259 template <
typename T_TICKS >
278 template <
typename T_TICKS >
279 INLINE
const std::vector< T_TICKS >&
284 template <
typename T_TICKS >
285 INLINE std::vector< double >
287 const std::size_t size =
__ticks.size();
288 std::vector< double >
ticks(size);
289 for (std::size_t i = std::size_t(0); i < size; ++i)
virtual std::vector< double > ticksAsDoubles() const
return the list of ticks as a vector of doubles
std::vector< T_TICKS > __ticks
void _copy(const Variable &aRV)
protected copy
virtual Idx index(const std::string &label) const
from the label to its index in var.
virtual Size domainSize() const
gum is the global namespace for all aGrUM entities
virtual ~DiscretizedVariable()
Destructor.
virtual std::string label(Idx i) const
const std::vector< T_TICKS > & ticks() const
Return the list of ticks.
bool isTick(const T_TICKS &aTick) const
DiscretizedVariable & addTick(const T_TICKS &aTick)
add a tick.
virtual double numerical(Idx indice) const
get a numerical representation of he indice-the value.
DiscretizedVariable(const std::string &aName, const std::string &aDesc)
Constructor.
Idx _pos(const T_TICKS &target) const
seach the class of target (internally use _dichotomy)
DiscretizedVariable< T_TICKS > & operator=(const DiscretizedVariable< T_TICKS > &aDRV)
operator =
const T_TICKS & tick(Idx i) const
from the index to the tick.
void eraseTicks()
erase all the Ticks
IDiscretizedVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
virtual DiscretizedVariable< T_TICKS > * clone() const
a virtual clone
const std::string toString() const
string version of *this
virtual const std::string domain() const
string represent the domain of the variable
virtual VarType varType() const
returns the type of variable
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const std::string & name() const
returns the name of the variable
void _copy(const DiscretizedVariable< T_TICKS > &aDRV)
make a copy TODO since we removed T_OtherData maybe some changes are needed in this method...
Idx _dichotomy(const T_TICKS &target, Idx min, Idx max) const
perform a dichotomy on ticks
#define GUM_ERROR(type, msg)