32 #ifndef DOXYGEN_SHOULD_SKIP_THIS 44 int DBCell::__string_max_index = 0;
47 Bijection< std::string, int >& DBCell::__strings() {
48 # ifdef GUM_DEBUG_MODE 49 static bool first_time =
true;
52 __debug__::__dec_creation(
53 "Bijection",
"__strings", 0,
"BCell string bijection", 0);
54 __debug__::__dec_creation(
55 "BijectionImplementation",
"__strings", 0,
"BCell string bijection", 0);
56 __debug__::__dec_creation(
57 "HashTable",
"__strings", 0,
"BCell string bijection", 0);
58 __debug__::__dec_creation(
59 "HashTable",
"__strings", 0,
"BCell string bijection", 0);
62 static Bijection< std::string, int > strings;
69 if (str.empty())
return false;
72 auto start_iter = str.begin() + str.find_first_not_of(
" \t");
73 auto end_iter = str.begin() + str.find_last_not_of(
" \t\r\n") + 1;
75 if (start_iter == end_iter)
return false;
78 if (*start_iter ==
'-') ++start_iter;
81 for (; start_iter != end_iter; ++start_iter) {
82 if ((*start_iter <
'0') || (*start_iter >
'9'))
return false;
91 if (str.empty())
return false;
94 auto start_iter = str.begin() + str.find_first_not_of(
" \t");
95 auto end_iter = str.begin() + str.find_last_not_of(
" \t\r\n") + 1;
97 if (start_iter == end_iter)
return false;
100 bool has_dot =
false;
101 bool has_exponent =
false;
102 bool has_digit =
false;
103 bool has_negation =
false;
104 for (; start_iter != end_iter; ++start_iter) {
105 if (*start_iter ==
'-') {
106 if (has_negation)
return false;
107 }
else if (*start_iter ==
'.') {
108 if (has_dot || has_exponent)
return false;
110 }
else if ((*start_iter ==
'e') || (*start_iter ==
'E')) {
111 if (has_exponent || !has_digit)
return false;
113 has_negation =
false;
114 }
else if ((*start_iter <
'0') || (*start_iter >
'9'))
126 if (new_type == __type)
return true;
132 __val_real = float(__val_integer);
138 const std::string& str = __strings().first(__val_index);
139 if (!
isReal(str))
return false;
140 __val_real = std::stof(str);
143 }
catch (std::invalid_argument&) {
return false; }
149 "type not supported by DBCell convertType");
156 const int nb = int(__val_real);
157 if (nb == __val_real) {
167 const std::string& str = __strings().first(__val_index);
169 __val_integer = std::stoi(str);
172 }
catch (std::invalid_argument&) {
return false; }
178 "type not supported by DBCell convertType");
186 sprintf(buffer,
"%g", __val_real);
187 const std::string str(buffer);
188 if (!__strings().existsFirst(str)) {
189 __strings().insert(str, __string_max_index);
190 __val_index = __string_max_index;
191 ++__string_max_index;
193 __val_index = __strings().second(str);
201 if (!__strings().existsFirst(str)) {
202 __strings().insert(str, __string_max_index);
203 __val_index = __string_max_index;
204 ++__string_max_index;
206 __val_index = __strings().second(str);
216 "type not supported by DBCell convertType");
223 GUM_ERROR(NotImplementedYet,
"type not supported by DBCell convertType");
231 std::string DBCell::__typeErrorMsg(
const std::string& true_type)
const {
232 std::stringstream str;
235 str <<
"The DBCell contains a real number instead of " << true_type;
239 str <<
"The DBCell contains an integer instead of " << true_type;
243 str <<
"The DBCell contains a string instead of " << true_type;
247 str <<
"The DBCell contains a missing value instead of " << true_type;
250 default:
GUM_ERROR(NotImplementedYet,
"DBCell type not implemented yet");
bool convertType(const EltType newtype)
try to convert the content of the DBCell into another type
static bool isInteger(const std::string &str)
determines whether a string corresponds precisely to an integer
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string to_string(const Formula &f)
static bool isReal(const std::string &str)
determine whether a string corresponds precisely to a real number
EltType
the set of types possibly taken by the last element read
#define GUM_ERROR(type, msg)