RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
patternValidation.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
13#define RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
14
16
17#include <iterator>
18
20
35template <typename InputIter, typename T, typename U>
36constexpr bool ValidRamp(InputIter begin, InputIter end, T offset, U slope) {
37 typename std::iterator_traits<InputIter>::value_type counter = offset;
38 typename std::iterator_traits<InputIter>::value_type delta = slope;
39 for (auto value = begin; value != end; ++value) {
40 if (*value != counter) {
41 return false;
42 }
43 counter += delta;
44 }
45 return true;
46}
47
61// metrix++: suppress std.code.magic:numbers
62template <typename InputIter, typename T>
63constexpr bool
64ValidAlternatingRamp(InputIter begin, InputIter end, std::uint32_t sample_id, T offset) {
65 using C = typename std::iterator_traits<InputIter>::value_type;
66 if constexpr (IS_COMPLEX_TYPE<C>) {
67 typename C::value_type cast_offset = offset;
68 if (sample_id % 2 == 0) {
69 return ValidRamp(begin, end, C(cast_offset, cast_offset + 1), C(+2, +2));
70 } else {
71 return ValidRamp(begin, end, C(-cast_offset, -cast_offset - 1), C(-2, -2));
72 }
73 } else if constexpr (std::is_signed_v<C>) {
74 C cast_offset = offset;
75 if (sample_id % 2 == 0) {
76 return ValidRamp(begin, end, cast_offset, +1);
77 } else {
78 return ValidRamp(begin, end, -cast_offset, -1);
79 }
80 } else { // unsigned
81 C cast_offset = offset;
82 if (sample_id % 2 == 0) {
83 return ValidRamp(begin, end, cast_offset, +1);
84 } else {
85 return ValidRamp(begin, end, std::numeric_limits<C>::max() - cast_offset, -1);
86 }
87 }
88}
89
90} // namespace rtctk::componentFramework
91
92#endif // RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
constexpr bool IS_COMPLEX_TYPE
Is true if the type is a std::complex<U> of some type U.
Definition typeTraits.hpp:287
Definition commandReplier.cpp:21
constexpr bool ValidRamp(InputIter begin, InputIter end, T offset, U slope)
Checks to see if the buffer contains a ramp of values.
Definition patternValidation.hpp:36
constexpr bool ValidAlternatingRamp(InputIter begin, InputIter end, std::uint32_t sample_id, T offset)
Checks to see if the buffer contains an alternating ramp of values.
Definition patternValidation.hpp:64
Provides useful mechanisms to test various type traits.