source: molecuilder/src/World.cpp@ 9565ec

Last change on this file since 9565ec was 9565ec, checked in by Frederik Heber <heber@…>, 16 years ago

singleton class World introduced, contains only cell_size from class molecule.

  • class World is actually code from Till Crueger from his branch StructureRefactoring.
  • has been introduced here in minimalistic form to allow molecule::cell_size to be outsourced to World::cell_size
  • access to cell_size can be obtained from anyhwere by invoking World::get()->cell_size
  • INFO: cell_size was placed in class molecule for the fragmentation procedure where the cell_size had to be individually adapted to each fragment.
  • all appearances have been changed accordingly. Where appropriate we have employed a const pointer onto cell_size.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 * world.cpp
3 *
4 * Created on: Mar 3, 2010
5 * Author: heber
6 */
7
8#include "World.hpp"
9
10double *World::cell_size = 0;
11
12/** Constructor of World.
13 *
14 */
15World::World()
16{
17 cell_size = new double[6];
18};
19
20/** Destructor of World.
21 *
22 */
23World::~World()
24{
25 delete[](cell_size);
26};
27
28
29// TODO: Hide boost-thread using Autotools stuff when no threads are used
30World* World::theWorld = 0;
31
32
33World* World::get(){
34 // boost supports RAII-Style locking, so we don't need to unlock
35 if(!theWorld) {
36 theWorld = new World();
37 }
38 return theWorld;
39}
40
41void World::destroy(){
42 delete theWorld;
43 theWorld = 0;
44}
45
46World* World::reset(){
47 World* oldWorld = 0;
48 {
49 oldWorld = theWorld;
50 theWorld = new World();
51 // oldworld does not need protection any more,
52 // since we should have the only reference
53
54 // worldLock handles access to the pointer,
55 // not to the object
56 } // scope-end releases the lock
57
58 // we have to let all the observers know that the
59 // oldWorld was destroyed. oldWorld calls subjectKilled
60 // upon destruction. Every Observer getting that signal
61 // should see that it gets the updated new world
62 delete oldWorld;
63}
Note: See TracBrowser for help on using the repository browser.