00001 #include "MercurySwapObject.h" 00002 #include "MercuryObjectFactory.h" 00003 00004 MercurySwapObject::~MercurySwapObject() 00005 { 00006 map< MString, MercuryObject*>::iterator i = m_swapobjects.begin(); 00007 00008 for (;i != m_swapobjects.end(); ++i) 00009 SAFE_DELETE( i->second ); 00010 } 00011 00012 void MercurySwapObject::Init() 00013 { 00014 MercuryObject::Init(); 00015 m_currentObject = NULL; 00016 } 00017 00018 void MercurySwapObject::AddSwapObject(const MString& key, MercuryObject* obj) 00019 { 00020 m_swapobjects[key] = obj; 00021 } 00022 00023 MercuryObject* MercurySwapObject::RemoveSwapObject(const MString& key) 00024 { 00025 MercuryObject* r = NULL; 00026 map< MString, MercuryObject*>::iterator i = m_swapobjects.find(key); 00027 if ( i != m_swapobjects.end() ) 00028 { 00029 r = i->second; 00030 if (r == m_currentObject) 00031 { 00032 RemoveObject(m_currentObject); 00033 m_currentObject = NULL; 00034 } 00035 } 00036 return r; 00037 } 00038 00039 bool MercurySwapObject::SwapTo(const MString& key) 00040 { 00041 map< MString, MercuryObject*>::iterator i = m_swapobjects.find(key); 00042 if ( i != m_swapobjects.end() ) 00043 { 00044 if (m_currentObject) 00045 ReplaceObject(m_currentObject, i->second); 00046 else 00047 AddObject(i->second); 00048 00049 m_currentObject = i->second; 00050 return true; 00051 } 00052 return false; 00053 } 00054 00055 REGISTER_OBJECT_TYPE( MercurySwapObject ); 00056 00057 /* 00058 * Copyright (c) 2005-2006, Charles Lohr 00059 * All rights reserved. 00060 * 00061 * Redistribution and use in source and binary forms, with or 00062 * without modification, are permitted provided that the following 00063 * conditions are met: 00064 * - Redistributions of source code must retain the above 00065 * copyright notice, this list of conditions and the following disclaimer. 00066 * - Redistributions in binary form must reproduce the above copyright 00067 * notice, this list of conditions and the following disclaimer in 00068 * the documentation and/or other materials provided with the distribution. 00069 * - Neither the name of the Mercury Engine nor the names of its 00070 * contributors may be used to endorse or promote products derived from 00071 * this software without specific prior written permission. 00072 * 00073 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00074 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00075 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00076 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00077 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00078 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00079 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00080 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00081 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00082 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00083 */