Singleton.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2006-2010 Jacek Sieka, arnetheduck on gmail point com
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef ADCHPP_SINGLETON_H
00020 #define ADCHPP_SINGLETON_H
00021 
00022 #include "common.h"
00023 
00024 namespace adchpp {
00025     
00031 template<typename T>
00032 class Singleton {
00033 public:
00034     Singleton() { }
00035     virtual ~Singleton() { }
00036 
00037     static T* getInstance() {
00038         dcassert(T::instance);
00039         return T::instance;
00040     }
00041     
00042     static void newInstance() {
00043         if(T::instance)
00044             delete T::instance;
00045         
00046         T::instance = new T();
00047     }
00048     
00049     static void deleteInstance() {
00050         delete T::instance;
00051         T::instance = NULL;
00052     }
00053 private:
00054     Singleton(const Singleton&);
00055     Singleton& operator=(const Singleton&);
00056 
00057 };
00058 
00059 }
00060 
00061 #endif // SINGLETON_H
Generated on Sat Nov 27 23:37:53 2010 for adchpp by  doxygen 1.6.3