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