bool CMapEventManager::Delete ( CLuaMain* pLuaMain, const char* szName, const CLuaFunctionRef& iLuaFunction ) { // Delete all the events with matching names bool bRemovedSomeone = false; EventsIter iter = m_EventsMap.begin (); while ( iter != m_EventsMap.end () ) { CMapEvent* pMapEvent = iter->second; // Matching VM? if ( pLuaMain == pMapEvent->GetVM () ) { // If name supplied, check name and function if ( !szName || ( ( strcmp ( pMapEvent->GetName (), szName ) == 0 ) && ( pMapEvent->GetLuaFunction () == iLuaFunction ) ) ) { // Not alredy being destroyed? if ( !pMapEvent->IsBeingDestroyed () ) { // Are we in an event handler? if ( m_bIteratingList ) { // Put it in the trashcan pMapEvent->SetBeingDestroyed ( true ); m_TrashCan.push_back ( pMapEvent ); // Remember that we deleted something bRemovedSomeone = true; } else { // Delete the object delete pMapEvent; // Remove from list and remember that we deleted something m_EventsMap.erase ( iter++ ); bRemovedSomeone = true; continue; } } } } // Increment iterator ++iter; } m_bHasEvents = !m_EventsMap.empty (); // Return whether we actually destroyed someone or not return bRemovedSomeone; }
bool CMapEventManager::Delete ( CLuaMain* pLuaMain, const char* szName, int iLuaFunction ) { // Delete all the events with matching names bool bRemovedSomeone = false; CMapEvent* pMapEvent = NULL; list < CMapEvent* > ::iterator iter = m_Events.begin (); while ( iter != m_Events.end () ) { pMapEvent = *iter; // Matching VM and name? if ( pLuaMain == pMapEvent->GetVM () && strcmp ( pMapEvent->GetName (), szName ) == 0 ) { // Same lua function? if ( pMapEvent->GetLuaFunction () == iLuaFunction ) { // Not alredy being destroyed? if ( !pMapEvent->IsBeingDestroyed () ) { // Are we in an event handler? if ( m_bIteratingList ) { // Put it in the trashcan pMapEvent->SetBeingDestroyed ( true ); m_TrashCan.push_back ( *iter ); // Remember that we deleted something bRemovedSomeone = true; } else { // Delete the object delete pMapEvent; // Remove from list and remember that we deleted something iter = m_Events.erase ( iter ); bRemovedSomeone = true; continue; } } } } // Increment iterator iter++; } // Return whether we actually destroyed someone or not return bRemovedSomeone; }
void CMapEventManager::Delete ( CLuaMain* pLuaMain ) { // Delete all the events with matching lua VM's CMapEvent* pMapEvent = NULL; list < CMapEvent* > ::iterator iter = m_Events.begin (); while ( iter != m_Events.end () ) { pMapEvent = *iter; // Maching VM's? if ( pMapEvent->GetVM () == pLuaMain ) { // Not already being destroyed? if ( !pMapEvent->IsBeingDestroyed () ) { // Are we iterating the list? if ( m_bIteratingList ) { // Add it to trashcan and mark as being destroyed pMapEvent->SetBeingDestroyed ( true ); m_TrashCan.push_back ( pMapEvent ); } else { // Delete the event and continue from where we left. // Remember to subtract from our iterator or we'll delete only every other element. delete pMapEvent; iter = m_Events.erase ( iter ); continue; } } } // Increment iterator ++iter; } }