fix long longs on linux

This commit is contained in:
Thomas Fussell 2015-10-02 01:57:39 -04:00
parent 8dc7342137
commit effe0e9340
4 changed files with 70 additions and 0 deletions

View File

@ -124,6 +124,10 @@ public:
void set_value(std::uint64_t i); void set_value(std::uint64_t i);
#ifdef _WIN32 #ifdef _WIN32
void set_value(unsigned long i); void set_value(unsigned long i);
#endif
#ifdef __linux__
void set_value(long long i);
void set_value(unsigned long long i);
#endif #endif
void set_value(float f); void set_value(float f);
void set_value(double d); void set_value(double d);

View File

@ -39,6 +39,10 @@ public:
explicit value(std::uint64_t i); explicit value(std::uint64_t i);
#ifdef _WIN32 #ifdef _WIN32
explicit value(unsigned long i); explicit value(unsigned long i);
#endif
#ifdef __linux__
explicit value(long long i);
explicit value(unsigned long long i);
#endif #endif
explicit value(float f); explicit value(float f);
explicit value(double d); explicit value(double d);

View File

@ -349,6 +349,18 @@ void cell::set_value(unsigned long i)
} }
#endif #endif
#ifdef __linux__
void cell::set_value(long long i)
{
d_->value_ = value(i);
}
void cell::set_value(unsigned long long i)
{
d_->value_ = value(i);
}
#endif
void cell::set_value(double d) void cell::set_value(double d)
{ {
d_->value_ = value(d); d_->value_ = value(d);

View File

@ -70,6 +70,16 @@ value::value(unsigned long i) : type_(type::numeric), numeric_value_(i)
} }
#endif #endif
#ifdef __linux__
value::value(long long i) : type_(type::numeric), numeric_value_(i)
{
}
value::value(unsigned long long i) : type_(type::numeric), numeric_value_(i)
{
}
#endif
value::value(float f) : type_(type::numeric), numeric_value_(f) value::value(float f) : type_(type::numeric), numeric_value_(f)
{ {
} }
@ -323,6 +333,46 @@ unsigned long value::as() const
} }
#endif #endif
#ifdef __linux__
template<>
long long value::as() const
{
switch (type_)
{
case type::boolean:
case type::numeric:
return static_cast<long long>(numeric_value_);
case type::string:
return std::stoi(string_value_);
case type::error:
throw std::runtime_error("invalid");
case type::null:
return 0;
}
return 0;
}
template<>
unsigned long long value::as() const
{
switch (type_)
{
case type::boolean:
case type::numeric:
return static_cast<unsigned long long>(numeric_value_);
case type::string:
return std::stoi(string_value_);
case type::error:
throw std::runtime_error("invalid");
case type::null:
return 0;
}
return 0;
}
#endif
template<> template<>
std::string value::as() const std::string value::as() const
{ {