mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-15 14:27:29 +00:00
Get to building.
This commit is contained in:
@@ -98,6 +98,9 @@ template <typename ClassifierT, typename TargetT>
|
|||||||
struct SubrangeDispatcher {
|
struct SubrangeDispatcher {
|
||||||
static constexpr int max = ClassifierT::max;
|
static constexpr int max = ClassifierT::max;
|
||||||
|
|
||||||
|
template <typename... Args> SubrangeDispatcher(Args&&... args) :
|
||||||
|
target(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
template <int n>
|
template <int n>
|
||||||
void perform(int begin, int end) {
|
void perform(int begin, int end) {
|
||||||
constexpr auto region = ClassifierT::region(n);
|
constexpr auto region = ClassifierT::region(n);
|
||||||
@@ -105,30 +108,30 @@ struct SubrangeDispatcher {
|
|||||||
const auto clipped_end = std::min(end, find_end(n));
|
const auto clipped_end = std::min(end, find_end(n));
|
||||||
|
|
||||||
if constexpr (n == find_begin(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)) {
|
if constexpr (n + 1 == find_end(n)) {
|
||||||
target.end<region>(clipped_end);
|
target.template end<region>(clipped_end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
constexpr int find_begin(int n) {
|
static constexpr int find_begin(int n) {
|
||||||
const auto type = ClassifierT::region(n);
|
const auto type = ClassifierT::region(n);
|
||||||
while(n && ClassifierT::region(n - 1) == type) --n;
|
while(n && ClassifierT::region(n - 1) == type) --n;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int find_end(int n) {
|
static constexpr int find_end(int n) {
|
||||||
const auto type = ClassifierT::region(n);
|
const auto type = ClassifierT::region(n);
|
||||||
while(n < ClassifierT::max && ClassifierT::region(n) == type) ++n;
|
while(n < ClassifierT::max && ClassifierT::region(n) == type) ++n;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetT ⌖
|
TargetT target;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
@interface DispatcherTests : XCTestCase
|
@interface DispatcherTests : XCTestCase
|
||||||
@end
|
@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 {
|
- (void)testRanges {
|
||||||
|
using Dispatcher = Reflection::SubrangeDispatcher<RangeClassifier, RangeTarget>;
|
||||||
|
Dispatcher dispatcher;
|
||||||
|
Reflection::RangeDispatcher<Dispatcher>::dispatch(dispatcher, 0, 10);
|
||||||
|
|
||||||
|
printf("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user