00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #ifndef UTILS_SINGLETON_H 00028 #define UTILS_SINGLETON_H 00029 00030 #include <PVLE/Export.h> 00031 #include <boost/utility.hpp> 00032 00033 namespace Util { 00034 00038 template <class T> 00039 class Singleton : public boost::noncopyable { 00040 protected: 00041 Singleton() {} 00042 virtual ~Singleton() {} 00043 00044 public: 00045 typedef T TObjectType; 00046 00048 // Dev note: it is not defined outside the class because there are problems with dynamic library export. 00049 #if defined(_MSC_VER) //&& (_MSC_VER<1400) 00050 //Workaround for bug in visual studio 7 (2003) which inlines functions with static variables 00051 __declspec(noinline) 00052 #endif 00053 static T & instance() { 00054 // Scott Meyer's Singleton 00055 static T uniqueT; 00056 return uniqueT; 00057 } 00058 }; 00059 00060 00061 00062 #if defined(_DEBUG) && defined(PVLE_UNIT_TESTS) 00068 class PVLE_EXPORT UnitTestSingleton : public Singleton<UnitTestSingleton> { 00069 public: 00070 UnitTestSingleton() : i(0) {} 00071 static void testPart1(); 00072 static void testPart2(); 00073 protected: 00074 int i; 00075 }; 00076 #endif 00077 00078 } // namespace Util 00079 00080 #endif // UTILS_SINGLETON_H