Changeset 7bfc19 for molecuilder/src/World.cpp
- Timestamp:
- Feb 24, 2010, 4:21:12 PM (16 years ago)
- Children:
- 5bf941
- Parents:
- 01d28a
- git-author:
- Tillmann Crueger <crueger@…> (02/24/10 15:29:12)
- git-committer:
- Tillmann Crueger <crueger@…> (02/24/10 16:21:12)
- File:
-
- 1 edited
-
molecuilder/src/World.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
molecuilder/src/World.cpp
r01d28a r7bfc19 51 51 52 52 53 atom *World::createAtom(){ 54 OBSERVE; 55 atom *res = NewAtom(); 56 res->setId(currAtomId++); 57 res->setWorld(this); 58 atoms[res->getId()] = res; 59 return res; 60 } 61 62 int World::registerAtom(atom *atom){ 63 OBSERVE; 64 atom->setId(currAtomId++); 65 atom->setWorld(this); 66 atoms[atom->getId()] = atom; 67 return atom->getId(); 68 } 69 70 void World::destroyAtom(atom* atom){ 71 OBSERVE; 72 int id = atom->getId(); 73 destroyAtom(id); 74 } 75 76 void World::destroyAtom(int id) { 77 OBSERVE; 78 atom *atom = atoms[id]; 79 assert(atom); 80 DeleteAtom(atom); 81 atoms.erase(id); 82 } 83 53 84 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 54 85 return new ManipulateAtomsProcess(op, descr,name,true); … … 160 191 161 192 World::World() : 162 dummyId(0),193 currAtomId(0), 163 194 periode(new periodentafel), 164 195 molecules_deprecated(new MoleculeListClass), … … 170 201 World::~World() 171 202 { 203 delete molecules_deprecated; 172 204 delete periode; 205 AtomList::iterator iter; 206 for(iter=atoms.begin();iter!=atoms.end();++iter){ 207 DeleteAtom((*iter).second); 208 } 209 atoms.clear(); 173 210 } 174 211 … … 183 220 184 221 void World::destroy(){ 185 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise186 theWorld->destroyLegacy();187 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.188 189 222 // boost supports RAII-Style locking, so we don't need to unlock 190 223 boost::mutex::scoped_lock guard(worldLock); … … 194 227 195 228 World* World::reset(){ 196 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise197 theWorld->destroyLegacy();198 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.199 200 229 World* oldWorld = 0; 201 230 { … … 224 253 return molecules_deprecated; 225 254 } 226 227 // some legacy stuff to let the World know about items created outside228 void World::registerAtom(atom *theAtom){229 OBSERVE;230 atoms[dummyId++] = theAtom;231 }232 233 void World::destroyLegacy(){234 //delete molecules_deprecated;235 }236 237 void World::unregisterAtom(atom *theAtom){238 OBSERVE;239 atoms.erase(theAtom->getId());240 }
Note:
See TracChangeset
for help on using the changeset viewer.
