Merge pull request #371 from dinghram/develop

from_json: change long to int64_t to remove OS ambiguity
This commit is contained in:
Jason Turner 2017-11-21 14:41:30 -07:00 committed by GitHub
commit bd6c83f3b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,7 +131,7 @@ class JSON
} }
Internal( double d ) : Float( d ), Type(Class::Floating) {} Internal( double d ) : Float( d ), Type(Class::Floating) {}
Internal( long l ) : Int( l ), Type(Class::Integral) {} Internal( int64_t l ) : Int( l ), Type(Class::Integral) {}
Internal( bool b ) : Bool( b ), Type(Class::Boolean) {} Internal( bool b ) : Bool( b ), Type(Class::Boolean) {}
Internal( std::string s ) : String(std::make_unique<std::string>(std::move(s))), Type(Class::String) {} Internal( std::string s ) : String(std::make_unique<std::string>(std::move(s))), Type(Class::String) {}
Internal() : Type(Class::Null) {} Internal() : Type(Class::Null) {}
@ -192,7 +192,7 @@ class JSON
std::unique_ptr<QuickFlatMap> Map; std::unique_ptr<QuickFlatMap> Map;
std::unique_ptr<std::string> String; std::unique_ptr<std::string> String;
double Float = 0; double Float = 0;
long Int = 0; int64_t Int = 0;
bool Bool = false; bool Bool = false;
Class Type = Class::Null; Class Type = Class::Null;
@ -248,7 +248,7 @@ class JSON
explicit JSON( T b, typename enable_if<is_same<T,bool>::value>::type* = nullptr ) : internal( static_cast<bool>(b) ) {} explicit JSON( T b, typename enable_if<is_same<T,bool>::value>::type* = nullptr ) : internal( static_cast<bool>(b) ) {}
template <typename T> template <typename T>
explicit JSON( T i, typename enable_if<is_integral<T>::value && !is_same<T,bool>::value>::type* = nullptr ) : internal( static_cast<long>(i) ) {} explicit JSON( T i, typename enable_if<is_integral<T>::value && !is_same<T,bool>::value>::type* = nullptr ) : internal( static_cast<int64_t>(i) ) {}
template <typename T> template <typename T>
explicit JSON( T f, typename enable_if<is_floating_point<T>::value>::type* = nullptr ) : internal( static_cast<double>(f) ) {} explicit JSON( T f, typename enable_if<is_floating_point<T>::value>::type* = nullptr ) : internal( static_cast<double>(f) ) {}
@ -335,8 +335,8 @@ class JSON
return ok ? internal.Float : 0.0; return ok ? internal.Float : 0.0;
} }
long to_int() const { bool b; return to_int( b ); } int64_t to_int() const { bool b; return to_int( b ); }
long to_int( bool &ok ) const { int64_t to_int( bool &ok ) const {
ok = (internal.Type == Class::Integral); ok = (internal.Type == Class::Integral);
return ok ? internal.Int : 0; return ok ? internal.Int : 0;
} }
@ -568,8 +568,8 @@ struct JSONParser {
char c = '\0'; char c = '\0';
bool isDouble = false; bool isDouble = false;
bool isNegative = false; bool isNegative = false;
int64_t exp = 0;
bool isExpNegative = false; bool isExpNegative = false;
long exp = 0;
if( offset < str.size() && str.at(offset) == '-' ) { if( offset < str.size() && str.at(offset) == '-' ) {
isNegative = true; isNegative = true;
++offset; ++offset;
@ -606,7 +606,7 @@ struct JSONParser {
break; break;
} }
} }
exp = chaiscript::parse_num<long>( exp_str ) * (isExpNegative?-1:1); exp = chaiscript::parse_num<int64_t>( exp_str ) * (isExpNegative?-1:1);
} }
else if( offset < str.size() && (!isspace( c ) && c != ',' && c != ']' && c != '}' )) { else if( offset < str.size() && (!isspace( c ) && c != ',' && c != ']' && c != '}' )) {
throw std::runtime_error(std::string("JSON ERROR: Number: unexpected character '") + c + "'"); throw std::runtime_error(std::string("JSON ERROR: Number: unexpected character '") + c + "'");
@ -617,9 +617,9 @@ struct JSONParser {
return JSON((isNegative?-1:1) * chaiscript::parse_num<double>( val ) * std::pow( 10, exp )); return JSON((isNegative?-1:1) * chaiscript::parse_num<double>( val ) * std::pow( 10, exp ));
} else { } else {
if( !exp_str.empty() ) { if( !exp_str.empty() ) {
return JSON((isNegative?-1:1) * static_cast<double>(chaiscript::parse_num<long>( val )) * std::pow( 10, exp )); return JSON((isNegative?-1:1) * static_cast<double>(chaiscript::parse_num<int64_t>( val )) * std::pow( 10, exp ));
} else { } else {
return JSON((isNegative?-1:1) * chaiscript::parse_num<long>( val )); return JSON((isNegative?-1:1) * chaiscript::parse_num<int64_t>( val ));
} }
} }
} }