Variant: Support 64-bit numeric values

Closes #2101.
This commit is contained in:
Tomas Babej 2021-01-01 23:57:34 -05:00
parent c4cdfdae64
commit a641e4315f
No known key found for this signature in database
GPG key ID: B0747C6578F7D2F5
2 changed files with 9 additions and 9 deletions

View file

@ -1838,7 +1838,7 @@ void Variant::cast (const enum type new_type)
case type_string: case type_string:
{ {
char temp[24]; char temp[24];
snprintf (temp, 24, "%d", _integer); snprintf (temp, 24, "%lld", _integer);
_string = temp; _string = temp;
} }
break; break;
@ -1851,7 +1851,7 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _real == 0.0 ? false : true; break; case type_boolean: _bool = _real == 0.0 ? false : true; break;
case type_integer: _integer = (int) _real; break; case type_integer: _integer = (long long) _real; break;
case type_real: break; case type_real: break;
case type_string: case type_string:
{ {
@ -1875,9 +1875,9 @@ void Variant::cast (const enum type new_type)
_string == "0.0") ? false : true; _string == "0.0") ? false : true;
break; break;
case type_integer: case type_integer:
_integer = (int) strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10)); _integer = (long long) strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10));
break; break;
case type_real: _real = strtod (_string.c_str (), nullptr); break; case type_real: _real = strtod (_string.c_str (), nullptr); break;
case type_string: break; case type_string: break;
case type_date: case type_date:
{ {
@ -1926,7 +1926,7 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _date != 0 ? true : false; break; case type_boolean: _bool = _date != 0 ? true : false; break;
case type_integer: _integer = (int) _date; break; case type_integer: _integer = (long long) _date; break;
case type_real: _real = static_cast<double>(_date); break; case type_real: _real = static_cast<double>(_date); break;
case type_string: _string = (std::string) *this; break; case type_string: _string = (std::string) *this; break;
case type_date: break; case type_date: break;
@ -1938,7 +1938,7 @@ void Variant::cast (const enum type new_type)
switch (new_type) switch (new_type)
{ {
case type_boolean: _bool = _duration != 0 ? true : false; break; case type_boolean: _bool = _duration != 0 ? true : false; break;
case type_integer: _integer = (int) _duration; break; case type_integer: _integer = (long long) _duration; break;
case type_real: _real = static_cast<double>(_duration); break; case type_real: _real = static_cast<double>(_duration); break;
case type_string: _string = (std::string) *this; break; case type_string: _string = (std::string) *this; break;
case type_date: _date = _duration; break; case type_date: _date = _duration; break;
@ -1973,7 +1973,7 @@ bool Variant::get_bool () const
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int Variant::get_integer () const long long Variant::get_integer () const
{ {
return _integer; return _integer;
} }

View file

@ -99,7 +99,7 @@ public:
bool trivial () const; bool trivial () const;
bool get_bool () const; bool get_bool () const;
int get_integer () const; long long get_integer () const;
double get_real () const; double get_real () const;
const std::string& get_string () const; const std::string& get_string () const;
time_t get_date () const; time_t get_date () const;
@ -108,7 +108,7 @@ public:
private: private:
enum type _type {type_boolean}; enum type _type {type_boolean};
bool _bool {false}; bool _bool {false};
int _integer {0}; long long _integer {0};
double _real {0.0}; double _real {0.0};
std::string _string {""}; std::string _string {""};
time_t _date {0}; time_t _date {0};