Advertisement
denesik

Generator.h

Jan 27th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #pragma once
  2.  
  3. #ifndef Generator_h__
  4. #define Generator_h__
  5.  
  6. // Генерация типа по переменной
  7. template<int v>
  8. struct Int2Type
  9. {
  10.   enum { value = v };
  11. };
  12.  
  13. static int counter = 0;
  14.  
  15. template <typename T> class SingleTon
  16. {
  17. public:
  18.   const static int get()
  19.   {
  20.     static bool init = false;
  21.     const static int id = counter;
  22.     if(!init)
  23.     {
  24.       ++counter;
  25.       init = true;
  26.     }
  27.     return id;
  28.   }
  29. protected:
  30.   SingleTon()          {}
  31.   virtual ~SingleTon() {}
  32. };
  33.                                  
  34. #define TYPE_ID(Type) SingleTon<Type>::get()
  35.  
  36.  
  37.  
  38.  
  39. #endif // Generator_h__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement