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