50#ifndef DOXYGEN_SHOULD_SKIP_THIS
62 const std::vector< std::string >& missing_symbols,
63 const bool fit_range) :
65 _variable_(
"var",
""), _fit_range_(fit_range) {
73 for (
auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
75 if (DBCell::isReal(*iter)) { this->missing_symbols_.erase(iter); }
80 if (!this->missing_symbols_.empty()) {
81 _nonfloat_missing_symbol_ = *(this->missing_symbols_.begin());
87 if (_fit_range_) _variable_.setLowerBound(std::numeric_limits< float >::infinity());
90 _real_variable_ = _variable_.
clone();
92 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
96 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
const bool fit_range) :
97 DBTranslator(DBTranslatedValueType::
CONTINUOUS, true, fit_range, 1), _variable_(
"var",
""),
98 _fit_range_(fit_range) {
102 if (_fit_range_) _variable_.setLowerBound(std::numeric_limits< float >::infinity());
105 _real_variable_ = _variable_.clone();
107 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
111 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
112 const IContinuousVariable& var,
113 const std::vector< std::string >& missing_symbols,
114 const bool fit_range) :
115 DBTranslator(DBTranslatedValueType::
CONTINUOUS, true, missing_symbols, fit_range, 1),
116 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
118 const auto lower_bound = float(var.lowerBoundAsDouble());
119 const auto upper_bound = float(var.upperBoundAsDouble());
120 _variable_.setLowerBound(lower_bound);
121 _variable_.setUpperBound(upper_bound);
125 bool non_float_symbol_found =
false;
126 for (
auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
128 if (DBCell::isReal(*iter)) {
129 const float missing_val = std::stof(*iter);
130 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
131 this->missing_symbols_.erase(iter);
132 }
else _status_float_missing_symbols_.insert(*iter,
false);
133 }
else if (!non_float_symbol_found) {
134 non_float_symbol_found =
true;
135 _nonfloat_missing_symbol_ = *iter;
140 _real_variable_ = var.clone();
142 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
146 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
const IContinuousVariable& var,
147 const bool fit_range) :
148 DBTranslator(DBTranslatedValueType::
CONTINUOUS, true, fit_range, 1),
149 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
151 const auto lower_bound = float(var.lowerBoundAsDouble());
152 const auto upper_bound = float(var.upperBoundAsDouble());
153 _variable_.setLowerBound(lower_bound);
154 _variable_.setUpperBound(upper_bound);
157 _real_variable_ = var.clone();
159 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
163 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
164 const DBTranslator4ContinuousVariable& from) :
165 DBTranslator(from), _variable_(from._variable_),
166 _status_float_missing_symbols_(from._status_float_missing_symbols_),
167 _nonfloat_missing_symbol_(from._nonfloat_missing_symbol_), _fit_range_(from._fit_range_) {
169 _real_variable_ = from._real_variable_->clone();
171 GUM_CONS_CPY(DBTranslator4ContinuousVariable);
175 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
176 DBTranslator4ContinuousVariable&& from) :
177 DBTranslator(
std::move(from)), _variable_(
std::move(from._variable_)),
178 _status_float_missing_symbols_(
std::move(from._status_float_missing_symbols_)),
179 _nonfloat_missing_symbol_(
std::move(from._nonfloat_missing_symbol_)),
180 _fit_range_(from._fit_range_) {
182 _real_variable_ = from._real_variable_;
183 from._real_variable_ =
nullptr;
185 GUM_CONS_MOV(DBTranslator4ContinuousVariable);
189 DBTranslator4ContinuousVariable* DBTranslator4ContinuousVariable::clone()
const {
190 return new DBTranslator4ContinuousVariable(*
this);
194 DBTranslator4ContinuousVariable&
195 DBTranslator4ContinuousVariable::operator=(
const DBTranslator4ContinuousVariable& from) {
197 DBTranslator::operator=(from);
198 _variable_ = from._variable_;
199 _status_float_missing_symbols_ = from._status_float_missing_symbols_;
200 _nonfloat_missing_symbol_ = from._nonfloat_missing_symbol_;
201 _fit_range_ = from._fit_range_;
203 if (_real_variable_ !=
nullptr)
delete _real_variable_;
204 _real_variable_ = from._real_variable_->clone();
211 DBTranslator4ContinuousVariable&
212 DBTranslator4ContinuousVariable::operator=(DBTranslator4ContinuousVariable&& from) {
214 DBTranslator::operator=(std::move(from));
215 _variable_ = std::move(from._variable_);
216 _status_float_missing_symbols_ = std::move(from._status_float_missing_symbols_);
217 _nonfloat_missing_symbol_ = std::move(from._nonfloat_missing_symbol_);
218 _fit_range_ = from._fit_range_;
220 if (_real_variable_ !=
nullptr)
delete _real_variable_;
221 _real_variable_ = from._real_variable_;
222 from._real_variable_ =
nullptr;
229 DBTranslatedValue DBTranslator4ContinuousVariable::translate(
const std::string& str) {
231 if (!DBCell::isReal(str)) {
232 if (this->isMissingSymbol(str)) {
233 return DBTranslatedValue{std::numeric_limits< float >::max()};
236 "String \"" << str <<
"\" cannot be translated because it is not a value for "
241 const float number = std::stof(str);
244 if (_variable_.belongs(number))
return DBTranslatedValue{number};
247 if (this->isMissingSymbol(str)) {
248 if (!_status_float_missing_symbols_[str]) { _status_float_missing_symbols_[str] =
true; }
249 return DBTranslatedValue{std::numeric_limits< float >::max()};
256 <<
"\" cannot be translated because it is "
257 "out of the domain of the continuous variable");
267 if (_variable_.lowerBound() == std::numeric_limits< float >::infinity()) {
268 _variable_.setLowerBound(number);
269 _variable_.setUpperBound(number);
270 return DBTranslatedValue{number};
277 const float lower_bound = _variable_.lowerBound();
278 const float upper_bound = _variable_.upperBound();
279 if (number < lower_bound) {
282 for (
const auto& missing: _status_float_missing_symbols_) {
283 if (missing.second) {
284 const float miss_val = std::stof(missing.first);
285 if ((miss_val >= number) && (miss_val <= upper_bound)) {
287 "String \"" << str <<
"\" cannot be translated because "
288 <<
"it would induce a new domain containing an already "
289 <<
"translated missing symbol");
296 for (
auto iter = _status_float_missing_symbols_.beginSafe();
297 iter != _status_float_missing_symbols_.endSafe();
299 if (iter.val() ==
false) {
300 const float miss_val = std::stof(iter.key());
301 if ((miss_val >= number) && (miss_val <= upper_bound)) {
302 this->missing_symbols_.erase(iter.key());
303 _status_float_missing_symbols_.erase(iter);
309 _variable_.setLowerBound(number);
311 return DBTranslatedValue{number};
315 for (
const auto& missing: _status_float_missing_symbols_) {
316 if (missing.second) {
317 const float miss_val = std::stof(missing.first);
318 if ((miss_val >= lower_bound) && (miss_val <= number)) {
320 "String \"" << str <<
"\" cannot be translated because "
321 <<
"it would induce a new domain containing an already "
322 <<
"translated missing symbol");
329 for (
auto iter = _status_float_missing_symbols_.beginSafe();
330 iter != _status_float_missing_symbols_.endSafe();
332 if (iter.val() ==
false) {
333 const float miss_val = std::stof(iter.key());
334 if ((miss_val >= lower_bound) && (miss_val <= number)) {
335 this->missing_symbols_.erase(iter.key());
336 _status_float_missing_symbols_.erase(iter);
342 _variable_.setUpperBound(number);
344 return DBTranslatedValue{number};
The databases' cell translators for continuous variables.
Exception : operation not allowed.
Exception : wrong type for this operation.
Error: An unknown label is found in the database.
DBTranslator4ContinuousVariable(const std::vector< std::string > &missing_symbols, const bool fit_range=false)
default constructor without any initial variable
The base class for all the tabular database cell translators.
virtual DBTranslator * clone() const =0
virtual copy constructor
#define GUM_ERROR(type, msg)
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities