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 00029 00030 #ifndef UTIL_DEBUG_GLOBALS_H 00031 #define UTIL_DEBUG_GLOBALS_H 00032 00033 #include <PVLE/Export.h> 00034 #include <PVLE/Util/Singleton.h> 00035 #include <PVLE/Util/TracedException.h> 00036 #include <string> 00037 #include <map> 00038 #include <boost/cast.hpp> 00039 00040 namespace Util { 00041 00044 template<typename T> 00045 class PVLE_EXPORT DG : public Util::Singleton<DG<T> > { 00046 public: 00047 void add(const std::string & name, T v) { map.insert(Pair(name, v)); } 00048 00049 T & operator()(const std::string & name) { 00050 typename Map::iterator it = map.find(name); 00051 if (it == map.end()) THROW_TRACED_FMT_EXCEPTION("Unknown debug global variable: '%1%'", name); 00052 return it->second; 00053 } 00054 00056 template<class U> 00057 U getAs(const std::string & name) { return boost::polymorphic_downcast<U>(operator()(name)); } 00058 00060 template<class U> 00061 U reinterpretAs(const std::string & name) { return reinterpret_cast<U>(operator()(name)); } 00062 00063 protected: 00064 typedef std::pair<std::string, T> Pair; 00065 typedef std::map<std::string, T> Map; 00066 Map map; 00067 }; 00068 00069 } // namespace Util 00070 00071 00072 00073 #include <boost/any.hpp> 00074 00075 namespace Util { 00076 00077 template PVLE_EXPORT class DG<boost::any>; // Explicit instantiation + template export 00078 template PVLE_EXPORT class DG<void*>; // Explicit instantiation + template export 00079 00080 //#pragma warning(push) 00081 //#pragma warning(disable : 4231) // warning C4231: nonstandard extension used : 'extern' before template explicit instantiation 00082 //PVLE_EXPORT_TEMPLATE template PVLE_EXPORT class DG<boost::any>; // Explicit instantiation + template export 00083 //PVLE_EXPORT_TEMPLATE template PVLE_EXPORT class DG<void*>; // Explicit instantiation + template export 00084 //#pragma warning(pop) 00085 00086 } // namespace Util 00087 00088 #endif // UTIL_DEBUG_GLOBALS_H