1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-09-27 18:55:48 +00:00

Get to building.

This commit is contained in:
Thomas Harte 2023-06-12 23:16:45 -04:00
parent 6e35d84a96
commit b00eac4a34
2 changed files with 52 additions and 6 deletions

View File

@ -98,6 +98,9 @@ template <typename ClassifierT, typename TargetT>
struct SubrangeDispatcher {
static constexpr int max = ClassifierT::max;
template <typename... Args> SubrangeDispatcher(Args&&... args) :
target(std::forward<Args>(args)...) {}
template <int n>
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<region>(clipped_start);
target.template begin<region>(clipped_start);
}
target.advance<region>(clipped_end - clipped_start);
target.template advance<region>(clipped_end - clipped_start);
if constexpr (n + 1 == find_end(n)) {
target.end<region>(clipped_end);
target.template end<region>(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 &target;
TargetT target;
};
}

View File

@ -12,6 +12,7 @@
#include <array>
#include <cassert>
#include <vector>
@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<Event> events;
template <RangeType type> void begin(int) {
events.emplace_back(Event::Type::Begin, type);
}
template <RangeType type> void end(int) {
events.emplace_back(Event::Type::End, type);
}
template <RangeType type> void advance(int length) {
events.emplace_back(Event::Type::Advance, type, length);
}
};
- (void)testRanges {
using Dispatcher = Reflection::SubrangeDispatcher<RangeClassifier, RangeTarget>;
Dispatcher dispatcher;
Reflection::RangeDispatcher<Dispatcher>::dispatch(dispatcher, 0, 10);
printf("");
}
@end