1 /* 2 * MessagePack for C++ version switcher 3 * 4 * Copyright (C) 2014 KONDO Takatoshi 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #ifndef MSGPACK_VERSIONING_HPP 19 #define MSGPACK_VERSIONING_HPP 20 21 #if !defined(MSGPACK_DEFAULT_API_VERSION) 22 #define MSGPACK_DEFAULT_API_VERSION 1 23 #endif 24 25 #define MSGPACK_DEFAULT_API_NS MSGPACK_DETAIL_PP_CAT(v, MSGPACK_DEFAULT_API_VERSION) 26 27 #if MSGPACK_DEFAULT_API_VERSION == 1 28 #define MSGPACK_DETAIL_PP_ENABLE_NS_v1 () 29 //#elif MSGPACK_DEFAULT_API_VERSION == 2 30 //#define MSGPACK_DETAIL_PP_ENABLE_NS_v2 () 31 #else 32 #error 33 #endif 34 35 #define MSGPACK_DETAIL_PP_CAT(a, ...) MSGPACK_DETAIL_PP_PRIMITIVE_CAT(a, __VA_ARGS__) 36 #define MSGPACK_DETAIL_PP_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ 37 38 #define MSGPACK_DETAIL_PP_IIF(c) MSGPACK_DETAIL_PP_PRIMITIVE_CAT(MSGPACK_DETAIL_PP_IIF_, c) 39 #define MSGPACK_DETAIL_PP_IIF_0(t, ...) __VA_ARGS__ 40 #define MSGPACK_DETAIL_PP_IIF_1(t, ...) t 41 42 #define MSGPACK_DETAIL_PP_PROBE(x) x, 1 43 44 #if defined(_MSC_VER) 45 46 #define MSGPACK_DETAIL_PP_MSVC_VA_ARGS_WORKAROUND(define, args) define args 47 #define MSGPACK_DETAIL_PP_CHECK(...) MSGPACK_DETAIL_PP_MSVC_VA_ARGS_WORKAROUND(MSGPACK_DETAIL_PP_CHECK_N, (__VA_ARGS__, 0)) 48 #define MSGPACK_DETAIL_PP_CHECK_N(x, n, ...) n 49 50 #else // defined(__MSC_VER) 51 52 #define MSGPACK_DETAIL_PP_CHECK(...) MSGPACK_DETAIL_PP_CHECK_N(__VA_ARGS__, 0) 53 #define MSGPACK_DETAIL_PP_CHECK_N(x, n, ...) n 54 55 #endif // defined(__MSC_VER) 56 57 58 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE(ns) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PROXY( MSGPACK_DETAIL_PP_ENABLE_NS_##ns ) 59 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PROXY(...) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PRIMIVIE(__VA_ARGS__) 60 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_PRIMIVIE(x) MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_COMBINE_ x 61 #define MSGPACK_DETAIL_PP_NS_ENABLED_PROBE_COMBINE_(...) MSGPACK_DETAIL_PP_PROBE(~) 62 63 #define MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns) MSGPACK_DETAIL_PP_CHECK(MSGPACK_DETAIL_PP_NS_ENABLED_PROBE(ns)) 64 65 #if __cplusplus < 201103L 66 #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_DETAIL_PP_IIF(MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns)) \ 67 (namespace ns{}; using namespace ns; namespace ns, \ 68 namespace ns) 69 70 #else // __cplusplus < 201103L 71 72 #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_DETAIL_PP_IIF(MSGPACK_DETAIL_PP_IS_NS_ENABLED(ns)) \ 73 (inline namespace ns, namespace ns) 74 75 #endif // __cplusplus < 201103L 76 77 #endif // MSGPACK_VERSIONING_HPP 78