/* * World.hpp * * Created on: Feb 3, 2010 * Author: crueger */ #ifndef WORLD_HPP_ #define WORLD_HPP_ #include #include #include #include #include #include #include "Patterns/Observer.hpp" #include "Patterns/Cacheable.hpp" // forward declarations class periodentafel; class MoleculeListClass; class atom; class molecule; class AtomDescriptor; class AtomDescriptor_impl; class ManipulateAtomsProcess; template class AtomsCalculation; class World : public Observable { // necessary for coupling with descriptors friend class AtomDescriptor_impl; friend class AtomDescriptor; // Actions, calculations etc associated with the World friend class ManipulateAtomsProcess; template friend class AtomsCalculation; typedef std::map AtomList; public: /***** getter and setter *****/ // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object periodentafel *&getPeriode(); atom* getAtom(AtomDescriptor descriptor); std::vector getAllAtoms(AtomDescriptor descriptor); template AtomsCalculation* calcOnAtoms(boost::function,std::string,AtomDescriptor); int numAtoms(); int numMolecules(); /***** Methods to work with the World *****/ molecule *createMolecule(); atom *createAtom(); int registerAtom(atom*); void destroyAtom(atom*); void destroyAtom(int); ManipulateAtomsProcess* manipulateAtoms(boost::function,std::string,AtomDescriptor); protected: /**** Iterators to use internal data structures */ class AtomIterator { public: AtomIterator(); AtomIterator(AtomDescriptor, World*); AtomIterator(const AtomIterator&); AtomIterator& operator=(const AtomIterator&); AtomIterator& operator++(); // prefix AtomIterator operator++(int); // postfix with dummy parameter bool operator==(const AtomIterator&); bool operator==(const AtomList::iterator&); bool operator!=(const AtomIterator&); bool operator!=(const AtomList::iterator&); atom* operator*(); int getCount(); protected: void advanceState(); World* world; AtomList::iterator state; boost::shared_ptr descr; int index; }; AtomIterator getAtomIter(AtomDescriptor descr); AtomList::iterator atomEnd(); /******* Internal manipulation routines for double callback and Observer mechanism ******/ void doManipulate(ManipulateAtomsProcess *); private: periodentafel *periode; AtomList atoms; int currAtomId; //!< stores the next available Id for atoms std::set molecules; /***** singleton Stuff *****/ public: static World* get(); static void destroy(); static World* reset(); private: World(); virtual ~World(); static World *theWorld; // this mutex only saves the singleton pattern... // use other mutexes to protect internal data as well // this mutex handles access to the pointer, not to the object!!! static boost::mutex worldLock; /***** * some legacy stuff that is include for now but will be removed later *****/ public: MoleculeListClass *&getMolecules(); private: MoleculeListClass *molecules_deprecated; }; #endif /* WORLD_HPP_ */