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 | // Casts a pointer to another pointer type and asserts that the cast was successful in debug mode | ||
| 18 | template <typename DstT, typename SrcT> | ||
| 19 | ALWAYS_INLINE static DstT spice_pointer_cast(SrcT source) | ||
| 20 | requires(std::is_pointer_v<SrcT> && std::is_pointer_v<DstT>) | ||
| 21 | { | ||
| 22 |
18/34✓ Branch 2 → 3 taken 11086 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 11431 times.
✗ Branch 3 → 5 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 11086 times.
✓ Branch 6 → 7 taken 59966 times.
✓ Branch 6 → 8 taken 11431 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 59966 times.
✓ Branch 24 → 25 taken 238609 times.
✗ Branch 24 → 26 not taken.
✓ Branch 26 → 27 taken 115 times.
✗ Branch 26 → 28 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 238609 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 115 times.
✓ Branch 36 → 37 taken 266 times.
✗ Branch 36 → 38 not taken.
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 266 times.
✓ Branch 56 → 57 taken 10 times.
✗ Branch 56 → 58 not taken.
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 10 times.
✓ Branch 60 → 61 taken 3115 times.
✗ Branch 60 → 62 not taken.
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 3115 times.
✓ Branch 85 → 86 taken 1782 times.
✗ Branch 85 → 87 not taken.
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 90 taken 1782 times.
|
326380 | assert(dynamic_cast<DstT>(source) != nullptr); |
| 23 | 326380 | return static_cast<DstT>(source); | |
| 24 | } | ||
| 25 | |||
| 26 | // Compile time check, if T is a vector of a class, that is derived from BaseT | ||
| 27 | template <typename T, typename BaseT> struct is_vector_of_derived_from { | ||
| 28 | using ElTy = std::remove_pointer_t<typename T::value_type>; | ||
| 29 | static constexpr bool value = std::is_base_of_v<BaseT, ElTy> && std::is_same_v<T, std::vector<typename T::value_type>>; | ||
| 30 | }; | ||
| 31 | template <typename T, typename BaseT> constexpr bool is_vector_of_derived_from_v = is_vector_of_derived_from<T, BaseT>::value; | ||
| 32 | |||
| 33 | // Fail with an assertion error message | ||
| 34 | #define assert_fail(msg) assert(false && (msg)) | ||
| 35 | |||
| 36 | #ifdef __GNUC__ | ||
| 37 | #pragma GCC diagnostic pop | ||
| 38 | #endif | ||
| 39 |