Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2021-2024 ChilliBits. All rights reserved. | ||
2 | |||
3 | #pragma once | ||
4 | |||
5 | #include <cassert> | ||
6 | |||
7 | #ifdef __GNUC__ | ||
8 | #pragma GCC diagnostic push | ||
9 | #pragma GCC diagnostic ignored "-Wattributes" | ||
10 | #endif | ||
11 | |||
12 | // Add this to the function signature to force inlining the function | ||
13 | #define ALWAYS_INLINE __attribute__((always_inline)) | ||
14 | |||
15 | // Casts a pointer to another pointer type and asserts that the cast was successful in debug mode | ||
16 | template <typename T> ALWAYS_INLINE static T spice_pointer_cast(auto source) { | ||
17 | static_assert(std::is_pointer_v<decltype(source)>, "Source is not a pointer type"); | ||
18 |
14/28✓ Branch 0 taken 15390 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15390 times.
✓ Branch 5 taken 13476 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 13476 times.
✓ Branch 10 taken 23320 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 23320 times.
✓ Branch 15 taken 539 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 539 times.
✓ Branch 20 taken 111 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 111 times.
✓ Branch 25 taken 539 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 539 times.
✓ Branch 30 taken 23 times.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✓ Branch 33 taken 23 times.
|
53398 | assert(dynamic_cast<T>(source) != nullptr); |
19 | 53398 | return static_cast<T>(source); | |
20 | } | ||
21 | |||
22 | // Fail with an assertion error message | ||
23 | #define assert_fail(msg) assert(false && (msg)) | ||
24 | |||
25 | #ifdef __GNUC__ | ||
26 | #pragma GCC diagnostic pop | ||
27 | #endif | ||
28 |