57#ifndef DOXYGEN_SHOULD_SKIP_THIS
63 template < GUM_Numeric GUM_SCALAR >
65 std::string_view aDesc,
66 GUM_SCALAR lower_bound,
67 GUM_SCALAR upper_bound) :
69 if (_lower_bound_ > _upper_bound_) { std::swap(_upper_bound_, _lower_bound_); }
70 GUM_CONSTRUCTOR(ContinuousVariable);
74 template < GUM_Numeric GUM_SCALAR >
75 ContinuousVariable< GUM_SCALAR >::ContinuousVariable(
76 const ContinuousVariable< GUM_SCALAR >& from) :
77 IContinuousVariable(from), _lower_bound_(from._lower_bound_),
78 _upper_bound_(from._upper_bound_) {
79 GUM_CONS_CPY(ContinuousVariable);
83 template < GUM_Numeric GUM_SCALAR >
84 template <
typename TX_VAL >
85 ContinuousVariable< GUM_SCALAR >::ContinuousVariable(
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 < GUM_Numeric GUM_SCALAR >
93 ContinuousVariable< GUM_SCALAR >::ContinuousVariable(ContinuousVariable< GUM_SCALAR >&& from) :
94 IContinuousVariable(
std::move(from)), _lower_bound_(from._lower_bound_),
95 _upper_bound_(from._upper_bound_) {
96 GUM_CONS_MOV(ContinuousVariable);
100 template < GUM_Numeric GUM_SCALAR >
101 ContinuousVariable< GUM_SCALAR >::~ContinuousVariable() {
102 GUM_DESTRUCTOR(ContinuousVariable);
106 template < GUM_Numeric GUM_SCALAR >
107 ContinuousVariable< GUM_SCALAR >* ContinuousVariable< GUM_SCALAR >::clone()
const {
108 return new ContinuousVariable< GUM_SCALAR >(*
this);
112 template < GUM_Numeric GUM_SCALAR >
113 ContinuousVariable< GUM_SCALAR >&
114 ContinuousVariable< GUM_SCALAR >::operator=(
const ContinuousVariable< GUM_SCALAR >& from) {
115 IContinuousVariable::operator=(from);
116 _lower_bound_ = from._lower_bound_;
117 _upper_bound_ = from._upper_bound_;
122 template < GUM_Numeric GUM_SCALAR >
123 template <
typename TX_VAL >
124 ContinuousVariable< GUM_SCALAR >&
125 ContinuousVariable< GUM_SCALAR >::operator=(
const ContinuousVariable< TX_VAL >& from) {
126 IContinuousVariable::operator=(from);
127 _lower_bound_ = GUM_SCALAR(from._lower_bound_);
128 _upper_bound_ = GUM_SCALAR(from._upper_bound_);
133 template < GUM_Numeric GUM_SCALAR >
134 ContinuousVariable< GUM_SCALAR >&
135 ContinuousVariable< GUM_SCALAR >::operator=(ContinuousVariable< GUM_SCALAR >&& from) {
136 IContinuousVariable::operator=(std::move(from));
137 _lower_bound_ = from._lower_bound_;
138 _upper_bound_ = from._upper_bound_;
143 template < GUM_Numeric GUM_SCALAR >
144 GUM_SCALAR ContinuousVariable< GUM_SCALAR >::operator[](std::string_view str)
const {
145 std::istringstream stream{std::string(str)};
149 if (belongs(value))
return value;
154 template < GUM_Numeric GUM_SCALAR >
155 GUM_SCALAR ContinuousVariable< GUM_SCALAR >::lowerBound()
const {
156 return _lower_bound_;
160 template < GUM_Numeric GUM_SCALAR >
161 double ContinuousVariable< GUM_SCALAR >::lowerBoundAsDouble()
const {
162 return (
double)_lower_bound_;
166 template < GUM_Numeric GUM_SCALAR >
167 GUM_SCALAR ContinuousVariable< GUM_SCALAR >::upperBound()
const {
168 return _upper_bound_;
172 template < GUM_Numeric GUM_SCALAR >
173 double ContinuousVariable< GUM_SCALAR >::upperBoundAsDouble()
const {
174 return (
double)_upper_bound_;
178 template < GUM_Numeric GUM_SCALAR >
179 void ContinuousVariable< GUM_SCALAR >::setLowerBound(
const GUM_SCALAR& new_bound) {
180 if (new_bound <= _upper_bound_) _lower_bound_ = new_bound;
185 template < GUM_Numeric GUM_SCALAR >
186 void ContinuousVariable< GUM_SCALAR >::setLowerBoundFromDouble(
const double new_bound) {
187 setLowerBound((GUM_SCALAR)new_bound);
191 template < GUM_Numeric GUM_SCALAR >
192 void ContinuousVariable< GUM_SCALAR >::setUpperBound(
const GUM_SCALAR& new_bound) {
193 if (new_bound >= _lower_bound_) _upper_bound_ = new_bound;
198 template < GUM_Numeric GUM_SCALAR >
199 void ContinuousVariable< GUM_SCALAR >::setUpperBoundFromDouble(
const double new_bound) {
200 setUpperBound((GUM_SCALAR)new_bound);
204 template < GUM_Numeric GUM_SCALAR >
205 VarType ContinuousVariable< GUM_SCALAR >::varType()
const {
206 return VarType::CONTINUOUS;
210 template < GUM_Numeric GUM_SCALAR >
211 std::string ContinuousVariable< GUM_SCALAR >::label(
const GUM_SCALAR& value)
const {
212 if (belongs(value))
return std::to_string(value);
217 template < GUM_Numeric GUM_SCALAR >
218 bool ContinuousVariable< GUM_SCALAR >::belongs(
const GUM_SCALAR& value)
const {
219 return (value >= _lower_bound_) && (value <= _upper_bound_);
223 template < GUM_Numeric GUM_SCALAR >
224 std::string ContinuousVariable< GUM_SCALAR >::domain()
const {
225 return std::format(
"[{};{}]", _lower_bound_, _upper_bound_);
229 template < GUM_Numeric GUM_SCALAR >
230 bool ContinuousVariable< GUM_SCALAR >::_checkSameDomain_(
const gum::Variable& aRV)
const {
232 const auto& cv =
static_cast< const ContinuousVariable< GUM_SCALAR >&
>(aRV);
233 return cv._lower_bound_ == _lower_bound_ && cv._upper_bound_ == _upper_bound_;
237 template < GUM_Numeric GUM_SCALAR >
238 std::string ContinuousVariable< GUM_SCALAR >::toString()
const {
239 std::string str(this->name());
245 template < GUM_Numeric GUM_SCALAR >
246 std::string ContinuousVariable< GUM_SCALAR >::toStringWithDescription()
const {
247 std::string str(this->description());
253 template < GUM_Numeric GUM_SCALAR >
254 std::ostream&
operator<<(std::ostream& stream,
const ContinuousVariable< GUM_SCALAR >& var) {
255 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)