 |
Sen API
Sen Libraries
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
8#ifndef SEN_CORE_BASE_COMPILER_MACROS_H
9#define SEN_CORE_BASE_COMPILER_MACROS_H
18#if defined(SEN_STRINGIFY_EX)
19# undef SEN_STRINGIFY_EX
21#define SEN_STRINGIFY_EX(x) #x
23#if defined(SEN_STRINGIFY)
26#define SEN_STRINGIFY(x) SEN_STRINGIFY_EX(x)
32#if defined(SEN_CONCAT_EX)
35#define SEN_CONCAT_EX(a, b) a##b
37#if defined(SEN_CONCAT)
40#define SEN_CONCAT(a, b) SEN_CONCAT_EX(a, b)
46#if defined(SEN_VERSION_ENCODE)
47# undef SEN_VERSION_ENCODE
49#define SEN_VERSION_ENCODE(major, minor, revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
55#if defined(SEN_VERSION_DECODE_MAJOR)
56# undef SEN_VERSION_DECODE_MAJOR
58#define SEN_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
64#if defined(SEN_VERSION_DECODE_MINOR)
65# undef SEN_VERSION_DECODE_MINOR
67#define SEN_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
73#if defined(SEN_VERSION_DECODE_REVISION)
74# undef SEN_VERSION_DECODE_REVISION
76#define SEN_VERSION_DECODE_REVISION(version) ((version) % 1000)
82#if defined(SEN_MSVC_VERSION)
83# undef SEN_MSVC_VERSION
85#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
87# define SEN_MSVC_VERSION \
88 SEN_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
89#elif defined(_MSC_FULL_VER) && !defined(__ICL)
91# define SEN_MSVC_VERSION \
92 SEN_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
93#elif defined(_MSC_VER) && !defined(__ICL)
94# define SEN_MSVC_VERSION SEN_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
97#if defined(SEN_MSVC_VERSION_CHECK)
98# undef SEN_MSVC_VERSION_CHECK
100#if !defined(SEN_MSVC_VERSION)
101# define SEN_MSVC_VERSION_CHECK(major, minor, patch) (0)
102#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
104# define SEN_MSVC_VERSION_CHECK(major, minor, patch) \
105 (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
106#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
108# define SEN_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
110# define SEN_MSVC_VERSION_CHECK(major, minor, patch) (_MSC_VER >= ((major * 100) + (minor)))
117#if defined(SEN_GNUC_VERSION)
118# undef SEN_GNUC_VERSION
120#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
121# define SEN_GNUC_VERSION SEN_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
122#elif defined(__GNUC__)
123# define SEN_GNUC_VERSION SEN_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
126#if defined(SEN_GCC_VERSION)
127# undef SEN_GCC_VERSION
129#if defined(SEN_GNUC_VERSION) && !defined(__clang__)
130# define SEN_GCC_VERSION SEN_GNUC_VERSION
133#if defined(SEN_GCC_VERSION_CHECK)
134# undef SEN_GCC_VERSION_CHECK
136#if defined(SEN_GCC_VERSION)
138# define SEN_GCC_VERSION_CHECK(major, minor, patch) (SEN_GCC_VERSION >= SEN_VERSION_ENCODE(major, minor, patch))
140# define SEN_GCC_VERSION_CHECK_SMALLER(major, minor, patch) (SEN_GCC_VERSION < SEN_VERSION_ENCODE(major, minor, patch))
143# define SEN_GCC_VERSION_CHECK(major, minor, patch) (0)
145# define SEN_GCC_VERSION_CHECK_SMALLER(major, minor, patch) (0)
152#if defined(SEN_HAS_ATTRIBUTE)
153# undef SEN_HAS_ATTRIBUTE
155#if defined(__has_attribute)
156# define SEN_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
158# define SEN_HAS_ATTRIBUTE(attribute) (0)
165#if defined(SEN_HAS_CPP_ATTRIBUTE)
166# undef SEN_HAS_CPP_ATTRIBUTE
168#if defined(__has_cpp_attribute) && defined(__cplusplus)
169# define SEN_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
171# define SEN_HAS_CPP_ATTRIBUTE(attribute) (0)
178#if defined(SEN_HAS_BUILTIN)
179# undef SEN_HAS_BUILTIN
181#if defined(__has_builtin)
182# define SEN_HAS_BUILTIN(builtin) __has_builtin(builtin)
184# define SEN_HAS_BUILTIN(builtin) (0)
191#if defined(SEN_HAS_EXTENSION)
192# undef SEN_HAS_EXTENSION
194#if defined(__has_extension)
195# define SEN_HAS_EXTENSION(extension) __has_extension(extension)
197# define SEN_HAS_EXTENSION(extension) (0)
206#if defined(SEN_DEPRECATED)
207# undef SEN_DEPRECATED
209#if defined(SEN_DEPRECATED_FOR)
210# undef SEN_DEPRECATED_FOR
212#if SEN_MSVC_VERSION_CHECK(14, 0, 0)
213# define SEN_DEPRECATED(since) __declspec(deprecated("Since " # since))
215# define SEN_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " # since "; use " # replacement))
216#elif SEN_HAS_EXTENSION(attribute_deprecated_with_message) || SEN_GCC_VERSION_CHECK(4, 5, 0)
217# define SEN_DEPRECATED(since) __attribute__((__deprecated__("Since " # since)))
219# define SEN_DEPRECATED_FOR(since, replacement) \
220 __attribute__((__deprecated__("Since " #since "; use " #replacement)))
221#elif defined(__cplusplus) && (__cplusplus >= 201402L)
222# define SEN_DEPRECATED(since) [[deprecated("Since " # since)]]
223# define SEN_DEPRECATED_FOR(since, replacement) [[deprecated("Since " # since "; use " # replacement)]]
224#elif SEN_HAS_ATTRIBUTE(deprecated) || SEN_GCC_VERSION_CHECK(3, 1, 0)
225# define SEN_DEPRECATED(since) __attribute__((__deprecated__))
226# define SEN_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
227#elif SEN_MSVC_VERSION_CHECK(13, 10, 0)
228# define SEN_DEPRECATED(since) __declspec(deprecated)
229# define SEN_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
231# define SEN_DEPRECATED(since)
232# define SEN_DEPRECATED_FOR(since, replacement)
239#if defined(SEN_UNAVAILABLE)
240# undef SEN_UNAVAILABLE
242#if SEN_HAS_ATTRIBUTE(warning) || SEN_GCC_VERSION_CHECK(4, 3, 0)
244# define SEN_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " # available_since)))
246# define SEN_UNAVAILABLE(available_since)
255#if defined(SEN_PRINTF_FORMAT)
256# undef SEN_PRINTF_FORMAT
258#if SEN_HAS_ATTRIBUTE(format) || SEN_GCC_VERSION_CHECK(3, 1, 0)
260# define SEN_PRINTF_FORMAT(string_idx, first_to_check) \
261 __attribute__((__format__(__printf__, string_idx, first_to_check)))
263# define SEN_PRINTF_FORMAT(string_idx, first_to_check)
270#if defined(SEN_ALWAYS_INLINE)
271# undef SEN_ALWAYS_INLINE
273#if SEN_HAS_ATTRIBUTE(always_inline) || SEN_GCC_VERSION_CHECK(4, 0, 0)
274# define SEN_ALWAYS_INLINE __attribute__((__always_inline__)) inline
275#elif SEN_MSVC_VERSION_CHECK(12, 0, 0)
276# define SEN_ALWAYS_INLINE __forceinline
278# define SEN_ALWAYS_INLINE inline
285#if defined(SEN_PREDICT)
288#if defined(SEN_LIKELY)
291#if defined(SEN_UNLIKELY)
294#if defined(SEN_UNPREDICTABLE)
295# undef SEN_UNPREDICTABLE
297#if SEN_HAS_BUILTIN(__builtin_unpredictable)
298# define SEN_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
300#if SEN_HAS_BUILTIN(__builtin_expect_with_probability) || SEN_GCC_VERSION_CHECK(9, 0, 0)
303# define SEN_PREDICT(expr, value, probability) __builtin_expect_with_probability((expr), (value), (probability))
305# define SEN_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1, (probability))
307# define SEN_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0, (probability))
309# define SEN_LIKELY(expr) __builtin_expect(!!(expr), 1)
310# define SEN_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
311#elif SEN_HAS_BUILTIN(__builtin_expect) || SEN_GCC_VERSION_CHECK(3, 0, 0)
313# define SEN_PREDICT(expr, expected, probability) \
314 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (static_cast<void>(expected), (expr)))
316# define SEN_PREDICT_TRUE(expr, probability) \
318 double senProbability = (probability); \
319 ((senProbability >= 0.9) ? __builtin_expect(!!(expr), 1) \
320 : ((senProbability <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
323# define SEN_PREDICT_FALSE(expr, probability) \
325 double senProbability = (probability); \
326 ((senProbability >= 0.9) ? __builtin_expect(!!(expr), 0) \
327 : ((senProbability <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
330# define SEN_LIKELY(expr) __builtin_expect(!!(expr), 1)
331# define SEN_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
333# define SEN_PREDICT(expr, expected, probability) (static_cast<void>(expected), (expr))
334# define SEN_PREDICT_TRUE(expr, probability) (!!(expr))
335# define SEN_PREDICT_FALSE(expr, probability) (!!(expr))
336# define SEN_LIKELY(expr) (!!(expr))
337# define SEN_UNLIKELY(expr) (!!(expr))
339#if !defined(SEN_UNPREDICTABLE)
340# define SEN_UNPREDICTABLE(expr) SEN_PREDICT(expr, 1, 0.5)
347#if defined(SEN_EXPORT)
350#if defined(SEN_IMPORT)
353#if defined(_WIN32) || defined(__CYGWIN__)
355# define SEN_EXPORT __declspec(dllexport)
356# define SEN_MAYBE_EXPORT(flag) SEN_MAYBE_EXPORT_##flag
357# define SEN_MAYBE_EXPORT_true SEN_EXPORT
358# define SEN_MAYBE_EXPORT_false
359# define SEN_IMPORT __declspec(dllimport)
361# if SEN_HAS_ATTRIBUTE(visibility) || SEN_GCC_VERSION_CHECK(3, 3, 0)
362# define SEN_PRIVATE __attribute__((__visibility__("hidden")))
363# define SEN_EXPORT __attribute__((__visibility__("default")))
364# define SEN_MAYBE_EXPORT(flag) SEN_MAYBE_EXPORT_##flag
365# define SEN_MAYBE_EXPORT_true SEN_EXPORT
366# define SEN_MAYBE_EXPORT_false
378#if defined(SEN_FALL_THROUGH)
379# undef SEN_FALL_THROUGH
381#if SEN_HAS_ATTRIBUTE(fallthrough) || SEN_GCC_VERSION_CHECK(7, 0, 0)
382# define SEN_FALL_THROUGH __attribute__((__fallthrough__))
383#elif SEN_HAS_CPP_ATTRIBUTE(fallthrough)
384# define SEN_FALL_THROUGH [[fallthrough]]
385#elif defined(__fallthrough)
386# define SEN_FALL_THROUGH __fallthrough
388# define SEN_FALL_THROUGH
395#if defined(SEN_UNREACHABLE)
396# undef SEN_UNREACHABLE
398#if defined(SEN_ASSUME)
401#if SEN_MSVC_VERSION_CHECK(13, 10, 0)
402# define SEN_ASSUME(expr) __assume(expr)
403#elif SEN_HAS_BUILTIN(__builtin_assume)
404# define SEN_ASSUME(expr) __builtin_assume(expr)
406#if SEN_HAS_BUILTIN(__builtin_unreachable) || SEN_GCC_VERSION_CHECK(4, 5, 0)
407# define SEN_UNREACHABLE() __builtin_unreachable()
408#elif defined(SEN_ASSUME)
409# define SEN_UNREACHABLE() SEN_ASSUME(0)
411#if !defined(SEN_ASSUME)
412# if defined(SEN_UNREACHABLE)
413# define SEN_ASSUME(expr) static_cast<void>((expr) ? 1 : (SEN_UNREACHABLE(), 1))
415# define SEN_ASSUME(expr) static_cast<void>(expr)
419#if !defined(SEN_UNREACHABLE)
420# define SEN_UNREACHABLE() SEN_ASSUME(0)
427#if defined(SEN_RETURNS_NON_NULL)
428# undef SEN_RETURNS_NON_NULL
430#if SEN_HAS_ATTRIBUTE(returns_nonnull) || SEN_GCC_VERSION_CHECK(4, 9, 0)
431# define SEN_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
432#elif defined(_Ret_notnull_)
433# define SEN_RETURNS_NON_NULL _Ret_notnull_
435# define SEN_RETURNS_NON_NULL
442#define SEN_COPY_CONSTRUCT(classname) classname(const classname& other)
443#define SEN_COPY_ASSIGN(classname) classname& operator=(const classname& other)
444#define SEN_MOVE_CONSTRUCT(classname) classname(classname&& other) noexcept
445#define SEN_MOVE_ASSIGN(classname) classname& operator=(classname&& other) noexcept
452#define SEN_NOCOPY_NOMOVE(classname) \
453 SEN_COPY_CONSTRUCT(classname) = delete; \
454 SEN_COPY_ASSIGN(classname) = delete; \
455 SEN_MOVE_CONSTRUCT(classname) = delete; \
456 SEN_MOVE_ASSIGN(classname) = delete;
463#define SEN_MOVE_ONLY(classname) \
465 SEN_COPY_CONSTRUCT(classname) = delete; \
466 SEN_COPY_ASSIGN(classname) = delete; \
467 SEN_MOVE_CONSTRUCT(classname) = default; \
468 SEN_MOVE_ASSIGN(classname) = default; \
477#define SEN_COPY_MOVE(classname) \
479 SEN_COPY_CONSTRUCT(classname) = default; \
480 SEN_COPY_ASSIGN(classname) = default; \
481 SEN_MOVE_CONSTRUCT(classname) = default; \
482 SEN_MOVE_ASSIGN(classname) = default; \
490#define SEN_PRIVATE_TAG \
494 explicit Private() = default; \