src/util/GlobalDefinitions.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <cassert> | ||
| 6 | #include <type_traits> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #ifdef __GNUC__ | ||
| 10 | #pragma GCC diagnostic push | ||
| 11 | #pragma GCC diagnostic ignored "-Wattributes" | ||
| 12 | #endif | ||
| 13 | |||
| 14 | // Add this to the function signature to force inlining the function | ||
| 15 | #define ALWAYS_INLINE __attribute__((always_inline)) | ||
| 16 | |||
| 17 | // Checks if a pointer is of a certain type | ||
| 18 | template <typename DstT, typename SrcT> | ||
| 19 | ALWAYS_INLINE static bool is(SrcT source) { | ||
| 20 |
19/38✓ Branch 2 → 3 taken 32093 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 64722 times.
✗ Branch 3 → 5 not taken.
✓ Branch 5 → 6 taken 39231 times.
✗ Branch 5 → 7 not taken.
✓ Branch 6 → 7 taken 122850 times.
✗ Branch 6 → 8 not taken.
✓ Branch 7 → 8 taken 245876 times.
✗ Branch 7 → 9 not taken.
✓ Branch 8 → 9 taken 332 times.
✗ Branch 8 → 10 not taken.
✓ Branch 14 → 15 taken 332 times.
✗ Branch 14 → 16 not taken.
✓ Branch 20 → 21 taken 596 times.
✗ Branch 20 → 22 not taken.
✓ Branch 24 → 25 taken 401465 times.
✗ Branch 24 → 26 not taken.
✓ Branch 25 → 26 taken 8528 times.
✗ Branch 25 → 27 not taken.
✓ Branch 26 → 27 taken 8966 times.
✗ Branch 26 → 28 not taken.
✓ Branch 28 → 29 taken 7200 times.
✗ Branch 28 → 30 not taken.
✓ Branch 32 → 33 taken 332 times.
✗ Branch 32 → 34 not taken.
✓ Branch 36 → 37 taken 10029 times.
✗ Branch 36 → 38 not taken.
✓ Branch 57 → 58 taken 108 times.
✗ Branch 57 → 59 not taken.
✓ Branch 58 → 59 taken 102365 times.
✗ Branch 58 → 60 not taken.
✓ Branch 61 → 62 taken 28773 times.
✗ Branch 61 → 63 not taken.
✓ Branch 85 → 86 taken 23242 times.
✗ Branch 85 → 87 not taken.
✓ Branch 99 → 100 taken 298246 times.
✗ Branch 99 → 101 not taken.
|
1395286 | return dynamic_cast<DstT>(source) != nullptr; |
| 21 | } | ||
| 22 | |||
| 23 | // Casts a pointer to another pointer type and asserts that the cast was successful in debug mode | ||
| 24 | template <typename DstT, typename SrcT> | ||
| 25 | ALWAYS_INLINE static DstT spice_pointer_cast(SrcT source) | ||
| 26 | requires(std::is_pointer_v<SrcT> && std::is_pointer_v<DstT>) | ||
| 27 | { | ||
| 28 |
14/28✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 31739 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 64722 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 39231 times.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 122850 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 245876 times.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 264 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 401465 times.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 8528 times.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 8634 times.
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 7200 times.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 10029 times.
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 22 times.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 68 taken 28773 times.
✗ Branch 90 → 91 not taken.
✓ Branch 90 → 92 taken 23242 times.
|
992575 | assert(is<DstT>(source)); |
| 29 | 992575 | return static_cast<DstT>(source); | |
| 30 | } | ||
| 31 | |||
| 32 | // Compile time check, if T is a vector of a class, that is derived from BaseT | ||
| 33 | template <typename T, typename BaseT> struct is_vector_of_derived_from { | ||
| 34 | using ElTy = std::remove_pointer_t<typename T::value_type>; | ||
| 35 | static constexpr bool value = std::is_base_of_v<BaseT, ElTy> && std::is_same_v<T, std::vector<typename T::value_type>>; | ||
| 36 | }; | ||
| 37 | template <typename T, typename BaseT> constexpr bool is_vector_of_derived_from_v = is_vector_of_derived_from<T, BaseT>::value; | ||
| 38 | |||
| 39 | // Fail with an assertion error message | ||
| 40 | #define assert_fail(msg) assert(false && (msg)) | ||
| 41 | |||
| 42 | #ifdef NDEBUG | ||
| 43 | #define SPICE_DEBUG false | ||
| 44 | #else | ||
| 45 | #define SPICE_DEBUG true | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifdef __GNUC__ | ||
| 49 | #pragma GCC diagnostic pop | ||
| 50 | #endif | ||
| 51 |