Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add macros for template version of DEFINE_TYPE_{NON_,}INTRUSIVE
  • Loading branch information
kunaltyagi committed Jun 25, 2022
commit efe20d5391fea93ef84315868471c741ced75dc5
34 changes: 34 additions & 0 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down