Giri's C++ Support Library
C++ library providing everything you need to quickly create awesome applications.
Singleton.h
Go to the documentation of this file.
1 
10 #ifndef SUPPORTLIB_SINGLETON_H
11 #define SUPPORTLIB_SINGLETON_H
12 #include "Object.h"
13 namespace giri {
54  template <typename T> class Singleton : public Object<T> {
55  public:
56 
62  template<typename... Args> static T*getInstance(Args... args){
63  if(m_Instance==nullptr)
64  m_Instance.reset(new T{ std::forward<Args>(args)... });
65  return m_Instance.get();
66  }
70  static void destroy(){
71  m_Instance = nullptr;
72  }
73  virtual ~Singleton() = default;
74  protected:
75  //No Object of Singleton can be created
76  Singleton() = default;
77 
78  private:
79  //Delete the Copyconstructor and the Assignmentoperator
80  Singleton(Singleton const& s) = delete;
81  Singleton& operator= (Singleton const& s) = delete;
82  inline static std::unique_ptr<T> m_Instance;
83  };
84 }
85 #endif //SUPPORTLIB_SINGLETON_H
Base class of all classes.
Base Class of all classes.
Definition: Object.h:33
Singleton Template Class.
Definition: Singleton.h:54
static void destroy()
Destroys the Object held by the Singleton.
Definition: Singleton.h:70
static T * getInstance(Args... args)
Generates a static Variable which can only be instanced once. Parameters depend on the inheriting cla...
Definition: Singleton.h:62
Namespace for giri's C++ support library.
Definition: Base64.h:47