diff --git a/src/ruc/json/fromjson.h b/src/ruc/json/fromjson.h index 4e8b82f..0a027f3 100644 --- a/src/ruc/json/fromjson.h +++ b/src/ruc/json/fromjson.h @@ -18,6 +18,7 @@ #include "ruc/json/array.h" #include "ruc/json/object.h" #include "ruc/meta/assert.h" +#include "ruc/meta/concepts.h" #include "ruc/meta/odr.h" namespace ruc::json { @@ -45,36 +46,15 @@ void fromJson(const Json& json, bool& boolean) boolean = json.asBool(); } -template -void fromJson(const Json& json, int32_t& number) +template +void fromJson(const Json& json, T& number) { VERIFY(json.type() == Json::Type::Number); - number = static_cast(json.asDouble()); + number = static_cast(json.asDouble()); } -template -void fromJson(const Json& json, uint32_t& number) -{ - VERIFY(json.type() == Json::Type::Number); - number = static_cast(json.asDouble()); -} - -template -void fromJson(const Json& json, int64_t& number) -{ - VERIFY(json.type() == Json::Type::Number); - number = static_cast(json.asDouble()); -} - -template -void fromJson(const Json& json, size_t& number) // uint64_t -{ - VERIFY(json.type() == Json::Type::Number); - number = static_cast(json.asDouble()); -} - -template -void fromJson(const Json& json, double& number) +template +void fromJson(const Json& json, T& number) { VERIFY(json.type() == Json::Type::Number); number = json.asDouble(); diff --git a/src/ruc/json/tojson.h b/src/ruc/json/tojson.h index a20fb67..4c3774f 100644 --- a/src/ruc/json/tojson.h +++ b/src/ruc/json/tojson.h @@ -15,6 +15,7 @@ #include "ruc/json/array.h" #include "ruc/json/object.h" +#include "ruc/meta/concepts.h" #include "ruc/meta/odr.h" namespace ruc::json { @@ -30,46 +31,22 @@ struct jsonConstructor { json.m_value.boolean = boolean; } - template - static void construct(Json& json, int32_t number) - { - json.destroy(); - json.m_type = Json::Type::Number; - json.m_value.number = static_cast(number); - } - - template - static void construct(Json& json, int64_t number) - { - json.destroy(); - json.m_type = Json::Type::Number; - json.m_value.number = static_cast(number); - } - - template - static void construct(Json& json, uint32_t number) + template + static void construct(Json& json, T number) { json.destroy(); json.m_type = Json::Type::Number; json.m_value.number = static_cast(number); } - template - static void construct(Json& json, size_t number) + template + static void construct(Json& json, T number) { json.destroy(); json.m_type = Json::Type::Number; json.m_value.number = static_cast(number); } - template - static void construct(Json& json, double number) - { - json.destroy(); - json.m_type = Json::Type::Number; - json.m_value.number = number; - } - template static void construct(Json& json, const char* string) {