source: molecuilder/src/World.hpp@ 7bfc19

Last change on this file since 7bfc19 was 7bfc19, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Made the world solely responsible for creating and destroying atoms.

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[2e8296]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
[5d4edf]11#include <string>
[d2d8f5]12#include <map>
[86b917]13#include <vector>
[120f8b]14#include <set>
[5d4edf]15#include <boost/thread.hpp>
[a5471c]16#include <boost/shared_ptr.hpp>
[2e8296]17
[5d4edf]18
[2e8296]19#include "Patterns/Observer.hpp"
20#include "Patterns/Cacheable.hpp"
21
22// forward declarations
23class periodentafel;
24class MoleculeListClass;
[42918b]25class atom;
[120f8b]26class molecule;
[86b917]27class AtomDescriptor;
[323177]28class AtomDescriptor_impl;
[5d4edf]29class ManipulateAtomsProcess;
[01d28a]30template<typename T>
31class AtomsCalculation;
[2e8296]32
33class World : public Observable
34{
[01d28a]35// necessary for coupling with descriptors
[323177]36friend class AtomDescriptor_impl;
[a5471c]37friend class AtomDescriptor;
38
[01d28a]39// Actions, calculations etc associated with the World
[5d4edf]40friend class ManipulateAtomsProcess;
[01d28a]41template<typename> friend class AtomsCalculation;
[5d4edf]42
[a5471c]43typedef std::map<int,atom*> AtomList;
[2e8296]44public:
45
46 /***** getter and setter *****/
[120f8b]47 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
48 periodentafel *&getPeriode();
[323177]49 atom* getAtom(AtomDescriptor descriptor);
50 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
[01d28a]51
52 template<typename T>
53 AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
54
[120f8b]55 int numAtoms();
56 int numMolecules();
57
58 /***** Methods to work with the World *****/
59 molecule *createMolecule();
[7bfc19]60 atom *createAtom();
61 int registerAtom(atom*);
62 void destroyAtom(atom*);
63 void destroyAtom(int);
[a5471c]64
[5d4edf]65 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
66
[a5471c]67protected:
68 /**** Iterators to use internal data structures */
69 class AtomIterator {
70 public:
[5d4edf]71 AtomIterator();
[a5471c]72 AtomIterator(AtomDescriptor, World*);
73 AtomIterator(const AtomIterator&);
[5d4edf]74 AtomIterator& operator=(const AtomIterator&);
75 AtomIterator& operator++(); // prefix
76 AtomIterator operator++(int); // postfix with dummy parameter
[a5471c]77 bool operator==(const AtomIterator&);
[5d4edf]78 bool operator==(const AtomList::iterator&);
[a5471c]79 bool operator!=(const AtomIterator&);
[5d4edf]80 bool operator!=(const AtomList::iterator&);
[a5471c]81 atom* operator*();
[5d4edf]82
83 int getCount();
[a5471c]84 protected:
85 void advanceState();
86 World* world;
87 AtomList::iterator state;
88 boost::shared_ptr<AtomDescriptor_impl> descr;
[5d4edf]89 int index;
[a5471c]90 };
91
92 AtomIterator getAtomIter(AtomDescriptor descr);
[5d4edf]93 AtomList::iterator atomEnd();
[a5471c]94
[9ef76a]95 /******* Internal manipulation routines for double callback and Observer mechanism ******/
96 void doManipulate(ManipulateAtomsProcess *);
97
[2e8296]98private:
99 periodentafel *periode;
[a5471c]100 AtomList atoms;
[7bfc19]101 int currAtomId; //!< stores the next available Id for atoms
[120f8b]102 std::set<molecule*> molecules;
[2e8296]103
104
105 /***** singleton Stuff *****/
106public:
107 static World* get();
108 static void destroy();
109 static World* reset();
110
111private:
112 World();
113 virtual ~World();
114
115 static World *theWorld;
116 // this mutex only saves the singleton pattern...
117 // use other mutexes to protect internal data as well
118 // this mutex handles access to the pointer, not to the object!!!
119 static boost::mutex worldLock;
120
121 /*****
122 * some legacy stuff that is include for now but will be removed later
123 *****/
124public:
[120f8b]125 MoleculeListClass *&getMolecules();
[42918b]126
[2e8296]127private:
[120f8b]128 MoleculeListClass *molecules_deprecated;
[2e8296]129};
130
131#endif /* WORLD_HPP_ */
Note: See TracBrowser for help on using the repository browser.