00001 /* 00002 * Singleton - template base class for singleton pattern. 00003 * 00004 * This file is part of the Rulbus Device Class Library (RDCL). 00005 * 00006 * Copyright (C) 2003-2004, Leiden University. 00007 * 00008 * This library is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * The library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with mngdriver; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * $Id: Singleton.h 2 2004-10-12 11:54:15Z moene $ 00023 */ 00024 00025 #ifndef __SINGLETON_H 00026 #define __SINGLETON_H 00027 00028 namespace Rulbus 00029 { 00063 template <typename T> 00064 class Singleton 00065 { 00066 public: 00067 static T& instance(); 00068 00069 protected: 00070 static T* theInstance; 00071 00072 }; 00073 00078 template <typename T> 00079 T* Singleton<T>::theInstance = 0; 00080 00085 template <typename T> 00086 T& Singleton<T>::instance() 00087 { 00088 if ( 0 == theInstance ) 00089 { 00090 theInstance = new T; 00091 } 00092 00093 return *theInstance; 00094 } 00095 00096 } // namespace Rulbus 00097 00098 #endif // __SINGLETON_H 00099 00100 /* 00101 * end of file 00102 */ 00103