Guest User

Untitled

a guest
Oct 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. using namespace std;
  5.  
  6. template <class T>
  7. class Singleton
  8. {
  9. public:
  10. static T* Instance() {
  11. if(!m_pInstance) m_pInstance = new T;
  12. return m_pInstance;
  13. }
  14.  
  15. protected:
  16. Singleton();
  17. ~Singleton();
  18.  
  19. private:
  20. Singleton(Singleton const&);
  21. Singleton& operator=(Singleton const&);
  22. static T* m_pInstance;
  23. };
  24.  
  25. template <class T> T* Singleton<T>::m_pInstance = NULL;
  26.  
  27. class Logger
  28. {
  29. private:
  30. string log;
  31.  
  32. public:
  33. Logger() {log = "0";};
  34. ~Logger() {};
  35. string getLog() {return log;};
  36. void setLog(string l) {log = l;};
  37. };
  38.  
  39. class TypeGeneric {};
  40.  
  41. class TypeZero : public TypeGeneric {};
  42.  
  43. class TypeOne : public TypeGeneric {};
  44.  
  45. TypeGeneric* factory()
  46. {
  47. string s = Singleton<Logger>::Instance()->getLog();
  48.  
  49. if(s == "0")
  50. return new TypeZero;
  51.  
  52. if(s == "1")
  53. return new TypeOne;
  54.  
  55. return NULL;
  56. }
  57.  
  58. template <class T>
  59. class list
  60. {
  61. private:
  62. T* next;
  63.  
  64. public:
  65. T* getNext() {return next;};
  66. };
  67.  
  68. int main()
  69. {
  70. Singleton<Logger>::Instance()->setLog("1");
  71. cout << Singleton<Logger>::Instance()->getLog() << endl;
  72. cout << factory() << endl;
  73.  
  74. return 0;
  75. }
Add Comment
Please, Sign In to add comment