next up previous contents
Next: Example 4: CD Player Up: listener Previous: Example 2: Using EventFilter   Contents

Example 3: Event recorder

  class Event1: public Event {} ;
  class Event2: public Event {} ;
  class Event3: public Event {} ;
  class Event4: public Event {} ;

  class A: public Subscriber {
  public:
    void event1(Event1*) {std::cerr << "1\n" ;}
    void event2(Event2*) {std::cerr << "2\n" ;}
    void event3(Event3*) {std::cerr << "3\n" ;}
    void event4(Event4*) {std::cerr << "4\n" ;}
  } ;

  int main() {
    EventRecorder recorder ;
    recorder.igs_record(Event1) ;
    recorder.igs_record(Event4) ;
    recorder.igs_record(Event2) ;
    recorder.igs_record(Event3) ;

    Publisher*  p = new Publisher ;
    A* a = new A ;
    igs_connect(p, a, igs_functor(a, A::event1)) ;
    igs_connect(p, a, igs_functor(a, A::event2)) ;
    igs_connect(p, a, igs_functor(a, A::event3)) ;
    igs_connect(p, a, igs_functor(a, A::event4)) ;

    recorder.play(p) ;
  }
Will print:
  1
  4
  2
  3



Frantz Maerten 2006-01-30