#ifndef DTKSINGLETON_H #define DTKSINGLETON_H #include template class dtkSingleton { public: static T& instance(void) { static QMutex mutex; if (!s_instance) { mutex.lock(); if (!s_instance) s_instance = new T; mutex.unlock(); } return (*s_instance); } private: dtkSingleton(void) {}; ~dtkSingleton(void) {}; private: Q_DISABLE_COPY(dtkSingleton) private: static T *s_instance; }; template T *dtkSingleton::s_instance = NULL; #define DTK_IMPLEMENT_SINGLETON(T) \ T *T::instance() \ { \ return &(dtkSingleton::instance()); \ } #endif //DTKSINGLETON