fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <tuple>
  4. #include <vector>
  5.  
  6. //#define USE_MEDIATOR
  7.  
  8. using namespace std;
  9.  
  10. template<class T>
  11. void show(T tup)
  12. {
  13. cout << "-----------------" << endl;
  14. cout << get<0>(tup) << endl;
  15. cout << get<1>(tup) << endl;
  16. cout << get<2>(tup) << endl;
  17. cout << "-----------------" << endl;
  18. }
  19.  
  20. template <class T>
  21. class NotifyParam
  22. {
  23. public:
  24. NotifyParam(T body)
  25. :body(body)
  26. {}
  27. T body;
  28. };
  29.  
  30. #ifdef USE_MEDIATOR
  31.  
  32. class MediatorBase
  33. {
  34. public:
  35. virtual void doCommand(NotifyParam notifyParam) = 0;
  36. };
  37.  
  38. class MediatorA : public MediatorBase
  39. {
  40. public:
  41. virtual void doCommand(NotifyParam notifyParam)
  42. {
  43. cout << "-----------------" << endl;
  44. cout << "----MediatorA----" << endl;
  45. show(notifyParam.body);
  46. }
  47. };
  48.  
  49. class MediatorB : public MediatorBase
  50. {
  51. public:
  52. virtual void doCommand(NotifyParam notifyParam)
  53. {
  54. cout << "-----------------" << endl;
  55. cout << "----MediatorB----" << endl;
  56. show(notifyParam.body);
  57. }
  58. };
  59.  
  60. #endif
  61.  
  62. int main ()
  63. {
  64. auto tup1 = make_tuple("A", 1, 0.3);
  65. NotifyParam<decltype(tup1)> pp1(tup1);
  66. show(pp1.body);
  67.  
  68. auto tup2 = make_tuple("B", "cc", 1);
  69. NotifyParam<decltype(tup2)> pp2(tup2);
  70. show(pp2.body);
  71.  
  72. #ifdef USE_MEDIATOR
  73.  
  74. vector<MediatorBase*> vt = {new MediatorA, new MediatorB};
  75.  
  76. for(auto it : vt)
  77. {
  78. it->doCommand(pp1.body);
  79. it->doCommand(pp2.body);
  80. }
  81.  
  82. #endif
  83.  
  84. return 0;
  85. }
  86.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
-----------------
A
1
0.3
-----------------
-----------------
B
cc
1
-----------------