Changes in src/World.hpp [88d586:6e97e5]
- File:
-
- 1 edited
-
src/World.hpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/World.hpp
r88d586 r6e97e5 16 16 #include <boost/shared_ptr.hpp> 17 17 18 #include "defs.hpp" 18 #include "types.hpp" 19 #include "Descriptors/SelectiveIterator.hpp" 19 20 #include "Patterns/Observer.hpp" 20 21 #include "Patterns/Cacheable.hpp" 22 #include "Patterns/Singleton.hpp" 23 21 24 22 25 // forward declarations … … 33 36 class AtomsCalculation; 34 37 35 class World : public Observable 38 39 40 class World : public Singleton<World>, public Observable 36 41 { 42 43 // Make access to constructor and destructor possible from inside the singleton 44 friend class Singleton<World>; 45 37 46 // necessary for coupling with descriptors 38 47 friend class AtomDescriptor_impl; … … 45 54 template<typename> friend class AtomsCalculation; 46 55 public: 56 57 // Types for Atom and Molecule structures 47 58 typedef std::map<atomId_t,atom*> AtomSet; 48 59 typedef std::map<moleculeId_t,molecule*> MoleculeSet; … … 150 161 151 162 // Atoms 152 153 class AtomIterator { 154 public: 155 AtomIterator(); 156 AtomIterator(AtomDescriptor, World*); 157 AtomIterator(const AtomIterator&); 158 AtomIterator& operator=(const AtomIterator&); 159 AtomIterator& operator++(); // prefix 160 AtomIterator operator++(int); // postfix with dummy parameter 161 bool operator==(const AtomIterator&); 162 bool operator==(const AtomSet::iterator&); 163 bool operator!=(const AtomIterator&); 164 bool operator!=(const AtomSet::iterator&); 165 atom* operator*(); 166 167 int getCount(); 168 protected: 169 void advanceState(); 170 AtomSet::iterator state; 171 boost::shared_ptr<AtomDescriptor_impl> descr; 172 int index; 173 174 World* world; 175 }; 163 typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator; 176 164 177 165 /** … … 187 175 * used for internal purposes, like AtomProcesses and AtomCalculations. 188 176 */ 189 Atom Set::iterator atomEnd();177 AtomIterator atomEnd(); 190 178 191 179 // Molecules 192 180 193 class MoleculeIterator { 194 public: 195 MoleculeIterator(); 196 MoleculeIterator(MoleculeDescriptor, World*); 197 MoleculeIterator(const MoleculeIterator&); 198 MoleculeIterator& operator=(const MoleculeIterator&); 199 MoleculeIterator& operator++(); // prefix 200 MoleculeIterator operator++(int); // postfix with dummy parameter 201 bool operator==(const MoleculeIterator&); 202 bool operator==(const MoleculeSet::iterator&); 203 bool operator!=(const MoleculeIterator&); 204 bool operator!=(const MoleculeSet::iterator&); 205 molecule* operator*(); 206 207 int getCount(); 208 protected: 209 void advanceState(); 210 MoleculeSet::iterator state; 211 boost::shared_ptr<MoleculeDescriptor_impl> descr; 212 int index; 213 214 World* world; 215 }; 181 typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator; 216 182 217 183 /** … … 227 193 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 228 194 */ 229 Molecule Set::iterator moleculeEnd();195 MoleculeIterator moleculeEnd(); 230 196 231 197 … … 240 206 241 207 periodentafel *periode; 208 public: 242 209 AtomSet atoms; 210 private: 243 211 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 244 212 atomId_t currAtomId; //!< stores the next available Id for atoms 245 213 MoleculeSet molecules; 246 214 moleculeId_t currMoleculeId; 247 248 249 /***** singleton Stuff *****/250 public:251 252 /**253 * get the currently active instance of the World.254 */255 static World* get();256 257 /**258 * destroy the currently active instance of the World.259 */260 static void destroy();261 262 /**263 * destroy the currently active instance of the World and immidiately264 * create a new one. Use this to reset while somebody is still Observing265 * the world and should reset the observed instance. All observers will be266 * sent the subjectKille() message from the old world.267 */268 static World* reset();269 270 215 private: 271 216 /** … … 280 225 */ 281 226 virtual ~World(); 282 283 static World *theWorld;284 // this mutex only saves the singleton pattern...285 // use other mutexes to protect internal data as well286 // this mutex handles access to the pointer, not to the object!!!287 static boost::mutex worldLock;288 227 289 228 /*****
Note:
See TracChangeset
for help on using the changeset viewer.
