|
|
|
@ -41,10 +41,6 @@ using std::move; |
|
|
|
|
* Serialization |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
static void dump(std::nullptr_t, string &out) { |
|
|
|
|
out += "null"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void dump(double value, string &out) { |
|
|
|
|
if (std::isfinite(value)) { |
|
|
|
|
char buf[32]; |
|
|
|
@ -55,10 +51,6 @@ static void dump(double value, string &out) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void dump(int value, string &out) { |
|
|
|
|
out += std::to_string(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void dump(int64_ value, string &out) { |
|
|
|
|
out += std::to_string(value); |
|
|
|
|
} |
|
|
|
@ -169,7 +161,7 @@ protected: |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class JsonDouble final : public Value<Json::NUMBER, double> { |
|
|
|
|
string as_string() const { return std::to_string(m_value); } |
|
|
|
|
string as_string() const override { return std::to_string(m_value); } |
|
|
|
|
bool bool_value() const override { return m_value != 0; } |
|
|
|
|
double number_value() const override { return static_cast<double>(m_value); } |
|
|
|
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); } |
|
|
|
@ -181,7 +173,7 @@ public: |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class JsonInt64 final : public Value<Json::NUMBER, int64_> { |
|
|
|
|
string as_string() const { return std::to_string(m_value); } |
|
|
|
|
string as_string() const override { return std::to_string(m_value); } |
|
|
|
|
bool bool_value() const override { return m_value != 0; } |
|
|
|
|
double number_value() const override { return static_cast<double>(m_value); } |
|
|
|
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); } |
|
|
|
@ -193,7 +185,7 @@ public: |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class JsonUInt64 final : public Value<Json::NUMBER, uint64_> { |
|
|
|
|
string as_string() const { return std::to_string(m_value); } |
|
|
|
|
string as_string() const override { return std::to_string(m_value); } |
|
|
|
|
bool bool_value() const override { return m_value != 0; } |
|
|
|
|
double number_value() const override { return static_cast<double>(m_value); } |
|
|
|
|
int64_ int64_value() const override { return static_cast<int64_>(m_value); } |
|
|
|
@ -211,7 +203,7 @@ public: |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class JsonString final : public Value<Json::STRING, string> { |
|
|
|
|
string as_string() const { return m_value; } |
|
|
|
|
string as_string() 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 |
|
|
|
@ -259,9 +251,23 @@ public: |
|
|
|
|
explicit JsonObject(Json::object &&value) : Value(move(value)) {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
class JsonNull final : public Value<Json::NUL, std::nullptr_t> { |
|
|
|
|
class JsonNull final : public JsonValue { |
|
|
|
|
public: |
|
|
|
|
JsonNull() : Value(nullptr) {} |
|
|
|
|
JsonNull() {} |
|
|
|
|
// Get type tag
|
|
|
|
|
Json::Type type() const override { |
|
|
|
|
return Json::NUL; |
|
|
|
|
} |
|
|
|
|
// Comparisons - only within type
|
|
|
|
|
bool equals(const JsonValue * other) const override { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
bool less(const JsonValue * other) const override { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
void dump(string &out) const override { |
|
|
|
|
out += "null"; |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/* * * * * * * * * * * * * * * * * * * *
|
|
|
|
|