Go to the documentation of this file.
10 #ifndef MSGPACK_DEFINE_DECL_HPP
11 #define MSGPACK_DEFINE_DECL_HPP
17 #if !defined(BOOST_PP_VARIADICS)
18 #define BOOST_PP_VARIADICS
21 #include <boost/preprocessor.hpp>
28 #define MSGPACK_DEFINE_ARRAY(...) \
29 template <typename Packer> \
30 void msgpack_pack(Packer& msgpack_pk) const \
32 msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
34 void msgpack_unpack(msgpack::object const& msgpack_o) \
36 msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
38 template <typename MSGPACK_OBJECT> \
39 void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
41 msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
44 #define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
45 #define MSGPACK_NVP(name, value) (name) (value)
47 #define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
49 BOOST_PP_IS_BEGIN_PARENS(elem), \
51 (BOOST_PP_STRINGIZE(elem))(elem) \
54 #define MSGPACK_DEFINE_MAP_IMPL(...) \
55 BOOST_PP_SEQ_TO_TUPLE( \
56 BOOST_PP_SEQ_FOR_EACH( \
57 MSGPACK_DEFINE_MAP_EACH_PROC, \
59 BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
63 #define MSGPACK_DEFINE_MAP(...) \
64 template <typename Packer> \
65 void msgpack_pack(Packer& msgpack_pk) const \
67 msgpack::type::make_define_map \
68 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
69 .msgpack_pack(msgpack_pk); \
71 void msgpack_unpack(msgpack::object const& msgpack_o) \
73 msgpack::type::make_define_map \
74 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
75 .msgpack_unpack(msgpack_o); \
77 template <typename MSGPACK_OBJECT> \
78 void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
80 msgpack::type::make_define_map \
81 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
82 .msgpack_object(msgpack_o, msgpack_z); \
85 #define MSGPACK_BASE_MAP(base) \
86 (BOOST_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
89 #define MSGPACK_ADD_ENUM(enum_name) \
92 MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { \
96 struct convert<enum_name> { \
97 msgpack::object const& operator()(msgpack::object const& msgpack_o, enum_name& msgpack_v) const { \
98 msgpack::underlying_type<enum_name>::type tmp; \
99 msgpack::operator>>(msgpack_o, tmp); \
100 msgpack_v = static_cast<enum_name>(tmp); \
105 struct object<enum_name> { \
106 void operator()(msgpack::object& msgpack_o, const enum_name& msgpack_v) const { \
107 msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v); \
108 msgpack::operator<<(msgpack_o, tmp); \
112 struct object_with_zone<enum_name> { \
113 void operator()(msgpack::object::with_zone& msgpack_o, const enum_name& msgpack_v) const { \
114 msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v); \
115 msgpack::operator<<(msgpack_o, tmp); \
119 struct pack<enum_name> { \
120 template <typename Stream> \
121 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& msgpack_o, const enum_name& msgpack_v) const { \
122 return msgpack::operator<<(msgpack_o, static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v)); \
131 #if defined(MSGPACK_USE_DEFINE_MAP)
132 #define MSGPACK_DEFINE MSGPACK_DEFINE_MAP
133 #define MSGPACK_BASE MSGPACK_BASE_MAP
135 #define MSGPACK_DEFINE MSGPACK_DEFINE_ARRAY
136 #define MSGPACK_BASE MSGPACK_BASE_ARRAY