Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    r6e97e5 r57adc7  
    1515#include "Descriptors/MoleculeDescriptor.hpp"
    1616#include "Descriptors/MoleculeDescriptor_impl.hpp"
    17 #include "Descriptors/SelectiveIterator_impl.hpp"
    1817#include "Actions/ManipulateAtomsProcess.hpp"
    19 
    20 #include "Patterns/Singleton_impl.hpp"
    2118
    2219using namespace std;
     
    173170    atomId_t id = *(atomIdPool.begin());
    174171    atomIdPool.erase(id);
    175     return id;
    176172  }
    177173}
     
    210206/******************************* Iterators ********************************/
    211207
    212 // Build the AtomIterator from template
    213 CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
    214 
     208/*
     209 * Actual Implementation of the iterators can be found in WorldIterators.cpp
     210 */
    215211
    216212World::AtomIterator World::getAtomIter(AtomDescriptor descr){
    217   return AtomIterator(descr,atoms);
    218 }
    219 
    220 World::AtomIterator World::atomEnd(){
    221   return AtomIterator(AllAtoms(),atoms,atoms.end());
    222 }
    223 
    224 // build the MoleculeIterator from template
    225 CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
     213  return AtomIterator(descr,this);
     214}
     215
     216World::AtomSet::iterator World::atomEnd(){
     217  return atoms.end();
     218}
    226219
    227220World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
    228   return MoleculeIterator(descr,molecules);
    229 }
    230 
    231 World::MoleculeIterator World::moleculeEnd(){
    232   return MoleculeIterator(AllMolecules(),molecules,molecules.end());
     221  return MoleculeIterator(descr,this);
     222}
     223
     224World::MoleculeSet::iterator World::moleculeEnd(){
     225  return molecules.end();
    233226}
    234227
    235228/******************************* Singleton Stuff **************************/
     229
     230// TODO: Hide boost-thread using Autotools stuff when no threads are used
     231World* World::theWorld = 0;
     232boost::mutex World::worldLock;
    236233
    237234World::World() :
     
    263260}
    264261
    265 // Explicit instantiation of the singleton mechanism at this point
    266 
    267 CONSTRUCT_SINGLETON(World)
     262World* World::get(){
     263  // boost supports RAII-Style locking, so we don't need to unlock
     264  boost::mutex::scoped_lock guard(worldLock);
     265  if(!theWorld) {
     266    theWorld = new World();
     267  }
     268  return theWorld;
     269}
     270
     271void World::destroy(){
     272  // boost supports RAII-Style locking, so we don't need to unlock
     273  boost::mutex::scoped_lock guard(worldLock);
     274  delete theWorld;
     275  theWorld = 0;
     276}
     277
     278World* World::reset(){
     279  World* oldWorld = 0;
     280  {
     281    // boost supports RAII-Style locking, so we don't need to unlock
     282    boost::mutex::scoped_lock guard(worldLock);
     283
     284    oldWorld = theWorld;
     285    theWorld = new World();
     286    // oldworld does not need protection any more,
     287    // since we should have the only reference
     288
     289    // worldLock handles access to the pointer,
     290    // not to the object
     291  } // scope-end releases the lock
     292
     293  // we have to let all the observers know that the
     294  // oldWorld was destroyed. oldWorld calls subjectKilled
     295  // upon destruction. Every Observer getting that signal
     296  // should see that it gets the updated new world
     297  delete oldWorld;
     298  return theWorld;
     299}
    268300
    269301/******************************* deprecated Legacy Stuff ***********************/
Note: See TracChangeset for help on using the changeset viewer.