RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
patternGeneration.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_PATTERNGENERATION_HPP
14#define RTCTK_COMPONENTFRAMEWORK_PATTERNGENERATION_HPP
15
17
18#include <algorithm>
19#include <cstdint>
20#include <iterator>
21
23
39template <typename InputIter, typename T, typename U>
40constexpr void GenerateRamp(InputIter begin, InputIter end, T offset, U slope) {
41 typename std::iterator_traits<InputIter>::value_type counter = offset;
42 typename std::iterator_traits<InputIter>::value_type delta = slope;
43 auto generator = [&counter, delta]() {
44 auto value = counter;
45 counter += delta;
46 return value;
47 };
48 std::generate(begin, end, generator);
49}
50
85// metrix++: suppress std.code.magic:numbers
86template <typename InputIter, typename T>
87constexpr void
88GenerateAlternatingRamp(InputIter begin, InputIter end, std::uint32_t sample_id, T offset) {
89 using C = typename std::iterator_traits<InputIter>::value_type;
90 if constexpr (IS_COMPLEX_TYPE<C>) {
91 typename C::value_type cast_offset = offset;
92 if (sample_id % 2 == 0) {
93 GenerateRamp(begin, end, C(cast_offset, cast_offset + 1), C(+2, +2));
94 } else {
95 GenerateRamp(begin, end, C(-cast_offset, -cast_offset - 1), C(-2, -2));
96 }
97 } else if constexpr (std::is_signed_v<C>) {
98 C cast_offset = offset;
99 if (sample_id % 2 == 0) {
100 GenerateRamp(begin, end, cast_offset, +1);
101 } else {
102 GenerateRamp(begin, end, -cast_offset, -1);
103 }
104 } else { // unsigned
105 C cast_offset = offset;
106 if (sample_id % 2 == 0) {
107 GenerateRamp(begin, end, cast_offset, +1);
108 } else {
109 GenerateRamp(begin, end, std::numeric_limits<C>::max() - cast_offset, -1);
110 }
111 }
112}
113
114} // namespace rtctk::componentFramework
115
116#endif // RTCTK_COMPONENTFRAMEWORK_PATTERNGENERATION_HPP
Definition commandReplier.cpp:22
constexpr void GenerateRamp(InputIter begin, InputIter end, T offset, U slope)
Generates a ramp of values.
Definition patternGeneration.hpp:40
constexpr void GenerateAlternatingRamp(InputIter begin, InputIter end, std::uint32_t sample_id, T offset)
Generates a ramp of values alternating on the sample ID.
Definition patternGeneration.hpp:88
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Provides useful mechanisms to test various type traits.