Changes in src/Atom/atom_bondedparticle.cpp [5aaa43:8cc22f]
- File:
-
- 1 edited
-
src/Atom/atom_bondedparticle.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Atom/atom_bondedparticle.cpp
r5aaa43 r8cc22f 52 52 BondedParticle::BondedParticle() 53 53 { 54 ListOfBonds. push_back(BondList());54 ListOfBonds.insert( std::make_pair(0, emptyList) ); 55 55 }; 56 56 … … 59 59 BondedParticle::~BondedParticle() 60 60 { 61 removeAllBonds(); 61 for(BondTrajectory_t::iterator iter = ListOfBonds.begin(); !ListOfBonds.empty(); 62 iter = ListOfBonds.begin()) { 63 removeAllBonds(iter->first); 64 ListOfBonds.erase(iter); 65 } 62 66 }; 63 67 … … 220 224 } 221 225 222 /** Removes all bonds in all timestepsand their instances, too.226 /** Removes all bonds in current timestep and their instances, too. 223 227 * 224 228 */ 225 229 void BondedParticle::removeAllBonds() 226 230 { 227 for (size_t index = 0; index < ListOfBonds.size(); ++index) 228 removeAllBonds(index); 231 removeAllBonds(WorldTime::getTime()); 229 232 } 230 233 … … 236 239 { 237 240 //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]); 238 for (BondList::iterator iter = (ListOfBonds[_step]).begin(); 239 !(ListOfBonds[_step]).empty(); 240 iter = (ListOfBonds[_step]).begin()) { 241 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds); 242 atom * const Other = (*iter)->GetOtherAtom(this); 243 ASSERT( Other != NULL, 244 "BondedParticle::removeAllBonds() - cannot find bond partner for " 245 +toString(**iter)+"."); 246 Other->UnregisterBond(_step, *iter); 247 UnregisterBond(_step, *iter); 248 } 241 BondTrajectory_t::iterator listiter = ListOfBonds.find(_step); 242 if (listiter != ListOfBonds.end()) 243 for (BondList::iterator iter = listiter->second.begin(); 244 !listiter->second.empty(); 245 iter = listiter->second.begin()) { 246 //LOG(3,"INFO: Clearing bond (" << *iter << ") " << *(*iter) << " of list " << &ListOfBonds); 247 atom * const Other = (*iter)->GetOtherAtom(this); 248 ASSERT( Other != NULL, 249 "BondedParticle::removeAllBonds() - cannot find bond partner for " 250 +toString(**iter)+"."); 251 Other->UnregisterBond(_step, *iter); 252 UnregisterBond(_step, *iter); 253 } 249 254 } 250 255 … … 260 265 if (Binder->Contains(this)) { 261 266 //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step); 262 if (ListOfBonds.size() <= _step) 263 ListOfBonds.resize(_step+1); 264 ListOfBonds[_step].push_back(Binder); 267 std::pair< BondTrajectory_t::iterator, bool> inserter = 268 ListOfBonds.insert( std::make_pair( _step, BondList(1, Binder)) ); 269 if (!inserter.second) 270 inserter.first->second.push_back(Binder); 265 271 if (WorldTime::getTime() == _step) 266 272 NOTIFY(AtomObservable::BondsAdded); … … 290 296 OBSERVE; 291 297 //LOG(0,"INFO: Unregistering bond "<< *Binder << " from list " << &ListOfBonds << " of atom " << *this << " at step " << step); 298 BondTrajectory_t::iterator listiter = ListOfBonds.find(_step); 299 if (listiter != ListOfBonds.end()) { 292 300 #ifndef NDEBUG 293 BondList::const_iterator iter =294 std::find(ListOfBonds[_step].begin(), ListOfBonds[_step].end(), Binder);295 ASSERT( iter != ListOfBonds[_step].end(),296 "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at "297 +toString(_step));301 BondList::const_iterator iter = 302 std::find(listiter->second.begin(), listiter->second.end(), Binder); 303 ASSERT( iter != listiter->second.end(), 304 "BondedParticle::UnregisterBond() - "+toString(*Binder)+" not contained at " 305 +toString(_step)); 298 306 #endif 299 Binder->removeAtom(this); 300 ListOfBonds[_step].remove(Binder); 301 if (WorldTime::getTime() == _step) 302 NOTIFY(AtomObservable::BondsRemoved); 303 status = true; 307 Binder->removeAtom(this); 308 listiter->second.remove(Binder); 309 if (WorldTime::getTime() == _step) 310 NOTIFY(AtomObservable::BondsRemoved); 311 status = true; 312 } 304 313 } else { 305 314 ELOG(1, *Binder << " does not contain " << *this << "."); … … 328 337 { 329 338 int step = -1; 330 int tempstep = 0; 331 for(std::vector<BondList>::const_iterator iter = ListOfBonds.begin(); 332 iter != ListOfBonds.end(); 333 ++iter,++tempstep) { 334 for (BondList::const_iterator bonditer = iter->begin(); 335 bonditer != iter->end(); 339 for(BondTrajectory_t::const_iterator listiter = ListOfBonds.begin(); 340 listiter != ListOfBonds.end(); 341 ++listiter) { 342 for (BondList::const_iterator bonditer = listiter->second.begin(); 343 bonditer != listiter->second.end(); 336 344 ++bonditer) { 337 345 if ((*bonditer) == Binder) { 338 step = tempstep;346 step = listiter->first; 339 347 break; 340 348 }
Note:
See TracChangeset
for help on using the changeset viewer.
