Changes in src/World.cpp [24a5e0:028c2e]
- File:
-
- 1 edited
-
src/World.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/World.cpp
r24a5e0 r028c2e 12 12 #include "periodentafel.hpp" 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 #include "Descriptors/AtomDescriptor_impl.hpp"15 #include "Actions/ManipulateAtomsProcess.hpp"16 14 17 15 using namespace std; … … 30 28 } 31 29 32 vector<atom*> World::getAllAtoms(){33 return getAllAtoms(AllAtoms());34 }35 36 30 int World::numAtoms(){ 37 31 return atoms.size(); … … 42 36 } 43 37 44 /******************** Methods to change World state *********************/45 46 38 molecule* World::createMolecule(){ 47 39 OBSERVE; 48 40 molecule *mol = NULL; 49 mol = NewMolecule(); 50 assert(!molecules.count(currMoleculeId)); 51 mol->setId(currMoleculeId++); 52 // store the molecule by ID 53 molecules[mol->getId()] = mol; 41 mol = new molecule(periode); 42 molecules_deprecated->insert(mol); 43 molecules.insert(mol); 54 44 mol->signOn(this); 55 45 return mol; 56 46 } 57 47 58 void World::destroyMolecule(molecule* mol){59 OBSERVE;60 destroyMolecule(mol->getId());61 }62 63 void World::destroyMolecule(moleculeId_t id){64 OBSERVE;65 molecule *mol = molecules[id];66 assert(mol);67 DeleteMolecule(mol);68 molecules.erase(id);69 }70 71 72 atom *World::createAtom(){73 OBSERVE;74 atom *res = NewAtom();75 assert(!atoms.count(currAtomId));76 res->setId(currAtomId++);77 res->setWorld(this);78 // store the atom by ID79 atoms[res->getId()] = res;80 return res;81 }82 83 int World::registerAtom(atom *atom){84 OBSERVE;85 assert(!atoms.count(currAtomId));86 atom->setId(currAtomId++);87 atom->setWorld(this);88 atoms[atom->getId()] = atom;89 return atom->getId();90 }91 92 void World::destroyAtom(atom* atom){93 OBSERVE;94 int id = atom->getId();95 destroyAtom(id);96 }97 98 void World::destroyAtom(atomId_t id) {99 OBSERVE;100 atom *atom = atoms[id];101 assert(atom);102 DeleteAtom(atom);103 atoms.erase(id);104 }105 106 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){107 return new ManipulateAtomsProcess(op, descr,name,true);108 }109 110 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){111 return manipulateAtoms(op,name,AllAtoms());112 }113 114 /********************* Internal Change methods for double Callback and Observer mechanism ********/115 116 void World::doManipulate(ManipulateAtomsProcess *proc){117 proc->signOn(this);118 {119 OBSERVE;120 proc->doManipulate(this);121 }122 proc->signOff(this);123 }124 125 /******************************* Iterators ********************************/126 127 /*128 * Actual Implementation of the iterators can be found in WorldIterators.cpp129 */130 131 World::AtomIterator World::getAtomIter(AtomDescriptor descr){132 return AtomIterator(descr,this);133 }134 135 World::AtomSet::iterator World::atomEnd(){136 return atoms.end();137 }138 48 139 49 /******************************* Singleton Stuff **************************/ … … 143 53 boost::mutex World::worldLock; 144 54 55 56 145 57 World::World() : 146 58 periode(new periodentafel), 147 atoms(), 148 currAtomId(0), 149 molecules(), 150 currMoleculeId(0), 151 molecules_deprecated(new MoleculeListClass(this)) 59 molecules_deprecated(new MoleculeListClass), 60 dummyId(0) 152 61 { 153 62 molecules_deprecated->signOn(this); … … 156 65 World::~World() 157 66 { 67 molecules_deprecated->signOff(this); 158 68 delete molecules_deprecated; 159 69 delete periode; 160 MoleculeSet::iterator molIter;161 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){162 DeleteMolecule((*molIter).second);163 }164 molecules.clear();165 AtomSet::iterator atIter;166 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){167 DeleteAtom((*atIter).second);168 }169 atoms.clear();170 70 } 171 71 … … 180 80 181 81 void World::destroy(){ 82 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise 83 theWorld->destroyLegacy(); 84 //WARNING: at this point we have a small race condition, when sombody now tries to access the world. 85 182 86 // boost supports RAII-Style locking, so we don't need to unlock 183 87 boost::mutex::scoped_lock guard(worldLock); … … 187 91 188 92 World* World::reset(){ 93 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise 94 theWorld->destroyLegacy(); 95 //WARNING: at this point we have a small race condition, when sombody now tries to access the world. 96 189 97 World* oldWorld = 0; 190 98 { … … 206 114 // should see that it gets the updated new world 207 115 delete oldWorld; 208 return theWorld;209 116 } 210 117 … … 214 121 return molecules_deprecated; 215 122 } 123 124 // some legacy stuff to let the World know about items created outside 125 void World::registerAtom(atom *theAtom){ 126 OBSERVE; 127 atoms[dummyId++] = theAtom; 128 } 129 130 void World::destroyLegacy(){ 131 //delete molecules_deprecated; 132 } 133 134 void World::unregisterAtom(atom *theAtom){ 135 OBSERVE; 136 atoms.erase(theAtom->getId()); 137 }
Note:
See TracChangeset
for help on using the changeset viewer.
