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