#include <climits>
#include <boost/algorithm/string.hpp> // for iequals
+#include <boost/lexical_cast.hpp>
#include <cmath>
}
bool
-Element::setValue(const int64_t) {
+Element::setValue(const long long int) {
return (false);
}
//
ElementPtr
fromStringstreamNumber(std::istream& in, int& pos) {
- long long int i;
- double d = 0.0;
- bool is_double = false;
- char* endptr;
-
std::string number = numberFromStringstream(in, pos);
- errno = 0;
- i = strtoll(number.c_str(), &endptr, 10);
- if (*endptr != '\0') {
- const char* ptr;
- errno = 0;
- d = strtod(ptr = number.c_str(), &endptr);
- is_double = true;
- if (*endptr != '\0' || ptr == endptr) {
- isc_throw(JSONError, std::string("Bad number: ") + number);
- } else {
- if (errno != 0) {
- isc_throw(JSONError, std::string("Number overflow: ") + number);
- }
+ if (number.find_first_of(".eE") < number.size()) {
+ try {
+ return (Element::create(boost::lexical_cast<double>(number)));
+ } catch (const boost::bad_lexical_cast&) {
+ isc_throw(JSONError, std::string("Number overflow: ") + number);
}
} else {
- if ((i == LLONG_MAX || i == LLONG_MIN) && errno != 0) {
+ try {
+ return (Element::create(boost::lexical_cast<int64_t>(number)));
+ } catch (const boost::bad_lexical_cast&) {
isc_throw(JSONError, std::string("Number overflow: ") + number);
}
}
-
- if (is_double) {
- return (Element::create(d));
- } else {
- return (Element::create(i));
- }
}
ElementPtr
/// is of the correct type
///
//@{
- virtual bool setValue(const int64_t v);
+ virtual bool setValue(const long long int v);
+ bool setValue(const long int i) { return (setValue(static_cast<long long int>(i))); };
+ bool setValue(const int i) { return (setValue(static_cast<long long int>(i))); };
virtual bool setValue(const double v);
virtual bool setValue(const bool t);
virtual bool setValue(const std::string& v);
using Element::getValue;
bool getValue(int64_t& t) const { t = i; return (true); }
using Element::setValue;
- bool setValue(int64_t v) { i = v; return (true); }
+ bool setValue(long long int v) { i = v; return (true); }
void toJSON(std::ostream& ss) const;
bool equals(const Element& other) const;
};