bool BoxClass::Replace(Route & oldroute, Route & newroute) { DEBUGLOG(smartptr,_T("oldroute; %p, newroute; %p"), (void*)oldroute.get(),(void*)newroute.get()); bool found = Remove(oldroute); mutASSERT(found); if (found) Add(newroute); DEBUGLOG(smartptr,_T("oldroute; %p, newroute; %p"), (void*)oldroute.get(),(void*)newroute.get()); return found; }
void BoxClass::Add(Route & route) { BoxLock lock(this); DEBUGLOG(smartptr,_T("Route; %p"),(void*)route.get()); #ifdef DEBUG routeListType::const_iterator i = find(routes.begin(),routes.end(),route); mutASSERT(i == routes.end()); mutASSERT(IsInBoxList(this)); #endif TRACEC; routes.push_back(route); DEBUGLOG(smartptr,_T("Route; %p saved"),(void*)route.get()); }
bool BoxClass::Remove(Route & route) { BoxLock lock(this); DEBUGLOG(smartptr,_T("Route: %p (%d)"), (void*)route.get(), (int)intrusive_ptr_get_refcount(route.get())); routeListType::iterator i = std::find(routes.begin(),routes.end(),route); bool found = (i != routes.end()); mutASSERT(found); if (found) { (*i).reset();// list can save some memory for reuse, // but route must be deleted routes.erase(i); } DEBUGLOG(smartptr,_T("Route; %p (%d)"),(void*)route.get(), (int)intrusive_ptr_get_refcount(route.get())); return found; }