Advertisement
denesik

MainGenerator.cpp

Jan 27th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include "Generator.h"
  2. #include <list>
  3.  
  4. class A;
  5. class B;
  6. class C;
  7.  
  8. class Base
  9. {
  10. public:
  11.   const int id;
  12.   Base(const int n)
  13.     : id(n)
  14.   {
  15.  
  16.   }
  17.   int GetId()
  18.   {
  19.     return id;
  20.   }
  21. };
  22.  
  23. class Test1 : public Base
  24. {
  25. public:
  26.   Test1()
  27.     : Base(TYPE_ID(Test1))
  28.   {
  29.  
  30.   }
  31. };
  32.  
  33. class Test2 : public Base
  34. {
  35. public:
  36.   Test2()
  37.     : Base(TYPE_ID(Test2))
  38.   {
  39.  
  40.   }
  41. };
  42.  
  43. class Test3 : public Base
  44. {
  45. public:
  46.   Test3()
  47.     : Base(TYPE_ID(Test3))
  48.   {
  49.  
  50.   }
  51. };
  52.  
  53. int main()
  54. {
  55.   int t1 = SingleTon<A>::get(); // 0
  56.   int t2 = SingleTon<A>::get(); // 0
  57.   int t3 = SingleTon<B>::get(); // 1
  58.   int t4 = SingleTon<A>::get(); // 0
  59.   int t5 = SingleTon<B>::get(); // 1
  60.   int t6 = SingleTon<C>::get(); // 2
  61.  
  62.   Test1 c0; // 3
  63.   Test1 c1; // 3
  64.   Test2 c2; // 4
  65.   Test2 c3; // 4
  66.   Test2 c4; // 4
  67.   Test3 c5; // 5
  68.  
  69.   std::list<Base *> baseList;
  70.   baseList.push_back(&c0);
  71.   baseList.push_back(&c1);
  72.   baseList.push_back(&c2);
  73.   baseList.push_back(&c3);
  74.   baseList.push_back(&c4);
  75.   baseList.push_back(&c5);
  76.  
  77.   for(auto it = baseList.begin(); it != baseList.end(); ++it)
  78.   {
  79.     if((*it)->GetId() == TYPE_ID(Test1))
  80.     {
  81.       printf("Test1\n");
  82.     }
  83.     if((*it)->GetId() == TYPE_ID(Test2))
  84.     {
  85.       printf("Test2\n");
  86.     }
  87.     if((*it)->GetId() == TYPE_ID(Test3))
  88.     {
  89.       printf("Test3\n");
  90.     }
  91.   }
  92.  
  93.   system("pause");
  94.  
  95.   return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement