Guest User

Untitled

a guest
Feb 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. template<class Sender>
  2. class Event {
  3. private:
  4. Sender *s;
  5. friend Sender;
  6.  
  7. protected:
  8. event(Sender *s) : s(s) {}
  9. void operator() { }
  10.  
  11. public:
  12. // register a function for the event
  13. void operator +=(void (*f)(Sender*)) { }
  14.  
  15. // deregister a function from the event
  16. void operator -=(void (*f)(Sender*)) { }
  17. }
  18.  
  19. class InternetConnectionListener {
  20. public:
  21. Event<InternetConnectionListener> onConnectionUp;
  22. Event<InternetConnectionListener> onConnectionDown;
  23.  
  24. private:
  25. void someMethodThatGetsCalledWhenNetworkStateChanges() {
  26. if (networkIsUp) {
  27. // only this class is allowed to execute the () operator
  28. onConnectionUp();
  29. } else {
  30. onConnectionDown();
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment