Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.hpp

    r6e97e5 r88d586  
    1616#include <boost/shared_ptr.hpp>
    1717
    18 #include "types.hpp"
    19 #include "Descriptors/SelectiveIterator.hpp"
     18#include "defs.hpp"
    2019#include "Patterns/Observer.hpp"
    2120#include "Patterns/Cacheable.hpp"
    22 #include "Patterns/Singleton.hpp"
    23 
    2421
    2522// forward declarations
     
    3633class AtomsCalculation;
    3734
    38 
    39 
    40 class World : public Singleton<World>, public Observable
     35class World : public Observable
    4136{
    42 
    43 // Make access to constructor and destructor possible from inside the singleton
    44 friend class Singleton<World>;
    45 
    4637// necessary for coupling with descriptors
    4738friend class AtomDescriptor_impl;
     
    5445template<typename> friend class AtomsCalculation;
    5546public:
    56 
    57   // Types for Atom and Molecule structures
    5847  typedef std::map<atomId_t,atom*> AtomSet;
    5948  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     
    161150
    162151  // Atoms
    163   typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
     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  };
    164176
    165177  /**
     
    175187   * used for internal purposes, like AtomProcesses and AtomCalculations.
    176188   */
    177   AtomIterator atomEnd();
     189  AtomSet::iterator atomEnd();
    178190
    179191  // Molecules
    180192
    181   typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
     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  };
    182216
    183217  /**
     
    193227   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
    194228   */
    195   MoleculeIterator moleculeEnd();
     229  MoleculeSet::iterator moleculeEnd();
    196230
    197231
     
    206240
    207241  periodentafel *periode;
    208 public:
    209242  AtomSet atoms;
    210 private:
    211243  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
    212244  atomId_t currAtomId; //!< stores the next available Id for atoms
    213245  MoleculeSet molecules;
    214246  moleculeId_t currMoleculeId;
     247
     248
     249  /***** singleton Stuff *****/
     250public:
     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
    215270private:
    216271  /**
     
    225280   */
    226281  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;
    227288
    228289  /*****
Note: See TracChangeset for help on using the changeset viewer.