#ifndef SINGLETON_H #define SINGLETON_H template struct DefaultSingletonCreator { static Product *create() { return new Product; } }; template struct NullSingletonCreator { static Product *create() { return 0; } }; template < class T, template class Creator = DefaultSingletonCreator > class Singleton { public: static T &self() { if ( !s_self ) s_self = Creator::create(); return *s_self; } protected: Singleton() { s_self = static_cast( this ); } ~Singleton() { s_self = 0; } private: Singleton( const Singleton &rhs ); Singleton &operator=( const Singleton &rhs ); static T *s_self; }; template class Creator> T *Singleton::s_self = 0; #endif // SINGLETON_H /* vim: et sw=4 ts=4 */