Ignore:
Timestamp:
Feb 24, 2010, 4:21:12 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
5bf941
Parents:
01d28a
git-author:
Tillmann Crueger <crueger@…> (02/24/10 15:29:12)
git-committer:
Tillmann Crueger <crueger@…> (02/24/10 16:21:12)
Message:

Made the world solely responsible for creating and destroying atoms.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/World.cpp

    r01d28a r7bfc19  
    5151
    5252
     53atom *World::createAtom(){
     54  OBSERVE;
     55  atom *res = NewAtom();
     56  res->setId(currAtomId++);
     57  res->setWorld(this);
     58  atoms[res->getId()] = res;
     59  return res;
     60}
     61
     62int World::registerAtom(atom *atom){
     63  OBSERVE;
     64  atom->setId(currAtomId++);
     65  atom->setWorld(this);
     66  atoms[atom->getId()] = atom;
     67  return atom->getId();
     68}
     69
     70void World::destroyAtom(atom* atom){
     71  OBSERVE;
     72  int id = atom->getId();
     73  destroyAtom(id);
     74}
     75
     76void World::destroyAtom(int id) {
     77  OBSERVE;
     78  atom *atom = atoms[id];
     79  assert(atom);
     80  DeleteAtom(atom);
     81  atoms.erase(id);
     82}
     83
    5384ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
    5485  return new ManipulateAtomsProcess(op, descr,name,true);
     
    160191
    161192World::World() :
    162     dummyId(0),
     193    currAtomId(0),
    163194    periode(new periodentafel),
    164195    molecules_deprecated(new MoleculeListClass),
     
    170201World::~World()
    171202{
     203  delete molecules_deprecated;
    172204  delete periode;
     205  AtomList::iterator iter;
     206  for(iter=atoms.begin();iter!=atoms.end();++iter){
     207    DeleteAtom((*iter).second);
     208  }
     209  atoms.clear();
    173210}
    174211
     
    183220
    184221void World::destroy(){
    185   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    186   theWorld->destroyLegacy();
    187   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    188 
    189222  // boost supports RAII-Style locking, so we don't need to unlock
    190223  boost::mutex::scoped_lock guard(worldLock);
     
    194227
    195228World* World::reset(){
    196   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    197   theWorld->destroyLegacy();
    198   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    199 
    200229  World* oldWorld = 0;
    201230  {
     
    224253  return molecules_deprecated;
    225254}
    226 
    227 // some legacy stuff to let the World know about items created outside
    228 void World::registerAtom(atom *theAtom){
    229   OBSERVE;
    230   atoms[dummyId++] = theAtom;
    231 }
    232 
    233 void World::destroyLegacy(){
    234   //delete molecules_deprecated;
    235 }
    236 
    237 void World::unregisterAtom(atom *theAtom){
    238   OBSERVE;
    239   atoms.erase(theAtom->getId());
    240 }
Note: See TracChangeset for help on using the changeset viewer.