Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.hpp

    r88d586 r6e97e5  
    1616#include <boost/shared_ptr.hpp>
    1717
    18 #include "defs.hpp"
     18#include "types.hpp"
     19#include "Descriptors/SelectiveIterator.hpp"
    1920#include "Patterns/Observer.hpp"
    2021#include "Patterns/Cacheable.hpp"
     22#include "Patterns/Singleton.hpp"
     23
    2124
    2225// forward declarations
     
    3336class AtomsCalculation;
    3437
    35 class World : public Observable
     38
     39
     40class World : public Singleton<World>, public Observable
    3641{
     42
     43// Make access to constructor and destructor possible from inside the singleton
     44friend class Singleton<World>;
     45
    3746// necessary for coupling with descriptors
    3847friend class AtomDescriptor_impl;
     
    4554template<typename> friend class AtomsCalculation;
    4655public:
     56
     57  // Types for Atom and Molecule structures
    4758  typedef std::map<atomId_t,atom*> AtomSet;
    4859  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     
    150161
    151162  // 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;
    176164
    177165  /**
     
    187175   * used for internal purposes, like AtomProcesses and AtomCalculations.
    188176   */
    189   AtomSet::iterator atomEnd();
     177  AtomIterator atomEnd();
    190178
    191179  // Molecules
    192180
    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;
    216182
    217183  /**
     
    227193   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    228194   */
    229   MoleculeSet::iterator moleculeEnd();
     195  MoleculeIterator moleculeEnd();
    230196
    231197
     
    240206
    241207  periodentafel *periode;
     208public:
    242209  AtomSet atoms;
     210private:
    243211  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
    244212  atomId_t currAtomId; //!< stores the next available Id for atoms
    245213  MoleculeSet molecules;
    246214  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 immidiately
    264    * create a new one. Use this to reset while somebody is still Observing
    265    * the world and should reset the observed instance. All observers will be
    266    * sent the subjectKille() message from the old world.
    267    */
    268   static World* reset();
    269 
    270215private:
    271216  /**
     
    280225   */
    281226  virtual ~World();
    282 
    283   static World *theWorld;
    284   // this mutex only saves the singleton pattern...
    285   // use other mutexes to protect internal data as well
    286   // this mutex handles access to the pointer, not to the object!!!
    287   static boost::mutex worldLock;
    288227
    289228  /*****
Note: See TracChangeset for help on using the changeset viewer.