Add macros for template version of DEFINE_TYPE_{NON_,}INTRUSIVE

This commit is contained in:
Kunal Tyagi 2021-06-26 21:56:17 +09:00
parent 028a397f2f
commit efe20d5391
2 changed files with 68 additions and 0 deletions

View File

@ -469,6 +469,40 @@
{ \
}
/*!
@brief macro to briefly define intrusive serialization of a given type to/from any basic_json object
@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_T
@since version 3.9.2
*/
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(Type, ...) \
template<typename BasicJsonType> \
friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
} \
template<typename BasicJsonType> \
friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
}
/*!
@brief macro to briefly define non-intrusive serialization of a given type to/from any basic_json object
@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T
@since version 3.9.2
*/
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(Type, ...) \
template<typename BasicJsonType> \
void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
} \
template<typename BasicJsonType> \
void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
}
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
#define JSON_USE_IMPLICIT_CONVERSIONS 1
#endif

View File

@ -2684,6 +2684,40 @@ using is_detected_convertible =
{ \
}
/*!
@brief macro to briefly define intrusive serialization of a given type to/from any basic_json object
@def NLOHMANN_DEFINE_TYPE_INTRUSIVE_T
@since version 3.9.2
*/
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_T(Type, ...) \
template<typename BasicJsonType> \
friend void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
} \
template<typename BasicJsonType> \
friend void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
} \
/*!
@brief macro to briefly define non-intrusive serialization of a given type to/from any basic_json object
@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T
@since version 3.9.2
*/
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_T(Type, ...) \
template<typename BasicJsonType> \
void to_json(BasicJsonType& nlohmann_json_j, const Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \
} \
template<typename BasicJsonType> \
void from_json(const BasicJsonType& nlohmann_json_j, Type& nlohmann_json_t) \
{ \
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) \
}
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
#define JSON_USE_IMPLICIT_CONVERSIONS 1
#endif