Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/World.cpp

    r23b547 ra77c96  
    1616#include "Descriptors/MoleculeDescriptor_impl.hpp"
    1717#include "Actions/ManipulateAtomsProcess.hpp"
    18 
    19 #include "Patterns/Singleton_impl.hpp"
    2018
    2119using namespace std;
     
    231229/******************************* Singleton Stuff **************************/
    232230
     231// TODO: Hide boost-thread using Autotools stuff when no threads are used
     232World* World::theWorld = 0;
     233boost::mutex World::worldLock;
     234
    233235World::World() :
    234236    periode(new periodentafel),
     
    259261}
    260262
    261 // Explicit instantiation of the singleton mechanism at this point
    262 
    263 CONSTRUCT_SINGLETON(World)
     263World* World::get(){
     264  // boost supports RAII-Style locking, so we don't need to unlock
     265  boost::mutex::scoped_lock guard(worldLock);
     266  if(!theWorld) {
     267    theWorld = new World();
     268  }
     269  return theWorld;
     270}
     271
     272void World::destroy(){
     273  // boost supports RAII-Style locking, so we don't need to unlock
     274  boost::mutex::scoped_lock guard(worldLock);
     275  delete theWorld;
     276  theWorld = 0;
     277}
     278
     279World* World::reset(){
     280  World* oldWorld = 0;
     281  {
     282    // boost supports RAII-Style locking, so we don't need to unlock
     283    boost::mutex::scoped_lock guard(worldLock);
     284
     285    oldWorld = theWorld;
     286    theWorld = new World();
     287    // oldworld does not need protection any more,
     288    // since we should have the only reference
     289
     290    // worldLock handles access to the pointer,
     291    // not to the object
     292  } // scope-end releases the lock
     293
     294  // we have to let all the observers know that the
     295  // oldWorld was destroyed. oldWorld calls subjectKilled
     296  // upon destruction. Every Observer getting that signal
     297  // should see that it gets the updated new world
     298  delete oldWorld;
     299  return theWorld;
     300}
    264301
    265302/******************************* deprecated Legacy Stuff ***********************/
Note: See TracChangeset for help on using the changeset viewer.