aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
config.hpp
1 //
2 // config.hpp
3 // **********
4 //
5 // Copyright (c) 2019 Sharon W (sharon at aegis dot gg)
6 //
7 // Distributed under the MIT License. (See accompanying file LICENSE)
8 //
9 
10 #pragma once
11 
12 #include "aegis/version.hpp"
13 #include "aegis/fwd.hpp"
14 
15 #if !defined(ASIO_NO_DEPRECATED)
16 #define ASIO_NO_DEPRECATED
17 #endif
18 
19 #if !defined(ASIO_STANDALONE)
20 #define ASIO_STANDALONE
21 #endif
22 
23 #if !defined(ASIO_HEADER_ONLY) && !defined(ASIO_DYN_LINK) && !defined(ASIO_SEPARATE_COMPILATION)
24 #define ASIO_HEADER_ONLY
25 #endif
26 
27 #if !defined(_WEBSOCKETPP_CPP11_STL_)
28 #define _WEBSOCKETPP_CPP11_STL_
29 #endif
30 
31 // Shamelessly make use of ASIO's config-style
32 
33 // Default to a header-only implementation. The user must specifically request
34 // separate compilation by defining either AEGIS_SEPARATE_COMPILATION or
35 // AEGIS_DYN_LINK (as a DLL/shared library implies separate compilation).
36 #if !defined(AEGIS_HEADER_ONLY)
37 # if !defined(AEGIS_SEPARATE_COMPILATION)
38 # if !defined(AEGIS_DYN_LINK)
39 # define AEGIS_HEADER_ONLY 1
40 # endif // !defined(AEGIS_DYN_LINK)
41 # endif // !defined(AEGIS_SEPARATE_COMPILATION)
42 #endif // !defined(AEGIS_HEADER_ONLY)
43 
44 #if defined(AEGIS_HEADER_ONLY)
45 # define AEGIS_DECL inline
46 #else // defined(AEGIS_HEADER_ONLY)
47 # if defined(_MSC_VER)
48 // We need to import/export our code only if the user has specifically asked
49 // for it by defining AEGIS_DYN_LINK.
50 # if defined(AEGIS_DYN_LINK)
51 // Export if this is our own source, otherwise import.
52 # if defined(AEGIS_SOURCE)
53 # define AEGIS_DECL __declspec(dllexport)
54 # else // defined(AEGIS_SOURCE)
55 # define AEGIS_DECL __declspec(dllimport)
56 # endif // defined(AEGIS_SOURCE)
57 # endif // defined(AEGIS_DYN_LINK)
58 # endif // defined(_MSC_VER)
59 #endif // defined(AEGIS_HEADER_ONLY)
60 
61 // If AEGIS_DECL isn't defined yet define it now.
62 #if !defined(AEGIS_DECL)
63 # define AEGIS_DECL
64 #endif // !defined(AEGIS_DECL)
65 
66 // Microsoft Visual C++ detection.
67 #if !defined(AEGIS_MSVC)
68 # if defined(_MSC_VER) && (defined(__INTELLISENSE__) \
69  || (!defined(__MWERKS__) && !defined(__EDG_VERSION__)))
70 # define AEGIS_MSVC _MSC_VER
71 # endif // defined(_MSC_VER) && defined(__INTELLISENSE__)
72  //|| (!defined(__MWERKS__) && !defined(__EDG_VERSION__)))
73 #endif // defined(AEGIS_MSVC)
74 #if defined(AEGIS_MSVC)
75 # include <ciso646> // Needed for _HAS_CXX17.
76 #endif // defined(AEGIS_MSVC)
77 
78 // Workaround for Microsoft Visual C++ __cplusplus value
79 #if defined(AEGIS_MSVC)
80 # if (_MSVC_LANG < 201402)
81 # error AegisLib requires C++14 or greater
82 # endif
83 #else
84 # if (__cplusplus < 201402)
85 # error AegisLib requires C++14 or greater
86 # endif
87 #endif
88 
89 #if (__cplusplus >= 201703) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703) || (defined(_HAS_CXX17) && _HAS_CXX17 != 0)
90 # define AEGIS_CXX17
91 #endif // (__cplusplus >= 201703) || (_MSVC_LANG >= 201703)
92 
93 // Support for std::optional over built-in
94 #if !defined(AEGIS_HAS_STD_OPTIONAL)
95 # if (__cplusplus >= 201703)
96 # if __has_include(<optional>)
97 # include <optional>
98 namespace aegis::lib
99 {
100 template<typename T> using optional = std::optional<T>;
101 constexpr auto nullopt = std::nullopt;
102 using bad_optional_access = std::bad_optional_access;
103 }
104 # define AEGIS_HAS_STD_OPTIONAL 1
105 # elif __has_include(<experimental/optional>)
106 # include <experimental/optional>
107 namespace aegis::lib
108 {
109 template<typename T> using optional = std::experimental::optional<T>;
110 constexpr auto nullopt = std::experimental::nullopt;
111 using bad_optional_access = std::experimental::bad_optional_access;
112 }
113 # define AEGIS_HAS_STD_OPTIONAL 1
114 # endif // __has_include(<optional>)
115 # elif (__cplusplus >= 201402) // c++14
116 # include "aegis/optional.hpp"
117 namespace aegis
118 {
119 namespace lib
120 {
121 template<typename T> using optional = std::experimental::optional<T>;
122 constexpr auto nullopt = std::experimental::nullopt;
123 using bad_optional_access = std::experimental::bad_optional_access;
124 }
125 }
126 # define AEGIS_HAS_STD_OPTIONAL 1
127 # define AEGIS_HAS_BUILTIN_OPTIONAL 1
128 # endif // (__cplusplus >= 201703)
129 # if defined(AEGIS_MSVC)
130 # if (_MSVC_LANG < 201703)
131 # include "aegis/optional.hpp"
132 namespace aegis
133 {
134 namespace lib
135 {
136 template<typename T> using optional = std::experimental::optional<T>;
137 constexpr auto nullopt = std::experimental::nullopt;
138 using bad_optional_access = std::experimental::bad_optional_access;
139 }
140 }
141 # define AEGIS_HAS_STD_OPTIONAL 1
142 # define AEGIS_HAS_BUILTIN_OPTIONAL 1
143 # else
144 # include <optional>
145 namespace aegis::lib
146 {
147 template<typename T> using optional = std::optional<T>;
148 constexpr auto nullopt = std::nullopt;
149 using bad_optional_access = std::bad_optional_access;
150 }
151 # define AEGIS_HAS_STD_OPTIONAL 1
152 # endif // (_MSC_VER >= 1910 && _HAS_CXX17)
153 # endif // defined(AEGIS_MSVC)
154 #endif // !defined(AEGIS_HAS_STD_OPTIONAL)
155 
156 #if !defined(AEGIS_HAS_STD_OPTIONAL)
157 # error Could not find a suitable optional library.
158 #endif
159 
160 // use std::shared_timed_mutex on C++14 or shared_mutex on C++17
161 #if !defined(AEGIS_HAS_STD_SHARED_MUTEX)
162 # if !defined(AEGIS_DISABLE_STD_SHARED_MUTEX)
163 # if (__cplusplus >= 201703) || (_MSVC_LANG >= 201703)
164 # define AEGIS_HAS_STD_SHARED_MUTEX 1
165 # endif // (__cplusplus >= 201703) || (_MSVC_LANG >= 201703)
166 # endif // !defined(AEGIS_DISABLE_STD_SHARED_MUTEX)
167 # if !defined(AEGIS_HAS_STD_SHARED_MUTEX)
168 # define AEGIS_HAS_STD_SHARED_MUTEX 0
169 # endif // !defined(AEGIS_HAS_STD_SHARED_MUTEX)
170 #endif // !defined(AEGIS_HAS_STD_SHARED_MUTEX)
171 
172 #if !defined(NDEBUG)
173 #include <cassert>
174 #endif
175 
177 #if defined(DEBUG) || defined(_DEBUG)
178 #define AEGIS_DEBUG(logger, ...) if (logger->should_log(spdlog::level::level_enum::debug)) logger->debug(__VA_ARGS__)
179 #define SPDLOG_STR_H(x) #x
180 #define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
181 #ifdef AEGIS_MSVC
182 #define AEGIS_TRACE(logger, ...) if (logger->should_log(spdlog::level::level_enum::trace)) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
183 #else
184 #define AEGIS_TRACE(logger, ...) if (logger->should_log(spdlog::level::level_enum::trace)) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
185 #endif
186 
187 #else
188 #define AEGIS_DEBUG(logger, ...) (void)0
189 #define AEGIS_TRACE(logger, ...) (void)0
190 #endif