56#ifndef DOXYGEN_SHOULD_SKIP_THIS
62 template <
typename GUM_SCALAR >
64 const std::string& aDesc,
65 GUM_SCALAR lower_bound,
66 GUM_SCALAR upper_bound) :
68 if (_lower_bound_ > _upper_bound_) { std::swap(_upper_bound_, _lower_bound_); }
69 GUM_CONSTRUCTOR(ContinuousVariable);
73 template <
typename GUM_SCALAR >
74 INLINE ContinuousVariable< GUM_SCALAR >::ContinuousVariable(
75 const ContinuousVariable< GUM_SCALAR >& from) :
76 IContinuousVariable(from), _lower_bound_(from._lower_bound_),
77 _upper_bound_(from._upper_bound_) {
78 GUM_CONS_CPY(ContinuousVariable);
82 template <
typename GUM_SCALAR >
83 template <
typename TX_VAL >
84 INLINE ContinuousVariable< GUM_SCALAR >::ContinuousVariable(
85 const ContinuousVariable< TX_VAL >& from) :
86 IContinuousVariable(from), _lower_bound_(GUM_SCALAR(from._lower_bound_)),
87 _upper_bound_(GUM_SCALAR(from._upper_bound_)) {
88 GUM_CONS_CPY(ContinuousVariable);
92 template <
typename GUM_SCALAR >
93 INLINE ContinuousVariable< GUM_SCALAR >::ContinuousVariable(
94 ContinuousVariable< GUM_SCALAR >&& from) :
95 IContinuousVariable(
std::move(from)), _lower_bound_(from._lower_bound_),
96 _upper_bound_(from._upper_bound_) {
97 GUM_CONS_MOV(ContinuousVariable);
101 template <
typename GUM_SCALAR >
102 INLINE ContinuousVariable< GUM_SCALAR >::~ContinuousVariable() {
103 GUM_DESTRUCTOR(ContinuousVariable);
107 template <
typename GUM_SCALAR >
108 INLINE ContinuousVariable< GUM_SCALAR >* ContinuousVariable< GUM_SCALAR >::clone()
const {
109 return new ContinuousVariable< GUM_SCALAR >(*
this);
113 template <
typename GUM_SCALAR >
114 INLINE ContinuousVariable< GUM_SCALAR >&
115 ContinuousVariable< GUM_SCALAR >::operator=(
const ContinuousVariable< GUM_SCALAR >& from) {
116 IContinuousVariable::operator=(from);
117 _lower_bound_ = from._lower_bound_;
118 _upper_bound_ = from._upper_bound_;
123 template <
typename GUM_SCALAR >
124 template <
typename TX_VAL >
125 INLINE ContinuousVariable< GUM_SCALAR >&
126 ContinuousVariable< GUM_SCALAR >::operator=(
const ContinuousVariable< TX_VAL >& from) {
127 IContinuousVariable::operator=(from);
128 _lower_bound_ = GUM_SCALAR(from._lower_bound_);
129 _upper_bound_ = GUM_SCALAR(from._upper_bound_);
134 template <
typename GUM_SCALAR >
135 INLINE ContinuousVariable< GUM_SCALAR >&
136 ContinuousVariable< GUM_SCALAR >::operator=(ContinuousVariable< GUM_SCALAR >&& from) {
137 IContinuousVariable::operator=(std::move(from));
138 _lower_bound_ = from._lower_bound_;
139 _upper_bound_ = from._upper_bound_;
144 template <
typename GUM_SCALAR >
145 INLINE GUM_SCALAR ContinuousVariable< GUM_SCALAR >::operator[](
const std::string& str)
const {
146 std::istringstream stream(str);
150 if (belongs(value))
return value;
155 template <
typename GUM_SCALAR >
156 INLINE GUM_SCALAR ContinuousVariable< GUM_SCALAR >::lowerBound()
const {
157 return _lower_bound_;
161 template <
typename GUM_SCALAR >
162 INLINE
double ContinuousVariable< GUM_SCALAR >::lowerBoundAsDouble()
const {
163 return (
double)_lower_bound_;
167 template <
typename GUM_SCALAR >
168 INLINE GUM_SCALAR ContinuousVariable< GUM_SCALAR >::upperBound()
const {
169 return _upper_bound_;
173 template <
typename GUM_SCALAR >
174 INLINE
double ContinuousVariable< GUM_SCALAR >::upperBoundAsDouble()
const {
175 return (
double)_upper_bound_;
179 template <
typename GUM_SCALAR >
180 INLINE
void ContinuousVariable< GUM_SCALAR >::setLowerBound(
const GUM_SCALAR& new_bound) {
181 if (new_bound <= _upper_bound_) _lower_bound_ = new_bound;
186 template <
typename GUM_SCALAR >
187 INLINE
void ContinuousVariable< GUM_SCALAR >::setLowerBoundFromDouble(
const double new_bound) {
188 setLowerBound((GUM_SCALAR)new_bound);
192 template <
typename GUM_SCALAR >
193 INLINE
void ContinuousVariable< GUM_SCALAR >::setUpperBound(
const GUM_SCALAR& new_bound) {
194 if (new_bound >= _lower_bound_) _upper_bound_ = new_bound;
199 template <
typename GUM_SCALAR >
200 INLINE
void ContinuousVariable< GUM_SCALAR >::setUpperBoundFromDouble(
const double new_bound) {
201 setUpperBound((GUM_SCALAR)new_bound);
205 template <
typename GUM_SCALAR >
206 INLINE
VarType ContinuousVariable< GUM_SCALAR >::varType()
const {
207 return VarType::CONTINUOUS;
211 template <
typename GUM_SCALAR >
212 INLINE std::string ContinuousVariable< GUM_SCALAR >::label(
const GUM_SCALAR& value)
const {
213 if (belongs(value))
return std::to_string(value);
218 template <
typename GUM_SCALAR >
219 INLINE
bool ContinuousVariable< GUM_SCALAR >::belongs(
const GUM_SCALAR& value)
const {
220 return (value >= _lower_bound_) && (value <= _upper_bound_);
224 template <
typename GUM_SCALAR >
225 INLINE std::string ContinuousVariable< GUM_SCALAR >::domain()
const {
226 std::ostringstream stream;
227 stream <<
'[' << _lower_bound_ <<
';' << _upper_bound_ <<
']';
232 template <
typename GUM_SCALAR >
233 INLINE
bool ContinuousVariable< GUM_SCALAR >::_checkSameDomain_(
const gum::Variable& aRV)
const {
235 const auto& cv =
static_cast< const ContinuousVariable< GUM_SCALAR >&
>(aRV);
236 return cv._lower_bound_ == _lower_bound_ && cv._upper_bound_ == _upper_bound_;
240 template <
typename GUM_SCALAR >
241 INLINE std::string ContinuousVariable< GUM_SCALAR >::toString()
const {
242 std::string str(this->name());
248 template <
typename GUM_SCALAR >
249 INLINE std::string ContinuousVariable< GUM_SCALAR >::toStringWithDescription()
const {
250 std::string str(this->description());
256 template <
typename GUM_SCALAR >
257 std::ostream&
operator<<(std::ostream& stream,
const ContinuousVariable< GUM_SCALAR >& var) {
258 return stream << var.toString();
friend class ContinuousVariable
A base class for continuous variables, independent of the GUM_SCALAR type.
Exception : out of bound.
Base class for every random variable.
Header of ContinuousVariable.
#define GUM_ERROR(type, msg)
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)