MessagePack for C++
versioning.hpp
Go to the documentation of this file.
1 /*
2  * MessagePack for C++ version switcher
3  *
4  * Copyright (C) 2014 KONDO Takatoshi
5  *
6  * Distributed under the Boost Software License, Version 1.0.
7  * (See accompanying file LICENSE_1_0.txt or copy at
8  * http://www.boost.org/LICENSE_1_0.txt)
9  */
10 #ifndef MSGPACK_VERSIONING_HPP
11 #define MSGPACK_VERSIONING_HPP
12 
13 #include "msgpack/cpp_version.hpp"
14 
15 #if !defined(MSGPACK_DEFAULT_API_VERSION)
16 #define MSGPACK_DEFAULT_API_VERSION 3
17 #endif
18 
19 #define MSGPACK_DEFAULT_API_NS MSGPACK_DETAIL_PP_CAT(v, MSGPACK_DEFAULT_API_VERSION)
20 
21 #if MSGPACK_DEFAULT_API_VERSION == 1
22 #define MSGPACK_DETAIL_PP_ENABLE_NS_v1 ()
23 #elif MSGPACK_DEFAULT_API_VERSION == 2
24 #define MSGPACK_DETAIL_PP_ENABLE_NS_v2 ()
25 #elif MSGPACK_DEFAULT_API_VERSION == 3
26 #define MSGPACK_DETAIL_PP_ENABLE_NS_v3 ()
27 #else
28 #error
29 #endif
30 
31 #define MSGPACK_DETAIL_PP_CAT(a, ...) MSGPACK_DETAIL_PP_PRIMITIVE_CAT(a, __VA_ARGS__)
32 #define MSGPACK_DETAIL_PP_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
33 
34 #define MSGPACK_DETAIL_PP_IIF(c) MSGPACK_DETAIL_PP_PRIMITIVE_CAT(MSGPACK_DETAIL_PP_IIF_, c)
35 #define MSGPACK_DETAIL_PP_IIF_0(t, ...) __VA_ARGS__
36 #define MSGPACK_DETAIL_PP_IIF_1(t, ...) t
37 
38 #define MSGPACK_DETAIL_PP_PROBE(x) x, 1
39 
40 #if defined(_MSC_VER)
41 
42 #define MSGPACK_DETAIL_PP_MSVC_VA_ARGS_WORKAROUND(define, args) define args
43 #define MSGPACK_DETAIL_PP_CHECK(...) MSGPACK_DETAIL_PP_MSVC_VA_ARGS_WORKAROUND(MSGPACK_DETAIL_PP_CHECK_N, (__VA_ARGS__, 0, 0))
44 #define MSGPACK_DETAIL_PP_CHECK_N(x, n, ...) n
45 
46 #else // defined(__MSC_VER)
47 
48 #define MSGPACK_DETAIL_PP_CHECK(...) MSGPACK_DETAIL_PP_CHECK_N(__VA_ARGS__, 0, 0)
49 #define MSGPACK_DETAIL_PP_CHECK_N(x, n, ...) n
50 
51 #endif // defined(__MSC_VER)
52 
53 
54 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE(ns) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PROXY( MSGPACK_DETAIL_PP_ENABLE_NS_##ns )
55 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PROXY(...) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PRIMIVIE(__VA_ARGS__)
56 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PRIMIVIE(x) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_COMBINE_ x
57 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_COMBINE_(...) MSGPACK_DETAIL_PP_PROBE(~)
58 
59 #define MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns) MSGPACK_DETAIL_PP_CHECK(MSGPACK_DETAIL_PP_NS_ENABLED_PROBE(ns))
60 
61 #ifdef MSGPACK_USE_CPP03
62 #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_DETAIL_PP_IIF(MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns)) \
63  (namespace ns{}; using namespace ns; namespace ns, \
64  namespace ns)
65 
66 #else // MSGPACK_USE_CPP03
67 
68 #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_DETAIL_PP_IIF(MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns)) \
69  (inline namespace ns, namespace ns)
70 
71 #endif // MSGPACK_USE_CPP03
72 
73 #endif // MSGPACK_VERSIONING_HPP