00001 // Copyright (c) 2003 - 2004 Anselm R. Garbe <anselmg at t-online.de> 00002 // See ../LICENSE.txt for license details. 00003 // 00004 // $Id: singleton.h 7 2007-05-24 11:03:53Z eg1981 $ 00005 00006 #ifndef __SINGLETON_H 00007 #define __SINGLETON_H 00008 00012 template <class T> class Singleton 00013 { 00014 00015 public: 00016 00017 static T *instance() { 00018 if (instance_ == 0) { 00019 // use default constructor 00020 instance_ = new T; 00021 } 00022 return instance_; 00023 } 00024 00025 private: 00026 00027 // the singleton instance 00028 static T *instance_; 00029 }; 00030 00031 template <class T> T* Singleton<T>::instance_ = 0; 00032 00033 #endif // __SINGLETON_H