diff --git a/ClockReceiver/RangeDispatcher.hpp b/ClockReceiver/RangeDispatcher.hpp index 24cd3e186..a327b8e67 100644 --- a/ClockReceiver/RangeDispatcher.hpp +++ b/ClockReceiver/RangeDispatcher.hpp @@ -98,6 +98,9 @@ template struct SubrangeDispatcher { static constexpr int max = ClassifierT::max; + template SubrangeDispatcher(Args&&... args) : + target(std::forward(args)...) {} + template void perform(int begin, int end) { constexpr auto region = ClassifierT::region(n); @@ -105,30 +108,30 @@ struct SubrangeDispatcher { const auto clipped_end = std::min(end, find_end(n)); if constexpr (n == find_begin(n)) { - target.begin(clipped_start); + target.template begin(clipped_start); } - target.advance(clipped_end - clipped_start); + target.template advance(clipped_end - clipped_start); if constexpr (n + 1 == find_end(n)) { - target.end(clipped_end); + target.template end(clipped_end); } } private: - constexpr int find_begin(int n) { + static constexpr int find_begin(int n) { const auto type = ClassifierT::region(n); while(n && ClassifierT::region(n - 1) == type) --n; return n; } - constexpr int find_end(int n) { + static constexpr int find_end(int n) { const auto type = ClassifierT::region(n); while(n < ClassifierT::max && ClassifierT::region(n) == type) ++n; return n; } - TargetT ⌖ + TargetT target; }; } diff --git a/OSBindings/Mac/Clock SignalTests/DispatcherTests.mm b/OSBindings/Mac/Clock SignalTests/DispatcherTests.mm index 25cb0ee95..f5545ac75 100644 --- a/OSBindings/Mac/Clock SignalTests/DispatcherTests.mm +++ b/OSBindings/Mac/Clock SignalTests/DispatcherTests.mm @@ -12,6 +12,7 @@ #include #include +#include @interface DispatcherTests : XCTestCase @end @@ -48,7 +49,49 @@ struct DoStep { } } +enum class RangeType { + Sync, Border +}; + +struct RangeClassifier { + static constexpr int max = 50; + + static constexpr RangeType region(int x) { + return x >= 10 && x < 20 ? RangeType::Sync : RangeType::Border; + } +}; + +struct RangeTarget { + struct Event { + enum class Type { + Begin, End, Advance + }; + Type event_type; + RangeType range_type; + int length = 0; + + Event(Type event_type, RangeType range_type) : event_type(event_type), range_type(range_type) {} + Event(Type event_type, RangeType range_type, int length) : event_type(event_type), range_type(range_type), length(length) {} + }; + std::vector events; + + template void begin(int) { + events.emplace_back(Event::Type::Begin, type); + } + template void end(int) { + events.emplace_back(Event::Type::End, type); + } + template void advance(int length) { + events.emplace_back(Event::Type::Advance, type, length); + } +}; + - (void)testRanges { + using Dispatcher = Reflection::SubrangeDispatcher; + Dispatcher dispatcher; + Reflection::RangeDispatcher::dispatch(dispatcher, 0, 10); + + printf(""); } @end