Add string,number->bool conversions
parent
97f06cb20c
commit
3a5b4477bc
|
@ -169,6 +169,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonDouble final : public Value<Json::NUMBER, double> {
|
class JsonDouble final : public Value<Json::NUMBER, double> {
|
||||||
|
bool bool_value() const override { return m_value != 0; }
|
||||||
double number_value() const override { return static_cast<double>(m_value); }
|
double number_value() const override { return static_cast<double>(m_value); }
|
||||||
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
||||||
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
||||||
|
@ -179,6 +180,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonInt64 final : public Value<Json::NUMBER, int64_> {
|
class JsonInt64 final : public Value<Json::NUMBER, int64_> {
|
||||||
|
bool bool_value() const override { return m_value != 0; }
|
||||||
double number_value() const override { return static_cast<double>(m_value); }
|
double number_value() const override { return static_cast<double>(m_value); }
|
||||||
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
||||||
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
||||||
|
@ -189,6 +191,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class JsonUInt64 final : public Value<Json::NUMBER, uint64_> {
|
class JsonUInt64 final : public Value<Json::NUMBER, uint64_> {
|
||||||
|
bool bool_value() const override { return m_value != 0; }
|
||||||
double number_value() const override { return static_cast<double>(m_value); }
|
double number_value() const override { return static_cast<double>(m_value); }
|
||||||
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); }
|
||||||
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
uint64_ uint64_value() const override { return static_cast<uint64_>(m_value); }
|
||||||
|
@ -206,6 +209,7 @@ public:
|
||||||
|
|
||||||
class JsonString final : public Value<Json::STRING, string> {
|
class JsonString final : public Value<Json::STRING, string> {
|
||||||
const string &string_value() const override { return m_value; }
|
const string &string_value() const override { return m_value; }
|
||||||
|
bool bool_value() const override { return m_value != "" && m_value != "0"; }
|
||||||
double number_value() const override { size_t pos = 0; double v = std::stod(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
double number_value() const override { size_t pos = 0; double v = std::stod(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
||||||
int64_ int64_value() const override { size_t pos = 0; int64_ v = std::stoll(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
int64_ int64_value() const override { size_t pos = 0; int64_ v = std::stoll(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
||||||
uint64_ uint64_value() const override { size_t pos = 0; uint64_ v = std::stoull(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
uint64_ uint64_value() const override { size_t pos = 0; uint64_ v = std::stoull(m_value, &pos); if (pos < m_value.length()) { v = 0; } return v; }
|
||||||
|
|
Loading…
Reference in New Issue