[5d1611] | 1 | /*
|
---|
| 2 | * World.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Feb 3, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef WORLD_HPP_
|
---|
| 9 | #define WORLD_HPP_
|
---|
| 10 |
|
---|
| 11 | #include <boost/thread.hpp>
|
---|
[d346b6] | 12 | #include <map>
|
---|
[fc1b24] | 13 | #include <vector>
|
---|
[354859] | 14 | #include <set>
|
---|
[5d1611] | 15 |
|
---|
| 16 | #include "Patterns/Observer.hpp"
|
---|
| 17 | #include "Patterns/Cacheable.hpp"
|
---|
| 18 |
|
---|
| 19 | // forward declarations
|
---|
| 20 | class periodentafel;
|
---|
| 21 | class MoleculeListClass;
|
---|
[4d9c01] | 22 | class atom;
|
---|
[354859] | 23 | class molecule;
|
---|
[fc1b24] | 24 | class AtomDescriptor;
|
---|
[7a1ce5] | 25 | class AtomDescriptor_impl;
|
---|
[5d1611] | 26 |
|
---|
| 27 | class World : public Observable
|
---|
| 28 | {
|
---|
[7a1ce5] | 29 | friend class AtomDescriptor_impl;
|
---|
[5d1611] | 30 | public:
|
---|
| 31 |
|
---|
| 32 | /***** getter and setter *****/
|
---|
[354859] | 33 | // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
|
---|
| 34 | periodentafel *&getPeriode();
|
---|
[7a1ce5] | 35 | atom* getAtom(AtomDescriptor descriptor);
|
---|
| 36 | std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
|
---|
[354859] | 37 | int numAtoms();
|
---|
| 38 | int numMolecules();
|
---|
| 39 |
|
---|
| 40 | /***** Methods to work with the World *****/
|
---|
| 41 | molecule *createMolecule();
|
---|
[5d1611] | 42 | private:
|
---|
| 43 | periodentafel *periode;
|
---|
[d346b6] | 44 | std::map<int,atom*> atoms;
|
---|
[354859] | 45 | std::set<molecule*> molecules;
|
---|
[5d1611] | 46 |
|
---|
| 47 |
|
---|
| 48 | /***** singleton Stuff *****/
|
---|
| 49 | public:
|
---|
| 50 | static World* get();
|
---|
| 51 | static void destroy();
|
---|
| 52 | static World* reset();
|
---|
| 53 |
|
---|
| 54 | private:
|
---|
| 55 | World();
|
---|
| 56 | virtual ~World();
|
---|
| 57 |
|
---|
| 58 | static World *theWorld;
|
---|
| 59 | // this mutex only saves the singleton pattern...
|
---|
| 60 | // use other mutexes to protect internal data as well
|
---|
| 61 | // this mutex handles access to the pointer, not to the object!!!
|
---|
| 62 | static boost::mutex worldLock;
|
---|
| 63 |
|
---|
| 64 | /*****
|
---|
| 65 | * some legacy stuff that is include for now but will be removed later
|
---|
| 66 | *****/
|
---|
| 67 | public:
|
---|
[354859] | 68 | MoleculeListClass *&getMolecules();
|
---|
[4d9c01] | 69 |
|
---|
| 70 | // functions used for the WorldContent template mechanism
|
---|
[d346b6] | 71 | void registerAtom(atom *theAtom);
|
---|
| 72 | void unregisterAtom(atom *theAtom);
|
---|
[5d1611] | 73 | private:
|
---|
[354859] | 74 | // this function cleans up anything that cannot be cleaned while the lock is active
|
---|
| 75 | // at a later point all these cleanups have to be moved to the World Class so the deadlock and
|
---|
| 76 | // race condition can both be avoided.
|
---|
| 77 | void destroyLegacy();
|
---|
| 78 |
|
---|
| 79 | MoleculeListClass *molecules_deprecated;
|
---|
[7a1ce5] | 80 |
|
---|
| 81 | // this is needed to assign unique IDs to atoms... so far
|
---|
| 82 | // IDs are not assigned upon Atom creation, so we cannot query the ID
|
---|
| 83 | // during construction. By using the dummy ID we can make sure all atoms
|
---|
| 84 | // are actually stored in the map and don't overwrite each other.
|
---|
| 85 | int dummyId;
|
---|
[5d1611] | 86 | };
|
---|
| 87 |
|
---|
| 88 | #endif /* WORLD_HPP_ */
|
---|