00001 /************************************************************************ 00002 filename: CEGUISchemeManager.cpp 00003 created: 21/2/2004 00004 author: Paul D Turner 00005 00006 purpose: Implements SchemeManager class 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #include "CEGUISchemeManager.h" 00027 #include "CEGUIExceptions.h" 00028 #include "CEGUILogger.h" 00029 #include "CEGUIScheme.h" 00030 00031 // Start of CEGUI namespace section 00032 namespace CEGUI 00033 { 00034 /************************************************************************* 00035 Static Data Definitions 00036 *************************************************************************/ 00037 // singleton instance pointer 00038 template<> SchemeManager* Singleton<SchemeManager>::ms_Singleton = NULL; 00039 00040 00041 00042 /************************************************************************* 00043 constructor 00044 *************************************************************************/ 00045 SchemeManager::SchemeManager(void) 00046 { 00047 Logger::getSingleton().logEvent((utf8*)"CEGUI::SchemeManager singleton created."); 00048 } 00049 00050 00051 /************************************************************************* 00052 Destructor 00053 *************************************************************************/ 00054 SchemeManager::~SchemeManager(void) 00055 { 00056 Logger::getSingleton().logEvent((utf8*)"---- Begining cleanup of GUI Scheme system ----"); 00057 00058 unloadAllSchemes(); 00059 00060 Logger::getSingleton().logEvent((utf8*)"CEGUI::SchemeManager singleton destroyed."); 00061 } 00062 00063 00064 /************************************************************************* 00065 Loads a scheme 00066 *************************************************************************/ 00067 Scheme* SchemeManager::loadScheme(const String& scheme_filename, const String& resourceGroup) 00068 { 00069 Logger::getSingleton().logEvent((utf8*)"Attempting to load Scheme from file '" + scheme_filename + "'."); 00070 00071 Scheme* tmp = new Scheme(scheme_filename, resourceGroup); 00072 String name = tmp->getName(); 00073 d_schemes[name] = tmp; 00074 return tmp; 00075 } 00076 00077 00078 /************************************************************************* 00079 Un-Loads a scheme 00080 *************************************************************************/ 00081 void SchemeManager::unloadScheme(const String& scheme_name) 00082 { 00083 SchemeRegistry::iterator pos = d_schemes.find(scheme_name); 00084 00085 if (pos != d_schemes.end()) 00086 { 00087 String tmpName(scheme_name); 00088 00089 delete pos->second; 00090 d_schemes.erase(pos); 00091 00092 Logger::getSingleton().logEvent((utf8*)"Scheme '" + tmpName + "' has been unloaded."); 00093 } 00094 00095 } 00096 00097 00098 /************************************************************************* 00099 Returns a pointer to the Scheme object with the specified name. 00100 *************************************************************************/ 00101 Scheme* SchemeManager::getScheme(const String& name) const 00102 { 00103 SchemeRegistry::const_iterator pos = d_schemes.find(name); 00104 00105 if (pos == d_schemes.end()) 00106 { 00107 throw UnknownObjectException("SchemeManager::getScheme - A Scheme object with the specified name '" + name +"' does not exist within the system"); 00108 } 00109 00110 return pos->second; 00111 } 00112 00113 00114 SchemeManager& SchemeManager::getSingleton(void) 00115 { 00116 return Singleton<SchemeManager>::getSingleton(); 00117 } 00118 00119 00120 SchemeManager* SchemeManager::getSingletonPtr(void) 00121 { 00122 return Singleton<SchemeManager>::getSingletonPtr(); 00123 } 00124 00125 00126 /************************************************************************* 00127 Return a SchemeManager::SchemeIterator object to iterate over the 00128 available schemes. 00129 *************************************************************************/ 00130 SchemeManager::SchemeIterator SchemeManager::getIterator(void) const 00131 { 00132 return SchemeIterator(d_schemes.begin(), d_schemes.end()); 00133 } 00134 00135 00136 /************************************************************************* 00137 Unload all schemes currently defined within the system. 00138 *************************************************************************/ 00139 void SchemeManager::unloadAllSchemes(void) 00140 { 00141 // unload all schemes 00142 while (!d_schemes.empty()) 00143 { 00144 unloadScheme(d_schemes.begin()->first); 00145 } 00146 00147 } 00148 00149 00150 } // End of CEGUI namespace section