Go to the documentation of this file.
10 #ifndef MSGPACK_DEFINE_DECL_HPP
11 #define MSGPACK_DEFINE_DECL_HPP
13 #if defined(MSGPACK_NO_BOOST)
19 #if !defined(MSGPACK_PP_VARIADICS)
20 #define MSGPACK_PP_VARIADICS
25 #define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
26 #define MSGPACK_NVP(name, value) (name) (value)
28 #define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
30 MSGPACK_PP_IS_BEGIN_PARENS(elem), \
32 (MSGPACK_PP_STRINGIZE(elem))(elem) \
35 #define MSGPACK_DEFINE_MAP_IMPL(...) \
36 MSGPACK_PP_SEQ_TO_TUPLE( \
37 MSGPACK_PP_SEQ_FOR_EACH( \
38 MSGPACK_DEFINE_MAP_EACH_PROC, \
40 MSGPACK_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
44 #define MSGPACK_DEFINE_MAP(...) \
45 template <typename Packer> \
46 void msgpack_pack(Packer& msgpack_pk) const \
48 msgpack::type::make_define_map \
49 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
50 .msgpack_pack(msgpack_pk); \
52 void msgpack_unpack(msgpack::object const& msgpack_o) \
54 msgpack::type::make_define_map \
55 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
56 .msgpack_unpack(msgpack_o); \
58 template <typename MSGPACK_OBJECT> \
59 void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
61 msgpack::type::make_define_map \
62 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
63 .msgpack_object(msgpack_o, msgpack_z); \
66 #define MSGPACK_BASE_MAP(base) \
67 (MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
75 #if !defined(BOOST_PP_VARIADICS)
76 #define BOOST_PP_VARIADICS
79 #include <boost/preprocessor.hpp>
81 #define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
82 #define MSGPACK_NVP(name, value) (name) (value)
84 #define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
86 BOOST_PP_IS_BEGIN_PARENS(elem), \
88 (BOOST_PP_STRINGIZE(elem))(elem) \
91 #define MSGPACK_DEFINE_MAP_IMPL(...) \
92 BOOST_PP_SEQ_TO_TUPLE( \
93 BOOST_PP_SEQ_FOR_EACH( \
94 MSGPACK_DEFINE_MAP_EACH_PROC, \
96 BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
100 #define MSGPACK_DEFINE_MAP(...) \
101 template <typename Packer> \
102 void msgpack_pack(Packer& msgpack_pk) const \
104 msgpack::type::make_define_map \
105 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
106 .msgpack_pack(msgpack_pk); \
108 void msgpack_unpack(msgpack::object const& msgpack_o) \
110 msgpack::type::make_define_map \
111 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
112 .msgpack_unpack(msgpack_o); \
114 template <typename MSGPACK_OBJECT> \
115 void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
117 msgpack::type::make_define_map \
118 MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
119 .msgpack_object(msgpack_o, msgpack_z); \
122 #define MSGPACK_BASE_MAP(base) \
123 (BOOST_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
132 #define MSGPACK_DEFINE_ARRAY(...) \
133 template <typename Packer> \
134 void msgpack_pack(Packer& msgpack_pk) const \
136 msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
138 void msgpack_unpack(msgpack::object const& msgpack_o) \
140 msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
142 template <typename MSGPACK_OBJECT> \
143 void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
145 msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
149 #define MSGPACK_ADD_ENUM(enum_name) \
150 namespace msgpack { \
152 MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { \
154 namespace adaptor { \
156 struct convert<enum_name> { \
157 msgpack::object const& operator()(msgpack::object const& msgpack_o, enum_name& msgpack_v) const { \
158 msgpack::underlying_type<enum_name>::type tmp; \
159 msgpack::operator>>(msgpack_o, tmp); \
160 msgpack_v = static_cast<enum_name>(tmp); \
165 struct object<enum_name> { \
166 void operator()(msgpack::object& msgpack_o, const enum_name& msgpack_v) const { \
167 msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v); \
168 msgpack::operator<<(msgpack_o, tmp); \
172 struct object_with_zone<enum_name> { \
173 void operator()(msgpack::object::with_zone& msgpack_o, const enum_name& msgpack_v) const { \
174 msgpack::underlying_type<enum_name>::type tmp = static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v); \
175 msgpack::operator<<(msgpack_o, tmp); \
179 struct pack<enum_name> { \
180 template <typename Stream> \
181 msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& msgpack_o, const enum_name& msgpack_v) const { \
182 return msgpack::operator<<(msgpack_o, static_cast<msgpack::underlying_type<enum_name>::type>(msgpack_v)); \
191 #if defined(MSGPACK_USE_DEFINE_MAP)
192 #define MSGPACK_DEFINE MSGPACK_DEFINE_MAP
193 #define MSGPACK_BASE MSGPACK_BASE_MAP
195 #define MSGPACK_DEFINE MSGPACK_DEFINE_ARRAY
196 #define MSGPACK_BASE MSGPACK_BASE_ARRAY