Changes in / [cd032d:a77c96]


Ignore:
Location:
src
Files:
4 deleted
45 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    rcd032d ra77c96  
    1717{
    1818  if(_doRegister){
    19     ActionRegistry::getInstance().registerAction(this);
     19    ActionRegistry::getRegistry()->registerAction(this);
    2020  }
    2121}
  • src/Actions/ActionRegistry.cpp

    rcd032d ra77c96  
    99#include "Actions/Action.hpp"
    1010
    11 #include "Patterns/Singleton_impl.hpp"
    12 
    1311#include <string>
    1412#include <cassert>
     
    1614
    1715using namespace std;
     16
     17ActionRegistry *ActionRegistry::theInstance=0;
    1818
    1919ActionRegistry::ActionRegistry()
     
    4343}
    4444
    45 CONSTRUCT_SINGLETON(ActionRegistry)
     45// singleton stuff
     46ActionRegistry* ActionRegistry::getRegistry(){
     47  if(!theInstance){
     48    theInstance = new ActionRegistry();
     49  }
     50  return theInstance;
     51}
     52
     53void ActionRegistry::purgeRegistry(){
     54  if(theInstance){
     55    delete theInstance;
     56    theInstance = 0;
     57  }
     58}
  • src/Actions/ActionRegistry.hpp

    rcd032d ra77c96  
    1212#include <map>
    1313
    14 #include "Patterns/Singleton.hpp"
    15 
    1614class Action;
    1715
    18 class ActionRegistry : public Singleton<ActionRegistry>
     16class ActionRegistry
    1917{
    20   friend class Singleton<ActionRegistry>;
    2118public:
    2219  Action* getActionByName(const std::string);
     
    2623  std::map<const std::string,Action*> actionMap;
    2724
     25// singleton stuff
     26public:
     27  static ActionRegistry* getRegistry();
     28  static void purgeRegistry();
    2829private:
    2930  ActionRegistry();
    3031  virtual ~ActionRegistry();
     32  static ActionRegistry *theInstance;
    3133};
    3234
  • src/Actions/AtomsCalculation_impl.hpp

    rcd032d ra77c96  
    2929template<typename T>
    3030std::vector<T>* AtomsCalculation<T>::doCalc(){
    31   World* world = World::getPointer();
     31  World* world = World::get();
    3232  int steps = world->numAtoms();
     33  int count = 0;
    3334  std::vector<T> *res = new std::vector<T>();
    3435  res->reserve(steps);
  • src/Actions/ManipulateAtomsProcess.cpp

    rcd032d ra77c96  
    2323
    2424void ManipulateAtomsProcess::call(){
    25   World::getInstance().doManipulate(this);
     25  World::get()->doManipulate(this);
    2626}
    2727
  • src/Actions/small_actions.cpp

    rcd032d ra77c96  
    2727  string filename;
    2828  molecule *mol = NULL;
    29   Dialog *dialog = UIFactory::getInstance().makeDialog();
     29  Dialog *dialog = UIFactory::get()->makeDialog();
    3030
    3131  dialog->queryMolecule("Enter index of molecule: ",&mol,molecules);
  • src/Descriptors/AtomDescriptor.cpp

    rcd032d ra77c96  
    6868
    6969World::AtomSet& AtomDescriptor_impl::getAtoms(){
    70   return World::getInstance().atoms;
     70  return World::get()->atoms;
    7171}
    7272
  • src/Descriptors/AtomTypeDescriptor.cpp

    rcd032d ra77c96  
    2929
    3030AtomDescriptor AtomByType(int Z){
    31   element * elem = World::getInstance().getPeriode()->FindElement(Z);
     31  element * elem = World::get()->getPeriode()->FindElement(Z);
    3232  return AtomByType(elem);
    3333}
  • src/Descriptors/MoleculeDescriptor.cpp

    rcd032d ra77c96  
    6868
    6969World::MoleculeSet& MoleculeDescriptor_impl::getMolecules(){
    70   return World::getInstance().molecules;
     70  return World::get()->molecules;
    7171}
    7272
  • src/Legacy/oldmenu.cpp

    rcd032d ra77c96  
    7878      case 'a': // absolute coordinates of atom
    7979        Log() << Verbose(0) << "Enter absolute coordinates." << endl;
    80         first = World::getInstance().createAtom();
     80        first = World::get()->createAtom();
    8181        first->x.AskPosition(mol->cell_size, false);
    8282        first->type = periode->AskElement();  // give type
     
    8585
    8686      case 'b': // relative coordinates of atom wrt to reference point
    87         first = World::getInstance().createAtom();
     87        first = World::get()->createAtom();
    8888        valid = true;
    8989        do {
     
    101101
    102102      case 'c': // relative coordinates of atom wrt to already placed atom
    103         first = World::getInstance().createAtom();
     103        first = World::get()->createAtom();
    104104        valid = true;
    105105        do {
     
    117117
    118118    case 'd': // two atoms, two angles and a distance
    119         first = World::getInstance().createAtom();
     119        first = World::get()->createAtom();
    120120        valid = true;
    121121        do {
     
    217217
    218218      case 'e': // least square distance position to a set of atoms
    219         first = World::getInstance().createAtom();
     219        first = World::get()->createAtom();
    220220        atoms = new (Vector*[128]);
    221221        valid = true;
     
    239239          mol->AddAtom(first);  // add to molecule
    240240        } else {
    241           World::getInstance().destroyAtom(first);
     241          World::get()->destroyAtom(first);
    242242          Log() << Verbose(0) << "Please enter at least two vectors!\n";
    243243        }
     
    782782        x.AddVector(&y); // per factor one cell width further
    783783        for (int k=count;k--;) { // go through every atom of the original cell
    784           first = World::getInstance().createAtom(); // create a new body
     784          first = World::get()->createAtom(); // create a new body
    785785          first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    786786          first->x.AddVector(&x);     // translate the coordinates
     
    912912void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
    913913  molecule *srcmol = NULL, *destmol = NULL;
    914   Dialog *dialog = UIFactory::getInstance().makeDialog();
     914  Dialog *dialog = UIFactory::get()->makeDialog();
    915915  dialog->queryMolecule("Enter index of destination molecule: ",&destmol, molecules);
    916916  dialog->queryMolecule("Enter index of source molecule to add from: ",&srcmol, molecules);
     
    926926void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
    927927  molecule *srcmol = NULL, *destmol = NULL;
    928   Dialog *dialog = UIFactory::getInstance().makeDialog();
     928  Dialog *dialog = UIFactory::get()->makeDialog();
    929929  dialog->queryMolecule("Enter index of matrix molecule (the variable one): ",&srcmol,molecules);
    930930  dialog->queryMolecule("Enter index of molecule to merge into (the fixed one): ",&destmol,molecules);
     
    10891089    A++;
    10901090  }
    1091   World::getInstance().destroyMolecule(mol);
     1091  World::get()->destroyMolecule(mol);
    10921092};
    10931093
  • src/Makefile.am

    rcd032d ra77c96  
    1818
    1919PATTERNSOURCE = Patterns/Observer.cpp
    20 PATTERNHEADER = Patterns/Cacheable.hpp \
    21                                 Patterns/Observer.hpp \
    22                 Patterns/Singleton.hpp
     20PATTERNHEADER = Patterns/Observer.hpp Patterns/Cacheable.hpp
    2321
    2422VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
  • src/UIElements/QT4/QTDialog.cpp

    rcd032d ra77c96  
    266266    parent(_parent)
    267267{
    268   periodentafel *periode = World::getInstance().getPeriode();
     268  periodentafel *periode = World::get()->getPeriode();
    269269  thisLayout = new QHBoxLayout();
    270270  titleLabel = new QLabel(QString(getTitle().c_str()));
     
    367367  QVariant data = theBox->itemData(newIndex);
    368368  int idx = data.toInt();
    369   (*content) = World::getInstance().getPeriode()->FindElement(idx);
    370   dialog->update();
    371 }
    372 
     369  (*content) = World::get()->getPeriode()->FindElement(idx);
     370  dialog->update();
     371}
     372
  • src/UIElements/TextDialog.cpp

    rcd032d ra77c96  
    136136  Log() << Verbose(0) << getTitle();
    137137  cin >> Z;
    138   tmp = World::getInstance().getPeriode()->FindElement(Z);
     138  tmp = World::get()->getPeriode()->FindElement(Z);
    139139  return tmp;
    140140}
  • src/UIElements/UIFactory.cpp

    rcd032d ra77c96  
    88
    99#include <cassert>
    10 #include "Patterns/Singleton_impl.hpp"
    1110#include "UIElements/UIFactory.hpp"
    1211
     
    1615#include "UIElements/QT4/QTUIFactory.hpp"
    1716#endif
     17
     18UIFactory *UIFactory::theFactory = 0;
    1819
    1920UIFactory::UIFactory()
     
    2930
    3031void UIFactory::makeUserInterface(InterfaceTypes type) {
     32  assert(theFactory == 0 && "makeUserInterface should only be called once");
    3133  switch(type) {
    3234    case Text :
    33       setInstance(new TextUIFactory());
     35      theFactory = new TextUIFactory();
    3436      break;
    3537#ifdef USE_GUI_QT
    3638    case QT4 :
    37       setInstance(new QTUIFactory());
     39      theFactory = new QTUIFactory();
    3840      break;
    3941#endif
     
    4446}
    4547
    46 CONSTRUCT_SINGLETON(UIFactory)
     48UIFactory* UIFactory::get(){
     49  assert(theFactory != 0 && "No UserInterface created prior to factory access");
     50  return theFactory;
     51}
     52
     53
     54void UIFactory::purgeInstance(){
     55  if(theFactory) {
     56    delete theFactory;
     57    theFactory = 0;
     58  }
     59}
  • src/UIElements/UIFactory.hpp

    rcd032d ra77c96  
    1717
    1818struct menuPopulaters;
    19 
    20 #include "Patterns/Singleton.hpp"
    21 
    2219/**
    2320 * Abstract Factory to create any kind of User interface object needed by the programm.
     
    2724 * UIs can be handled in a concise abstract way.
    2825 */
    29 class UIFactory : public Singleton<UIFactory,false>
     26class UIFactory
    3027{
    3128
     
    5350  UIFactory();
    5451
     52// singleton stuff
     53private:
     54  static UIFactory *theFactory;
     55
    5556public:
    5657  /**
     
    5960  static void makeUserInterface(InterfaceTypes type);
    6061
     62  /**
     63   * get the previously created factory
     64   */
     65  static UIFactory* get();
     66
     67  /**
     68   * Destroy the created factory.
     69   *
     70   * Make sure that all UIElements that were created by the factory are destroyed before calling this method.
     71   */
     72  static void purgeInstance();
    6173};
    6274
  • src/Views/QT4/QTStatusBar.cpp

    rcd032d ra77c96  
    2121  QStatusBar(_parent),
    2222  parent(_parent),
    23   atomCount(World::getInstance().numAtoms()),
    24   moleculeCount(World::getInstance().numMolecules())
     23  atomCount(World::get()->numAtoms()),
     24  moleculeCount(World::get()->numMolecules())
    2525{
    26   World::getInstance().signOn(this);
     26  World::get()->signOn(this);
    2727  Process::AddObserver(this);
    2828  statusLabel = new QLabel(this);
     
    3535{
    3636  Process::RemoveObserver(this);
    37   World::getInstance().signOff(this);
     37  World::get()->signOff(this);
    3838}
    3939
    4040void QTStatusBar::update(Observable *subject){
    41   if (subject==World::getPointer()){
    42     atomCount = World::getInstance().numAtoms();
    43     moleculeCount = World::getInstance().numMolecules();
     41  if (subject==World::get()){
     42    atomCount = World::get()->numAtoms();
     43    moleculeCount = World::get()->numMolecules();
    4444    redrawStatus();
    4545  }
     
    4747    // we probably have some process
    4848    Process *proc;
    49     if((proc=dynamic_cast<Process*>(subject))){
     49    if(proc=dynamic_cast<Process*>(subject)){
    5050      redrawProcess(proc);
    5151    }
     
    5555void QTStatusBar::subjectKilled(Observable *subject){
    5656  // Processes don't notify when they are killed
    57   atomCount = World::getInstance().numAtoms();
    58   moleculeCount = World::getInstance().numMolecules();
    59   World::getInstance().signOn(this);
     57  atomCount = World::get()->numAtoms();
     58  moleculeCount = World::get()->numMolecules();
     59  World::get()->signOn(this);
    6060  redrawStatus();
    6161}
  • src/World.cpp

    rcd032d 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 ***********************/
  • src/World.hpp

    rcd032d ra77c96  
    1919#include "Patterns/Observer.hpp"
    2020#include "Patterns/Cacheable.hpp"
    21 #include "Patterns/Singleton.hpp"
    22 
    2321
    2422// forward declarations
     
    3533class AtomsCalculation;
    3634
    37 
    38 
    39 class World : public Singleton<World>, public Observable
     35class World : public Observable
    4036{
    41 
    42 // Make access to constructor and destructor possible from inside the singleton
    43 friend class Singleton<World>;
    44 
    4537// necessary for coupling with descriptors
    4638friend class AtomDescriptor_impl;
     
    5345template<typename> friend class AtomsCalculation;
    5446public:
    55 
    56   // Types for Atom and Molecule structures
    5747  typedef std::map<atomId_t,atom*> AtomSet;
    5848  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     
    161151  // Atoms
    162152
    163   class AtomIterator :
    164     public std::iterator<std::iterator_traits<AtomSet::iterator>::difference_type,
    165                          std::iterator_traits<AtomSet::iterator>::value_type,
    166                          std::iterator_traits<AtomSet::iterator>::pointer,
    167                          std::iterator_traits<AtomSet::iterator>::reference>
    168   {
     153  class AtomIterator {
    169154  public:
    170 
    171     typedef AtomSet::iterator _Iter;
    172     typedef _Iter::value_type value_type;
    173     typedef _Iter::difference_type difference_type;
    174     typedef _Iter::pointer pointer;
    175     typedef _Iter::reference reference;
    176     typedef _Iter::iterator_category iterator_category;
    177 
    178 
    179155    AtomIterator();
    180156    AtomIterator(AtomDescriptor, World*);
     
    215191  // Molecules
    216192
    217   class MoleculeIterator :
    218     public std::iterator<std::iterator_traits<MoleculeSet::iterator>::difference_type,
    219                          std::iterator_traits<MoleculeSet::iterator>::value_type,
    220                          std::iterator_traits<MoleculeSet::iterator>::pointer,
    221                          std::iterator_traits<MoleculeSet::iterator>::reference>
    222   {
     193  class MoleculeIterator {
    223194  public:
    224 
    225     typedef MoleculeSet::iterator _Iter;
    226     typedef _Iter::value_type value_type;
    227     typedef _Iter::difference_type difference_type;
    228     typedef _Iter::pointer pointer;
    229     typedef _Iter::reference reference;
    230     typedef _Iter::iterator_category iterator_category;
    231 
    232195    MoleculeIterator();
    233196    MoleculeIterator(MoleculeDescriptor, World*);
     
    282245  MoleculeSet molecules;
    283246  moleculeId_t currMoleculeId;
     247
     248
     249  /***** singleton Stuff *****/
     250public:
     251
     252  /**
     253   * get the currently active instance of the World.
     254   */
     255  static World* get();
     256
     257  /**
     258   * destroy the currently active instance of the World.
     259   */
     260  static void destroy();
     261
     262  /**
     263   * destroy the currently active instance of the World and immidiately
     264   * create a new one. Use this to reset while somebody is still Observing
     265   * the world and should reset the observed instance. All observers will be
     266   * sent the subjectKille() message from the old world.
     267   */
     268  static World* reset();
     269
    284270private:
    285271  /**
     
    294280   */
    295281  virtual ~World();
     282
     283  static World *theWorld;
     284  // this mutex only saves the singleton pattern...
     285  // use other mutexes to protect internal data as well
     286  // this mutex handles access to the pointer, not to the object!!!
     287  static boost::mutex worldLock;
    296288
    297289  /*****
  • src/WorldIterators.cpp

    rcd032d ra77c96  
    1717
    1818World::AtomIterator::AtomIterator(){
    19   state = World::getInstance().atomEnd();
     19  state = World::get()->atomEnd();
    2020}
    2121
     
    9595
    9696World::MoleculeIterator::MoleculeIterator(){
    97   state = World::getInstance().moleculeEnd();
     97  state = World::get()->moleculeEnd();
    9898}
    9999
  • src/atom.cpp

    rcd032d ra77c96  
    5050  res->FixedIon = FixedIon;
    5151  res->node = &x;
    52   World::getInstance().registerAtom(res);
     52  World::get()->registerAtom(res);
    5353  return res;
    5454}
  • src/atom_atominfo.cpp

    rcd032d ra77c96  
    2929
    3030void AtomInfo::setType(int Z) {
    31   element *elem = World::getInstance().getPeriode()->FindElement(Z);
     31  element *elem = World::get()->getPeriode()->FindElement(Z);
    3232  setType(elem);
    3333}
  • src/boundary.cpp

    rcd032d ra77c96  
    801801{
    802802        Info FunctionInfo(__func__);
    803   molecule *Filling = World::getInstance().createMolecule();
     803  molecule *Filling = World::get()->createMolecule();
    804804  Vector CurrentPosition;
    805805  int N[NDIM];
  • src/builder.cpp

    rcd032d ra77c96  
    14331433     }
    14341434     if (mol == NULL) {
    1435        mol = World::getInstance().createMolecule();
     1435       mol = World::get()->createMolecule();
    14361436       mol->ActiveFlag = true;
    14371437       if (ConfigFileName != NULL)
     
    14821482                SaveFlag = true;
    14831483                Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
    1484                 first = World::getInstance().createAtom();
     1484                first = World::get()->createAtom();
    14851485                first->type = periode->FindElement(atoi(argv[argptr]));
    14861486                if (first->type != NULL)
     
    16351635                Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    16361636                // construct water molecule
    1637                 molecule *filler = World::getInstance().createMolecule();
     1637                molecule *filler = World::get()->createMolecule();
    16381638                molecule *Filling = NULL;
    16391639                atom *second = NULL, *third = NULL;
     
    16421642//                first->x.Zero();
    16431643//                filler->AddAtom(first);
    1644                 first = World::getInstance().createAtom();
     1644                first = World::get()->createAtom();
    16451645                first->type = periode->FindElement(1);
    16461646                first->x.Init(0.441, -0.143, 0.);
    16471647                filler->AddAtom(first);
    1648                 second = World::getInstance().createAtom();
     1648                second = World::get()->createAtom();
    16491649                second->type = periode->FindElement(1);
    16501650                second->x.Init(-0.464, 1.137, 0.0);
    16511651                filler->AddAtom(second);
    1652                 third = World::getInstance().createAtom();
     1652                third = World::get()->createAtom();
    16531653                third->type = periode->FindElement(8);
    16541654                third->x.Init(-0.464, 0.177, 0.);
     
    16651665                  molecules->insert(Filling);
    16661666                }
    1667                 World::getInstance().destroyMolecule(filler);
     1667                World::get()->destroyMolecule(filler);
    16681668                argptr+=6;
    16691669              }
     
    20982098                      x.AddVector(&y); // per factor one cell width further
    20992099                      for (int k=count;k--;) { // go through every atom of the original cell
    2100                         first = World::getInstance().createAtom(); // create a new body
     2100                        first = World::get()->createAtom(); // create a new body
    21012101                        first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    21022102                        first->x.AddVector(&x);      // translate the coordinates
     
    21692169void cleanUp(config *configuration){
    21702170  UIFactory::purgeInstance();
    2171   World::purgeInstance();
     2171  World::destroy();
    21722172  delete(configuration);
    21732173  Log() << Verbose(0) <<  "Maximum of allocated memory: "
     
    21782178  logger::purgeInstance();
    21792179  errorLogger::purgeInstance();
    2180   ActionRegistry::purgeInstance();
     2180  ActionRegistry::purgeRegistry();
    21812181}
    21822182
     
    21932193    setVerbosity(0);
    21942194    /* structure of ParseCommandLineOptions will be refactored later */
    2195     j = ParseCommandLineOptions(argc, argv,  World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName);
     2195    j = ParseCommandLineOptions(argc, argv,  World::get()->getMolecules(), World::get()->getPeriode(), *configuration, ConfigFileName);
    21962196    switch (j){
    21972197        case 255:
     
    22032203            break;
    22042204    }
    2205     if(World::getInstance().numMolecules() == 0){
    2206         mol = World::getInstance().createMolecule();
    2207         World::getInstance().getMolecules()->insert(mol);
     2205    if(World::get()->numMolecules() == 0){
     2206        mol = World::get()->createMolecule();
     2207        World::get()->getMolecules()->insert(mol);
    22082208        if(mol->cell_size[0] == 0.){
    22092209            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
     
    22282228      UIFactory::makeUserInterface(UIFactory::Text);
    22292229#endif
    2230       MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
     2230      MainWindow *mainWindow = UIFactory::get()->makeMainWindow(populaters,World::get()->getMolecules(), configuration, World::get()->getPeriode(), ConfigFileName);
    22312231      mainWindow->display();
    22322232
     
    22342234    }
    22352235
    2236     if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath))
     2236    if(World::get()->getPeriode()->StorePeriodentafel(configuration->databasepath))
    22372237        Log() << Verbose(0) << "Saving of elements.db successful." << endl;
    22382238
  • src/config.cpp

    rcd032d ra77c96  
    733733            sprintf(keyword,"%s_%i",name, j+1);
    734734            if (repetition == 0) {
    735               neues = World::getInstance().createAtom();
     735              neues = World::get()->createAtom();
    736736              AtomList[i][j] = neues;
    737737              LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    812812          sprintf(keyword,"%s_%i",name, j+1);
    813813          if (repetition == 0) {
    814             neues = World::getInstance().createAtom();
     814            neues = World::get()->createAtom();
    815815            AtomList[i][j] = neues;
    816816            LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    851851void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    852852{
    853   molecule *mol = World::getInstance().createMolecule();
     853  molecule *mol = World::get()->createMolecule();
    854854  ifstream *file = new ifstream(filename);
    855855  if (file == NULL) {
     
    10891089void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    10901090{
    1091   molecule *mol = World::getInstance().createMolecule();
     1091  molecule *mol = World::get()->createMolecule();
    10921092  ifstream *file = new ifstream(filename);
    10931093  if (file == NULL) {
     
    12881288        }
    12891289        istringstream input2(zeile);
    1290         atom *neues = World::getInstance().createAtom();
     1290        atom *neues = World::get()->createAtom();
    12911291        input2 >> neues->x.x[0]; // x
    12921292        input2 >> neues->x.x[1]; // y
     
    17881788  char filename[MAXSTRINGSIZE];
    17891789  ofstream output;
    1790   molecule *mol = World::getInstance().createMolecule();
     1790  molecule *mol = World::get()->createMolecule();
    17911791  mol->SetNameFromFilename(ConfigFileName);
    17921792
     
    18991899  }
    19001900
    1901   World::getInstance().destroyMolecule(mol);
     1901  World::get()->destroyMolecule(mol);
    19021902};
    19031903
  • src/errorlogger.cpp

    rcd032d ra77c96  
    99#include "errorlogger.hpp"
    1010#include "verbose.hpp"
    11 #include "Patterns/Singleton_impl.hpp"
    1211
    1312ofstream null("/dev/null");
     13
     14errorLogger* errorLogger::instance = NULL;
    1415int errorLogger::verbosity = 2;
    1516ostream* errorLogger::nix = &null;
     
    2223errorLogger::errorLogger()
    2324{
     25  instance = NULL;
    2426  verbosity = 2;
    2527};
     
    3234}
    3335
    34 CONSTRUCT_SINGLETON(errorLogger)
     36/**
     37 * Returns the singleton errorLogger instance.
     38 *
     39 * \return errorLogger instance
     40 */
     41errorLogger* errorLogger::getInstance() {
     42  if (instance == NULL) {
     43    instance = new errorLogger();
     44  }
     45
     46  return instance;
     47}
     48
     49
     50/**
     51 * Purges the current errorLogger instance.
     52 */
     53void errorLogger::purgeInstance() {
     54  if (instance != NULL) {
     55    delete instance;
     56  }
     57
     58  instance = NULL;
     59}
    3560
    3661/**
  • src/errorlogger.hpp

    rcd032d ra77c96  
    1111#include <iostream>
    1212
    13 #include "Patterns/Singleton.hpp"
    14 
    1513using namespace std;
    1614
    1715class Verbose;
    1816
    19 class errorLogger : public Singleton<errorLogger>{
    20   friend class Singleton<errorLogger>;
     17class errorLogger {
    2118public :
    2219  static ostream *nix;
    2320  static int verbosity;
    2421
     22  static errorLogger* getInstance();
     23  static void purgeInstance();
    2524  static bool DoOutput();
    2625  static void setVerbosity(int verbosityLevel);
     
    3231  ~errorLogger();
    3332
     33private:
     34  static errorLogger* instance;
    3435};
    3536
  • src/log.cpp

    rcd032d ra77c96  
    1515 */
    1616void setVerbosity(int verbosityLevel) {
    17   logger::getInstance().setVerbosity(verbosityLevel);
    18   errorLogger::getInstance().setVerbosity(verbosityLevel);
     17  logger::getInstance()->setVerbosity(verbosityLevel);
     18  errorLogger::getInstance()->setVerbosity(verbosityLevel);
    1919}
    2020
     
    2424 * \param indentation level of the message to log
    2525 */
    26 class logger& Log() {
     26class logger * Log() {
    2727  return logger::getInstance();
    2828}
     
    3333 * \param indentation level of the message to log
    3434 */
    35 class errorLogger & eLog() {
     35class errorLogger * eLog() {
    3636  return errorLogger::getInstance();
    3737}
  • src/logger.cpp

    rcd032d ra77c96  
    99#include "logger.hpp"
    1010#include "verbose.hpp"
    11 #include "Patterns/Singleton_impl.hpp"
    1211
    1312ofstream nullStream("/dev/null");
    1413
     14logger* logger::instance = NULL;
    1515int logger::verbosity = 2;
    1616ostream* logger::nix = &nullStream;
     
    2323logger::logger()
    2424{
     25  instance = NULL;
    2526  verbosity = 2;
    2627};
     
    3334}
    3435
    35 CONSTRUCT_SINGLETON(logger)
     36/**
     37 * Returns the singleton logger instance.
     38 *
     39 * \return logger instance
     40 */
     41logger* logger::getInstance() {
     42  if (instance == NULL) {
     43    instance = new logger();
     44  }
     45
     46  return instance;
     47}
     48
     49
     50/**
     51 * Purges the current logger instance.
     52 */
     53void logger::purgeInstance() {
     54  if (instance != NULL) {
     55    delete instance;
     56  }
     57
     58  instance = NULL;
     59}
    3660
    3761/**
  • src/logger.hpp

    rcd032d ra77c96  
    1111#include <iostream>
    1212
    13 #include "Patterns/Singleton.hpp"
    14 
    1513using namespace std;
    1614
    1715class Verbose;
    1816
    19 class logger : public Singleton<logger> {
    20   friend class Singleton<logger>;
     17class logger {
    2118public :
    2219  static ostream *nix;
    2320  static int verbosity;
    2421
     22  static logger* getInstance();
     23  static void purgeInstance();
    2524  static bool DoOutput();
    2625  static void setVerbosity(int verbosityLevel);
     
    3130  /** Do not call this destructor directly, use purgeInstance() instead. */
    3231  ~logger();
     32
     33private:
     34  static logger* instance;
    3335};
    3436
  • src/molecule.cpp

    rcd032d ra77c96  
    3131 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3232 */
    33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()),
     33molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()),
    3434  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3535  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
     
    5656
    5757molecule *NewMolecule(){
    58   return new molecule(World::getInstance().getPeriode());
     58  return new molecule(World::get()->getPeriode());
    5959}
    6060
     
    261261  switch(TopBond->BondDegree) {
    262262    case 1:
    263       FirstOtherAtom = World::getInstance().createAtom();    // new atom
     263      FirstOtherAtom = World::get()->createAtom();    // new atom
    264264      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    265265      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    318318
    319319      // create the two Hydrogens ...
    320       FirstOtherAtom = World::getInstance().createAtom();
    321       SecondOtherAtom = World::getInstance().createAtom();
     320      FirstOtherAtom = World::get()->createAtom();
     321      SecondOtherAtom = World::get()->createAtom();
    322322      FirstOtherAtom->type = elemente->FindElement(1);
    323323      SecondOtherAtom->type = elemente->FindElement(1);
     
    373373    case 3:
    374374      // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
    375       FirstOtherAtom = World::getInstance().createAtom();
    376       SecondOtherAtom = World::getInstance().createAtom();
    377       ThirdOtherAtom = World::getInstance().createAtom();
     375      FirstOtherAtom = World::get()->createAtom();
     376      SecondOtherAtom = World::get()->createAtom();
     377      ThirdOtherAtom = World::get()->createAtom();
    378378      FirstOtherAtom->type = elemente->FindElement(1);
    379379      SecondOtherAtom->type = elemente->FindElement(1);
     
    494494    MDSteps++;
    495495  for(i=0;i<NumberOfAtoms;i++){
    496     Walker = World::getInstance().createAtom();
     496    Walker = World::get()->createAtom();
    497497    getline(xyzfile,line,'\n');
    498498    istringstream *item = new istringstream(line);
  • src/molecule_dynamics.cpp

    rcd032d ra77c96  
    486486  bool status = true;
    487487  int MaxSteps = configuration.MaxOuterStep;
    488   MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer());
     488  MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get());
    489489  // Get the Permutation Map by MinimiseConstrainedPotential
    490490  atom **PermutationMap = NULL;
     
    506506  Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
    507507  for (int step = 0; step <= MaxSteps; step++) {
    508     mol = World::getInstance().createMolecule();
     508    mol = World::get()->createMolecule();
    509509    MoleculePerStep->insert(mol);
    510510    Walker = start;
  • src/molecule_fragmentation.cpp

    rcd032d ra77c96  
    676676  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    677677  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    678   BondFragments = new MoleculeListClass(World::getPointer());
     678  BondFragments = new MoleculeListClass(World::get());
    679679  int k=0;
    680680  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     
    927927{
    928928  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    929   molecule *Leaf = World::getInstance().createMolecule();
     929  molecule *Leaf = World::get()->createMolecule();
    930930
    931931//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
  • src/moleculelist.cpp

    rcd032d ra77c96  
    215215  // remove src
    216216  ListOfMolecules.remove(srcmol);
    217   World::getInstance().destroyMolecule(srcmol);
     217  World::get()->destroyMolecule(srcmol);
    218218  return true;
    219219};
     
    750750void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    751751{
    752   molecule *mol = World::getInstance().createMolecule();
     752  molecule *mol = World::get()->createMolecule();
    753753  atom *Walker = NULL;
    754754  atom *Advancer = NULL;
     
    775775    }
    776776    // remove the molecule
    777     World::getInstance().destroyMolecule(*MolRunner);
     777    World::get()->destroyMolecule(*MolRunner);
    778778    ListOfMolecules.erase(MolRunner);
    779779  }
     
    797797  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    798798  for (int i=0;i<MolCount;i++) {
    799     molecules[i] = World::getInstance().createMolecule();
     799    molecules[i] = World::get()->createMolecule();
    800800    molecules[i]->ActiveFlag = true;
    801801    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     
    895895  OBSERVE;
    896896  molecule *mol = NULL;
    897   mol = World::getInstance().createMolecule();
     897  mol = World::get()->createMolecule();
    898898  insert(mol);
    899899};
     
    904904  char filename[MAXSTRINGSIZE];
    905905  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    906   mol = World::getInstance().createMolecule();
     906  mol = World::get()->createMolecule();
    907907  do {
    908908    Log() << Verbose(0) << "Enter file name: ";
     
    962962      mol = *ListRunner;
    963963      ListOfMolecules.erase(ListRunner);
    964       World::getInstance().destroyMolecule(mol);
     964      World::get()->destroyMolecule(mol);
    965965      break;
    966966    }
     
    10091009  // remove the leaf itself
    10101010  if (Leaf != NULL) {
    1011     World::getInstance().destroyMolecule(Leaf);
     1011    World::get()->destroyMolecule(Leaf);
    10121012    Leaf = NULL;
    10131013  }
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    rcd032d ra77c96  
    5757
    5858  // construct periodentafel
    59   tafel = World::getInstance().getPeriode();
     59  tafel = World::get()->getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161
    6262  // construct molecule (tetraeder of hydrogens)
    63   TestMolecule = World::getInstance().createMolecule();
    64   Walker = World::getInstance().createAtom();
     63  TestMolecule = World::get()->createMolecule();
     64  Walker = World::get()->createAtom();
    6565  Walker->type = hydrogen;
    6666  Walker->node->Init(1., 0., 1. );
    6767  TestMolecule->AddAtom(Walker);
    68   Walker = World::getInstance().createAtom();
     68  Walker = World::get()->createAtom();
    6969  Walker->type = hydrogen;
    7070  Walker->node->Init(0., 1., 1. );
    7171  TestMolecule->AddAtom(Walker);
    72   Walker = World::getInstance().createAtom();
     72  Walker = World::get()->createAtom();
    7373  Walker->type = hydrogen;
    7474  Walker->node->Init(1., 1., 0. );
    7575  TestMolecule->AddAtom(Walker);
    76   Walker = World::getInstance().createAtom();
     76  Walker = World::get()->createAtom();
    7777  Walker->type = hydrogen;
    7878  Walker->node->Init(0., 0., 0. );
     
    8282  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8383
    84   TestList = World::getInstance().getMolecules();
     84  TestList = World::get()->getMolecules();
    8585  TestMolecule->ActiveFlag = true;
    8686  TestList->insert(TestMolecule);
     
    104104
    105105  delete(point);
    106   World::purgeInstance();
     106  World::destroy();
    107107  MemoryUsageObserver::purgeInstance();
    108108  logger::purgeInstance();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    rcd032d ra77c96  
    6161
    6262  // construct periodentafel
    63   tafel = World::getInstance().getPeriode();
     63  tafel = World::get()->getPeriode();
    6464  tafel->AddElement(hydrogen);
    6565  tafel->AddElement(carbon);
    6666
    6767  // construct molecule (tetraeder of hydrogens) base
    68   TestMolecule = World::getInstance().createMolecule();
    69   Walker = World::getInstance().createAtom();
     68  TestMolecule = World::get()->createMolecule();
     69  Walker = World::get()->createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(1., 0., 1. );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::getInstance().createAtom();
     73  Walker = World::get()->createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(0., 1., 1. );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::getInstance().createAtom();
     77  Walker = World::get()->createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(1., 1., 0. );
    8080  TestMolecule->AddAtom(Walker);
    81   Walker = World::getInstance().createAtom();
     81  Walker = World::get()->createAtom();
    8282  Walker->type = hydrogen;
    8383  Walker->node->Init(0., 0., 0. );
     
    8787  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8888
    89   TestList = World::getInstance().getMolecules();
     89  TestList = World::get()->getMolecules();
    9090  TestMolecule->ActiveFlag = true;
    9191  TestList->insert(TestMolecule);
     
    100100
    101101  // add outer atoms
    102   Walker = World::getInstance().createAtom();
     102  Walker = World::get()->createAtom();
    103103  Walker->type = carbon;
    104104  Walker->node->Init(4., 0., 4. );
    105105  TestMolecule->AddAtom(Walker);
    106   Walker = World::getInstance().createAtom();
     106  Walker = World::get()->createAtom();
    107107  Walker->type = carbon;
    108108  Walker->node->Init(0., 4., 4. );
    109109  TestMolecule->AddAtom(Walker);
    110   Walker = World::getInstance().createAtom();
     110  Walker = World::get()->createAtom();
    111111  Walker->type = carbon;
    112112  Walker->node->Init(4., 4., 0. );
    113113  TestMolecule->AddAtom(Walker);
    114114  // add inner atoms
    115   Walker = World::getInstance().createAtom();
     115  Walker = World::get()->createAtom();
    116116  Walker->type = carbon;
    117117  Walker->node->Init(0.5, 0.5, 0.5 );
     
    135135  // note that all the atoms are cleaned by TestMolecule
    136136  delete(LC);
    137   World::purgeInstance();
     137  World::destroy();
    138138  MemoryUsageObserver::purgeInstance();
    139139  logger::purgeInstance();
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    rcd032d ra77c96  
    5656
    5757  // construct periodentafel
    58   tafel = World::getInstance().getPeriode();
     58  tafel = World::get()->getPeriode();
    5959  tafel->AddElement(hydrogen);
    6060
    6161  // construct molecule (tetraeder of hydrogens)
    62   TestMolecule = World::getInstance().createMolecule();
    63   Walker = World::getInstance().createAtom();
     62  TestMolecule = World::get()->createMolecule();
     63  Walker = World::get()->createAtom();
    6464  Walker->type = hydrogen;
    6565  Walker->node->Init(1., 0., 1. );
    6666  TestMolecule->AddAtom(Walker);
    67   Walker = World::getInstance().createAtom();
     67  Walker = World::get()->createAtom();
    6868  Walker->type = hydrogen;
    6969  Walker->node->Init(0., 1., 1. );
    7070  TestMolecule->AddAtom(Walker);
    71   Walker = World::getInstance().createAtom();
     71  Walker = World::get()->createAtom();
    7272  Walker->type = hydrogen;
    7373  Walker->node->Init(1., 1., 0. );
    7474  TestMolecule->AddAtom(Walker);
    75   Walker = World::getInstance().createAtom();
     75  Walker = World::get()->createAtom();
    7676  Walker->type = hydrogen;
    7777  Walker->node->Init(0., 0., 0. );
     
    8181  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8282
    83   TestList = World::getInstance().getMolecules();
     83  TestList = World::get()->getMolecules();
    8484  TestMolecule->ActiveFlag = true;
    8585  TestList->insert(TestMolecule);
     
    100100
    101101  // note that all the atoms are cleaned by TestMolecule
    102   World::purgeInstance();
     102  World::destroy();
    103103  MemoryUsageObserver::purgeInstance();
    104104  logger::purgeInstance();
  • src/unittests/AtomDescriptorTest.cpp

    rcd032d ra77c96  
    2929// set up and tear down
    3030void AtomDescriptorTest::setUp(){
    31   World::getInstance();
     31  World::get();
    3232  for(int i=0;i<ATOM_COUNT;++i){
    33     atoms[i]= World::getInstance().createAtom();
     33    atoms[i]= World::get()->createAtom();
    3434    atomIds[i]= atoms[i]->getId();
    3535  }
     
    3737
    3838void AtomDescriptorTest::tearDown(){
    39   World::purgeInstance();
     39  World::destroy();
    4040}
    4141
     
    7373
    7474void AtomDescriptorTest::AtomBaseSetsTest(){
    75   std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
     75  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms));
    7878
    79   std::vector<atom*> noAtoms = World::getInstance().getAllAtoms(NoAtoms());
     79  std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms());
    8080  CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
    8181}
     
    8383  // test Atoms from boundaries and middle of the set
    8484  atom* testAtom;
    85   testAtom = World::getInstance().getAtom(AtomById(atomIds[0]));
     85  testAtom = World::get()->getAtom(AtomById(atomIds[0]));
    8686  CPPUNIT_ASSERT(testAtom);
    8787  CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
    88   testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT/2]));
     88  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));
    8989  CPPUNIT_ASSERT(testAtom);
    9090  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
    91   testAtom = World::getInstance().getAtom(AtomById(atomIds[ATOM_COUNT-1]));
     91  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));
    9292  CPPUNIT_ASSERT(testAtom);
    9393  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
     
    103103  }
    104104  // test from outside of set
    105   testAtom = World::getInstance().getAtom(AtomById(outsideId));
     105  testAtom = World::get()->getAtom(AtomById(outsideId));
    106106  CPPUNIT_ASSERT(!testAtom);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()||NoAtoms());
     111    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    115115
    116116  {
    117     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||AllAtoms());
     117    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    121121
    122122  {
    123     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()&&AllAtoms());
     123    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()&&AllAtoms());
    124124    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    125125  }
    126126
    127127  {
    128     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&NoAtoms());
     128    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&NoAtoms());
    129129    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    130130  }
    131131
    132132  {
    133     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!AllAtoms());
     133    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!AllAtoms());
    134134    CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
    135135  }
    136136
    137137  {
    138     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(!NoAtoms());
     138    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms));
     
    143143  // exclude and include some atoms
    144144  {
    145     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
     145    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    146146    std::set<atomId_t> excluded;
    147147    excluded.insert(atomIds[ATOM_COUNT/2]);
     
    152152
    153153  {
    154     std::vector<atom*> testAtoms = World::getInstance().getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
     154    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    155155    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    156156    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
  • src/unittests/Makefile.am

    rcd032d ra77c96  
    2929  MoleculeDescriptorTest \
    3030  ObserverTest \
    31   SingletonTest \
    3231  StackClassUnitTest \
    3332  TesselationUnitTest \
     
    6766  MoleculeDescriptorTest.cpp \
    6867  ObserverTest.cpp \
    69   SingletonTest.cpp \
    7068  stackclassunittest.cpp \
    7169  tesselationunittest.cpp \
     
    125123MoleculeDescriptorTest_LDADD = ${ALLLIBS}
    126124
    127 SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
    128 SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB}
    129 
    130125StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
    131126StackClassUnitTest_LDADD = ${ALLLIBS}
  • src/unittests/MoleculeDescriptorTest.cpp

    rcd032d ra77c96  
    2929// set up and tear down
    3030void MoleculeDescriptorTest::setUp(){
    31   World::getInstance();
     31  World::get();
    3232  for(int i=0;i<MOLECULE_COUNT;++i){
    33     molecules[i]= World::getInstance().createMolecule();
     33    molecules[i]= World::get()->createMolecule();
    3434    moleculeIds[i]= molecules[i]->getId();
    3535  }
     
    3737
    3838void MoleculeDescriptorTest::tearDown(){
    39   World::purgeInstance();
     39  World::destroy();
    4040}
    4141
     
    7373
    7474void MoleculeDescriptorTest::MoleculeBaseSetsTest(){
    75   std::vector<molecule*> allMolecules = World::getInstance().getAllMolecules(AllMolecules());
     75  std::vector<molecule*> allMolecules = World::get()->getAllMolecules(AllMolecules());
    7676  CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(allMolecules,moleculeIds));
    7777  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(allMolecules));
    7878
    79   std::vector<molecule*> noMolecules = World::getInstance().getAllMolecules(NoMolecules());
     79  std::vector<molecule*> noMolecules = World::get()->getAllMolecules(NoMolecules());
    8080  CPPUNIT_ASSERT_EQUAL( true , noMolecules.empty());
    8181}
     
    8383  // test Molecules from boundaries and middle of the set
    8484  molecule* testMolecule;
    85   testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[0]));
     85  testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[0]));
    8686  CPPUNIT_ASSERT(testMolecule);
    8787  CPPUNIT_ASSERT_EQUAL( moleculeIds[0], testMolecule->getId());
    88   testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
     88  testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT/2]));
    8989  CPPUNIT_ASSERT(testMolecule);
    9090  CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecule->getId());
    91   testMolecule = World::getInstance().getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
     91  testMolecule = World::get()->getMolecule(MoleculeById(moleculeIds[MOLECULE_COUNT-1]));
    9292  CPPUNIT_ASSERT(testMolecule);
    9393  CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT-1], testMolecule->getId());
     
    103103  }
    104104  // test from outside of set
    105   testMolecule = World::getInstance().getMolecule(MoleculeById(outsideId));
     105  testMolecule = World::get()->getMolecule(MoleculeById(outsideId));
    106106  CPPUNIT_ASSERT(!testMolecule);
    107107}
     
    109109  // test some elementary set operations
    110110  {
    111     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()||NoMolecules());
     111    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()||NoMolecules());
    112112    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    113113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    115115
    116116  {
    117     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||AllMolecules());
     117    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()||AllMolecules());
    118118    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    119119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    121121
    122122  {
    123     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()&&AllMolecules());
     123    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()&&AllMolecules());
    124124    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    125125  }
    126126
    127127  {
    128     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&NoMolecules());
     128    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()&&NoMolecules());
    129129    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    130130  }
    131131
    132132  {
    133     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!AllMolecules());
     133    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!AllMolecules());
    134134    CPPUNIT_ASSERT_EQUAL( true , testMolecules.empty());
    135135  }
    136136
    137137  {
    138     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(!NoMolecules());
     138    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(!NoMolecules());
    139139    CPPUNIT_ASSERT_EQUAL( true , hasAllMolecules(testMolecules,moleculeIds));
    140140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateMolecules(testMolecules));
     
    143143  // exclude and include some molecules
    144144  {
    145     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
     145    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(AllMolecules()&&(!MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
    146146    std::set<moleculeId_t> excluded;
    147147    excluded.insert(moleculeIds[MOLECULE_COUNT/2]);
     
    152152
    153153  {
    154     std::vector<molecule*> testMolecules = World::getInstance().getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
     154    std::vector<molecule*> testMolecules = World::get()->getAllMolecules(NoMolecules()||(MoleculeById(moleculeIds[MOLECULE_COUNT/2])));
    155155    CPPUNIT_ASSERT_EQUAL( (size_t)1, testMolecules.size());
    156156    CPPUNIT_ASSERT_EQUAL( moleculeIds[MOLECULE_COUNT/2], testMolecules[0]->getId());
  • src/unittests/analysisbondsunittest.cpp

    rcd032d ra77c96  
    6161
    6262  // construct periodentafel
    63   tafel = World::getInstance().getPeriode();
     63  tafel = World::get()->getPeriode();
    6464  tafel->AddElement(hydrogen);
    6565  tafel->AddElement(carbon);
    6666
    6767  // construct molecule (tetraeder of hydrogens)
    68   TestMolecule = World::getInstance().createMolecule();
    69   Walker = World::getInstance().createAtom();
     68  TestMolecule = World::get()->createMolecule();
     69  Walker = World::get()->createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(1.5, 0., 1.5 );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::getInstance().createAtom();
     73  Walker = World::get()->createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(0., 1.5, 1.5 );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::getInstance().createAtom();
     77  Walker = World::get()->createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(1.5, 1.5, 0. );
    8080  TestMolecule->AddAtom(Walker);
    81   Walker = World::getInstance().createAtom();
     81  Walker = World::get()->createAtom();
    8282  Walker->type = hydrogen;
    8383  Walker->node->Init(0., 0., 0. );
    8484  TestMolecule->AddAtom(Walker);
    85   Walker = World::getInstance().createAtom();
     85  Walker = World::get()->createAtom();
    8686  Walker->type = carbon;
    8787  Walker->node->Init(0.5, 0.5, 0.5 );
     
    117117
    118118  // remove molecule
    119   World::getInstance().destroyMolecule(TestMolecule);
     119  World::get()->destroyMolecule(TestMolecule);
    120120  // note that all the atoms are cleaned by TestMolecule
    121   World::purgeInstance();
     121  World::destroy();
    122122};
    123123
  • src/unittests/atomsCalculationTest.cpp

    rcd032d ra77c96  
    2323#include "World_calculations.hpp"
    2424#include "atom.hpp"
    25 
    26 #ifdef HAVE_TESTRUNNER
    27 #include "UnitTestMain.hpp"
    28 #endif /*HAVE_TESTRUNNER*/
    2925
    3026// Registers the fixture into the 'registry'
     
    5551// set up and tear down
    5652void atomsCalculationTest::setUp(){
    57   World::getInstance();
     53  World::get();
    5854  for(int i=0;i<ATOM_COUNT;++i){
    5955    atoms[i]= new AtomStub(i);
    60     World::getInstance().registerAtom(atoms[i]);
     56    World::get()->registerAtom(atoms[i]);
    6157  }
    6258}
    6359void atomsCalculationTest::tearDown(){
    64   World::purgeInstance();
    65   ActionRegistry::purgeInstance();
     60  World::destroy();
     61  ActionRegistry::purgeRegistry();
    6662}
    6763
     
    9692}
    9793
     94static void operation(atom* _atom){
     95  AtomStub *atom = dynamic_cast<AtomStub*>(_atom);
     96  assert(atom);
     97  atom->doSomething();
     98}
     99
     100
    98101void atomsCalculationTest::testCalculateSimple(){
    99   AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
     102  AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms());
    100103  std::vector<int> allIds = (*calc)();
    101104  CPPUNIT_ASSERT(hasAll(allIds,0,ATOM_COUNT));
     
    105108void atomsCalculationTest::testCalculateExcluded(){
    106109  int excluded = ATOM_COUNT/2;
    107   AtomsCalculation<int> *calc = World::getInstance().calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
     110  AtomsCalculation<int> *calc = World::get()->calcOnAtoms<int>(boost::bind(&atom::getId,_1),"FOO",AllAtoms() && !AtomById(excluded));
    108111  std::vector<int> allIds = (*calc)();
    109112  std::set<int> excluded_set;
  • src/unittests/bondgraphunittest.cpp

    rcd032d ra77c96  
    5757
    5858  // construct periodentafel
    59   tafel = World::getInstance().getPeriode();
     59  tafel = World::get()->getPeriode();
    6060  tafel->AddElement(hydrogen);
    6161  tafel->AddElement(carbon);
    6262
    6363  // construct molecule (tetraeder of hydrogens)
    64   TestMolecule = World::getInstance().createMolecule();
    65   Walker = World::getInstance().createAtom();
     64  TestMolecule = World::get()->createMolecule();
     65  Walker = World::get()->createAtom();
    6666  Walker->type = hydrogen;
    6767  Walker->node->Init(1., 0., 1. );
    6868  TestMolecule->AddAtom(Walker);
    69   Walker = World::getInstance().createAtom();
     69  Walker = World::get()->createAtom();
    7070  Walker->type = hydrogen;
    7171  Walker->node->Init(0., 1., 1. );
    7272  TestMolecule->AddAtom(Walker);
    73   Walker = World::getInstance().createAtom();
     73  Walker = World::get()->createAtom();
    7474  Walker->type = hydrogen;
    7575  Walker->node->Init(1., 1., 0. );
    7676  TestMolecule->AddAtom(Walker);
    77   Walker = World::getInstance().createAtom();
     77  Walker = World::get()->createAtom();
    7878  Walker->type = hydrogen;
    7979  Walker->node->Init(0., 0., 0. );
     
    102102
    103103  // remove molecule
    104   World::getInstance().destroyMolecule(TestMolecule);
     104  World::get()->destroyMolecule(TestMolecule);
    105105  // note that all the atoms, molecules, the tafel and the elements
    106106  // are all cleaned when the world is destroyed
    107   World::purgeInstance();
     107  World::destroy();
    108108  MemoryUsageObserver::purgeInstance();
    109109  logger::purgeInstance();
  • src/unittests/listofbondsunittest.cpp

    rcd032d ra77c96  
    5151
    5252  // construct periodentafel
    53   tafel = World::getInstance().getPeriode();
     53  tafel = World::get()->getPeriode();
    5454  tafel->AddElement(hydrogen);
    5555
    5656  // construct molecule (tetraeder of hydrogens)
    57   TestMolecule = World::getInstance().createMolecule();
    58   Walker = World::getInstance().createAtom();
     57  TestMolecule = World::get()->createMolecule();
     58  Walker = World::get()->createAtom();
    5959  Walker->type = hydrogen;
    6060  Walker->node->Init(1., 0., 1. );
    6161  TestMolecule->AddAtom(Walker);
    62   Walker = World::getInstance().createAtom();
     62  Walker = World::get()->createAtom();
    6363  Walker->type = hydrogen;
    6464  Walker->node->Init(0., 1., 1. );
    6565  TestMolecule->AddAtom(Walker);
    66   Walker = World::getInstance().createAtom();
     66  Walker = World::get()->createAtom();
    6767  Walker->type = hydrogen;
    6868  Walker->node->Init(1., 1., 0. );
    6969  TestMolecule->AddAtom(Walker);
    70   Walker = World::getInstance().createAtom();
     70  Walker = World::get()->createAtom();
    7171  Walker->type = hydrogen;
    7272  Walker->node->Init(0., 0., 0. );
     
    8282{
    8383  // remove
    84   World::getInstance().destroyMolecule(TestMolecule);
     84  World::get()->destroyMolecule(TestMolecule);
    8585  // note that all the atoms, molecules, the tafel and the elements
    8686  // are all cleaned when the world is destroyed
    87   World::purgeInstance();
     87  World::destroy();
    8888  MemoryUsageObserver::purgeInstance();
    8989  logger::purgeInstance();
     
    250250
    251251  // remove atom2
    252   World::getInstance().destroyAtom(atom2);
     252  World::get()->destroyAtom(atom2);
    253253
    254254  // check bond if removed from other atom
  • src/unittests/logunittest.cpp

    rcd032d ra77c96  
    4040void LogTest::logTest()
    4141{
    42   logger::getInstance().setVerbosity(2);
     42  logger::getInstance()->setVerbosity(2);
    4343  Log() << Verbose(0) << "Verbosity level is set to 2." << endl;
    4444  Log() << Verbose(0) << "Test level 0" << endl;
  • src/unittests/manipulateAtomsTest.cpp

    rcd032d ra77c96  
    2222#include "atom.hpp"
    2323
    24 #ifdef HAVE_TESTRUNNER
    25 #include "UnitTestMain.hpp"
    26 #endif /*HAVE_TESTRUNNER*/
    27 
    2824// Registers the fixture into the 'registry'
    2925CPPUNIT_TEST_SUITE_REGISTRATION( manipulateAtomsTest );
     
    3430  AtomStub(int _id) :
    3531  atom(),
    36   manipulated(false),
    37   id(_id)
     32  id(_id),
     33  manipulated(false)
    3834  {}
    3935
     
    7066// set up and tear down
    7167void manipulateAtomsTest::setUp(){
    72   World::getInstance();
     68  World::get();
    7369  for(int i=0;i<ATOM_COUNT;++i){
    7470    atoms[i]= new AtomStub(i);
    75     World::getInstance().registerAtom(atoms[i]);
     71    World::get()->registerAtom(atoms[i]);
    7672  }
    7773}
    7874void manipulateAtomsTest::tearDown(){
    79   World::purgeInstance();
    80   ActionRegistry::purgeInstance();
     75  World::destroy();
     76  ActionRegistry::purgeRegistry();
     77}
     78
     79// some helper functions
     80static bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
     81  for(int i=min;i<max;++i){
     82    if(!excluded.count(i)){
     83      std::vector<atom*>::iterator iter;
     84      bool res=false;
     85      for(iter=atoms.begin();iter!=atoms.end();++iter){
     86        res |= (*iter)->getId() == i;
     87      }
     88      if(!res) {
     89        cout << "Atom " << i << " missing in returned list" << endl;
     90        return false;
     91      }
     92    }
     93  }
     94  return true;
     95}
     96
     97static bool hasNoDuplicates(std::vector<atom*> atoms){
     98  std::set<int> found;
     99  std::vector<atom*>::iterator iter;
     100  for(iter=atoms.begin();iter!=atoms.end();++iter){
     101    int id = (*iter)->getId();
     102    if(found.count(id))
     103      return false;
     104    found.insert(id);
     105  }
     106  return true;
    81107}
    82108
     
    89115
    90116void manipulateAtomsTest::testManipulateSimple(){
    91   ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
     117  ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms());
    92118  proc->call();
    93   std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
     119  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    94120  std::vector<atom*>::iterator iter;
    95121  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    102128
    103129void manipulateAtomsTest::testManipulateExcluded(){
    104   ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     130  ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
    105131  proc->call();
    106   std::vector<atom*> allAtoms = World::getInstance().getAllAtoms(AllAtoms());
     132  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    107133  std::vector<atom*>::iterator iter;
    108134  for(iter=allAtoms.begin();iter!=allAtoms.end();++iter){
     
    119145void manipulateAtomsTest::testObserver(){
    120146  countObserver *obs = new countObserver();
    121   World::getInstance().signOn(obs);
    122   ManipulateAtomsProcess *proc = World::getInstance().manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
     147  World::get()->signOn(obs);
     148  ManipulateAtomsProcess *proc = World::get()->manipulateAtoms(boost::bind(operation,_1),"FOO",AllAtoms() && !AtomById(ATOM_COUNT/2));
    123149  proc->call();
    124150
    125151  CPPUNIT_ASSERT_EQUAL(1,obs->count);
    126   World::getInstance().signOff(obs);
     152  World::get()->signOff(obs);
    127153  delete obs;
    128154}
Note: See TracChangeset for help on using the changeset viewer.