00001 #include "UnitTypeManager.h" 00002 00003 #include "OgreException.h" 00004 using Ogre::Exception; 00005 00006 template<> ASR::UnitTypeManager* Singleton<ASR::UnitTypeManager>::ms_Singleton = 0; 00007 00008 00009 namespace ASR 00010 { 00011 // ---------------------------------------------------------------------------- 00012 UnitTypeManager* UnitTypeManager::getSingletonPtr(void) 00013 { 00014 return ms_Singleton; 00015 } 00016 UnitTypeManager& UnitTypeManager::getSingleton(void) 00017 { 00018 assert( ms_Singleton ); return ( *ms_Singleton ); 00019 } 00020 00021 00022 // ---------------------------------------------------------------------------- 00023 UnitTypeManager::UnitTypeManager() 00024 { 00025 } 00026 00027 00028 // ---------------------------------------------------------------------------- 00029 UnitTypeManager::~UnitTypeManager() 00030 { 00031 removeAllUnitTypes (); 00032 } 00033 00034 00035 // ---------------------------------------------------------------------------- 00036 UnitType* UnitTypeManager::createUnitType ( const String& typeName ) 00037 { 00038 UnitTypeMap::iterator iter = mUnitTypes.find ( typeName ); 00039 if ( iter != mUnitTypes.end() ) 00040 throw Exception ( Exception::ERR_DUPLICATE_ITEM, "Type already exists", "UnitTypeManager::createUnitType" ); 00041 00042 UnitType* unitType = new UnitType ( typeName ); 00043 mUnitTypes[typeName] = unitType; 00044 return unitType; 00045 } 00046 00047 00048 // ---------------------------------------------------------------------------- 00049 UnitType* UnitTypeManager::getUnitType ( const String& typeName ) 00050 { 00051 UnitTypeMap::iterator iter = mUnitTypes.find ( typeName ); 00052 if ( iter == mUnitTypes.end() ) 00053 throw Exception ( Exception::ERR_ITEM_NOT_FOUND, "Type not found", "UnitTypeManager::createUnitType" ); 00054 00055 return (*iter).second; 00056 } 00057 00058 00059 // ----------------------------------------------------------------------------() 00060 void UnitTypeManager::removeUnitType ( const String& typeName ) 00061 { 00062 UnitTypeMap::iterator iter = mUnitTypes.find ( typeName ); 00063 if ( iter == mUnitTypes.end() ) 00064 throw Exception ( Exception::ERR_ITEM_NOT_FOUND, "Type not found", "UnitTypeManager::createUnitType" ); 00065 00066 delete (*iter).second; 00067 mUnitTypes.erase ( iter ); 00068 } 00069 00070 00071 // ---------------------------------------------------------------------------- 00072 void UnitTypeManager::removeAllUnitTypes() 00073 { 00074 UnitTypeMap::iterator iter; 00075 for ( iter = mUnitTypes.begin(); iter != mUnitTypes.end(); iter++ ) 00076 { 00077 delete (*iter).second; 00078 } 00079 00080 mUnitTypes.clear (); 00081 } 00082 }