aboutsummaryrefslogtreecommitdiff
path: root/common/singleton.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/singleton.h')
-rw-r--r--common/singleton.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/common/singleton.h b/common/singleton.h
index 849bf208bb..1a7b339bf6 100644
--- a/common/singleton.h
+++ b/common/singleton.h
@@ -33,13 +33,13 @@ namespace Common {
/**
* Generic template base class for implementing the singleton design pattern.
*/
-template <class T>
+template<class T>
class Singleton : NonCopyable {
private:
- Singleton<T>(const Singleton<T>&);
- Singleton<T>& operator= (const Singleton<T>&);
+ Singleton<T>(const Singleton<T> &);
+ Singleton<T> &operator=(const Singleton<T> &);
- static T* _singleton;
+ static T *_singleton;
/**
* The default object factory used by the template class Singleton.
@@ -53,10 +53,15 @@ private:
//FIXME evc4 and msvc7 doesn't like it as private member
public:
#endif
- static T* makeInstance() {
+ static T *makeInstance() {
return new T();
}
+ static void destroyInstance() {
+ delete _singleton;
+ _singleton = 0;
+ }
+
public:
static T& instance() {
@@ -71,9 +76,9 @@ public:
_singleton = T::makeInstance();
return *_singleton;
}
- virtual void destroy() {
- delete _singleton;
- _singleton = 0;
+
+ static void destroy() {
+ T::destroyInstance();
}
protected:
Singleton<T>() { }
@@ -86,7 +91,7 @@ protected:
typedef T SingletonBaseType;
};
-#define DECLARE_SINGLETON(T) template<> T* Common::Singleton<T>::_singleton=0
+#define DECLARE_SINGLETON(T) template<> T *Common::Singleton<T>::_singleton = 0
} // End of namespace Common