source: molecuilder/src/World.cpp@ 323177

Last change on this file since 323177 was 323177, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Rebuilt AtomDescriptors using PIMPL-Idiom and added unittest for descriptors

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * World.cpp
3 *
4 * Created on: Feb 3, 2010
5 * Author: crueger
6 */
7
8#include "World.hpp"
9
10#include "atom.hpp"
11#include "Descriptors/AtomDescriptor.hpp"
12
13using namespace std;
14
15/******************************* getter and setter ************************/
16periodentafel* World::getPeriode(){
17 return periode;
18}
19
20atom* World::getAtom(AtomDescriptor descriptor){
21 return descriptor.find();
22}
23
24vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
25 return descriptor.findAll();
26}
27
28/******************************* Singleton Stuff **************************/
29
30// TODO: Hide boost-thread using Autotools stuff when no threads are used
31World* World::theWorld = 0;
32boost::mutex World::worldLock;
33
34
35
36World::World() :
37 dummyId(0)
38{}
39
40World::~World()
41{}
42
43World* World::get(){
44 // boost supports RAII-Style locking, so we don't need to unlock
45 boost::mutex::scoped_lock guard(worldLock);
46 if(!theWorld) {
47 theWorld = new World();
48 }
49 return theWorld;
50}
51
52void World::destroy(){
53 // boost supports RAII-Style locking, so we don't need to unlock
54 boost::mutex::scoped_lock guard(worldLock);
55 delete theWorld;
56 theWorld = 0;
57}
58
59World* World::reset(){
60 World* oldWorld = 0;
61 {
62 // boost supports RAII-Style locking, so we don't need to unlock
63 boost::mutex::scoped_lock guard(worldLock);
64
65 oldWorld = theWorld;
66 theWorld = new World();
67 // oldworld does not need protection any more,
68 // since we should have the only reference
69
70 // worldLock handles access to the pointer,
71 // not to the object
72 } // scope-end releases the lock
73
74 // we have to let all the observers know that the
75 // oldWorld was destroyed. oldWorld calls subjectKilled
76 // upon destruction. Every Observer getting that signal
77 // should see that it gets the updated new world
78 delete oldWorld;
79}
80
81/******************************* deprecated Legacy Stuff ***********************/
82
83MoleculeListClass *World::getMolecules() {
84 return molecules;
85}
86
87// some legacy stuff to let the World know about items created outside
88void World::registerAtom(atom *theAtom){
89 OBSERVE;
90 atoms[dummyId++] = theAtom;
91}
92
93void World::unregisterAtom(atom *theAtom){
94 OBSERVE;
95 atoms.erase(theAtom->getId());
96}
Note: See TracBrowser for help on using the repository browser.