| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #pragma once | |||
| 2 | ||||
| 3 | #include <cstddef> | |||
| 4 | #include <cstring> | |||
| 5 | ||||
| 6 | #include "scaled_channel.h" | |||
| 7 | #include "critical_error.h" | |||
| 8 | ||||
| 9 | /** | |||
| 10 | * Copies an array from src to dest. The lengths of the arrays must match. | |||
| 11 | */ | |||
| 12 | template <typename DElement, typename SElement, size_t N> | |||
| 13 | 23044 | constexpr void copyArray(DElement (&dest)[N], const SElement (&src)[N]) { | ||
| 14 |
48/52void copyArray<scaled_channel<unsigned char, 1, 100>, float, 8ul>(scaled_channel<unsigned char, 1, 100> (&) [8ul], float const (&) [8ul]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void copyArray<unsigned short, float, 16ul>(unsigned short (&) [16ul], float const (&) [16ul]):
✓ Branch 0 taken 10144 times.
✓ Branch 1 taken 634 times.
void copyArray<scaled_channel<unsigned char, 1, 20>, float, 16ul>(scaled_channel<unsigned char, 1, 20> (&) [16ul], float const (&) [16ul]):
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 15 times.
void copyArray<scaled_channel<unsigned char, 50, 1>, float, 8ul>(scaled_channel<unsigned char, 50, 1> (&) [8ul], float const (&) [8ul]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
void copyArray<scaled_channel<unsigned short, 100, 1>, float, 8ul>(scaled_channel<unsigned short, 100, 1> (&) [8ul], float const (&) [8ul]):
✓ Branch 0 taken 4696 times.
✓ Branch 1 taken 587 times.
void copyArray<unsigned short, float, 4ul>(unsigned short (&) [4ul], float const (&) [4ul]):
✓ Branch 0 taken 2348 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<short, 100, 1>, float, 8ul>(scaled_channel<short, 100, 1> (&) [8ul], float const (&) [8ul]):
✓ Branch 0 taken 14160 times.
✓ Branch 1 taken 1770 times.
void copyArray<signed char, float, 8ul>(signed char (&) [8ul], float const (&) [8ul]):
✓ Branch 0 taken 4696 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<unsigned char, 1, 20>, int, 16ul>(scaled_channel<unsigned char, 1, 20> (&) [16ul], int const (&) [16ul]):
✓ Branch 0 taken 9392 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<short, 1, 1>, int, 16ul>(scaled_channel<short, 1, 1> (&) [16ul], int const (&) [16ul]):
✓ Branch 0 taken 9392 times.
✓ Branch 1 taken 587 times.
void copyArray<unsigned short, unsigned char, 16ul>(unsigned short (&) [16ul], unsigned char const (&) [16ul]):
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 7 times.
void copyArray<unsigned short, int, 4ul>(unsigned short (&) [4ul], int const (&) [4ul]):
✓ Branch 0 taken 9396 times.
✓ Branch 1 taken 2349 times.
void copyArray<scaled_channel<signed char, 10, 1>, int, 4ul>(scaled_channel<signed char, 10, 1> (&) [4ul], int const (&) [4ul]):
✓ Branch 0 taken 9392 times.
✓ Branch 1 taken 2348 times.
void copyArray<scaled_channel<short, 10, 1>, double, 5ul>(scaled_channel<short, 10, 1> (&) [5ul], double const (&) [5ul]):
✓ Branch 0 taken 14675 times.
✓ Branch 1 taken 2935 times.
void copyArray<scaled_channel<short, 10, 1>, double, 8ul>(scaled_channel<short, 10, 1> (&) [8ul], double const (&) [8ul]):
✓ Branch 0 taken 28176 times.
✓ Branch 1 taken 3522 times.
void copyArray<signed char, int, 8ul>(signed char (&) [8ul], int const (&) [8ul]):
✓ Branch 0 taken 4696 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<short, 1, 1>, int, 4ul>(scaled_channel<short, 1, 1> (&) [4ul], int const (&) [4ul]):
✓ Branch 0 taken 2352 times.
✓ Branch 1 taken 588 times.
void copyArray<unsigned short, float, 8ul>(unsigned short (&) [8ul], float const (&) [8ul]):
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 16 times.
void copyArray<scaled_channel<unsigned int, 10, 1>, float, 2ul>(scaled_channel<unsigned int, 10, 1> (&) [2ul], float const (&) [2ul]):
✓ Branch 0 taken 2366 times.
✓ Branch 1 taken 1183 times.
void copyArray<scaled_channel<int, 10, 1>, int, 2ul>(scaled_channel<int, 10, 1> (&) [2ul], int const (&) [2ul]):
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
void copyArray<scaled_channel<unsigned char, 1, 5>, unsigned short, 8ul>(scaled_channel<unsigned char, 1, 5> (&) [8ul], unsigned short const (&) [8ul]):
✓ Branch 0 taken 4696 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<short, 1, 1>, signed char, 8ul>(scaled_channel<short, 1, 1> (&) [8ul], signed char const (&) [8ul]):
✓ Branch 0 taken 4696 times.
✓ Branch 1 taken 587 times.
void copyArray<scaled_channel<unsigned char, 100, 1>, float, 8ul>(scaled_channel<unsigned char, 100, 1> (&) [8ul], float const (&) [8ul]):
✓ Branch 0 taken 18784 times.
✓ Branch 1 taken 2348 times.
void copyArray<scaled_channel<unsigned char, 2, 1>, float, 16ul>(scaled_channel<unsigned char, 2, 1> (&) [16ul], float const (&) [16ul]):
✓ Branch 0 taken 9632 times.
✓ Branch 1 taken 602 times.
void copyArray<scaled_channel<short, 1, 1>, float, 16ul>(scaled_channel<short, 1, 1> (&) [16ul], float const (&) [16ul]):
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 15 times.
void copyArray<scaled_channel<unsigned char, 1, 100>, float, 16ul>(scaled_channel<unsigned char, 1, 100> (&) [16ul], float const (&) [16ul]):
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 15 times.
|
8/10void copyArray<unsigned short, float, 16ul>(unsigned short (&) [16ul], float const (&) [16ul]):
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
void copyArray<unsigned short, unsigned char, 16ul>(unsigned short (&) [16ul], unsigned char const (&) [16ul]):
✓ Decision 'true' taken 112 times.
✓ Decision 'false' taken 7 times.
void copyArray<scaled_channel<short, 1, 1>, int, 4ul>(scaled_channel<short, 1, 1> (&) [4ul], int const (&) [4ul]):
✓ Decision 'true' taken 2352 times.
✓ Decision 'false' taken 588 times.
void copyArray<scaled_channel<int, 10, 1>, int, 2ul>(scaled_channel<int, 10, 1> (&) [2ul], int const (&) [2ul]):
✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
void copyArray<scaled_channel<unsigned char, 2, 1>, float, 16ul>(scaled_channel<unsigned char, 2, 1> (&) [16ul], float const (&) [16ul]):
✓ Decision 'true' taken 9632 times.
✓ Decision 'false' taken 602 times.
|
187695 | for (size_t i = 0; i < N; i++) { |
| 15 | 164651 | dest[i] = src[i]; | ||
| 16 | } | |||
| 17 | 23044 | } | ||
| 18 | ||||
| 19 | // specialization that can use memcpy when src and dest types match | |||
| 20 | template <typename DElement, size_t N> | |||
| 21 | constexpr void copyArray(scaled_channel<DElement, 1, 1> (&dest)[N], const DElement (&src)[N]) { | |||
| 22 | memcpy(dest, src, sizeof(DElement) * N); | |||
| 23 | } | |||
| 24 | ||||
| 25 | template <typename DElement, size_t N> | |||
| 26 | 3555 | constexpr void copyArray(DElement (&dest)[N], const DElement (&src)[N]) { | ||
| 27 | 3555 | memcpy(dest, src, sizeof(DElement) * N); | ||
| 28 | 3555 | } | ||
| 29 | ||||
| 30 | /** | |||
| 31 | * Copies an array from src to the beginning of dst. If dst is larger | |||
| 32 | * than src, then only the elements copied from src will be touched. | |||
| 33 | * Any remaining elements at the end will be untouched. | |||
| 34 | */ | |||
| 35 | template <typename TElement, size_t NSrc, size_t NDest> | |||
| 36 | 1 | constexpr void copyArrayPartial(TElement (&dest)[NDest], const TElement (&src)[NSrc]) { | ||
| 37 | static_assert(NDest >= NSrc, "Source array must be larger than destination."); | |||
| 38 | ||||
| 39 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
|
2/2✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 1 time.
|
3 | for (size_t i = 0; i < NSrc; i++) { |
| 40 | 2 | dest[i] = src[i]; | ||
| 41 | } | |||
| 42 | 1 | } | ||
| 43 | ||||
| 44 | namespace efi | |||
| 45 | { | |||
| 46 | template <typename T, size_t N> | |||
| 47 | 446962756 | constexpr size_t size(const T(&)[N]) { | ||
| 48 | 446962756 | return N; | ||
| 49 | } | |||
| 50 | ||||
| 51 | // Zero the passed object | |||
| 52 | template <typename T> | |||
| 53 | 587 | constexpr void clear(T* obj) { | ||
| 54 | #ifdef WE_HAVE_CRITICAL_ERROR_METHOD | |||
| 55 | if (obj == nullptr) { | |||
| 56 | efiCriticalError("clear nullptr"); | |||
| 57 | return; | |||
| 58 | } | |||
| 59 | #endif // WE_HAVE_CRITICAL_ERROR_METHOD | |||
| 60 | // The cast to void* is to prevent errors like: | |||
| 61 | // clearing an object of non-trivial type 'struct persistent_config_s'; use assignment or value-initialization instead | |||
| 62 | // This is technically wrong, but we know config objects only ever actually | |||
| 63 | // contain integral types, though they may be wrapped in a scaled_channel | |||
| 64 | 587 | memset(reinterpret_cast<void*>(obj), 0, sizeof(T)); | ||
| 65 | 587 | } | ||
| 66 | ||||
| 67 | template <typename T> | |||
| 68 | constexpr void clear(T& obj) { | |||
| 69 | clear(&obj); | |||
| 70 | } | |||
| 71 | } // namespace efi | |||
| 72 |