Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. typedef void * (*EveFunc)(void *param);
  5.  
  6. void * WindowEventCallBack (void * param);
  7. void * SystemEventCallBack (void * param);
  8.  
  9.  
  10.  
  11.  
  12.  
  13. void handle_events();
  14.  
  15. struct Event
  16. {
  17.  
  18. EveFunc type;
  19. void *param ;
  20. Event(void *param,EveFunc type) : param(param),type(type) {}
  21. };
  22.  
  23. std::vector <Event> events;
  24.  
  25.  
  26. int main()
  27. {
  28. int i = 5;
  29. Event event((void*)&i,WindowEventCallBack);
  30. events.push_back(event);
  31.  
  32.  
  33. std::pair<int,int> vars = std::make_pair(6,6);
  34. Event event2((void*)&vars,SystemEventCallBack);
  35. events.push_back(event2);
  36.  
  37.  
  38. handle_events();
  39.  
  40. return 0;
  41. }
  42.  
  43.  
  44.  
  45. void * SystemEventCallBack (void * param)
  46. {
  47. int var1 = static_cast<std::pair<int,int>*>(param)->first;
  48. int var2 = static_cast<std::pair<int,int>*>(param)->second;
  49.  
  50. std::cout << var1 << std::endl;
  51. std::cout << var2 << std::endl;
  52.  
  53. }
  54. void * WindowEventCallBack (void * param)
  55. {
  56.  
  57. int WindowId = * static_cast<int*>(param);
  58. std::cout << WindowId << std::endl;
  59.  
  60.  
  61. }
  62. void handle_events()
  63. {
  64. for( int i = 0 ; i < events.size(); i++)
  65. {
  66. events[i].type(events[i].param);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement