@@ -73,36 +73,33 @@ namespace detail
73
73
template <typename T>
74
74
struct helper ;
75
75
76
- #define DEFINE_JSON_CONVERSION_HELPERS (TYPE, CHECK_TYPE_MEMBER, CONVERT_TYPE_MEMBER ) \
77
- template <> \
78
- struct helper <TYPE> \
79
- { \
80
- static bool isOfType (Json::Value const & _input) \
81
- { \
82
- return _input.CHECK_TYPE_MEMBER (); \
83
- } \
84
- static TYPE get (Json::Value const & _input) \
85
- { \
86
- return _input.CONVERT_TYPE_MEMBER (); \
87
- } \
88
- static TYPE getOrDefault (Json::Value const & _input, TYPE _default = {}) \
89
- { \
90
- TYPE result = _default; \
91
- if (helper::isOfType (_input)) \
92
- result = _input.CONVERT_TYPE_MEMBER (); \
93
- return result; \
94
- } \
95
- };
96
-
97
- DEFINE_JSON_CONVERSION_HELPERS (float , isDouble, asFloat)
98
- DEFINE_JSON_CONVERSION_HELPERS (double , isDouble, asDouble)
99
- DEFINE_JSON_CONVERSION_HELPERS (std::string, isString, asString)
100
- DEFINE_JSON_CONVERSION_HELPERS (Json::Int, isInt, asInt)
101
- DEFINE_JSON_CONVERSION_HELPERS (Json::Int64, isInt64, asInt64)
102
- DEFINE_JSON_CONVERSION_HELPERS (Json::UInt, isUInt, asUInt)
103
- DEFINE_JSON_CONVERSION_HELPERS (Json::UInt64, isUInt64, asUInt64)
76
+ template <typename T, bool (Json::Value::*checkMember)() const , T(Json::Value::*convertMember)() const >
77
+ struct helper_impl
78
+ {
79
+ static bool isOfType (Json::Value const & _input)
80
+ {
81
+ return (_input.*checkMember)();
82
+ }
83
+ static T get (Json::Value const & _input)
84
+ {
85
+ return (_input.*convertMember)();
86
+ }
87
+ static T getOrDefault (Json::Value const & _input, T _default = {})
88
+ {
89
+ T result = _default;
90
+ if (isOfType (_input))
91
+ result = (_input.*convertMember)();
92
+ return result;
93
+ }
94
+ };
104
95
105
- #undef DEFINE_JSON_CONVERSION_HELPERS
96
+ template <> struct helper <float >: helper_impl<float , &Json::Value::isDouble, &Json::Value::asFloat> {};
97
+ template <> struct helper <double >: helper_impl<double , &Json::Value::isDouble, &Json::Value::asDouble> {};
98
+ template <> struct helper <std::string>: helper_impl<std::string, &Json::Value::isString, &Json::Value::asString> {};
99
+ template <> struct helper <Json::Int>: helper_impl<Json::Int, &Json::Value::isInt, &Json::Value::asInt> {};
100
+ template <> struct helper <Json::Int64>: helper_impl<Json::Int64, &Json::Value::isInt64, &Json::Value::asInt64> {};
101
+ template <> struct helper <Json::UInt>: helper_impl<Json::UInt, &Json::Value::isUInt, &Json::Value::asUInt> {};
102
+ template <> struct helper <Json::UInt64>: helper_impl<Json::UInt64, &Json::Value::isUInt64, &Json::Value::asUInt64> {};
106
103
107
104
} // namespace detail
108
105
0 commit comments