Singleton.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef ADCHPP_SINGLETON_H
00020 #define ADCHPP_SINGLETON_H
00021
00022 #include "common.h"
00023
00024 namespace adchpp {
00025
00031 template<typename T>
00032 class Singleton {
00033 public:
00034 Singleton() { }
00035 virtual ~Singleton() { }
00036
00037 static T* getInstance() {
00038 dcassert(T::instance);
00039 return T::instance;
00040 }
00041
00042 static void newInstance() {
00043 if(T::instance)
00044 delete T::instance;
00045
00046 T::instance = new T();
00047 }
00048
00049 static void deleteInstance() {
00050 delete T::instance;
00051 T::instance = NULL;
00052 }
00053 private:
00054 Singleton(const Singleton&);
00055 Singleton& operator=(const Singleton&);
00056
00057 };
00058
00059 }
00060
00061 #endif // SINGLETON_H