Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env dub
- /+ dub.sdl:
- name "rx_filter_subject"
- dependency "rx" version="*"
- dependency "rtree" version="*"
- +/
- import std.stdio : writeln;
- import rx;
- import rtree;
- struct message {
- int x;
- int y;
- }
- static class myWidget : Observer!message {
- this(int x0, int y0, int x1, int y1){
- x[0] = x0;
- x[1] = x1;
- y[0] = y0;
- y[1] = y1;
- }
- void put(message obj) {hit();}
- void completed() {}
- void failure(Exception ex) {}
- void hit(){writeln("Hit!");}
- int[2] x;
- int[2] y;
- }
- alias SI = RTree!(long, int, 2, float); // datatype, index element type, dimensions, fractional index element type
- static class FilterSubject : SubjectObject!message {
- SI spitialIndex;
- this(){
- spitialIndex = new SI();
- }
- // alias subscribe = typeof(super).subscribe;
- Disposable subscribe(myWidget observer){
- spitialIndex.insert(observer.x, observer.y, cast(long)cast(void*)observer);
- return NopDisposable.instance;
- }
- }
- void main() {
- auto rx_message = new FilterSubject;
- message a;
- a.x = 1;
- a.y = 1;
- // nothing happens, nothing subscribed
- rx_message.put(a);
- // nothing happens, subscribe is a noop
- auto widget = new myWidget(1,1,3,3);
- rx_message.subscribe(widget);
- rx_message.put(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement