Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Atom/atom_bondedparticle.cpp

    r8cc22f r5aaa43  
    5252BondedParticle::BondedParticle()
    5353{
    54   ListOfBonds.insert( std::make_pair(0, emptyList) );
     54  ListOfBonds.push_back(BondList());
    5555};
    5656
     
    5959BondedParticle::~BondedParticle()
    6060{
    61   for(BondTrajectory_t::iterator iter = ListOfBonds.begin(); !ListOfBonds.empty();
    62       iter = ListOfBonds.begin()) {
    63     removeAllBonds(iter->first);
    64     ListOfBonds.erase(iter);
    65   }
     61  removeAllBonds();
    6662};
    6763
     
    224220}
    225221
    226 /** Removes all bonds in current timestep and their instances, too.
     222/** Removes all bonds in all timesteps and their instances, too.
    227223 *
    228224 */
    229225void BondedParticle::removeAllBonds()
    230226{
    231   removeAllBonds(WorldTime::getTime());
     227  for (size_t index = 0; index < ListOfBonds.size(); ++index)
     228    removeAllBonds(index);
    232229}
    233230
     
    239236{
    240237  //LOG(3,"INFO: Clearing all bonds of " << *this << ": " << ListOfBonds[_step]);
    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     }
     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  }
    254249}
    255250
     
    265260    if (Binder->Contains(this)) {
    266261      //LOG(3,"INFO: Registering bond "<< *Binder << " with atom " << *this << " at step " << _step);
    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);
     262      if (ListOfBonds.size() <= _step)
     263        ListOfBonds.resize(_step+1);
     264      ListOfBonds[_step].push_back(Binder);
    271265      if (WorldTime::getTime() == _step)
    272266        NOTIFY(AtomObservable::BondsAdded);
     
    296290      OBSERVE;
    297291      //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()) {
    300292#ifndef NDEBUG
    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));
     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));
    306298#endif
    307         Binder->removeAtom(this);
    308         listiter->second.remove(Binder);
    309         if (WorldTime::getTime() == _step)
    310           NOTIFY(AtomObservable::BondsRemoved);
    311         status = true;
    312       }
     299      Binder->removeAtom(this);
     300      ListOfBonds[_step].remove(Binder);
     301      if (WorldTime::getTime() == _step)
     302        NOTIFY(AtomObservable::BondsRemoved);
     303      status = true;
    313304    } else {
    314305      ELOG(1, *Binder << " does not contain " << *this << ".");
     
    337328{
    338329  int step = -1;
    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();
     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();
    344336        ++bonditer) {
    345337      if ((*bonditer) == Binder) {
    346         step = listiter->first;
     338        step = tempstep;
    347339        break;
    348340      }
Note: See TracChangeset for help on using the changeset viewer.