.[ ČeskéHry.cz ].

Laboratoř ČeskýchHer.cz - PasteBin

Vložit nový kód

ČeskéHry.cz - KOMUNITA HERNÍCH VÝVOJÁŘŮ

  1. Watch Film Movies online streaming subtitle
    44 min
  2. Watch Online movie streaming HD english italiano
    13 hod
  3. 2025041723h59min56sec
    14 hod
  4. 2025041723h51min28sec
    14 hod
  5. 2025041723h43min44sec
    14 hod
  6. 2025041723h35min24sec
    14 hod
  7. 2025041723h27min39sec
    14 hod
  8. 2025041723h19min51sec
    14 hod
  9. 2025041723h12min03sec
    14 hod
  10. 2025041723h04min15sec
    15 hod
Link: http://nopaste.ceske-hry.cz/subdom/nopaste223400
Zaslal: signal slot v C++11
Popis: signal slot v C++11
Jazyk: C++
Vloženo: 30.11.2011, 20:43
Stáhnout jako soubor
  1. #include <iostream>
  2. #include <memory>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. template<typename ... P>
  8. class FunctionCall
  9. {
  10. public:
  11. virtual void call(P...par)=0;
  12. };
  13.  
  14. template<typename T, typename ... P>
  15. class FunctionCallT : public FunctionCall<P...>
  16. {
  17. T *o;
  18. void (T::*f)(P...);
  19. public:
  20. FunctionCallT(T &obj, void (T::*fun)(P...))
  21. {
  22. o = &obj;
  23. f = fun;
  24. }
  25. void call(P...par)
  26. {
  27. (o->*f)(par...);
  28. }
  29. };
  30.  
  31. template <typename...P>
  32. class Signal
  33. {
  34. map<void *,unique_ptr<FunctionCall<P...>>> cal;
  35. public:
  36. template<typename T>
  37. void connect(T &o, void (T::*f)(P...))
  38. {
  39. cal[&o] = unique_ptr<FunctionCallT<T, P...>>(new FunctionCallT<T, P...>(o, f));
  40. }
  41. void disconnect(void *o)
  42. {
  43. cal.erase(o);
  44. }
  45. void operator()(P...par)
  46. {
  47. for(auto &i : cal)
  48. i.second->call(par...);
  49. }
  50. };
  51.  
  52.  
  53. class Slot
  54. {
  55. public:
  56. int c;
  57. void funkcia(int a, float b)
  58. {
  59. cout << "funkcia " << c << " " << a << " " << b << endl;
  60. }
  61. void em()
  62. {
  63. cout << "null " << c << endl;
  64. }
  65. };
  66.  
  67. int main()
  68. {
  69. Slot slot1,slot2;
  70. slot1.c = 1;
  71. slot2.c = 2;
  72. Signal<int, float> signal1;
  73. signal1.connect(slot1, &Slot::funkcia);
  74. signal1.connect(slot2, &Slot::funkcia);
  75.  
  76. Signal<> signal2;
  77. signal2.connect(slot1, &Slot::em);
  78.  
  79. signal1(3, 4.0f);
  80. signal2();
  81.  
  82. return 0;
  83. }
  84.