Changes in src/molecule.cpp [833b15:a7aebd]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
r833b15 ra7aebd 49 49 #include "CodePatterns/enumeration.hpp" 50 50 #include "CodePatterns/Log.hpp" 51 #include "CodePatterns/Observer/Notification.hpp" 51 52 #include "config.hpp" 52 53 #include "Descriptors/AtomIdDescriptor.hpp" … … 146 147 OBSERVE; 147 148 if(atomIdPool.reserveId(newNr)){ 149 _lastchangedatom = target; 148 150 NOTIFY(AtomNrChanged); 149 151 if (oldNr != -1) // -1 is reserved and indicates no number … … 207 209 { 208 210 OBSERVE; 209 NOTIFY(AtomRemoved);210 211 const_iterator iter = loc; 211 212 ++iter; 212 213 atom * const _atom = const_cast<atom *>(*loc); 214 { 215 _lastchangedatom = _atom; 216 NOTIFY(AtomRemoved); 217 } 213 218 atomIds.erase( _atom->getId() ); 214 219 { … … 226 231 { 227 232 OBSERVE; 228 NOTIFY(AtomRemoved); 233 { 234 _lastchangedatom = key; 235 NOTIFY(AtomRemoved); 236 } 229 237 const_iterator iter = find(key); 230 238 if (iter != end()){ … … 247 255 OBSERVE; 248 256 NOTIFY(AtomInserted); 257 _lastchangedatom = key; 249 258 std::pair<iterator,bool> res = atomIds.insert(key->getId()); 250 259 if (res.second) { // push atom if went well … … 637 646 /** Destroys all atoms inside this molecule. 638 647 */ 639 void molecule::removeAtomsinMolecule()648 void removeAtomsinMolecule(molecule *&_mol) 640 649 { 641 650 // remove each atom from world 642 for( iterator AtomRunner = begin(); !empty(); AtomRunner =begin())651 for(molecule::iterator AtomRunner = _mol->begin(); !_mol->empty(); AtomRunner = _mol->begin()) 643 652 World::getInstance().destroyAtom(*AtomRunner); 653 // make sure that pointer os not usable 654 _mol = NULL; 644 655 }; 645 656 … … 974 985 for(const_iterator iter = begin(); iter != end(); ++iter) 975 986 center += (*iter)->getPosition(); 976 center *= 1./(double)size(); 987 if (begin() != end()) 988 center *= 1./(double)size(); 977 989 for(const_iterator iter = begin(); iter != end(); ++iter) { 978 990 const Vector &position = (*iter)->getPosition(); … … 995 1007 } 996 1008 1009 void molecule::update(Observable *publisher) 1010 { 1011 ASSERT(0, "molecule::update() - did not sign on for any general updates."); 1012 } 1013 1014 void molecule::recieveNotification(Observable *publisher, Notification_ptr notification) 1015 { 1016 const atom * const _atom = dynamic_cast<atom *>(publisher); 1017 if ((_atom != NULL) && containsAtom(_atom)) { 1018 #ifdef LOG_OBSERVER 1019 observerLog().addMessage() << "++ Update of Observer "<< observerLog().getName(static_cast<Observer *>(this)) 1020 << " received notification from atom " << _atom->getId() << " for channel " 1021 << notification->getChannelNo() << "."; 1022 #endif 1023 switch (notification->getChannelNo()) { 1024 case AtomObservable::PositionChanged: 1025 { 1026 // emit others about one of our atoms moved 1027 _lastchangedatom = const_cast<atom *>(_atom); 1028 OBSERVE; 1029 NOTIFY(AtomMoved); 1030 break; 1031 } 1032 default: 1033 ASSERT( 0, "molecule::recieveNotification() - we did not sign up for channel " 1034 +toString(notification->getChannelNo())); 1035 break; 1036 } 1037 } 1038 } 1039 1040 void molecule::subjectKilled(Observable *publisher) 1041 { 1042 // do nothing, atom does it all 1043 } 1044 1045 997 1046 // construct idpool 998 1047 CONSTRUCT_IDPOOL(atomId_t, continuousId)
Note:
See TracChangeset
for help on using the changeset viewer.