packio
config.h
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
5 #ifndef PACKIO_CONFIG_H
6 #define PACKIO_CONFIG_H
7 
8 #include <mutex>
9 #include <unordered_map>
10 #include <utility>
11 
12 #if !defined(PACKIO_HAS_MSGPACK)
13 #define PACKIO_HAS_MSGPACK __has_include(<msgpack.hpp>)
14 #endif // !defined(PACKIO_HAS_MSGPACK)
15 
16 #if !defined(PACKIO_HAS_NLOHMANN_JSON)
17 #define PACKIO_HAS_NLOHMANN_JSON __has_include(<nlohmann/json.hpp>)
18 #endif // !defined(PACKIO_HAS_NLOHMANN_JSON)
19 
20 #if !defined(PACKIO_HAS_BOOST_JSON)
21 #define PACKIO_HAS_BOOST_JSON __has_include(<boost/json.hpp>)
22 #endif // !defined(PACKIO_HAS_BOOST_JSON)
23 
24 #if !defined(PACKIO_STANDALONE_ASIO)
25 // If we cannot find boost but we can find asio, fallback to it
26 #define PACKIO_STANDALONE_ASIO (!__has_include(<boost/asio.hpp>) && __has_include(<asio.hpp>))
27 #endif // !defined(PACKIO_STANDALONE_ASIO)
28 
29 #if PACKIO_STANDALONE_ASIO
30 #include <asio.hpp>
31 #else // defined(PACKIO_STANDALONE_ASIO)
32 #include <boost/asio.hpp>
33 #endif // PACKIO_STANDALONE_ASIO
34 
35 #if defined(BOOST_ASIO_HAS_CO_AWAIT) || defined(ASIO_HAS_CO_AWAIT) \
36  || defined(PACKIO_DOCUMENTATION)
37 #define PACKIO_HAS_CO_AWAIT 1
38 #endif
39 
40 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) || defined(ASIO_HAS_LOCAL_SOCKETS) \
41  || defined(PACKIO_DOCUMENTATION)
42 #define PACKIO_HAS_LOCAL_SOCKETS 1
43 #endif
44 
45 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
46 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
47  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(e)
48 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN)
49 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) ASIO_DEFAULT_COMPLETION_TOKEN(e)
50 #elif defined(PACKIO_DOCUMENTATION)
51 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
52  = typename net::default_completion_token<e>::type()
53 #else
54 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e)
55 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN)
56 
57 #if defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
58 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
59  BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
60 #elif defined(ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
61 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e) \
62  ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
63 #elif defined(PACKIO_DOCUMENTATION)
64 #define PACKIO_DEFAULT_COMPLETION_TOKEN(e) \
65  = typename net::default_completion_token<e>::type
66 #else
67 #define PACKIO_DEFAULT_COMPLETION_TOKEN_TYPE(e)
68 #endif // defined(BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE)
69 
70 #if defined(BOOST_ASIO_COMPLETION_TOKEN_FOR)
71 #define PACKIO_COMPLETION_TOKEN_FOR(s) BOOST_ASIO_COMPLETION_TOKEN_FOR(s)
72 #elif defined(ASIO_COMPLETION_TOKEN_FOR)
73 #define PACKIO_COMPLETION_TOKEN_FOR(s) ASIO_COMPLETION_TOKEN_FOR(s)
74 #else
75 #define PACKIO_COMPLETION_TOKEN_FOR(s) typename
76 #endif // defined (BOOST_ASIO_COMPLETION_TOKEN_FOR)
77 
78 namespace packio {
79 
80 #if PACKIO_STANDALONE_ASIO
81 namespace net = ::asio;
82 using error_code = std::error_code;
83 using system_error = std::system_error;
84 using error_category = std::error_category;
85 #else // defined(PACKIO_STANDALONE_ASIO)
86 namespace net = ::boost::asio;
87 using error_code = boost::system::error_code;
88 using system_error = boost::system::system_error;
89 using error_category = boost::system::error_category;
90 #endif // PACKIO_STANDALONE_ASIO
91 
92 template <typename... Args>
93 using default_map = std::unordered_map<Args...>;
94 using default_mutex = std::mutex;
95 
96 namespace internal {
97 
98 #if PACKIO_STANDALONE_ASIO
99 #if ASIO_VERSION >= 101700
100 using any_io_executor = net::any_io_executor;
101 #else // ASIO_VERSION >= 101700
102 using any_io_executor = net::executor;
103 #endif // ASIO_VERSION >= 101700
104 #else // PACKIO_STANDALONE_ASIO
105 #if BOOST_VERSION >= 107400
106 using any_io_executor = net::any_io_executor;
107 #else // BOOST_VERSION >= 107400
108 using any_io_executor = net::executor;
109 #endif // BOOST_VERSION >= 107400
110 #endif // PACKIO_STANDALONE_ASIO
111 
112 } // internal
113 } // packio
114 
115 #endif // PACKIO_CONFIG_H
The packio namespace.
Definition: arg.h:14