|
10 | 10 | #ifndef MSGPACK_DEFINE_DECL_HPP |
11 | 11 | #define MSGPACK_DEFINE_DECL_HPP |
12 | 12 |
|
13 | | -// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp |
| 13 | +#if defined(MSGPACK_NO_BOOST) |
| 14 | + |
| 15 | +// MSGPACK_PP_VARIADICS is defined in msgpack/preprocessor/config/config.hpp |
14 | 16 | // http://www.boost.org/libs/preprocessor/doc/ref/variadics.html |
15 | 17 | // However, supporting compiler detection is not complete. msgpack-c requires |
16 | | -// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly. |
17 | | -#if !defined(BOOST_PP_VARIADICS) |
18 | | -#define BOOST_PP_VARIADICS |
| 18 | +// variadic macro arguments support. So MSGPACK_PP_VARIADICS is defined here explicitly. |
| 19 | +#if !defined(MSGPACK_PP_VARIADICS) |
| 20 | +#define MSGPACK_PP_VARIADICS |
19 | 21 | #endif |
20 | 22 |
|
21 | | -#include <boost/preprocessor.hpp> |
| 23 | +#include <msgpack/preprocessor.hpp> |
22 | 24 |
|
23 | | -#include "msgpack/versioning.hpp" |
| 25 | +#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this))) |
| 26 | +#define MSGPACK_NVP(name, value) (name) (value) |
24 | 27 |
|
25 | | -// for MSGPACK_ADD_ENUM |
26 | | -#include "msgpack/adaptor/int.hpp" |
| 28 | +#define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \ |
| 29 | + MSGPACK_PP_IF( \ |
| 30 | + MSGPACK_PP_IS_BEGIN_PARENS(elem), \ |
| 31 | + elem, \ |
| 32 | + (MSGPACK_PP_STRINGIZE(elem))(elem) \ |
| 33 | + ) |
27 | 34 |
|
28 | | -#define MSGPACK_DEFINE_ARRAY(...) \ |
| 35 | +#define MSGPACK_DEFINE_MAP_IMPL(...) \ |
| 36 | + MSGPACK_PP_SEQ_TO_TUPLE( \ |
| 37 | + MSGPACK_PP_SEQ_FOR_EACH( \ |
| 38 | + MSGPACK_DEFINE_MAP_EACH_PROC, \ |
| 39 | + 0, \ |
| 40 | + MSGPACK_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \ |
| 41 | + ) \ |
| 42 | + ) |
| 43 | + |
| 44 | +#define MSGPACK_DEFINE_MAP(...) \ |
29 | 45 | template <typename Packer> \ |
30 | 46 | void msgpack_pack(Packer& msgpack_pk) const \ |
31 | 47 | { \ |
32 | | - msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \ |
| 48 | + msgpack::type::make_define_map \ |
| 49 | + MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \ |
| 50 | + .msgpack_pack(msgpack_pk); \ |
33 | 51 | } \ |
34 | 52 | void msgpack_unpack(msgpack::object const& msgpack_o) \ |
35 | 53 | { \ |
36 | | - msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \ |
| 54 | + msgpack::type::make_define_map \ |
| 55 | + MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \ |
| 56 | + .msgpack_unpack(msgpack_o); \ |
37 | 57 | }\ |
38 | 58 | template <typename MSGPACK_OBJECT> \ |
39 | 59 | void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \ |
40 | 60 | { \ |
41 | | - msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \ |
| 61 | + msgpack::type::make_define_map \ |
| 62 | + MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \ |
| 63 | + .msgpack_object(msgpack_o, msgpack_z); \ |
42 | 64 | } |
43 | 65 |
|
| 66 | +#define MSGPACK_BASE_MAP(base) \ |
| 67 | + (MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this))) |
| 68 | + |
| 69 | +#else // defined(MSGPACK_NO_BOOST) |
| 70 | + |
| 71 | +// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp |
| 72 | +// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html |
| 73 | +// However, supporting compiler detection is not complete. msgpack-c requires |
| 74 | +// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly. |
| 75 | +#if !defined(BOOST_PP_VARIADICS) |
| 76 | +#define BOOST_PP_VARIADICS |
| 77 | +#endif |
| 78 | + |
| 79 | +#include <boost/preprocessor.hpp> |
| 80 | + |
44 | 81 | #define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this))) |
45 | 82 | #define MSGPACK_NVP(name, value) (name) (value) |
46 | 83 |
|
|
85 | 122 | #define MSGPACK_BASE_MAP(base) \ |
86 | 123 | (BOOST_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this))) |
87 | 124 |
|
| 125 | +#endif // defined(MSGPACK_NO_BOOST) |
| 126 | + |
| 127 | +#include "msgpack/versioning.hpp" |
| 128 | + |
| 129 | +// for MSGPACK_ADD_ENUM |
| 130 | +#include "msgpack/adaptor/int.hpp" |
| 131 | + |
| 132 | +#define MSGPACK_DEFINE_ARRAY(...) \ |
| 133 | + template <typename Packer> \ |
| 134 | + void msgpack_pack(Packer& msgpack_pk) const \ |
| 135 | + { \ |
| 136 | + msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \ |
| 137 | + } \ |
| 138 | + void msgpack_unpack(msgpack::object const& msgpack_o) \ |
| 139 | + { \ |
| 140 | + msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \ |
| 141 | + }\ |
| 142 | + template <typename MSGPACK_OBJECT> \ |
| 143 | + void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \ |
| 144 | + { \ |
| 145 | + msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \ |
| 146 | + } |
| 147 | + |
88 | 148 | // MSGPACK_ADD_ENUM must be used in the global namespace. |
89 | 149 | #define MSGPACK_ADD_ENUM(enum_name) \ |
90 | 150 | namespace msgpack { \ |
|
0 commit comments