De-macro helpers.

This commit is contained in:
Daniel Kirchner 2022-11-01 12:49:22 +01:00
parent c23093e0f0
commit 74be278242

View File

@ -73,36 +73,33 @@ namespace detail
template<typename T> template<typename T>
struct helper; struct helper;
#define DEFINE_JSON_CONVERSION_HELPERS(TYPE, CHECK_TYPE_MEMBER, CONVERT_TYPE_MEMBER) \ template<typename T, bool(Json::Value::*checkMember)() const, T(Json::Value::*convertMember)() const>
template<> \ struct helper_impl
struct helper<TYPE> \ {
{ \ static bool isOfType(Json::Value const& _input)
static bool isOfType(Json::Value const& _input) \ {
{ \ return (_input.*checkMember)();
return _input.CHECK_TYPE_MEMBER(); \ }
} \ static T get(Json::Value const& _input)
static TYPE get(Json::Value const& _input) \ {
{ \ return (_input.*convertMember)();
return _input.CONVERT_TYPE_MEMBER(); \ }
} \ static T getOrDefault(Json::Value const& _input, T _default = {})
static TYPE getOrDefault(Json::Value const& _input, TYPE _default = {}) \ {
{ \ T result = _default;
TYPE result = _default; \ if (isOfType(_input))
if (helper::isOfType(_input)) \ result = (_input.*convertMember)();
result = _input.CONVERT_TYPE_MEMBER(); \ return result;
return result; \ }
} \ };
};
DEFINE_JSON_CONVERSION_HELPERS(float, isDouble, asFloat) template<> struct helper<float>: helper_impl<float, &Json::Value::isDouble, &Json::Value::asFloat> {};
DEFINE_JSON_CONVERSION_HELPERS(double, isDouble, asDouble) template<> struct helper<double>: helper_impl<double, &Json::Value::isDouble, &Json::Value::asDouble> {};
DEFINE_JSON_CONVERSION_HELPERS(std::string, isString, asString) template<> struct helper<std::string>: helper_impl<std::string, &Json::Value::isString, &Json::Value::asString> {};
DEFINE_JSON_CONVERSION_HELPERS(Json::Int, isInt, asInt) template<> struct helper<Json::Int>: helper_impl<Json::Int, &Json::Value::isInt, &Json::Value::asInt> {};
DEFINE_JSON_CONVERSION_HELPERS(Json::Int64, isInt64, asInt64) template<> struct helper<Json::Int64>: helper_impl<Json::Int64, &Json::Value::isInt64, &Json::Value::asInt64> {};
DEFINE_JSON_CONVERSION_HELPERS(Json::UInt, isUInt, asUInt) template<> struct helper<Json::UInt>: helper_impl<Json::UInt, &Json::Value::isUInt, &Json::Value::asUInt> {};
DEFINE_JSON_CONVERSION_HELPERS(Json::UInt64, isUInt64, asUInt64) template<> struct helper<Json::UInt64>: helper_impl<Json::UInt64, &Json::Value::isUInt64, &Json::Value::asUInt64> {};
#undef DEFINE_JSON_CONVERSION_HELPERS
} // namespace detail } // namespace detail