28 #ifndef DOXYGEN_SHOULD_SKIP_THIS 43 template <
template <
typename >
class ALLOC >
44 template <
template <
typename >
class XALLOC >
46 const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
55 __variable(
"var",
""), __fit_range(fit_range) {
79 __variable.setLowerBound(std::numeric_limits< float >::infinity());
82 __real_variable = __variable.clone();
89 template <
template <
typename >
class ALLOC >
96 __variable(
"var",
""), __fit_range(fit_range) {
101 __variable.setLowerBound(std::numeric_limits< float >::infinity());
104 __real_variable = __variable.clone();
111 template <
template <
typename >
class ALLOC >
112 template <
typename GUM_SCALAR,
template <
typename >
class XALLOC >
114 const ContinuousVariable< GUM_SCALAR >& var,
115 const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
116 const bool fit_range,
124 __variable(var.name(), var.description()), __fit_range(fit_range) {
126 const float lower_bound = float(var.lowerBound());
127 const float upper_bound = float(var.upperBound());
128 __variable.setLowerBound(lower_bound);
129 __variable.setUpperBound(upper_bound);
133 bool non_float_symbol_found =
false;
138 const float missing_val = std::stof(*iter);
139 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
142 __status_float_missing_symbols.insert(*iter,
false);
143 }
else if (!non_float_symbol_found) {
144 non_float_symbol_found =
true;
145 __nonfloat_missing_symbol = *iter;
150 __real_variable = var.clone();
157 template <
template <
typename >
class ALLOC >
158 template <
typename GUM_SCALAR >
160 const ContinuousVariable< GUM_SCALAR >& var,
161 const bool fit_range,
166 __variable(var.name(), var.description()), __fit_range(fit_range) {
168 const float lower_bound = float(var.lowerBound());
169 const float upper_bound = float(var.upperBound());
170 __variable.setLowerBound(lower_bound);
171 __variable.setUpperBound(upper_bound);
174 __real_variable = var.clone();
181 template <
template <
typename >
class ALLOC >
182 template <
template <
typename >
class XALLOC >
184 const IContinuousVariable& var,
185 const std::vector< std::string, XALLOC< std::string > >& missing_symbols,
186 const bool fit_range,
194 __variable(var.name(), var.description()), __fit_range(fit_range) {
196 const float lower_bound = float(var.lowerBoundAsDouble());
197 const float upper_bound = float(var.upperBoundAsDouble());
198 __variable.setLowerBound(lower_bound);
199 __variable.setUpperBound(upper_bound);
203 bool non_float_symbol_found =
false;
208 const float missing_val = std::stof(*iter);
209 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
212 __status_float_missing_symbols.insert(*iter,
false);
213 }
else if (!non_float_symbol_found) {
214 non_float_symbol_found =
true;
215 __nonfloat_missing_symbol = *iter;
220 __real_variable = var.clone();
227 template <
template <
typename >
class ALLOC >
229 const IContinuousVariable& var,
230 const bool fit_range,
235 __variable(var.name(), var.description()), __fit_range(fit_range) {
237 const float lower_bound = var.lowerBoundAsDouble();
238 const float upper_bound = var.upperBoundAsDouble();
239 __variable.setLowerBound(lower_bound);
240 __variable.setUpperBound(upper_bound);
243 __real_variable = var.clone();
250 template <
template <
typename >
class ALLOC >
252 const DBTranslator4ContinuousVariable< ALLOC >& from,
256 __variable(from.__variable),
257 __status_float_missing_symbols(from.__status_float_missing_symbols),
258 __nonfloat_missing_symbol(from.__nonfloat_missing_symbol),
259 __fit_range(from.__fit_range) {
261 __real_variable = from.__real_variable->clone();
268 template <
template <
typename >
class ALLOC >
270 const DBTranslator4ContinuousVariable< ALLOC >& from) :
275 template <
template <
typename >
class ALLOC >
277 DBTranslator4ContinuousVariable< ALLOC >&& from,
281 __variable(
std::move(from.__variable)),
282 __status_float_missing_symbols(
283 std::move(from.__status_float_missing_symbols)),
284 __nonfloat_missing_symbol(
std::move(from.__nonfloat_missing_symbol)),
285 __fit_range(from.__fit_range) {
287 __real_variable = from.__real_variable;
288 from.__real_variable =
nullptr;
295 template <
template <
typename >
class ALLOC >
297 DBTranslator4ContinuousVariable< ALLOC >&& from) :
303 template <
template <
typename >
class ALLOC >
304 DBTranslator4ContinuousVariable< ALLOC >*
308 ALLOC< DBTranslator4ContinuousVariable< ALLOC > > allocator(alloc);
309 DBTranslator4ContinuousVariable< ALLOC >* translator = allocator.allocate(1);
311 allocator.construct(translator, *
this, alloc);
313 allocator.deallocate(translator, 1);
321 template <
template <
typename >
class ALLOC >
322 INLINE DBTranslator4ContinuousVariable< ALLOC >*
329 template <
template <
typename >
class ALLOC >
332 if (__real_variable !=
nullptr)
delete __real_variable;
339 template <
template <
typename >
class ALLOC >
340 DBTranslator4ContinuousVariable< ALLOC >&
342 operator=(
const DBTranslator4ContinuousVariable< ALLOC >& from) {
345 __variable = from.__variable;
346 __status_float_missing_symbols = from.__status_float_missing_symbols;
347 __nonfloat_missing_symbol = from.__nonfloat_missing_symbol;
348 __fit_range = from.__fit_range;
350 if (__real_variable !=
nullptr)
delete __real_variable;
351 __real_variable = from.__real_variable->clone();
359 template <
template <
typename >
class ALLOC >
360 DBTranslator4ContinuousVariable< ALLOC >&
362 operator=(DBTranslator4ContinuousVariable< ALLOC >&& from) {
365 __variable = std::move(from.__variable);
366 __status_float_missing_symbols =
367 std::move(from.__status_float_missing_symbols);
368 __nonfloat_missing_symbol = std::move(from.__nonfloat_missing_symbol);
369 __fit_range = from.__fit_range;
371 if (__real_variable !=
nullptr)
delete __real_variable;
372 __real_variable = from.__real_variable;
373 from.__real_variable =
nullptr;
381 template <
template <
typename >
class ALLOC >
383 const std::string& str) {
387 return DBTranslatedValue{std::numeric_limits< float >::max()};
392 <<
"\" cannot be translated because it is not a number");
396 const float number = std::stof(str);
399 if (__variable.belongs(number))
return DBTranslatedValue{number};
403 if (!__status_float_missing_symbols[str]) {
404 __status_float_missing_symbols[str] =
true;
406 return DBTranslatedValue{std::numeric_limits< float >::max()};
413 <<
"\" cannot be translated because it is " 414 "out of the domain of the continuous variable");
424 if (__variable.lowerBound() == std::numeric_limits< float >::infinity()) {
425 __variable.setLowerBound(number);
426 __variable.setUpperBound(number);
427 return DBTranslatedValue{number};
434 const float lower_bound = __variable.lowerBound();
435 const float upper_bound = __variable.upperBound();
436 if (number < lower_bound) {
439 for (
const auto& missing : __status_float_missing_symbols) {
440 if (missing.second) {
441 const float miss_val = std::stof(missing.first);
442 if ((miss_val >= number) && (miss_val <= upper_bound)) {
445 << str <<
"\" cannot be translated because " 446 <<
"it would induce a new domain containing an already " 447 <<
"translated missing symbol");
454 for (
auto iter = __status_float_missing_symbols.beginSafe();
455 iter != __status_float_missing_symbols.endSafe();
457 if (iter.val() ==
false) {
458 const float miss_val = std::stof(iter.key());
459 if ((miss_val >= number) && (miss_val <= upper_bound)) {
461 __status_float_missing_symbols.erase(iter);
467 __variable.setLowerBound(number);
469 return DBTranslatedValue{number};
473 for (
const auto& missing : __status_float_missing_symbols) {
474 if (missing.second) {
475 const float miss_val = std::stof(missing.first);
476 if ((miss_val >= lower_bound) && (miss_val <= number)) {
479 << str <<
"\" cannot be translated because " 480 <<
"it would induce a new domain containing an already " 481 <<
"translated missing symbol");
488 for (
auto iter = __status_float_missing_symbols.beginSafe();
489 iter != __status_float_missing_symbols.endSafe();
491 if (iter.val() ==
false) {
492 const float miss_val = std::stof(iter.key());
493 if ((miss_val >= lower_bound) && (miss_val <= number)) {
495 __status_float_missing_symbols.erase(iter);
501 __variable.setUpperBound(number);
503 return DBTranslatedValue{number};
509 template <
template <
typename >
class ALLOC >
511 const DBTranslatedValue translated_val)
const {
512 if (translated_val.cont_val == std::numeric_limits< float >::max()) {
513 if (!__nonfloat_missing_symbol.empty())
return __nonfloat_missing_symbol;
518 if ((translated_val.cont_val < __variable.lowerBound())
519 || (translated_val.cont_val > __variable.upperBound())) {
521 "The back translation of " 522 << translated_val.cont_val
523 <<
" could not be found because the value is outside the " 524 <<
"domain of the continuous variable");
528 sprintf(buffer,
"%g", translated_val.cont_val);
529 return std::string(buffer);
534 template <
template <
typename >
class ALLOC >
541 template <
template <
typename >
class ALLOC >
542 INLINE HashTable< std::size_t,
544 ALLOC< std::pair< std::size_t, std::size_t > > >
546 return HashTable< std::size_t,
548 ALLOC< std::pair< std::size_t, std::size_t > > >();
553 template <
template <
typename >
class ALLOC >
556 return std::numeric_limits< std::size_t >::max();
561 template <
template <
typename >
class ALLOC >
562 INLINE
const IContinuousVariable*
565 __real_variable->setUpperBoundFromDouble(__variable.upperBound());
566 return __real_variable;
571 template <
template <
typename >
class ALLOC >
572 INLINE DBTranslatedValue
574 return DBTranslatedValue{std::numeric_limits< float >::max()};
virtual DBTranslatedValue translate(const std::string &str) final
returns the translation of a string
virtual void setLowerBoundFromDouble(const double new_bound)=0
updates the lower bound of the domain of the variable
virtual ~DBTranslator4ContinuousVariable()
destructor
bool empty() const noexcept
Indicates whether the set is the empty set.
typename DBTranslator< ALLOC >::allocator_type allocator_type
type for the allocators passed in arguments of methods
virtual DBTranslator4ContinuousVariable< ALLOC > * clone() const
virtual copy constructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void erase(const Key &k)
Erases an element from the set.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
DBTranslator(DBTranslatedValueType val_type, const std::vector< std::string, XALLOC< std::string > > &missing_symbols, const bool editable_dictionary=true, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type())
default constructor
iterator begin() const
The usual unsafe begin iterator to parse the set.
DBTranslator4ContinuousVariable< ALLOC > & operator=(const DBTranslator4ContinuousVariable< ALLOC > &from)
copy operator
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
virtual std::size_t domainSize() const final
returns std::numeric_limits<std::size_t>::max ()
DBTranslator4ContinuousVariable(const std::vector< std::string, XALLOC< std::string > > &missing_symbols, const bool fit_range=false, const allocator_type &alloc=allocator_type())
default constructor without any initial variable
virtual bool needsReordering() const final
indicates that the translations should never be reordered
allocator_type getAllocator() const
returns the allocator used by the translator
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
static bool isReal(const std::string &str)
determine whether a string corresponds precisely to a real number
Set< std::string, ALLOC< std::string > > _missing_symbols
the set of missing symbols
DBTranslator< ALLOC > & operator=(const DBTranslator< ALLOC > &from)
copy operator
virtual HashTable< std::size_t, std::size_t, ALLOC< std::pair< std::size_t, std::size_t > > > reorder() final
returns an empty mapping, indicating that old tanslations are equal to the newly reordered ones...
virtual std::string translateBack(const DBTranslatedValue translated_val) const final
returns the original value for a given translation
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
bool isMissingSymbol(const std::string &str) const
indicates whether a string corresponds to a missing symbol
#define GUM_ERROR(type, msg)
virtual const IContinuousVariable * variable() const final
returns the variable stored into the translator
virtual DBTranslatedValue missingValue() const final
returns the translation of a missing value