void CAtom::remove_guard( CAtom** ptr ) { if( !*ptr ) return; GuardMap* map = guard_map(); if( !map || map->empty() ) return; bool more = false; // if the CAtom has more pointers attached to it. GuardMap::iterator it = map->find( *ptr ); const GuardMap::iterator end = map->end(); for( ; it != end && it->first == *ptr; ++it ) { if( it->second == ptr ) { if( !more ) { ++it; more = ( it != end ) && ( it->first == *ptr ); --it; } map->erase( it ); break; } more = true; } if( !more ) ( *ptr )->set_has_guards( false ); }
void CAtom::clear_guards( CAtom* o ) { GuardMap* map = 0; try { map = guard_map(); } catch( std::bad_alloc& ) { // do nothing in case of OOM - code below is safe } if( !map || map->empty() ) return; GuardMap::iterator it = map->find( o ); GuardMap::iterator first = it; const GuardMap::iterator end = map->end(); for( ; it != end && it->first == o; ++it ) *it->second = 0; map->erase( first, it ); o->set_has_guards( false ); }