diff --git a/json11.cpp b/json11.cpp index d60c84f..e0ae291 100644 --- a/json11.cpp +++ b/json11.cpp @@ -169,6 +169,7 @@ protected: }; class JsonDouble final : public Value { + bool bool_value() const override { return m_value != 0; } double number_value() const override { return static_cast(m_value); } int64_ int64_value() const override { return static_cast(m_value); } uint64_ uint64_value() const override { return static_cast(m_value); } @@ -179,6 +180,7 @@ public: }; class JsonInt64 final : public Value { + bool bool_value() const override { return m_value != 0; } double number_value() const override { return static_cast(m_value); } int64_ int64_value() const override { return static_cast(m_value); } uint64_ uint64_value() const override { return static_cast(m_value); } @@ -189,6 +191,7 @@ public: }; class JsonUInt64 final : public Value { + bool bool_value() const override { return m_value != 0; } double number_value() const override { return static_cast(m_value); } int64_ int64_value() const override { return static_cast(m_value); } uint64_ uint64_value() const override { return static_cast(m_value); } @@ -206,6 +209,7 @@ public: class JsonString final : public 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; } 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; }