| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <cassert> | ||
| 6 | #include <type_traits> | ||
| 7 | |||
| 8 | #ifdef __GNUC__ | ||
| 9 | #pragma GCC diagnostic push | ||
| 10 | #pragma GCC diagnostic ignored "-Wattributes" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | // Add this to the function signature to force inlining the function | ||
| 14 | #define ALWAYS_INLINE __attribute__((always_inline)) | ||
| 15 | |||
| 16 | // Casts a pointer to another pointer type and asserts that the cast was successful in debug mode | ||
| 17 | template <typename DstT, typename SrcT> | ||
| 18 | ALWAYS_INLINE static DstT spice_pointer_cast(SrcT source) | ||
| 19 | requires(std::is_pointer_v<SrcT> && std::is_pointer_v<DstT>) | ||
| 20 | { | ||
| 21 |
22/40✓ Branch 2 → 3 taken 10844 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 11230 times.
✗ Branch 3 → 5 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 10844 times.
✓ Branch 6 → 7 taken 59156 times.
✓ Branch 6 → 8 taken 11230 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 59156 times.
✓ Branch 24 → 25 taken 236465 times.
✗ Branch 24 → 26 not taken.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 236465 times.
✓ Branch 39 → 40 taken 266 times.
✗ Branch 39 → 41 not taken.
✓ Branch 40 → 41 taken 167 times.
✗ Branch 40 → 42 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 266 times.
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 167 times.
✓ Branch 49 → 50 taken 26 times.
✗ Branch 49 → 51 not taken.
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 26 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 3095 times.
✗ Branch 60 → 62 not taken.
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 3095 times.
✓ Branch 83 → 84 taken 1790 times.
✗ Branch 83 → 85 not taken.
✓ Branch 86 → 87 taken 176 times.
✓ Branch 86 → 88 taken 1790 times.
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 91 taken 176 times.
|
323225 | assert(dynamic_cast<DstT>(source) != nullptr); |
| 22 | 323225 | return static_cast<DstT>(source); | |
| 23 | } | ||
| 24 | |||
| 25 | // Fail with an assertion error message | ||
| 26 | #define assert_fail(msg) assert(false && (msg)) | ||
| 27 | |||
| 28 | #ifdef __GNUC__ | ||
| 29 | #pragma GCC diagnostic pop | ||
| 30 | #endif | ||
| 31 |