| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | /** @file | ||
| 30 | * @brief Basic gate namespace typedefs and utility interfaces | ||
| 31 | * @ingroup gatecore_cpp | ||
| 32 | */ | ||
| 33 | |||
| 34 | |||
| 35 | #ifndef GATE_GATETYPES_HPP_INCLUDED | ||
| 36 | #define GATE_GATETYPES_HPP_INCLUDED | ||
| 37 | |||
| 38 | #include "gate/gate_core_api.hpp" | ||
| 39 | #include "gate/gatetypes.h" | ||
| 40 | |||
| 41 | #if defined(_MSC_VER) | ||
| 42 | |||
| 43 | # if (_MSC_VER <= 1309) | ||
| 44 | /* VC++ 6.0 + VC++ 7.0 */ | ||
| 45 | # define GATE_COMPILER_USE_ENUMS_AS_TEMPLATE_CONSTANTS 1 | ||
| 46 | # endif | ||
| 47 | |||
| 48 | # if (_MSC_VER >= 1310) /* VC++ 2003 or newer */ | ||
| 49 | # define GATE_COMPILER_SUPPORTS_CPP_ARRAY_SIZE_DEDUCTION 1 | ||
| 50 | # define GATE_COMPILER_SUPPORTS_CPP_PARTIAL_TEMPLATE_SPECIALIZATION 1 | ||
| 51 | # endif | ||
| 52 | |||
| 53 | # if (_MSC_VER >= 1600) /* VC++ 2010 or newer */ | ||
| 54 | # define GATE_COMPILER_SUPPORTS_CPP_AUTO 1 | ||
| 55 | # define GATE_COMPILER_SUPPORTS_CPP_DECLTYPE 1 | ||
| 56 | # define GATE_COMPILER_SUPPORTS_CPP_MOVEREFS 1 | ||
| 57 | # define GATE_COMPILER_SUPPORTS_CPP_OVERRIDE 1 | ||
| 58 | # define GATE_COMPILER_SUPPORTS_CPP_LAMBDA 1 | ||
| 59 | # define GATE_COMPILER_SUPPORTS_CPP_STD11 1 /* C++11 support available */ | ||
| 60 | |||
| 61 | # endif | ||
| 62 | |||
| 63 | # if (_MSC_VER >= 1700) /* VC++ 2012 or newer */ | ||
| 64 | # define GATE_COMPILER_SUPPORTS_CPP_FINAL 1 | ||
| 65 | # endif | ||
| 66 | |||
| 67 | # if (_MSC_VER >= 1800) /* VC++ 2013 or newer */ | ||
| 68 | # if (_MSC_VER < 1900) | ||
| 69 | # define GATEXX_ATTR_NORETURN __declspec(noreturn) | ||
| 70 | # endif | ||
| 71 | # endif | ||
| 72 | |||
| 73 | # if (_MSC_VER >= 1900) /* VC++ 2015 or newer */ | ||
| 74 | # define GATE_COMPULER_SUPPORTS_CPP_NORETURN 1 | ||
| 75 | # define GATE_COMPILER_SUPPORTS_CPP_CONSTEXPR 1 | ||
| 76 | # define GATE_COMPILER_SUPPORTS_CPP_NOEXCEPT 1 | ||
| 77 | # endif | ||
| 78 | |||
| 79 | # if (_MSC_VER < 1900) /* prior VC 2015 */ | ||
| 80 | # if (_MSC_VER >= 1700) /* special case for VC2012: allow C++ macro-keywords like noexcept */ | ||
| 81 | # define _ALLOW_KEYWORD_MACROS 1 | ||
| 82 | # endif | ||
| 83 | # endif | ||
| 84 | |||
| 85 | #endif | ||
| 86 | |||
| 87 | #if defined(__GNUC__) || defined(__clang__) | ||
| 88 | # define GATE_COMPILER_SUPPORTS_CPP_ARRAY_SIZE_DEDUCTION 1 | ||
| 89 | # define GATE_COMPILER_SUPPORTS_CPP_PARTIAL_TEMPLATE_SPECIALIZATION 1 | ||
| 90 | |||
| 91 | # if __cplusplus >= 201103L | ||
| 92 | # define GATE_COMPILER_SUPPORTS_CPP_AUTO 1 | ||
| 93 | # define GATE_COMPILER_SUPPORTS_CPP_DECLTYPE 1 | ||
| 94 | # define GATE_COMPILER_SUPPORTS_CPP_MOVEREFS 1 | ||
| 95 | # define GATE_COMPILER_SUPPORTS_CPP_OVERRIDE 1 | ||
| 96 | # define GATE_COMPILER_SUPPORTS_CPP_LAMBDA 1 | ||
| 97 | # define GATE_COMPILER_SUPPORTS_CPP_STD11 1 | ||
| 98 | # define GATE_COMPILER_SUPPORTS_CPP_FINAL 1 | ||
| 99 | # define GATE_COMPILER_SUPPORTS_CPP_NOEXCEPT 1 | ||
| 100 | # define GATE_COMPILER_SUPPORTS_CPP_CONSTEXPR 1 | ||
| 101 | # endif | ||
| 102 | #endif | ||
| 103 | |||
| 104 | #if defined(__WATCOMC__) | ||
| 105 | # define GATE_COMPILER_SUPPORTS_CPP_PARTIAL_TEMPLATE_SPECIALIZATION | ||
| 106 | /* no further C++11 features expected */ | ||
| 107 | #endif | ||
| 108 | |||
| 109 | |||
| 110 | #if !defined(GATE_COMPILER_SUPPORTS_CPP_NOEXCEPT) | ||
| 111 | # define noexcept throw() | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #if !defined(GATE_COMPILER_SUPPORTS_CPP_OVERRIDE) | ||
| 115 | # define override | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #if !defined(GATE_COMPILER_SUPPORTS_CPP_FINAL) | ||
| 119 | # define final | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #if !defined(GATE_COMPILER_SUPPORTS_CPP_CONSTEXPR) | ||
| 123 | # define constexpr const | ||
| 124 | # define GATE_CONSTEXPR_VAR | ||
| 125 | # define GATE_CONSTEXPR_FUNC | ||
| 126 | #else | ||
| 127 | # define GATE_CONSTEXPR_VAR constexpr | ||
| 128 | # define GATE_CONSTEXPR_FUNC constexpr | ||
| 129 | #endif | ||
| 130 | |||
| 131 | #if !defined(GATEXX_ATTR_NORETURN) | ||
| 132 | # if defined(GATE_COMPULER_SUPPORTS_CPP_NORETURN) | ||
| 133 | # define GATEXX_ATTR_NORETURN [[noreturn]] | ||
| 134 | # else | ||
| 135 | # define GATEXX_ATTR_NORETURN | ||
| 136 | # endif | ||
| 137 | #endif | ||
| 138 | |||
| 139 | namespace gate | ||
| 140 | { | ||
| 141 | |||
| 142 | #if __cplusplus >= 201103L | ||
| 143 | # define GATEXX_TYPE_ALIAS(existing_name, new_name) using new_name = existing_name | ||
| 144 | #else | ||
| 145 | # define GATEXX_TYPE_ALIAS(existing_name, new_name) typedef existing_name new_name | ||
| 146 | #endif | ||
| 147 | GATEXX_TYPE_ALIAS(::gate_char8_t, char_8_t); | ||
| 148 | GATEXX_TYPE_ALIAS(::gate_char16_t, char_16_t); | ||
| 149 | GATEXX_TYPE_ALIAS(::gate_char32_t, char_32_t); | ||
| 150 | |||
| 151 | GATEXX_TYPE_ALIAS(::gate_bool_t, bool_t); | ||
| 152 | GATEXX_TYPE_ALIAS(::gate_int8_t, int8_t); | ||
| 153 | GATEXX_TYPE_ALIAS(::gate_int16_t, int16_t); | ||
| 154 | GATEXX_TYPE_ALIAS(::gate_int32_t, int32_t); | ||
| 155 | GATEXX_TYPE_ALIAS(::gate_int64_t, int64_t); | ||
| 156 | GATEXX_TYPE_ALIAS(::gate_uint8_t, uint8_t); | ||
| 157 | GATEXX_TYPE_ALIAS(::gate_uint16_t, uint16_t); | ||
| 158 | GATEXX_TYPE_ALIAS(::gate_uint32_t, uint32_t); | ||
| 159 | GATEXX_TYPE_ALIAS(::gate_uint64_t, uint64_t); | ||
| 160 | |||
| 161 | GATEXX_TYPE_ALIAS(::gate_real32_t, real32_t); | ||
| 162 | GATEXX_TYPE_ALIAS(::gate_real64_t, real64_t); | ||
| 163 | |||
| 164 | GATEXX_TYPE_ALIAS(::gate_intptr_t, intptr_t); | ||
| 165 | GATEXX_TYPE_ALIAS(::gate_uintptr_t, uintptr_t); | ||
| 166 | GATEXX_TYPE_ALIAS(::gate_size_t, size_t); | ||
| 167 | GATEXX_TYPE_ALIAS(::gate_index_t, index_t); | ||
| 168 | |||
| 169 | GATEXX_TYPE_ALIAS(::gate_result_t, result_t); | ||
| 170 | GATEXX_TYPE_ALIAS(::gate_enumint_t, enumint_t); | ||
| 171 | GATEXX_TYPE_ALIAS(::gate_handle_t, handle_t); | ||
| 172 | |||
| 173 | GATEXX_TYPE_ALIAS(::gate_hash_code_t, hash_code_t); | ||
| 174 | |||
| 175 | |||
| 176 | GATE_CORE_CPP_API extern void panic(result_t resultCode, char const* source); | ||
| 177 | |||
| 178 | #define GATE_PANIC(resultCode) panic(resultCode, GATE_CURRENT_FUNCTION_NAME) | ||
| 179 | |||
| 180 | |||
| 181 | /// @brief | ||
| 182 | class GATE_CORE_CPP_API IRunnable | ||
| 183 | { | ||
| 184 | public: | ||
| 185 | virtual ~IRunnable() noexcept; | ||
| 186 | |||
| 187 | virtual void run() = 0; | ||
| 188 | }; | ||
| 189 | |||
| 190 | |||
| 191 | /// @brief | ||
| 192 | class GATE_CORE_CPP_API IQuitable | ||
| 193 | { | ||
| 194 | public: | ||
| 195 | virtual ~IQuitable() noexcept; | ||
| 196 | |||
| 197 | virtual void quit() = 0; | ||
| 198 | }; | ||
| 199 | |||
| 200 | |||
| 201 | /// @brief | ||
| 202 | class GATE_CORE_CPP_API ICancelable | ||
| 203 | { | ||
| 204 | public: | ||
| 205 | virtual ~ICancelable() noexcept; | ||
| 206 | |||
| 207 | virtual void cancel() = 0; | ||
| 208 | }; | ||
| 209 | |||
| 210 | |||
| 211 | /// @brief | ||
| 212 | class UnusableType | ||
| 213 | { | ||
| 214 | private: | ||
| 215 | UnusableType(); | ||
| 216 | UnusableType(UnusableType&); | ||
| 217 | UnusableType& operator=(UnusableType&); | ||
| 218 | ~UnusableType(); | ||
| 219 | public: | ||
| 220 | static const bool value; | ||
| 221 | }; | ||
| 222 | |||
| 223 | |||
| 224 | /// @brief | ||
| 225 | /// @tparam T | ||
| 226 | template<class T> | ||
| 227 | class SafeBoolBase | ||
| 228 | { | ||
| 229 | private: | ||
| 230 | ✗ | void safe_bool_method() const | |
| 231 | { | ||
| 232 | ✗ | } | |
| 233 | |||
| 234 | public: | ||
| 235 | typedef void(SafeBoolBase::* bool_type)() const; | ||
| 236 | |||
| 237 | public: | ||
| 238 | 3 | operator bool_type() const | |
| 239 | { | ||
| 240 | 3 | T const& derived_impl = *static_cast<T const*>(this); | |
| 241 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
|
3 | return !derived_impl ? 0 : &SafeBoolBase<T>::safe_bool_method; |
| 242 | } | ||
| 243 | }; | ||
| 244 | |||
| 245 | struct GATE_CORE_CPP_API NonCopyable | ||
| 246 | { | ||
| 247 | private: | ||
| 248 | NonCopyable(NonCopyable const&); | ||
| 249 | NonCopyable& operator=(NonCopyable const&); | ||
| 250 | protected: | ||
| 251 | 572 | NonCopyable() noexcept {} | |
| 252 | }; | ||
| 253 | |||
| 254 | #if defined(GATE_COMPILER_SUPPORTS_CPP_MOVEREFS) | ||
| 255 | # define GATE_MOVEREF(type) type && | ||
| 256 | #else | ||
| 257 | # define GATE_MOVEREF(type) UnusableType & | ||
| 258 | #endif | ||
| 259 | |||
| 260 | 148 | template<class T, class U> T union_cast(U src) | |
| 261 | { | ||
| 262 | union | ||
| 263 | { | ||
| 264 | U src; | ||
| 265 | T dst; | ||
| 266 | } converter; | ||
| 267 | |||
| 268 | 148 | converter.src = src; | |
| 269 | 148 | return converter.dst; | |
| 270 | } | ||
| 271 | |||
| 272 | } | ||
| 273 | |||
| 274 | #define GATE_ENUM_FLAGS_DECLARE(enum_type) \ | ||
| 275 | template<class T> T operator|(T const& a, enum_type const& b) \ | ||
| 276 | { \ | ||
| 277 | return static_cast< T >(static_cast<int>(a) | static_cast<int>(b)); \ | ||
| 278 | } \ | ||
| 279 | template<class T> T operator&(T const& a, enum_type const& b) \ | ||
| 280 | { \ | ||
| 281 | return static_cast< T >(static_cast<int>(a) & static_cast<int>(b)); \ | ||
| 282 | } \ | ||
| 283 | template<class T> T operator==(T const& a, enum_type const& b) \ | ||
| 284 | { \ | ||
| 285 | return static_cast<int>(a) == static_cast<int>(b); \ | ||
| 286 | } | ||
| 287 | |||
| 288 | #endif | ||
| 289 |