RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
patternValidation.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
14#define RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
15
17
18#include <iterator>
19
21
36template <typename InputIter, typename T, typename U>
37constexpr bool ValidRamp(InputIter begin, InputIter end, T offset, U slope) {
38 typename std::iterator_traits<InputIter>::value_type counter = offset;
39 typename std::iterator_traits<InputIter>::value_type delta = slope;
40 for (auto value = begin; value != end; ++value) {
41 if (*value != counter) {
42 return false;
43 }
44 counter += delta;
45 }
46 return true;
47}
48
62// metrix++: suppress std.code.magic:numbers
63template <typename InputIter, typename T>
64constexpr bool
65ValidAlternatingRamp(InputIter begin, InputIter end, std::uint32_t sample_id, T offset) {
66 using C = typename std::iterator_traits<InputIter>::value_type;
67 if constexpr (IS_COMPLEX_TYPE<C>) {
68 typename C::value_type cast_offset = offset;
69 if (sample_id % 2 == 0) {
70 return ValidRamp(begin, end, C(cast_offset, cast_offset + 1), C(+2, +2));
71 } else {
72 return ValidRamp(begin, end, C(-cast_offset, -cast_offset - 1), C(-2, -2));
73 }
74 } else if constexpr (std::is_signed_v<C>) {
75 C cast_offset = offset;
76 if (sample_id % 2 == 0) {
77 return ValidRamp(begin, end, cast_offset, +1);
78 } else {
79 return ValidRamp(begin, end, -cast_offset, -1);
80 }
81 } else { // unsigned
82 C cast_offset = offset;
83 if (sample_id % 2 == 0) {
84 return ValidRamp(begin, end, cast_offset, +1);
85 } else {
86 return ValidRamp(begin, end, std::numeric_limits<C>::max() - cast_offset, -1);
87 }
88 }
89}
90
91} // namespace rtctk::componentFramework
92
93#endif // RTCTK_COMPONENTFRAMEWORK_PATTERNVALIDATION_HPP
Definition commandReplier.cpp:22
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:37
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
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:65
Provides useful mechanisms to test various type traits.