Guest User

Untitled

a guest
Nov 23rd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. struct CEvent
  2. {
  3.     enum class CType
  4.     {
  5.         EVENT_1,
  6.         EVENT_2,
  7.         EVENT_3,
  8.     } m_Type;
  9.     union
  10.     {
  11.         struct
  12.         {
  13.             unsigned int m_X;
  14.             unsigned int m_Y;
  15.             int m_State
  16.         } m_Event1;
  17.         struct
  18.         {
  19.             /* ... */
  20.         } m_Event2;
  21.         struct
  22.         {
  23.             /* ... */
  24.         } m_Event3;
  25.     };
  26. };
  27.  
  28. class IObserver
  29. {
  30. public:
  31.     virtual ~IObserver(){}
  32.     virtual void onEvent(const CEvent& Event) = 0;
  33. }
  34.  
  35. /* obserwowany obiekt */
  36. CEvent e;
  37. // odpowiednio wypelnij zdarzenie
  38. notifyAll(e);
  39.  
  40. /* obserwator */
  41. void CEventHandler::onEvent(const CEvent& Event)
  42. {
  43.     switch(Event.m_Type)
  44.     {
  45.         /* odczytaj dane w zaleznosci od typu */
  46.     }
  47.     // ...
  48. }
Add Comment
Please, Sign In to add comment