Changes in / [c695c9:5f612ee]


Ignore:
Files:
113 added
68 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rc695c9 r5f612ee  
    33
    44EXTRA_DIST = autogen.sh
     5
     6.PHONY: doc
     7doc:
     8        cd doc && make doxygen-docs
  • configure.ac

    rc695c9 r5f612ee  
    2727
    2828# Boost libraries
    29 #AX_BOOST_BASE([1.33.1])
     29AX_BOOST_BASE([1.33.1])
    3030#AX_BOOST_PROGRAM_OPTIONS
    3131#AX_BOOST_FOREACH
    3232#AX_BOOST_FILESYSTEM
    33 #AX_BOOST_THREAD
     33AX_BOOST_THREAD
    3434#AX_BOOST_PROGRAM_OPTIONS
    3535#AX_BOOST_SERIALIZATION
     
    6666fi
    6767
     68# add replacement/saturation hydrogen or not
     69AC_ARG_ENABLE([ecut],AS_HELP_STRING([--enable-ecut],[Use ECut TestRunnerClient (default is yes)]),
     70              [enable_ecut=$enableval], [enable_ecut=yes])
     71if test x"$enable_ecut" = xyes; then
     72  AC_DEFINE(HAVE_ECUT,1, ["Use ECut TestRunnerClient instead of our own."])
     73  AC_SUBST(HAVE_ECUT)
     74fi
     75
    6876# Check for "extern inline", using a modified version
    6977# of the test for AC_C_INLINE from acspecific.mt
  • doc/Doxyfile

    rc695c9 r5f612ee  
    114114EXCLUDE                =
    115115EXCLUDE_SYMLINKS       = NO
    116 EXCLUDE_PATTERNS       =
     116EXCLUDE_PATTERNS       = */unittests/* \
     117                                                 */test/*
    117118EXAMPLE_PATH           =
    118119EXAMPLE_PATTERNS       = *
     
    125126# configuration options related to source browsing
    126127#---------------------------------------------------------------------------
    127 SOURCE_BROWSER         = NO
    128 INLINE_SOURCES         = NO
    129 STRIP_CODE_COMMENTS    = YES
     128SOURCE_BROWSER         = YES
     129INLINE_SOURCES         = YES
     130STRIP_CODE_COMMENTS    = NO
    130131REFERENCED_BY_RELATION = NO
    131132REFERENCES_RELATION    = NO
  • src/Makefile.am

    rc695c9 r5f612ee  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    10 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp triangleintersectionlist.cpp vector.cpp verbose.cpp World.cpp
    11 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp triangleintersectionlist.cpp vector.hpp verbose.hpp World.hpp
     10ACTIONSSOURCE = Actions/Action.cpp \
     11                                Actions/ActionHistory.cpp \
     12                                Actions/ActionRegistry.cpp \
     13                                Actions/ActionSequence.cpp \
     14                                Actions/ErrorAction.cpp \
     15                                Actions/MakroAction.cpp \
     16                                Actions/ManipulateAtomsProcess.cpp \
     17                                Actions/MethodAction.cpp \
     18                Actions/Process.cpp \
     19                Actions/small_actions.cpp
     20               
     21                 
     22ACTIONSHEADER = Actions/Action.hpp \
     23                                Actions/ActionHistory.hpp \
     24                                Actions/ActionRegistry.hpp \
     25                                Actions/ActionSequence.hpp \
     26                            Actions/Calculation.hpp \
     27                            Actions/Calculation_impl.hpp \
     28                            Actions/ErrorAction.hpp \
     29                            Actions/MakroAction.hpp \
     30                            Actions/ManipulateAtomsProcess.hpp \
     31                            Actions/MethodAction.hpp \
     32                            Actions/Process.hpp \
     33                            Actions/small_actions.hpp
     34                           
     35                           
     36
     37PATTERNSOURCE = Patterns/Observer.cpp
     38PATTERNHEADER = Patterns/Cacheable.hpp \
     39                                Patterns/Observer.hpp \
     40                Patterns/Singleton.hpp
     41
     42VIEWSOURCE = Views/View.cpp Views/StringView.cpp Views/MethodStringView.cpp Views/StreamStringView.cpp
     43VIEWHEADER = Views/View.hpp Views/StringView.hpp Views/MethodStringView.hpp Views/StreamStringView.hpp
     44
     45MENUSOURCE = Menu/Menu.cpp Menu/TextMenu.cpp Menu/MenuItem.cpp Menu/SubMenuItem.cpp Menu/ActionMenuItem.cpp Menu/SeperatorItem.cpp Menu/DisplayMenuItem.cpp
     46MENUHEADER = Menu/Menu.hpp Menu/TextMenu.hpp Menu/MenuItem.hpp Menu/SubMenuItem.hpp Menu/ActionMenuItem.hpp Menu/SeperatorItem.hpp Menu/DisplayMenuItem.hpp
     47
     48UISOURCE = ${ACTIONSSOURCE} ${VIEWSOURCE} ${MENUSOURCE} UIElements/UIFactory.cpp UIElements/TextUIFactory.cpp UIElements/MainWindow.cpp UIElements/TextWindow.cpp UIElements/TextStatusIndicator.cpp UIElements/Dialog.cpp UIElements/TextDialog.cpp
     49UIHEADER = ${ACTIONSHEADER} ${VIEWHEADER} ${MENUHEADER} UIElements/UIFactory.hpp UIElements/TextUIFactory.hpp UIElements/MainWindow.hpp UIElements/TextWindow.hpp UIElements/TextStatusIndicator.hpp UIElements/Dialog.hpp UIElements/TextDialog.hpp
     50
     51# all these files are only used for legacy reasons while the transition is in progress
     52# they are only needed to keep the program usable at any point of the transition and will be
     53# deleted once everything is fully refactored
     54LEGACYSOURCE = Legacy/oldmenu.cpp
     55LEGACYHEADER = Legacy/oldmenu.hpp
     56
     57DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp \
     58                                   Descriptors/AtomIdDescriptor.cpp \
     59                                   Descriptors/AtomTypeDescriptor.cpp \
     60                                   Descriptors/MoleculeDescriptor.cpp \
     61                                   Descriptors/MoleculeIdDescriptor.cpp
     62                                   
     63                                   
     64DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \
     65                                   Descriptors/AtomIdDescriptor.hpp \
     66                                   Descriptors/AtomTypeDescriptor.hpp \
     67                                   Descriptors/MoleculeDescriptor.hpp \
     68                                   Descriptors/MoleculeIdDescriptor.hpp
     69                                   
     70
     71
     72SOURCE = ${ANALYSISSOURCE} \
     73                 ${ATOMSOURCE} \
     74                 ${PATTERNSOURCE} \
     75                 ${UISOURCE} \
     76                 ${DESCRIPTORSOURCE} \
     77                 ${LEGACYSOURCE} \
     78                 bond.cpp \
     79                 bondgraph.cpp \
     80                 boundary.cpp \
     81                 config.cpp \
     82                 element.cpp \
     83                 ellipsoid.cpp \
     84                 errorlogger.cpp \
     85                 graph.cpp \
     86                 helpers.cpp \
     87                 Helpers/Assert.cpp \
     88                 info.cpp \
     89                 leastsquaremin.cpp \
     90                 linkedcell.cpp \
     91                 lists.cpp \
     92                 log.cpp \
     93                 logger.cpp \
     94                 memoryusageobserver.cpp \
     95                 moleculelist.cpp \
     96                 molecule.cpp \
     97                 molecule_dynamics.cpp \
     98                 molecule_fragmentation.cpp \
     99                 molecule_geometry.cpp \
     100                 molecule_graph.cpp \
     101                 molecule_pointcloud.cpp \
     102                 parser.cpp \
     103                 periodentafel.cpp \
     104                 tesselation.cpp \
     105                 tesselationhelpers.cpp \
     106                 triangleintersectionlist.cpp \
     107                 vector.cpp \
     108                 verbose.cpp \
     109                 World.cpp
     110
     111HEADER = \
     112  ${ANALYSISHEADER} \
     113  ${ATOMHEADER} \
     114  ${PATTERNHEADER} \
     115  ${UIHEADER} \
     116  ${DESCRIPTORHEADER} \
     117  ${LEGACYHEADER} \
     118  bond.hpp \
     119  bondgraph.hpp \
     120  boundary.hpp \
     121  config.hpp \
     122  defs.hpp \
     123  element.hpp \
     124  ellipsoid.hpp \
     125  errorlogger.hpp \
     126  graph.hpp \
     127  helpers.hpp \
     128  info.hpp \
     129  leastsquaremin.hpp \
     130  linkedcell.hpp \
     131  lists.hpp \
     132  log.hpp \
     133  logger.hpp \
     134  memoryallocator.hpp \
     135  memoryusageobserver.hpp \
     136  molecule.hpp \
     137  molecule_template.hpp \
     138  parser.hpp \
     139  periodentafel.hpp \
     140  stackclass.hpp \
     141  tesselation.hpp \
     142  tesselationhelpers.hpp \
     143  triangleintersectionlist.hpp \
     144  vector.hpp \
     145  verbose.hpp \
     146  World.hpp
    12147
    13148BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
     
    20155libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER}
    21156molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    22 molecuilder_LDFLAGS = $(BOOST_LIB)
     157molecuilder_LDFLAGS = $(BOOST_LDFLAGS)
    23158molecuilder_SOURCES = builder.cpp
    24 molecuilder_LDADD = libmolecuilder.a libgslwrapper.a
     159molecuilder_LDADD = libmolecuilder.a libgslwrapper.a $(BOOST_LIB) ${BOOST_THREAD_LIB}
    25160joiner_SOURCES = joiner.cpp datacreator.cpp parser.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    26 joiner_LDADD = libmolecuilder.a
     161joiner_LDADD = libmolecuilder.a $(BOOST_LIB) ${BOOST_THREAD_LIB}
    27162analyzer_SOURCES = analyzer.cpp datacreator.cpp parser.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp
    28 analyzer_LDADD = libmolecuilder.a
     163analyzer_LDADD = libmolecuilder.a $(BOOST_LIB) ${BOOST_THREAD_LIB}
    29164
    30165#EXTRA_DIST = ${molecuilder_DATA}
  • src/World.cpp

    rc695c9 r5f612ee  
    11/*
    2  * world.cpp
     2 * World.cpp
    33 *
    4  *  Created on: Mar 3, 2010
     4 *  Created on: Feb 3, 2010
    55 *      Author: crueger
    66 */
    77
    8 #include <string.h>
    9 
    10 #include "defs.hpp"
    118#include "World.hpp"
    129
    13 double *World::cell_size = 0;
    14 char *World::DefaultName = 0;
    15 
    16 /** Constructor of World.
    17  *
    18  */
    19 World::World()
     10#include "atom.hpp"
     11#include "molecule.hpp"
     12#include "periodentafel.hpp"
     13#include "Descriptors/AtomDescriptor.hpp"
     14#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Descriptors/MoleculeDescriptor.hpp"
     16#include "Descriptors/MoleculeDescriptor_impl.hpp"
     17#include "Descriptors/SelectiveIterator_impl.hpp"
     18#include "Actions/ManipulateAtomsProcess.hpp"
     19
     20#include "Patterns/Singleton_impl.hpp"
     21
     22using namespace std;
     23
     24/******************************* getter and setter ************************/
     25periodentafel *&World::getPeriode(){
     26  return periode;
     27}
     28
     29// Atoms
     30
     31atom* World::getAtom(AtomDescriptor descriptor){
     32  return descriptor.find();
     33}
     34
     35vector<atom*> World::getAllAtoms(AtomDescriptor descriptor){
     36  return descriptor.findAll();
     37}
     38
     39vector<atom*> World::getAllAtoms(){
     40  return getAllAtoms(AllAtoms());
     41}
     42
     43int World::numAtoms(){
     44  return atoms.size();
     45}
     46
     47// Molecules
     48
     49molecule *World::getMolecule(MoleculeDescriptor descriptor){
     50  return descriptor.find();
     51}
     52
     53std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
     54  return descriptor.findAll();
     55}
     56
     57int World::numMolecules(){
     58  return molecules_deprecated->ListOfMolecules.size();
     59}
     60
     61// system
     62
     63double * World::getDomain() {
     64  return cell_size;
     65}
     66
     67void World::setDomain(double * matrix)
     68{
     69
     70}
     71
     72char * World::getDefaultName() {
     73  return defaultName;
     74}
     75
     76void World::setDefaultName(char * name)
     77{
     78  delete[](defaultName);
     79  const int length = strlen(name);
     80  defaultName = new char[length+2];
     81  if (length < MAXSTRINGSIZE)
     82    strncpy(defaultName, name, length);
     83  else
     84    strcpy(defaultName, "none");
     85};
     86
     87
     88/******************** Methods to change World state *********************/
     89
     90molecule* World::createMolecule(){
     91  OBSERVE;
     92  molecule *mol = NULL;
     93  mol = NewMolecule();
     94  assert(!molecules.count(currMoleculeId));
     95  mol->setId(currMoleculeId++);
     96  // store the molecule by ID
     97  molecules[mol->getId()] = mol;
     98  mol->signOn(this);
     99  return mol;
     100}
     101
     102void World::destroyMolecule(molecule* mol){
     103  OBSERVE;
     104  destroyMolecule(mol->getId());
     105}
     106
     107void World::destroyMolecule(moleculeId_t id){
     108  OBSERVE;
     109  molecule *mol = molecules[id];
     110  assert(mol);
     111  DeleteMolecule(mol);
     112  molecules.erase(id);
     113}
     114
     115double *World::cell_size = NULL;
     116char *World::defaultName = NULL;
     117
     118atom *World::createAtom(){
     119  OBSERVE;
     120  atomId_t id = getNextAtomId();
     121  atom *res = NewAtom(id);
     122  res->setWorld(this);
     123  // store the atom by ID
     124  atoms[res->getId()] = res;
     125  return res;
     126}
     127
     128
     129int World::registerAtom(atom *atom){
     130  OBSERVE;
     131  atomId_t id = getNextAtomId();
     132  atom->setId(id);
     133  atom->setWorld(this);
     134  atoms[atom->getId()] = atom;
     135  return atom->getId();
     136}
     137
     138void World::destroyAtom(atom* atom){
     139  OBSERVE;
     140  int id = atom->getId();
     141  destroyAtom(id);
     142}
     143
     144void World::destroyAtom(atomId_t id) {
     145  OBSERVE;
     146  atom *atom = atoms[id];
     147  assert(atom);
     148  DeleteAtom(atom);
     149  atoms.erase(id);
     150  releaseAtomId(id);
     151}
     152
     153bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
     154  OBSERVE;
     155  // in case this call did not originate from inside the atom, we redirect it,
     156  // to also let it know that it has changed
     157  if(!target){
     158    target = atoms[oldId];
     159    assert(target && "Atom with that ID not found");
     160    return target->changeId(newId);
     161  }
     162  else{
     163    if(reserveAtomId(newId)){
     164      atoms.erase(oldId);
     165      atoms.insert(pair<atomId_t,atom*>(newId,target));
     166      return true;
     167    }
     168    else{
     169      return false;
     170    }
     171  }
     172}
     173
     174ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
     175  return new ManipulateAtomsProcess(op, descr,name,true);
     176}
     177
     178ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
     179  return manipulateAtoms(op,name,AllAtoms());
     180}
     181
     182/********************* Internal Change methods for double Callback and Observer mechanism ********/
     183
     184void World::doManipulate(ManipulateAtomsProcess *proc){
     185  proc->signOn(this);
     186  {
     187    OBSERVE;
     188    proc->doManipulate(this);
     189  }
     190  proc->signOff(this);
     191}
     192/******************************* IDManagement *****************************/
     193
     194// Atoms
     195
     196atomId_t World::getNextAtomId(){
     197  // see if we can reuse some Id
     198  if(atomIdPool.empty()){
     199    return currAtomId++;
     200  }
     201  else{
     202    // we give out the first ID from the pool
     203    atomId_t id = *(atomIdPool.begin());
     204    atomIdPool.erase(id);
     205    return id;
     206  }
     207}
     208
     209void World::releaseAtomId(atomId_t id){
     210  atomIdPool.insert(id);
     211  // defragmentation of the pool
     212  set<atomId_t>::reverse_iterator iter;
     213  // go through all Ids in the pool that lie immediately below the border
     214  while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){
     215    atomIdPool.erase(--currAtomId);
     216  }
     217}
     218
     219bool World::reserveAtomId(atomId_t id){
     220  if(id>=currAtomId ){
     221    // add all ids between the new one and current border as available
     222    for(atomId_t pos=currAtomId; pos<id; ++pos){
     223      atomIdPool.insert(pos);
     224    }
     225    currAtomId=id+1;
     226    return true;
     227  }
     228  else if(atomIdPool.count(id)){
     229    atomIdPool.erase(id);
     230    return true;
     231  }
     232  else{
     233    // this ID could not be reserved
     234    return false;
     235  }
     236}
     237
     238// Molecules
     239
     240/******************************* Iterators ********************************/
     241
     242// Build the AtomIterator from template
     243CONSTRUCT_SELECTIVE_ITERATOR(atom*,World::AtomSet,AtomDescriptor);
     244
     245
     246World::AtomIterator World::getAtomIter(AtomDescriptor descr){
     247  return AtomIterator(descr,atoms);
     248}
     249
     250World::AtomIterator World::atomEnd(){
     251  return AtomIterator(AllAtoms(),atoms,atoms.end());
     252}
     253
     254// build the MoleculeIterator from template
     255CONSTRUCT_SELECTIVE_ITERATOR(molecule*,World::MoleculeSet,MoleculeDescriptor);
     256
     257World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
     258  return MoleculeIterator(descr,molecules);
     259}
     260
     261World::MoleculeIterator World::moleculeEnd(){
     262  return MoleculeIterator(AllMolecules(),molecules,molecules.end());
     263}
     264
     265/******************************* Singleton Stuff **************************/
     266
     267World::World() :
     268    periode(new periodentafel),
     269    atoms(),
     270    currAtomId(0),
     271    molecules(),
     272    currMoleculeId(0),
     273    molecules_deprecated(new MoleculeListClass(this))
    20274{
    21275  cell_size = new double[6];
     
    26280  cell_size[4] = 0.;
    27281  cell_size[5] = 20.;
    28   DefaultName = new char[MAXSTRINGSIZE];
    29   strcpy(DefaultName, "none");
    30 };
    31 
    32 /** Destructor of World.
    33  *
    34  */
     282  defaultName = new char[MAXSTRINGSIZE];
     283  strcpy(defaultName, "none");
     284  molecules_deprecated->signOn(this);
     285}
     286
    35287World::~World()
    36288{
    37   delete[](cell_size);
    38   delete[](DefaultName);
    39 };
    40 
    41 
    42 // TODO: Hide boost-thread using Autotools stuff when no threads are used
    43 World* World::theWorld = 0;
    44 
    45 
    46 World* World::get(){
    47   // boost supports RAII-Style locking, so we don't need to unlock
    48   if(!theWorld) {
    49     theWorld = new World();
    50   }
    51   return theWorld;
    52 }
    53 
    54 void World::destroy(){
    55   delete theWorld;
    56   theWorld = 0;
    57 }
    58 
    59 World* World::reset(){
    60   World* oldWorld = 0;
    61   {
    62     oldWorld = theWorld;
    63     theWorld = new World();
    64     // oldworld does not need protection any more,
    65     // since we should have the only reference
    66 
    67     // worldLock handles access to the pointer,
    68     // not to the object
    69   } // scope-end releases the lock
    70 
    71   // we have to let all the observers know that the
    72   // oldWorld was destroyed. oldWorld calls subjectKilled
    73   // upon destruction. Every Observer getting that signal
    74   // should see that it gets the updated new world
    75   delete oldWorld;
    76 }
     289  molecules_deprecated->signOff(this);
     290  delete[] cell_size;
     291  delete[] defaultName;
     292  delete molecules_deprecated;
     293  delete periode;
     294  MoleculeSet::iterator molIter;
     295  for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
     296    DeleteMolecule((*molIter).second);
     297  }
     298  molecules.clear();
     299  AtomSet::iterator atIter;
     300  for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
     301    DeleteAtom((*atIter).second);
     302  }
     303  atoms.clear();
     304}
     305
     306// Explicit instantiation of the singleton mechanism at this point
     307
     308CONSTRUCT_SINGLETON(World)
     309
     310/******************************* deprecated Legacy Stuff ***********************/
     311
     312MoleculeListClass *&World::getMolecules() {
     313  return molecules_deprecated;
     314}
  • src/World.hpp

    rc695c9 r5f612ee  
    11/*
    2  * world.hpp
     2 * World.hpp
    33 *
    4  *  Created on: Mar 3, 2010
    5  *      Author: heber
     4 *  Created on: Feb 3, 2010
     5 *      Author: crueger
    66 */
    77
     
    99#define WORLD_HPP_
    1010
    11 using namespace std;
    12 
    1311/*********************************************** includes ***********************************/
     12
     13#include <string>
     14#include <map>
     15#include <vector>
     16#include <set>
     17#include <boost/thread.hpp>
     18#include <boost/shared_ptr.hpp>
     19
     20#include "types.hpp"
     21#include "Descriptors/SelectiveIterator.hpp"
     22#include "Patterns/Observer.hpp"
     23#include "Patterns/Cacheable.hpp"
     24#include "Patterns/Singleton.hpp"
    1425
    1526// include config.h
     
    1829#endif
    1930
     31// forward declarations
     32class periodentafel;
     33class MoleculeListClass;
     34class atom;
     35class molecule;
     36class AtomDescriptor;
     37class AtomDescriptor_impl;
     38class MoleculeDescriptor;
     39class MoleculeDescriptor_impl;
     40class ManipulateAtomsProcess;
     41template<typename T>
     42class AtomsCalculation;
    2043
    2144/****************************************** forward declarations *****************************/
     
    2346/********************************************** Class World *******************************/
    2447
    25 class World
     48class World : public Singleton<World>, public Observable
    2649{
    27   /***** singleton Stuff *****/
     50
     51// Make access to constructor and destructor possible from inside the singleton
     52friend class Singleton<World>;
     53
     54// necessary for coupling with descriptors
     55friend class AtomDescriptor_impl;
     56friend class AtomDescriptor;
     57friend class MoleculeDescriptor_impl;
     58friend class MoleculeDescriptor;
     59
     60// Actions, calculations etc associated with the World
     61friend class ManipulateAtomsProcess;
     62template<typename> friend class AtomsCalculation;
    2863public:
    29   static World* get();
    30   static void destroy();
    31   static World* reset();
    32 
     64
     65  // Types for Atom and Molecule structures
     66  typedef std::map<atomId_t,atom*> AtomSet;
     67  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
     68
     69  /***** getter and setter *****/
     70  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
     71  /**
     72   * returns the periodentafel for the world.
     73   */
     74  periodentafel *&getPeriode();
     75
     76  /**
     77   * returns the first atom that matches a given descriptor.
     78   * Do not rely on ordering for descriptors that match more than one atom.
     79   */
     80  atom* getAtom(AtomDescriptor descriptor);
     81
     82  /**
     83   * returns a vector containing all atoms that match a given descriptor
     84   */
     85  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     86  std::vector<atom*> getAllAtoms();
     87
     88  /**
     89   * returns a calculation that calls a given function on all atoms matching a descriptor.
     90   * the calculation is not called at this point and can be used as an action, i.e. be stored in
     91   * menus, be kept around for later use etc.
     92   */
     93  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
     94  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
     95
     96  /**
     97   * get the number of atoms in the World
     98   */
     99  int numAtoms();
     100
     101  /**
     102   * returns the first molecule that matches a given descriptor.
     103   * Do not rely on ordering for descriptors that match more than one molecule.
     104   */
     105  molecule *getMolecule(MoleculeDescriptor descriptor);
     106
     107  /**
     108   * returns a vector containing all molecules that match a given descriptor
     109   */
     110  std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
     111
     112  /**
     113   * get the number of molecules in the World
     114   */
     115  int numMolecules();
     116
     117  /**
     118   * get the domain size as a symmetric matrix (6 components)
     119   */
     120  double * getDomain();
     121
     122  /**
     123   * set the domain size as a symmetric matrix (6 components)
     124   */
     125  void setDomain(double * matrix);
     126
     127  /**
     128   * get the default name
     129   */
     130  char * getDefaultName();
     131
     132  /**
     133   * set the default name
     134   */
     135  void setDefaultName(char * name);
     136
     137  /***** Methods to work with the World *****/
     138
     139  /**
     140   * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
     141   * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
     142   */
     143  molecule *createMolecule();
     144
     145  void destroyMolecule(molecule*);
     146  void destroyMolecule(moleculeId_t);
     147
     148  /**
     149   * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
     150   * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
     151   */
     152  atom *createAtom();
     153
     154  /**
     155   * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
     156   * Do not re-register Atoms already known to the world since this will cause double-frees.
     157   */
     158  int registerAtom(atom*);
     159
     160  /**
     161     * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     162     * atom directly since this will leave the pointer inside the world.
     163   */
     164  void destroyAtom(atom*);
     165
     166  /**
     167   * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     168   * atom directly since this will leave the pointer inside the world.
     169   */
     170  void destroyAtom(atomId_t);
     171
     172  /**
     173   * used when changing an atom Id.
     174   * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
     175   *
     176   * Return value indicates wether the change could be done or not.
     177   */
     178  bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
     179
     180  /**
     181   * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
     182   * called at this time, so it can be passed around, stored inside menuItems etc.
     183   */
     184  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
     185  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
     186
     187protected:
     188  /**** Iterators to use internal data structures */
     189
     190  // Atoms
     191  typedef SelectiveIterator<atom*,AtomSet,AtomDescriptor> AtomIterator;
     192
     193  /**
     194   * returns an iterator over all Atoms matching a given descriptor.
     195   * used for internal purposes, like AtomProcesses and AtomCalculations.
     196   */
     197  AtomIterator getAtomIter(AtomDescriptor descr);
     198
     199  /**
     200   * returns an iterator to the end of the AtomSet. Due to overloading this iterator
     201   * can be compared to iterators produced by getAtomIter (see the mis-matching types).
     202   * Thus it can be used to detect when such an iterator is at the end of the list.
     203   * used for internal purposes, like AtomProcesses and AtomCalculations.
     204   */
     205  AtomIterator atomEnd();
     206
     207  // Molecules
     208
     209  typedef SelectiveIterator<molecule*,MoleculeSet,MoleculeDescriptor> MoleculeIterator;
     210
     211  /**
     212   * returns an iterator over all Molecules matching a given descriptor.
     213   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     214   */
     215  MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     216
     217  /**
     218   * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
     219   * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
     220   * Thus it can be used to detect when such an iterator is at the end of the list.
     221   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     222   */
     223  MoleculeIterator moleculeEnd();
     224
     225
     226  /******* Internal manipulation routines for double callback and Observer mechanism ******/
     227  void doManipulate(ManipulateAtomsProcess *);
     228
     229private:
     230
     231  atomId_t getNextAtomId();
     232  void releaseAtomId(atomId_t);
     233  bool reserveAtomId(atomId_t);
     234
     235  periodentafel *periode;
    33236  static double *cell_size;
    34   static char *DefaultName;
    35 
    36 private:
     237  static char *defaultName;
     238public:
     239  AtomSet atoms;
     240private:
     241  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
     242  atomId_t currAtomId; //!< stores the next available Id for atoms
     243  MoleculeSet molecules;
     244  moleculeId_t currMoleculeId;
     245private:
     246  /**
     247   * private constructor to ensure creation of the world using
     248   * the singleton pattern.
     249   */
    37250  World();
     251
     252  /**
     253   * private destructor to ensure destruction of the world using the
     254   * singleton pattern.
     255   */
    38256  virtual ~World();
    39257
    40   static World *theWorld;
     258  /*****
     259   * some legacy stuff that is include for now but will be removed later
     260   *****/
     261public:
     262  MoleculeListClass *&getMolecules();
     263
     264private:
     265  MoleculeListClass *molecules_deprecated;
    41266};
    42267
  • src/analysis_correlation.cpp

    rc695c9 r5f612ee  
    5757                if (Walker->nr < OtherWalker->nr)
    5858                  if ((type2 == NULL) || (OtherWalker->type == type2)) {
    59                     distance = Walker->node->PeriodicDistance(OtherWalker->node, World::get()->cell_size);
     59                    distance = Walker->node->PeriodicDistance(OtherWalker->node, World::getInstance().getDomain());
    6060                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    6161                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    9898  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    9999    if ((*MolWalker)->ActiveFlag) {
    100       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     100      double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    101101      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    102102      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     
    176176        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    177177        if ((type == NULL) || (Walker->type == type)) {
    178           distance = Walker->node->PeriodicDistance(point, World::get()->cell_size);
     178          distance = Walker->node->PeriodicDistance(point, World::getInstance().getDomain());
    179179          DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    180180          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
     
    210210  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    211211    if ((*MolWalker)->ActiveFlag) {
    212       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     212      double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    213213      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    214214      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     
    278278      DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
    279279
    280 
    281280  return outmap;
    282281};
     
    315314  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    316315    if ((*MolWalker)->ActiveFlag) {
    317       double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     316      double * FullMatrix = ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    318317      double * FullInverseMatrix = InverseMatrix(FullMatrix);
    319318      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
  • src/atom.cpp

    rc695c9 r5f612ee  
    1313#include "parser.hpp"
    1414#include "vector.hpp"
     15#include "World.hpp"
    1516
    1617/************************************* Functions for class atom *************************************/
     
    1920/** Constructor of class atom.
    2021 */
    21 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)
     22atom::atom() :
     23  previous(NULL), next(NULL), father(this), sort(&nr)
    2224{
    2325  node = &x;  // TesselPoint::x can only be referenced from here
     
    2628/** Constructor of class atom.
    2729 */
    28 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr)
     30atom::atom(atom *pointer) :
     31    ParticleInfo(pointer),
     32    previous(NULL), next(NULL), father(pointer), sort(&nr)
    2933{
    3034  type = pointer->type;  // copy element of atom
     
    3438  node = &x;
    3539};
     40
     41atom *atom::clone(){
     42  atom *res = new atom();
     43  res->previous=0;
     44  res->next=0;
     45  res->father = this;
     46  res->sort = &res->nr;
     47  res->type = type;
     48  res->x.CopyVector(&this->x);
     49  res->v.CopyVector(&this->v);
     50  res->FixedIon = FixedIon;
     51  res->node = &x;
     52  World::getInstance().registerAtom(res);
     53  return res;
     54}
    3655
    3756
     
    263282};
    264283
     284World *atom::getWorld(){
     285  return world;
     286}
     287
     288void atom::setWorld(World* _world){
     289  world = _world;
     290}
     291
     292bool atom::changeId(atomId_t newId){
     293  // first we move ourselves in the world
     294  // the world lets us know if that succeeded
     295  if(world->changeAtomId(id,newId,this)){
     296    id = newId;
     297    return true;
     298  }
     299  else{
     300    return false;
     301  }
     302}
     303
     304void atom::setId(atomId_t _id) {
     305  id=_id;
     306}
     307
     308atomId_t atom::getId() {
     309  return id;
     310}
     311
     312atom* NewAtom(atomId_t _id){
     313  atom * res =new atom();
     314  res->setId(_id);
     315  return res;
     316}
     317
     318void DeleteAtom(atom* atom){
     319  delete atom;
     320}
  • src/atom.hpp

    rc695c9 r5f612ee  
    2828#include "atom_trajectoryparticle.hpp"
    2929#include "tesselation.hpp"
     30#include "types.hpp"
    3031
    3132/****************************************** forward declarations *****************************/
    3233
    3334class Vector;
     35class World;
    3436
    3537/********************************************** declarations *******************************/
     
    3941 */
    4042class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo {
     43  friend atom* NewAtom(atomId_t);
     44  friend void  DeleteAtom(atom*);
    4145  public:
    4246    atom *previous; //!< previous atom in molecule list
     
    4549    int *sort;      //!< sort criteria
    4650
    47   atom();
    48   atom(class atom *pointer);
    49   virtual ~atom();
     51  virtual atom *clone();
    5052
    5153  bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
     
    6769  bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const;
    6870
     71  // getter and setter
     72
     73  /**
     74   * returns the World that contains this atom.
     75   * Use this if you need to get the world without locking
     76   * the singleton for example.
     77   *
     78   */
     79  World *getWorld();
     80  void setWorld(World*);
     81
     82  virtual atomId_t getId();
     83  virtual bool changeId(atomId_t newId);
     84
     85  /**
     86   * this function sets the Id without notifying the world. Only use it, if the world has already
     87   * gotten an ID for this Atom.
     88   */
     89   virtual void setId(atomId_t);
     90
     91  protected:
     92    /**
     93     * Protected constructor to ensure construction of atoms through the world.
     94     * see World::createAtom()
     95     */
     96    atom();
     97
     98    /**
     99     * Protected copy-constructor to ensure construction of atoms by cloning.
     100     * see atom::clone()
     101     */
     102    atom(class atom *pointer);
     103
     104    /**
     105     * Protected destructor to ensure destruction of atoms through the world.
     106     * see World::destroyAtom()
     107     */
     108    virtual ~atom();
    69109  private:
     110    World* world;
     111    atomId_t id;
    70112};
    71113
     114/**
     115 * internal method used by the world. Do not use if you don't know what you are doing.
     116 * You might get burned...
     117 * Use World::createAtom() instead.
     118 */
     119atom* NewAtom(atomId_t _id);
     120
     121/**
     122* internal method used by the world. Do not use if you don't know what you are doing.
     123 * You might get burned...
     124 * Use World::destroyAtom() instead.
     125 */
     126void  DeleteAtom(atom*);
     127
     128
    72129#endif /* ATOM_HPP_ */
  • src/atom_atominfo.cpp

    rc695c9 r5f612ee  
    66 */
    77
     8#include "periodentafel.hpp"
     9#include "World.hpp"
    810#include "atom_atominfo.hpp"
    911
     
    1820};
    1921
     22const element *AtomInfo::getType(){
     23  return type;
     24}
     25
     26void AtomInfo::setType(const element* _type) {
     27  type = _type;
     28}
     29
     30void AtomInfo::setType(int Z) {
     31  const element *elem = World::getInstance().getPeriode()->FindElement(Z);
     32  setType(elem);
     33}
  • src/atom_atominfo.hpp

    rc695c9 r5f612ee  
    3232  Vector v;       //!< velocity vector of atom, giving last velocity within cell
    3333  Vector F;       //!< Force vector of atom, giving last force within cell
    34   element *type;  //!< pointing to element
     34  const element *type;  //!< pointing to element
    3535
    3636  AtomInfo();
    3737  ~AtomInfo();
     38
     39  const element *getType();
     40  void setType(const element *);
     41  void setType(int);
    3842
    3943private:
  • src/atom_particleinfo.cpp

    rc695c9 r5f612ee  
    1212 */
    1313ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {};
     14
     15ParticleInfo::ParticleInfo(ParticleInfo *pointer) :
     16    nr(pointer->nr),
     17    Name(pointer->Name)
     18    {}
     19
    1420
    1521/** Destructor of ParticleInfo.
  • src/atom_particleinfo.hpp

    rc695c9 r5f612ee  
    3131
    3232  ParticleInfo();
     33  ParticleInfo(ParticleInfo*);
    3334  ~ParticleInfo();
    3435
  • src/boundary.cpp

    rc695c9 r5f612ee  
    44 */
    55
     6#include "World.hpp"
    67#include "atom.hpp"
    78#include "bond.hpp"
     
    802803{
    803804        Info FunctionInfo(__func__);
    804   molecule *Filling = new molecule(filler->elemente);
     805  molecule *Filling = World::getInstance().createMolecule();
    805806  Vector CurrentPosition;
    806807  int N[NDIM];
    807808  int n[NDIM];
    808   double *M =  ReturnFullMatrixforSymmetric(World::get()->cell_size);
     809  double *M =  ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
    809810  double Rotations[NDIM*NDIM];
    810811  double *MInverse = InverseMatrix(M);
     
    919920            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl);
    920921            // copy atom ...
    921             CopyAtoms[Walker->nr] = new atom(Walker);
     922            CopyAtoms[Walker->nr] = Walker->clone();
    922923            CopyAtoms[Walker->nr]->x.CopyVector(&Inserter);
    923924            Filling->AddAtom(CopyAtoms[Walker->nr]);
  • src/builder.cpp

    rc695c9 r5f612ee  
    4848
    4949
     50#include <boost/bind.hpp>
     51
    5052using namespace std;
    5153
     
    6567#include "linkedcell.hpp"
    6668#include "log.hpp"
    67 #include "memoryusageobserverunittest.hpp"
     69#include "memoryusageobserver.hpp"
    6870#include "molecule.hpp"
    6971#include "periodentafel.hpp"
     72#include "UIElements/UIFactory.hpp"
     73#include "UIElements/MainWindow.hpp"
     74#include "UIElements/Dialog.hpp"
     75#include "Menu/ActionMenuItem.hpp"
     76#include "Actions/ActionRegistry.hpp"
     77#include "Actions/ActionHistory.hpp"
     78#include "Actions/MethodAction.hpp"
     79#include "Actions/small_actions.hpp"
     80#include "World.hpp"
    7081#include "version.h"
    7182#include "World.hpp"
    7283
    7384/********************************************* Subsubmenu routine ************************************/
    74 
     85#if 0
    7586/** Submenu for adding atoms to the molecule.
    7687 * \param *periode periodentafel
     
    105116        cout << Verbose(0) << "Enter absolute coordinates." << endl;
    106117        first = new atom;
    107         first->x.AskPosition(World::get()->cell_size, false);
     118        first->x.AskPosition(World::getInstance().getDomain(), false);
    108119        first->type = periode->AskElement();  // give type
    109120        mol->AddAtom(first);  // add to molecule
     
    116127          if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
    117128          cout << Verbose(0) << "Enter reference coordinates." << endl;
    118           x.AskPosition(World::get()->cell_size, true);
     129          x.AskPosition(World::getInstance().getDomain(), true);
    119130          cout << Verbose(0) << "Enter relative coordinates." << endl;
    120           first->x.AskPosition(World::get()->cell_size, false);
     131          first->x.AskPosition(World::getInstance().getDomain(), false);
    121132          first->x.AddVector((const Vector *)&x);
    122133          cout << Verbose(0) << "\n";
     
    133144          second = mol->AskAtom("Enter atom number: ");
    134145          DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl);
    135           first->x.AskPosition(World::get()->cell_size, false);
     146          first->x.AskPosition(World::getInstance().getDomain(), false);
    136147          for (int i=NDIM;i--;) {
    137148            first->x.x[i] += second->x.x[i];
     
    260271        if (i >= 2) {
    261272          first->x.LSQdistance((const Vector **)atoms, i);
    262 
    263273          first->x.Output();
    264274          first->type = periode->AskElement();  // give type
     
    360370    case 'b': // normal vector of mirror plane
    361371      cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
    362       n.AskPosition(World::get()->cell_size,0);
     372      n.AskPosition(World::getInstance().getDomain(),0);
    363373      n.Normalize();
    364374      break;
     
    427437    case 'b': // normal vector of mirror plane
    428438      DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl);
    429       n.AskPosition(World::get()->cell_size,0);
     439      n.AskPosition(World::getInstance().getDomain(),0);
    430440      n.Normalize();
    431441      break;
     
    867877          x.Zero();
    868878          y.Zero();
    869           y.x[abs(axis)-1] = World::get()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     879          y.x[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    870880          for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    871881            x.AddVector(&y); // per factor one cell width further
     
    890900            mol->Translate(&x);
    891901          }
    892           World::get()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
     902          World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
    893903        }
    894904      }
     
    947957        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    948958        DoLog(0) && (Log() << Verbose(0) << "Enter translation vector." << endl);
    949         x.AskPosition(World::get()->cell_size,0);
     959        x.AskPosition(World::getInstance().getDomain(),0);
    950960        mol->Center.AddVector((const Vector *)&x);
    951961     }
     
    9911001      break;
    9921002    case 'c':
    993       mol = new molecule(periode);
     1003      mol = World::getInstance().createMolecule();
    9941004      molecules->insert(mol);
    9951005      break;
     
    9991009        char filename[MAXSTRINGSIZE];
    10001010        DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
    1001         mol = new molecule(periode);
     1011        mol = World::getInstance().createMolecule();
    10021012        do {
    10031013          DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
     
    10071017        // center at set box dimensions
    10081018        mol->CenterEdge(&center);
    1009         double * const cell_size = World::get()->cell_size;
     1019        double * const cell_size = World::getInstance().getDomain();
    10101020        cell_size[0] = center.x[0];
    10111021        cell_size[1] = 0;
     
    12581268};
    12591269
    1260 
    12611270/********************************************** Test routine **************************************/
    12621271
     
    13421351};
    13431352
     1353#endif
     1354
    13441355/** Tries given filename or standard on saving the config file.
    13451356 * \param *ConfigFileName name of file
     
    13521363  char filename[MAXSTRINGSIZE];
    13531364  ofstream output;
    1354   molecule *mol = new molecule(periode);
     1365  molecule *mol = World::getInstance().createMolecule();
    13551366  mol->SetNameFromFilename(ConfigFileName);
    13561367
     
    14631474  }
    14641475
    1465   delete(mol);
     1476  World::getInstance().destroyMolecule(mol);
    14661477};
    14671478
     
    14761487 * \return exit code (0 - successful, all else - something's wrong)
    14771488 */
    1478 static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName)
     1489static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode,\
     1490                                   config& configuration, char *&ConfigFileName)
    14791491{
    14801492  Vector x,y,z,n;  // coordinates for absolute point in cell volume
     
    15731585              j = -1;
    15741586              DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
    1575               double * const cell_size = World::get()->cell_size;
     1587              double * const cell_size = World::getInstance().getDomain();
    15761588              for (int i=0;i<6;i++) {
    15771589                cell_size[i] = atof(argv[argptr+i]);
     
    16061618          case 'X':
    16071619            {
    1608               char **name = &(World::get()->DefaultName);
    1609               delete[](*name);
    1610               const int length = strlen(argv[argptr]);
    1611               *name = new char[length+2];
    1612               strncpy(*name, argv[argptr], length);
    1613               DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *name << "." << endl);
     1620              World::getInstance().setDefaultName(argv[argptr]);
     1621              DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *World::getInstance().getDefaultName() << "." << endl);
    16141622            }
    16151623            break;
     
    16781686     }
    16791687     if (mol == NULL) {
    1680        mol = new molecule(periode);
     1688       mol = World::getInstance().createMolecule();
    16811689       mol->ActiveFlag = true;
    16821690       if (ConfigFileName != NULL)
     
    17261734              } else {
    17271735                SaveFlag = true;
    1728                 DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ");
    1729                 first = new atom;
     1736                Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
     1737                first = World::getInstance().createAtom();
    17301738                first->type = periode->FindElement(atoi(argv[argptr]));
    17311739                if (first->type != NULL)
     
    18331841                          const double BinEnd = atof(argv[argptr+6]);
    18341842
    1835                           element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
    1836                           element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2]));
     1843                          const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1844                          const element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2]));
    18371845                          PairCorrelationMap *correlationmap = NULL;
    18381846                          if (periodic)
     
    18641872                          const double BinEnd = atof(argv[argptr+8]);
    18651873
    1866                           element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1874                          const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
    18671875                          Vector *Point = new Vector((const double) atof(argv[argptr+1]),(const double) atof(argv[argptr+2]),(const double) atof(argv[argptr+3]));
    18681876                          CorrelationToPointMap *correlationmap = NULL;
     
    19241932                          }
    19251933                          LCList = new LinkedCell(Boundary, LCWidth);
    1926                           element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1934                          const element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
    19271935                          FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
    19281936                          CorrelationToSurfaceMap *surfacemap = NULL;
     
    19942002                DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl);
    19952003                // construct water molecule
    1996                 molecule *filler = new molecule(periode);
     2004                molecule *filler = World::getInstance().createMolecule();
    19972005                if (!filler->AddXYZFile(argv[argptr])) {
    19982006                  DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl);
     
    20012009                configuration.BG->ConstructBondGraph(filler);
    20022010                molecule *Filling = NULL;
     2011                atom *second = NULL, *third = NULL;
     2012                first = World::getInstance().createAtom();
     2013                first->type = periode->FindElement(1);
     2014                first->x.Init(0.441, -0.143, 0.);
     2015                filler->AddAtom(first);
     2016                second = World::getInstance().createAtom();
     2017                second->type = periode->FindElement(1);
     2018                second->x.Init(-0.464, 1.137, 0.0);
     2019                filler->AddAtom(second);
     2020                third = World::getInstance().createAtom();
     2021                third->type = periode->FindElement(8);
     2022                third->x.Init(-0.464, 0.177, 0.);
     2023                filler->AddAtom(third);
     2024                filler->AddBond(first, third, 1);
     2025                filler->AddBond(second, third, 1);
    20032026                // call routine
    20042027                double distance[NDIM];
     
    20102033                  molecules->insert(Filling);
    20112034                }
    2012                 delete(filler);
     2035                World::getInstance().destroyMolecule(filler);
    20132036                argptr+=6;
    20142037              }
     
    22182241                factor[2] = atof(argv[argptr+2]);
    22192242                mol->Scale((const double ** const)&factor);
    2220                 double * const cell_size = World::get()->cell_size;
     2243                double * const cell_size = World::getInstance().getDomain();
    22212244                for (int i=0;i<NDIM;i++) {
    22222245                  j += i+1;
     
    22382261                j = -1;
    22392262                DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
    2240                 double * const cell_size = World::get()->cell_size;
     2263                double * const cell_size = World::getInstance().getDomain();
    22412264                for (int i=0;i<6;i++) {
    22422265                  cell_size[i] = atof(argv[argptr+i]);
     
    22572280                j = -1;
    22582281                DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
    2259                 double * const cell_size = World::get()->cell_size;
     2282                double * const cell_size = World::getInstance().getDomain();
    22602283                for (int i=0;i<6;i++) {
    22612284                  cell_size[i] = atof(argv[argptr+i]);
     
    22812304                mol->SetBoxDimension(&x);
    22822305                // translate each coordinate by boundary
    2283                 double * const cell_size = World::get()->cell_size;
     2306                double * const cell_size = World::getInstance().getDomain();
    22842307                j=-1;
    22852308                for (int i=0;i<NDIM;i++) {
     
    23252348                DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
    23262349                start = clock();
    2327                 mol->CreateAdjacencyList(atof(argv[argptr++]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
     2350                mol->CreateAdjacencyList(atof(argv[argptr]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
    23282351                DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
    23292352                if (mol->first->next != mol->last) {
    2330                   ExitFlag = mol->FragmentMolecule(atoi(argv[argptr]), &configuration);
     2353                  ExitFlag = mol->FragmentMolecule(atoi(argv[argptr+1]), &configuration);
    23312354                }
    23322355                end = clock();
     
    24172440              } else {
    24182441                SaveFlag = true;
    2419                 double * const cell_size = World::get()->cell_size;
     2442                double * const cell_size = World::getInstance().getDomain();
    24202443                for (int axis = 1; axis <= NDIM; axis++) {
    24212444                  int faktor = atoi(argv[argptr++]);
    24222445                  int count;
    2423                   element ** Elements;
     2446                  const element ** Elements;
    24242447                  Vector ** vectors;
    24252448                  if (faktor < 1) {
     
    24302453                  if (mol->AtomCount != 0) {  // if there is more than none
    24312454                    count = mol->AtomCount;   // is changed becausing of adding, thus has to be stored away beforehand
    2432                     Elements = new element *[count];
     2455                    Elements = new const element *[count];
    24332456                    vectors = new Vector *[count];
    24342457                    j = 0;
     
    24482471                      x.AddVector(&y); // per factor one cell width further
    24492472                      for (int k=count;k--;) { // go through every atom of the original cell
    2450                         first = new atom(); // create a new body
     2473                        first = World::getInstance().createAtom(); // create a new body
    24512474                        first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    24522475                        first->x.AddVector(&x);      // translate the coordinates
     
    24792502    } while (argptr < argc);
    24802503    if (SaveFlag)
    2481       SaveConfig(ConfigFileName, &configuration, periode, molecules);
     2504      configuration.SaveAll(ConfigFileName, periode, molecules);
    24822505  } else {  // no arguments, hence scan the elements db
    24832506    if (periode->LoadPeriodentafel(configuration.databasepath))
     
    24902513};
    24912514
     2515/***************************************** Functions used to build all menus **********************/
     2516
     2517void populateEditMoleculesMenu(Menu* editMoleculesMenu,MoleculeListClass *molecules, config *configuration, periodentafel *periode){
     2518  // build the EditMoleculesMenu
     2519  Action *createMoleculeAction = new MethodAction("createMoleculeAction",boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
     2520  new ActionMenuItem('c',"create new molecule",editMoleculesMenu,createMoleculeAction);
     2521
     2522  Action *loadMoleculeAction = new MethodAction("loadMoleculeAction",boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
     2523  new ActionMenuItem('l',"load molecule from xyz file",editMoleculesMenu,loadMoleculeAction);
     2524
     2525  Action *changeFilenameAction = new ChangeMoleculeNameAction(molecules);
     2526  new ActionMenuItem('n',"change molecule's name",editMoleculesMenu,changeFilenameAction);
     2527
     2528  Action *giveFilenameAction = new MethodAction("giveFilenameAction",boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
     2529  new ActionMenuItem('N',"give molecules filename",editMoleculesMenu,giveFilenameAction);
     2530
     2531  Action *parseAtomsAction = new MethodAction("parseAtomsAction",boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
     2532  new ActionMenuItem('p',"parse atoms in xyz file into molecule",editMoleculesMenu,parseAtomsAction);
     2533
     2534  Action *eraseMoleculeAction = new MethodAction("eraseMoleculeAction",boost::bind(&MoleculeListClass::eraseMolecule,molecules));
     2535  new ActionMenuItem('r',"remove a molecule",editMoleculesMenu,eraseMoleculeAction);
     2536
     2537}
     2538
     2539
    24922540/********************************************** Main routine **************************************/
    24932541
    2494 int main(int argc, char **argv)
    2495 {
    2496   periodentafel *periode = new periodentafel; // and a period table of all elements
    2497   MoleculeListClass *molecules = new MoleculeListClass;  // list of all molecules
    2498   molecule *mol = NULL;
    2499   config *configuration = new config;
    2500   char choice;  // menu choice char
    2501   Vector x,y,z,n;  // coordinates for absolute point in cell volume
    2502   ifstream test;
    2503   ofstream output;
    2504   string line;
    2505   char *ConfigFileName = NULL;
    2506   int j;
    2507 
    2508   cout << ESPACKVersion << endl;
    2509 
    2510   DoLog(1) && (Log() << Verbose(1) << "test" << endl);
    2511   DoLog(3) && (Log() << Verbose(1) << "test");
    2512 
    2513   setVerbosity(0);
    2514 
    2515   // =========================== PARSE COMMAND LINE OPTIONS ====================================
    2516   j = ParseCommandLineOptions(argc, argv, molecules, periode, *configuration, ConfigFileName);
    2517   switch(j) {
    2518     case 255:  // something went wrong
    2519     case 2:  // just for -f option
    2520     case 1:  // just for -v and -h options
    2521       delete(molecules); // also free's all molecules contained
    2522       delete(periode);
    2523       delete(configuration);
    2524       Log() << Verbose(0) <<  "Maximum of allocated memory: "
    2525         << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
    2526       Log() << Verbose(0) <<  "Remaining non-freed memory: "
    2527         << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    2528       MemoryUsageObserver::getInstance()->purgeInstance();
    2529       logger::purgeInstance();
    2530       errorLogger::purgeInstance();
    2531      return (j == 1 ? 0 : j);
    2532     default:
    2533       break;
    2534   }
    2535 
    2536   // General stuff
    2537   if (molecules->ListOfMolecules.size() == 0) {
    2538     mol = new molecule(periode);
    2539     double * const cell_size = World::get()->cell_size;
    2540     if (cell_size[0] == 0.) {
    2541       DoLog(0) && (Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl);
    2542       for (int i=0;i<6;i++) {
    2543         DoLog(1) && (Log() << Verbose(1) << "Cell size" << i << ": ");
    2544         cin >> cell_size[i];
    2545       }
    2546     }
    2547     mol->ActiveFlag = true;
    2548     molecules->insert(mol);
    2549   }
    2550 
    2551   // =========================== START INTERACTIVE SESSION ====================================
    2552 
    2553   // now the main construction loop
    2554   DoLog(0) && (Log() << Verbose(0) << endl << "Now comes the real construction..." << endl);
    2555   do {
    2556     DoLog(0) && (Log() << Verbose(0) << endl << endl);
    2557     DoLog(0) && (Log() << Verbose(0) << "============Molecule list=======================" << endl);
    2558     molecules->Enumerate((ofstream *)&cout);
    2559     DoLog(0) && (Log() << Verbose(0) << "============Menu===============================" << endl);
    2560     DoLog(0) && (Log() << Verbose(0) << "a - set molecule (in)active" << endl);
    2561     DoLog(0) && (Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl);
    2562     DoLog(0) && (Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl);
    2563     DoLog(0) && (Log() << Verbose(0) << "M - Merge molecules" << endl);
    2564     DoLog(0) && (Log() << Verbose(0) << "m - manipulate atoms" << endl);
    2565     DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
    2566     DoLog(0) && (Log() << Verbose(0) << "c - edit the current configuration" << endl);
    2567     DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
    2568     DoLog(0) && (Log() << Verbose(0) << "s - save current setup to config file" << endl);
    2569     DoLog(0) && (Log() << Verbose(0) << "T - call the current test routine" << endl);
    2570     DoLog(0) && (Log() << Verbose(0) << "q - quit" << endl);
    2571     DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
    2572     DoLog(0) && (Log() << Verbose(0) << "Input: ");
    2573     cin >> choice;
    2574 
    2575     switch (choice) {
    2576       case 'a':  // (in)activate molecule
    2577         {
    2578           DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    2579           cin >> j;
    2580           for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
    2581             if ((*ListRunner)->IndexNr == j)
    2582               (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
    2583         }
    2584         break;
    2585 
    2586       case 'c': // edit each field of the configuration
    2587        configuration->Edit();
    2588        break;
    2589 
    2590       case 'e': // create molecule
    2591         EditMolecules(periode, molecules);
    2592         break;
    2593 
    2594       case 'g': // manipulate molecules
    2595         ManipulateMolecules(periode, molecules, configuration);
    2596         break;
    2597 
    2598       case 'M':  // merge molecules
    2599         MergeMolecules(periode, molecules);
    2600         break;
    2601 
    2602       case 'm': // manipulate atoms
    2603         ManipulateAtoms(periode, molecules, configuration);
    2604         break;
    2605 
    2606       case 'q': // quit
    2607         break;
    2608 
    2609       case 's': // save to config file
    2610         SaveConfig(ConfigFileName, configuration, periode, molecules);
    2611         break;
    2612 
    2613       case 'T':
    2614         testroutine(molecules);
    2615         break;
    2616 
    2617       default:
    2618         break;
    2619     };
    2620   } while (choice != 'q');
    2621 
    2622   // save element data base
    2623   if (periode->StorePeriodentafel(configuration->databasepath)) //ElementsFileName
    2624     DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db successful." << endl);
    2625   else
    2626     DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db failed." << endl);
    2627 
    2628   delete(molecules); // also free's all molecules contained
    2629   delete(periode);
     2542void cleanUp(config *configuration){
     2543  UIFactory::purgeInstance();
     2544  World::purgeInstance();
    26302545  delete(configuration);
    2631 
    26322546  Log() << Verbose(0) <<  "Maximum of allocated memory: "
    26332547    << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
     
    26372551  logger::purgeInstance();
    26382552  errorLogger::purgeInstance();
    2639 
     2553  ActionRegistry::purgeInstance();
     2554}
     2555
     2556int main(int argc, char **argv)
     2557{
     2558    molecule *mol = NULL;
     2559    config *configuration = new config;
     2560    Vector x, y, z, n;
     2561    ifstream test;
     2562    ofstream output;
     2563    string line;
     2564    char *ConfigFileName = NULL;
     2565    int j;
     2566
     2567    cout << ESPACKVersion << endl;
     2568
     2569    setVerbosity(0);
     2570    // need to init the history before any action is created
     2571    ActionHistory::init();
     2572    /* structure of ParseCommandLineOptions will be refactored later */
     2573    j = ParseCommandLineOptions(argc, argv,  World::getInstance().getMolecules(), World::getInstance().getPeriode(), *configuration, ConfigFileName);
     2574    switch (j){
     2575        case 255:
     2576        case 2:
     2577        case 1:
     2578            cleanUp(configuration);
     2579            return (j == 1 ? 0 : j);
     2580        default:
     2581            break;
     2582    }
     2583    if(World::getInstance().numMolecules() == 0){
     2584        mol = World::getInstance().createMolecule();
     2585        World::getInstance().getMolecules()->insert(mol);
     2586        cout << "Molecule created" << endl;
     2587        if(World::getInstance().getDomain()[0] == 0.){
     2588            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
     2589            for(int i = 0;i < 6;i++){
     2590                Log() << Verbose(1) << "Cell size" << i << ": ";
     2591                cin >> World::getInstance().getDomain()[i];
     2592            }
     2593        }
     2594        mol->ActiveFlag = true;
     2595    }
     2596
     2597    {
     2598      cout << ESPACKVersion << endl;
     2599
     2600      setVerbosity(0);
     2601
     2602      menuPopulaters populaters;
     2603      populaters.MakeEditMoleculesMenu = populateEditMoleculesMenu;
     2604
     2605      UIFactory::makeUserInterface(UIFactory::Text);
     2606      MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow(populaters,World::getInstance().getMolecules(), configuration, World::getInstance().getPeriode(), ConfigFileName);
     2607      mainWindow->display();
     2608      delete mainWindow;
     2609    }
     2610
     2611    if(World::getInstance().getPeriode()->StorePeriodentafel(configuration->databasepath))
     2612        Log() << Verbose(0) << "Saving of elements.db successful." << endl;
     2613
     2614    else
     2615        Log() << Verbose(0) << "Saving of elements.db failed." << endl;
     2616
     2617  cleanUp(configuration);
    26402618  return (0);
    26412619}
  • src/config.cpp

    rc695c9 r5f612ee  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    500501//        case 'j': // BoxLength
    501502//          Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
    502 //          double * const cell_size = World::get()->cell_size;
     503//          double * const cell_size = World::getInstance().getDomain();
    503504//          for (int i=0;i<6;i++) {
    504505//            Log() << Verbose(0) << "Cell size" << i << ": ";
     
    676677{
    677678  int MaxTypes = 0;
    678   element *elementhash[MAX_ELEMENTS];
     679  const element *elementhash[MAX_ELEMENTS];
    679680  char name[MAX_ELEMENTS];
    680681  char keyword[MAX_ELEMENTS];
     
    734735            sprintf(keyword,"%s_%i",name, j+1);
    735736            if (repetition == 0) {
    736               neues = new atom();
     737              neues = World::getInstance().createAtom();
    737738              AtomList[i][j] = neues;
    738739              LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    813814          sprintf(keyword,"%s_%i",name, j+1);
    814815          if (repetition == 0) {
    815             neues = new atom();
     816            neues = World::getInstance().createAtom();
    816817            AtomList[i][j] = neues;
    817818            LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    852853void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    853854{
    854   molecule *mol = new molecule(periode);
     855  molecule *mol = World::getInstance().createMolecule();
    855856  ifstream *file = new ifstream(filename);
    856857  if (file == NULL) {
     
    967968  // Unit cell and magnetic field
    968969  ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
    969   double * const cell_size = World::get()->cell_size;
     970  double * const cell_size = World::getInstance().getDomain();
    970971  cell_size[0] = BoxLength[0];
    971972  cell_size[1] = BoxLength[3];
     
    10911092void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    10921093{
    1093   molecule *mol = new molecule(periode);
     1094  molecule *mol = World::getInstance().createMolecule();
    10941095  ifstream *file = new ifstream(filename);
    10951096  if (file == NULL) {
     
    11091110  string zeile;
    11101111  string dummy;
    1111   element *elementhash[128];
     1112  const element *elementhash[128];
    11121113  int Z = -1;
    11131114  int No = -1;
     
    11721173
    11731174  ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
    1174   double * const cell_size = World::get()->cell_size;
     1175  double * const cell_size = World::getInstance().getDomain();
    11751176  cell_size[0] = BoxLength[0];
    11761177  cell_size[1] = BoxLength[3];
     
    12911292        }
    12921293        istringstream input2(zeile);
    1293         atom *neues = new atom();
     1294        atom *neues = World::getInstance().createAtom();
    12941295        input2 >> neues->x.x[0]; // x
    12951296        input2 >> neues->x.x[1]; // y
     
    13161317  // bring MaxTypes up to date
    13171318  mol->CountElements();
    1318   const double * const cell_size = World::get()->cell_size;
     1319  const double * const cell_size = World::getInstance().getDomain();
    13191320  ofstream * const output = new ofstream(filename, ios::out);
    13201321  if (output != NULL) {
     
    17841785};
    17851786
     1787
     1788/** Tries given filename or standard on saving the config file.
     1789 * \param *ConfigFileName name of file
     1790 * \param *periode pointer to periodentafel structure with all the elements
     1791 * \param *molecules list of molecules structure with all the atoms and coordinates
     1792 */
     1793void config::SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules)
     1794{
     1795  char filename[MAXSTRINGSIZE];
     1796  ofstream output;
     1797  molecule *mol = World::getInstance().createMolecule();
     1798  mol->SetNameFromFilename(ConfigFileName);
     1799
     1800  if (!strcmp(configpath, GetDefaultPath())) {
     1801    eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
     1802  }
     1803
     1804
     1805  // first save as PDB data
     1806  if (ConfigFileName != NULL)
     1807    strcpy(filename, ConfigFileName);
     1808  if (output == NULL)
     1809    strcpy(filename,"main_pcp_linux");
     1810  Log() << Verbose(0) << "Saving as pdb input ";
     1811  if (SavePDB(filename, molecules))
     1812    Log() << Verbose(0) << "done." << endl;
     1813  else
     1814    Log() << Verbose(0) << "failed." << endl;
     1815
     1816  // then save as tremolo data file
     1817  if (ConfigFileName != NULL)
     1818    strcpy(filename, ConfigFileName);
     1819  if (output == NULL)
     1820    strcpy(filename,"main_pcp_linux");
     1821  Log() << Verbose(0) << "Saving as tremolo data input ";
     1822  if (SaveTREMOLO(filename, molecules))
     1823    Log() << Verbose(0) << "done." << endl;
     1824  else
     1825    Log() << Verbose(0) << "failed." << endl;
     1826
     1827  // translate each to its center and merge all molecules in MoleculeListClass into this molecule
     1828  int N = molecules->ListOfMolecules.size();
     1829  int *src = new int[N];
     1830  N=0;
     1831  for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1832    src[N++] = (*ListRunner)->IndexNr;
     1833    (*ListRunner)->Translate(&(*ListRunner)->Center);
     1834  }
     1835  molecules->SimpleMultiAdd(mol, src, N);
     1836  delete[](src);
     1837
     1838  // ... and translate back
     1839  for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
     1840    (*ListRunner)->Center.Scale(-1.);
     1841    (*ListRunner)->Translate(&(*ListRunner)->Center);
     1842    (*ListRunner)->Center.Scale(-1.);
     1843  }
     1844
     1845  Log() << Verbose(0) << "Storing configuration ... " << endl;
     1846  // get correct valence orbitals
     1847  mol->CalculateOrbitals(*this);
     1848  InitMaxMinStopStep = MaxMinStopStep = MaxPsiDouble;
     1849  if (ConfigFileName != NULL) { // test the file name
     1850    strcpy(filename, ConfigFileName);
     1851    output.open(filename, ios::trunc);
     1852  } else if (strlen(configname) != 0) {
     1853    strcpy(filename, configname);
     1854    output.open(configname, ios::trunc);
     1855    } else {
     1856      strcpy(filename, DEFAULTCONFIG);
     1857      output.open(DEFAULTCONFIG, ios::trunc);
     1858    }
     1859  output.close();
     1860  output.clear();
     1861  Log() << Verbose(0) << "Saving of config file ";
     1862  if (Save(filename, periode, mol))
     1863    Log() << Verbose(0) << "successful." << endl;
     1864  else
     1865    Log() << Verbose(0) << "failed." << endl;
     1866
     1867  // and save to xyz file
     1868  if (ConfigFileName != NULL) {
     1869    strcpy(filename, ConfigFileName);
     1870    strcat(filename, ".xyz");
     1871    output.open(filename, ios::trunc);
     1872  }
     1873  if (output == NULL) {
     1874    strcpy(filename,"main_pcp_linux");
     1875    strcat(filename, ".xyz");
     1876    output.open(filename, ios::trunc);
     1877  }
     1878  Log() << Verbose(0) << "Saving of XYZ file ";
     1879  if (mol->MDSteps <= 1) {
     1880    if (mol->OutputXYZ(&output))
     1881      Log() << Verbose(0) << "successful." << endl;
     1882    else
     1883      Log() << Verbose(0) << "failed." << endl;
     1884  } else {
     1885    if (mol->OutputTrajectoriesXYZ(&output))
     1886      Log() << Verbose(0) << "successful." << endl;
     1887    else
     1888      Log() << Verbose(0) << "failed." << endl;
     1889  }
     1890  output.close();
     1891  output.clear();
     1892
     1893  // and save as MPQC configuration
     1894  if (ConfigFileName != NULL)
     1895    strcpy(filename, ConfigFileName);
     1896  if (output == NULL)
     1897    strcpy(filename,"main_pcp_linux");
     1898  Log() << Verbose(0) << "Saving as mpqc input ";
     1899  if (SaveMPQC(filename, mol))
     1900    Log() << Verbose(0) << "done." << endl;
     1901  else
     1902    Log() << Verbose(0) << "failed." << endl;
     1903
     1904  if (!strcmp(configpath, GetDefaultPath())) {
     1905    eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
     1906  }
     1907
     1908  World::getInstance().destroyMolecule(mol);
     1909};
     1910
    17861911/** Reads parameter from a parsed file.
    17871912 * The file is either parsed for a certain keyword or if null is given for
  • src/config.hpp

    rc695c9 r5f612ee  
    146146  bool SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const;
    147147
     148  void SaveAll(char *ConfigFileName, periodentafel *periode, MoleculeListClass *molecules);
     149
    148150  void Edit();
    149151  bool GetIsAngstroem() const;
  • src/datacreator.cpp

    rc695c9 r5f612ee  
    771771{
    772772  stringstream line(Force.Header[Force.MatrixCounter]);
    773   char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
     773  const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
    774774  string token;
    775775
     
    803803{
    804804  stringstream line(Force.Header[Force.MatrixCounter]);
    805   char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
     805  const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};
    806806  string token;
    807807
  • src/defs.hpp

    rc695c9 r5f612ee  
    3131
    3232enum Shading { white, lightgray, darkgray, black };  //!< color in Breadth-First-Search analysis
     33
     34
    3335
    3436//enum CutCyclicBond { KeepBond,  SaturateBond }; //!< Saturation scheme either atom- or bondwise
     
    7678#define UPDATECOUNT 10  //!< update ten sites per BOSSANOVA interval
    7779
     80#define STD_MENU_LENGTH 60
     81#define STD_MENU_TITLE_SPACER '='
     82#define STD_SEPERATOR_SPACER '-'
     83
    7884#endif /*DEFS_HPP_*/
  • src/element.cpp

    rc695c9 r5f612ee  
    1010#include "element.hpp"
    1111
     12using namespace std;
     13
    1214/************************************* Functions for class element **********************************/
    1315
    1416/** Constructor of class element.
    1517 */
    16 element::element() {
    17   Z = -1;
    18   No = -1;
    19   previous = NULL;
    20   next = NULL;
    21   sort = NULL;
     18element::element() :
     19  mass(0),
     20  CovalentRadius(0),
     21  VanDerWaalsRadius(0),
     22        Z(-1),
     23        previous(NULL),
     24        next(NULL),
     25        sort(NULL),
     26        No(-1),
     27        Valence(0),
     28        NoValenceOrbitals(0)
     29{
    2230};
    2331
     
    2937 * \param *out outstream
    3038 */
    31 bool element::Output(ofstream * const out) const
     39bool element::Output(ostream * const out) const
    3240{
    3341  if (out != NULL) {
     
    4452 * \param NoOfAtoms total number of atom of this element type
    4553 */
    46 bool element::Checkout(ofstream * const out, const int Number, const int NoOfAtoms) const
     54bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const
    4755{
    4856  if (out != NULL) {
     
    5260    return false;
    5361};
     62
     63atomicNumber_t element::getNumber() const{
     64  return Z;
     65}
     66
     67string element::getSymbol() const{
     68  return string(symbol);
     69}
  • src/element.hpp

    rc695c9 r5f612ee  
    99#define ELEMENT_HPP_
    1010
    11 using namespace std;
    12 
    1311/*********************************************** includes ***********************************/
    1412
     
    1917
    2018#include <iostream>
     19#include <string>
    2120
    2221#include "defs.hpp"
     22#include "types.hpp"
    2323
    2424/********************************************** declarations *******************************/
     
    5050  ~element();
    5151
     52  // accessor functions
     53  atomicNumber_t getNumber() const;
     54  std::string getSymbol() const;
     55
    5256  //> print element entries to screen
    53   bool Output(ofstream * const out) const;
    54   bool Checkout(ofstream * const out, const int No, const int NoOfAtoms) const;
     57  bool Output(std::ostream * const out) const;
     58  bool Checkout(std::ostream * const out, const int No, const int NoOfAtoms) const;
    5559
    5660  private:
  • src/errorlogger.cpp

    rc695c9 r5f612ee  
    99#include "errorlogger.hpp"
    1010#include "verbose.hpp"
     11#include "Patterns/Singleton_impl.hpp"
    1112
    1213ofstream null("/dev/null");
    13 
    14 errorLogger* errorLogger::instance = NULL;
    1514int errorLogger::verbosity = 2;
    1615ostream* errorLogger::nix = &null;
     
    2322errorLogger::errorLogger()
    2423{
    25   instance = NULL;
    2624  verbosity = 2;
    2725};
     
    3432}
    3533
    36 /**
    37  * Returns the singleton errorLogger instance.
    38  *
    39  * \return errorLogger instance
    40  */
    41 errorLogger* 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  */
    53 void errorLogger::purgeInstance() {
    54   if (instance != NULL) {
    55     delete instance;
    56   }
    57 
    58   instance = NULL;
    59 }
     34CONSTRUCT_SINGLETON(errorLogger)
    6035
    6136/**
  • src/errorlogger.hpp

    rc695c9 r5f612ee  
    1111#include <iostream>
    1212
     13#include "Patterns/Singleton.hpp"
     14
    1315using namespace std;
    1416
    1517class Verbose;
    1618
    17 class errorLogger {
     19class errorLogger : public Singleton<errorLogger>{
     20  friend class Singleton<errorLogger>;
    1821public :
    1922  static ostream *nix;
    2023  static int verbosity;
    2124
    22   static errorLogger* getInstance();
    23   static void purgeInstance();
    2425  static bool DoOutput();
    2526  static void setVerbosity(int verbosityLevel);
     
    3132  ~errorLogger();
    3233
    33 private:
    34   static errorLogger* instance;
    3534};
    3635
  • src/gslmatrix.cpp

    rc695c9 r5f612ee  
    178178        gsl_matrix_set(dest, j,i, gsl_matrix_get(matrix, i,j) );
    179179      }
    180     delete(matrix);
     180    gsl_matrix_free(matrix);
    181181    matrix = dest;
    182182    flip(rows, columns);
  • src/helpers.hpp

    rc695c9 r5f612ee  
    187187};
    188188
    189 
     189#define PLURAL_S(v) (((v)==1)?"":"s")
     190
     191// this is to allow different modes of access for
     192// maps and sets
     193template<typename Res,typename T>
     194struct _take{
     195  Res get(T value) const;
     196};
     197
     198// if we have a set,vector etc we can directly access the result
     199template<typename Res>
     200struct _take<Res,Res>{
     201  static inline Res get(Res value){
     202    return value;
     203  }
     204};
     205
     206// if we have a map we have to access the second part of
     207// the pair
     208template<typename Res,typename T1>
     209struct _take<Res,std::pair<T1,Res> >{
     210  static inline Res get(std::pair<T1,Res> value){
     211    return value.second;
     212  }
     213};
    190214
    191215#endif /*HELPERS_HPP_*/
  • src/leastsquaremin.hpp

    rc695c9 r5f612ee  
    4242  gsl_vector *x;
    4343  const molecule *mol;
    44   element *type;
     44  const element *type;
    4545};
    4646
  • src/lists.hpp

    rc695c9 r5f612ee  
    99#define LISTS_HPP_
    1010
     11class atom;
     12
    1113/******************************** Some templates for list management ***********************************/
    1214
     
    1820{
    1921  X *vorher = end->previous;
    20   if (vorher != NULL)
     22  if (vorher != 0)
    2123    vorher->next = walker;
    2224  end->previous = walker;
     
    3133template <typename X> void unlink(X *walker)
    3234{
    33   if (walker->next != NULL)
     35  if (walker->next != 0)
    3436    walker->next->previous = walker->previous;
    35   if (walker->previous != NULL)
     37  if (walker->previous != 0)
    3638    walker->previous->next = walker->next;
    37   walker->next = NULL;
    38   walker->previous= NULL;
     39  walker->next = 0;
     40  walker->previous= 0;
    3941};
    4042
     
    4648template <typename X>  bool add(X *pointer, X *end)
    4749{
    48   if (end != NULL) {
     50  if (end != 0) {
    4951    link(pointer, end);
    5052  } else {
    51     pointer->previous = NULL;
    52     pointer->next = NULL;
     53    pointer->previous = 0;
     54    pointer->next = 0;
    5355  }
    5456  return true;
     
    5961 * \param *start  begin of list
    6062 * \param *end  end of list
    61  * \return X - if found, NULL - if not found
     63 * \return X - if found, 0 - if not found
    6264 */
    6365template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
     
    6870    if (*walker->sort == *suche) return (walker);
    6971  }
    70   return NULL;
     72  return 0;
    7173};
    7274
     
    7779template <typename X> void removewithoutcheck(X *walker)
    7880{
    79   if (walker != NULL) {
     81  if (walker != 0) {
    8082    unlink(walker);
    8183    delete(walker);
    82     walker = NULL;
     84    walker = 0;
    8385  }
    8486};
     87
     88/** Removes an item from the list without check.
     89 *  specialized for atoms, because these have to be removed from the world as well
     90 *  the implementation for this declaration is in lists.cpp
     91 * \param *walker item to be removed
     92 * \return true - removing succeeded, false - given item not found in list
     93 */
     94template <> void removewithoutcheck<atom>(atom *walker);
    8595
    8696/** Removes an item from the list, checks if exists.
     
    99109  }*/
    100110  // atom found, now unlink
    101   if (walker != NULL)
     111  if (walker != 0)
    102112    removewithoutcheck(walker);
    103113  else
     
    114124{
    115125  X *pointer = start->next;
    116   X *walker = NULL;
     126  X *walker = 0;
    117127  while (pointer != end) { // go through list
    118128    walker = pointer; // mark current
     
    131141{
    132142  X *Binder = me;
    133   while(Binder->previous != NULL)
     143  while(Binder->previous != 0)
    134144    Binder = Binder->previous;
    135145  return Binder;
     
    143153{
    144154  X *Binder = me;
    145   while(Binder->next != NULL)
     155  while(Binder->next != 0)
    146156    Binder = Binder->next;
    147157  return Binder;
  • src/log.cpp

    rc695c9 r5f612ee  
    1515 */
    1616void setVerbosity(int verbosityLevel) {
    17   logger::getInstance()->setVerbosity(verbosityLevel);
     17  logger::getInstance().setVerbosity(verbosityLevel);
    1818}
    1919
     
    2323 * \param indentation level of the message to log
    2424 */
    25 class logger * Log() {
     25class logger& Log() {
    2626  return logger::getInstance();
    2727}
     
    3535 */
    3636bool DoLog(int verbose) {
    37   return (verbose <= logger::getInstance()->verbosity);
     37  return (verbose <= logger::getInstance().verbosity);
    3838}
    3939
     
    4646 */
    4747bool DoeLog(int verbose) {
    48   return (verbose <= errorLogger::getInstance()->verbosity);
     48  return (verbose <= errorLogger::getInstance().verbosity);
    4949}
    5050
     
    5454 * \param indentation level of the message to log
    5555 */
    56 class errorLogger * eLog() {
     56class errorLogger & eLog() {
    5757  return errorLogger::getInstance();
    5858}
  • src/logger.cpp

    rc695c9 r5f612ee  
    99#include "logger.hpp"
    1010#include "verbose.hpp"
     11#include "Patterns/Singleton_impl.hpp"
    1112
    1213ofstream nullStream("/dev/null");
    1314
    14 logger* logger::instance = NULL;
    1515int logger::verbosity = 2;
    1616ostream* logger::nix = &nullStream;
     
    2323logger::logger()
    2424{
    25   instance = NULL;
    2625  verbosity = 2;
    2726};
     
    3433}
    3534
    36 /**
    37  * Returns the singleton logger instance.
    38  *
    39  * \return logger instance
    40  */
    41 logger* 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  */
    53 void logger::purgeInstance() {
    54   if (instance != NULL) {
    55     delete instance;
    56   }
    57 
    58   instance = NULL;
    59 }
     35CONSTRUCT_SINGLETON(logger)
    6036
    6137/**
  • src/logger.hpp

    rc695c9 r5f612ee  
    1111#include <iostream>
    1212
     13#include "Patterns/Singleton.hpp"
     14
    1315using namespace std;
    1416
    1517class Verbose;
    1618
    17 class logger {
     19class logger : public Singleton<logger> {
     20  friend class Singleton<logger>;
    1821public :
    1922  static ostream *nix;
    2023  static int verbosity;
    2124
    22   static logger* getInstance();
    23   static void purgeInstance();
    2425  static bool DoOutput();
    2526  static void setVerbosity(int verbosityLevel);
     
    3031  /** Do not call this destructor directly, use purgeInstance() instead. */
    3132  ~logger();
    32 
    33 private:
    34   static logger* instance;
    3533};
    3634
  • src/molecule.cpp

    rc695c9 r5f612ee  
    66
    77#include <cstring>
    8 
     8#include <boost/bind.hpp>
     9
     10#include "World.hpp"
    911#include "atom.hpp"
    1012#include "bond.hpp"
     
    3032 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3133 */
    32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(new atom), end(new atom),
     34molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::getInstance().createAtom()), end(World::getInstance().createAtom()),
    3335  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3436  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
    35   ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start)
     37  ActiveFlag(false), IndexNr(-1),
     38  formula(this,boost::bind(&molecule::calcFormula,this)),
     39  last_atom(0),
     40  InternalPointer(start)
    3641{
    3742  // init atom chain list
     
    4651  for(int i=MAX_ELEMENTS;i--;)
    4752    ElementsInMolecule[i] = 0;
    48   strcpy(name,World::get()->DefaultName);
    49 };
     53  strcpy(name,World::getInstance().getDefaultName());
     54};
     55
     56molecule *NewMolecule(){
     57  return new molecule(World::getInstance().getPeriode());
     58}
    5059
    5160/** Destructor of class molecule.
     
    5766  delete(first);
    5867  delete(last);
    59   delete(end);
    60   delete(start);
    61 };
     68  end->getWorld()->destroyAtom(end);
     69  start->getWorld()->destroyAtom(start);
     70};
     71
     72
     73void DeleteMolecule(molecule *mol){
     74  delete mol;
     75}
     76
     77// getter and setter
     78const std::string molecule::getName(){
     79  return std::string(name);
     80}
     81
     82void molecule::setName(const std::string _name){
     83  OBSERVE;
     84  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     85}
     86
     87moleculeId_t molecule::getId(){
     88  return id;
     89}
     90
     91void molecule::setId(moleculeId_t _id){
     92  id =_id;
     93}
     94
     95const std::string molecule::getFormula(){
     96  return *formula;
     97}
     98
     99std::string molecule::calcFormula(){
     100  std::map<atomicNumber_t,unsigned int> counts;
     101  stringstream sstr;
     102  periodentafel *periode = World::getInstance().getPeriode();
     103  for(atom *Walker = start; Walker != end; Walker = Walker->next) {
     104    counts[Walker->type->getNumber()]++;
     105  }
     106  std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     107  for(iter = counts.rbegin(); iter != counts.rend(); ++iter) {
     108    atomicNumber_t Z = (*iter).first;
     109    sstr << periode->FindElement(Z)->symbol << (*iter).second;
     110  }
     111  return sstr.str();
     112}
    62113
    63114
     
    69120bool molecule::AddAtom(atom *pointer)
    70121{
     122  bool retval = false;
     123  OBSERVE;
    71124  if (pointer != NULL) {
    72125    pointer->sort = &pointer->nr;
     
    85138      }
    86139    }
    87     return add(pointer, end);
    88   } else
    89     return false;
     140    retval = add(pointer, end);
     141  }
     142  return retval;
    90143};
    91144
     
    97150atom * molecule::AddCopyAtom(atom *pointer)
    98151{
     152  atom *retval = NULL;
     153  OBSERVE;
    99154  if (pointer != NULL) {
    100     atom *walker = new atom(pointer);
     155    atom *walker = pointer->clone();
    101156    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    102157    strcpy (walker->Name, pointer->Name);
     
    106161      NoNonHydrogen++;
    107162    AtomCount++;
    108     return walker;
    109   } else
    110     return NULL;
     163    retval=walker;
     164  }
     165  return retval;
    111166};
    112167
     
    147202bool molecule::AddHydrogenReplacementAtom(bond *TopBond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem)
    148203{
     204  bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
     205  OBSERVE;
    149206  double bondlength;  // bond length of the bond to be replaced/cut
    150207  double bondangle;  // bond angle of the bond to be replaced/cut
    151208  double BondRescale;   // rescale value for the hydrogen bond length
    152   bool AllWentWell = true;    // flag gathering the boolean return value of molecule::AddAtom and other functions, as return value on exit
    153209  bond *FirstBond = NULL, *SecondBond = NULL; // Other bonds in double bond case to determine "other" plane
    154210  atom *FirstOtherAtom = NULL, *SecondOtherAtom = NULL, *ThirdOtherAtom = NULL; // pointer to hydrogen atoms to be added
     
    158214  double *matrix = NULL;
    159215  bond *Binder = NULL;
    160   double * const cell_size = World::get()->cell_size;
     216  double * const cell_size = World::getInstance().getDomain();
    161217
    162218//  Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
     
    205261  switch(TopBond->BondDegree) {
    206262    case 1:
    207       FirstOtherAtom = new atom();    // new atom
     263      FirstOtherAtom = World::getInstance().createAtom();    // new atom
    208264      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    209265      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    262318
    263319      // create the two Hydrogens ...
    264       FirstOtherAtom = new atom();
    265       SecondOtherAtom = new atom();
     320      FirstOtherAtom = World::getInstance().createAtom();
     321      SecondOtherAtom = World::getInstance().createAtom();
    266322      FirstOtherAtom->type = elemente->FindElement(1);
    267323      SecondOtherAtom->type = elemente->FindElement(1);
     
    317373    case 3:
    318374      // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
    319       FirstOtherAtom = new atom();
    320       SecondOtherAtom = new atom();
    321       ThirdOtherAtom = new atom();
     375      FirstOtherAtom = World::getInstance().createAtom();
     376      SecondOtherAtom = World::getInstance().createAtom();
     377      ThirdOtherAtom = World::getInstance().createAtom();
    322378      FirstOtherAtom->type = elemente->FindElement(1);
    323379      SecondOtherAtom->type = elemente->FindElement(1);
     
    413469bool molecule::AddXYZFile(string filename)
    414470{
     471
    415472  istringstream *input = NULL;
    416473  int NumberOfAtoms = 0; // atom number in xyz read
     
    426483    return false;
    427484
     485  OBSERVE;
    428486  getline(xyzfile,line,'\n'); // Read numer of atoms in file
    429487  input = new istringstream(line);
     
    436494    MDSteps++;
    437495  for(i=0;i<NumberOfAtoms;i++){
    438     Walker = new atom;
     496    Walker = World::getInstance().createAtom();
    439497    getline(xyzfile,line,'\n');
    440498    istringstream *item = new istringstream(line);
     
    474532molecule *molecule::CopyMolecule()
    475533{
    476   molecule *copy = new molecule(elemente);
     534  molecule *copy = World::getInstance().createMolecule();
    477535  atom *LeftAtom = NULL, *RightAtom = NULL;
    478536
     
    517575 */
    518576molecule* molecule::CopyMoleculeFromSubRegion(const Vector offset, const double *parallelepiped) const {
    519   molecule *copy = new molecule(elemente);
     577  molecule *copy = World::getInstance().createMolecule();
    520578
    521579  ActOnCopyWithEachAtomIfTrue ( &molecule::AddCopyAtom, copy, &atom::IsInParallelepiped, offset, parallelepiped );
     
    603661void molecule::SetBoxDimension(Vector *dim)
    604662{
    605   double * const cell_size = World::get()->cell_size;
     663  double * const cell_size = World::getInstance().getDomain();
    606664  cell_size[0] = dim->x[0];
    607665  cell_size[1] = 0.;
     
    694752bool molecule::CheckBounds(const Vector *x) const
    695753{
    696   double * const cell_size = World::get()->cell_size;
     754  double * const cell_size = World::getInstance().getDomain();
    697755  bool result = true;
    698756  int j =-1;
     
    10851143  }
    10861144};
     1145
     1146void molecule::flipActiveFlag(){
     1147  ActiveFlag = !ActiveFlag;
     1148}
  • src/molecule.hpp

    rc695c9 r5f612ee  
    2727#include <vector>
    2828
     29#include <string>
     30
     31#include "defs.hpp"
    2932#include "graph.hpp"
    3033#include "stackclass.hpp"
    3134#include "tesselation.hpp"
     35#include "Patterns/Observer.hpp"
     36#include "Patterns/Cacheable.hpp"
    3237
    3338/****************************************** forward declarations *****************************/
     
    8085 * Class incorporates number of types
    8186 */
    82 class molecule : public PointCloud {
     87class molecule : public PointCloud , public Observable {
     88  friend molecule *NewMolecule();
     89  friend void DeleteMolecule(molecule *);
    8390  public:
    8491    const periodentafel * const elemente; //!< periodic table with each element
     
    98105    bool ActiveFlag;    //!< in a MoleculeListClass used to discern active from inactive molecules
    99106    Vector Center;      //!< Center of molecule in a global box
     107    int IndexNr;        //!< index of molecule in a MoleculeListClass
    100108    char name[MAXSTRINGSIZE];         //!< arbitrary name
    101     int IndexNr;        //!< index of molecule in a MoleculeListClass
    102 
    103   molecule(const periodentafel * const teil);
    104   virtual ~molecule();
     109
     110  private:
     111    Cacheable<string> formula;
     112    moleculeId_t id;
     113  protected:
     114    molecule(const periodentafel * const teil);
     115    virtual ~molecule();
     116
     117
     118public:
     119  //getter and setter
     120  const std::string getName();
     121  moleculeId_t getId();
     122  void setId(moleculeId_t);
     123  void setName(const std::string);
     124  const std::string getFormula();
     125  std::string calcFormula();
     126
    105127
    106128  // re-definition of virtual functions from PointCloud
     
    298320  bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep);
    299321
     322  // Manipulation routines
     323  void flipActiveFlag();
     324
    300325  private:
    301326  int last_atom;      //!< number given to last atom
     
    303328};
    304329
     330molecule *NewMolecule();
     331void DeleteMolecule(molecule* mol);
     332
    305333#include "molecule_template.hpp"
    306334
    307335/** A list of \a molecule classes.
    308336 */
    309 class MoleculeListClass {
     337class MoleculeListClass : public Observable {
    310338  public:
    311339    MoleculeList ListOfMolecules; //!< List of the contained molecules
    312340    int MaxIndex;
    313341
    314   MoleculeListClass();
     342  MoleculeListClass(World *world);
    315343  ~MoleculeListClass();
    316344
     
    321349  bool OutputConfigForListOfFragments(config *configuration, int *SortIndex);
    322350  int NumberOfActiveMolecules();
    323   void Enumerate(ofstream *out);
     351  void Enumerate(ostream *out);
    324352  void Output(ofstream *out);
    325353  void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration);
    326354  int CountAllAtoms() const;
     355
     356  // Methods moved here from the menus
     357  // TODO: more refactoring needed on these methods
     358  void flipChosen();
     359  void createNewMolecule(periodentafel *periode);
     360  void loadFromXYZ(periodentafel *periode);
     361  void setMoleculeFilename();
     362  void parseXYZIntoMolecule();
     363  void eraseMolecule();
     364
    327365
    328366  // merging of molecules
     
    335373
    336374  private:
     375  World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
    337376};
    338377
  • src/molecule_dynamics.cpp

    rc695c9 r5f612ee  
    66 */
    77
     8#include "World.hpp"
    89#include "atom.hpp"
    910#include "config.hpp"
     
    162163double molecule::ConstrainedPotential(struct EvaluatePotential &Params)
    163164{
    164   double tmp, result;
    165 
     165  double tmp = 0.;
     166  double result = 0.;
    166167  // go through every atom
    167168  atom *Runner = NULL;
     
    485486  bool status = true;
    486487  int MaxSteps = configuration.MaxOuterStep;
    487   MoleculeListClass *MoleculePerStep = new MoleculeListClass();
     488  MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::getPointer());
    488489  // Get the Permutation Map by MinimiseConstrainedPotential
    489490  atom **PermutationMap = NULL;
     
    505506  DoLog(1) && (Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl);
    506507  for (int step = 0; step <= MaxSteps; step++) {
    507     mol = new molecule(elemente);
     508    mol = World::getInstance().createMolecule();
    508509    MoleculePerStep->insert(mol);
    509510    Walker = start;
  • src/molecule_fragmentation.cpp

    rc695c9 r5f612ee  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    676677  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    677678  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    678   BondFragments = new MoleculeListClass();
     679  BondFragments = new MoleculeListClass(World::getPointer());
    679680  int k=0;
    680681  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     
    929930{
    930931  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    931   molecule *Leaf = new molecule(elemente);
     932  molecule *Leaf = World::getInstance().createMolecule();
    932933
    933934//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
     
    16571658  atom *Walker = NULL;
    16581659  atom *OtherWalker = NULL;
    1659   double * const cell_size = World::get()->cell_size;
     1660  double * const cell_size = World::getInstance().getDomain();
    16601661  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    16611662  enum Shading *ColorList = NULL;
  • src/molecule_geometry.cpp

    rc695c9 r5f612ee  
    2727  bool status = true;
    2828  const Vector *Center = DetermineCenterOfAll();
    29   double * const cell_size = World::get()->cell_size;
     29  double * const cell_size = World::getInstance().getDomain();
    3030  double *M = ReturnFullMatrixforSymmetric(cell_size);
    3131  double *Minv = InverseMatrix(M);
     
    4848{
    4949  bool status = true;
    50   double * const cell_size = World::get()->cell_size;
     50  double * const cell_size = World::getInstance().getDomain();
    5151  double *M = ReturnFullMatrixforSymmetric(cell_size);
    5252  double *Minv = InverseMatrix(M);
     
    229229void molecule::TranslatePeriodically(const Vector *trans)
    230230{
    231   double * const cell_size = World::get()->cell_size;
     231  double * const cell_size = World::getInstance().getDomain();
    232232  double *M = ReturnFullMatrixforSymmetric(cell_size);
    233233  double *Minv = InverseMatrix(M);
     
    256256{
    257257  atom *Walker = start;
    258   double * const cell_size = World::get()->cell_size;
     258  double * const cell_size = World::getInstance().getDomain();
    259259  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    260260  double *inversematrix = InverseMatrix(cell_size);
  • src/molecule_graph.cpp

    rc695c9 r5f612ee  
    107107  LinkedCell *LC = NULL;
    108108  bool free_BG = false;
    109   double * const cell_size = World::get()->cell_size;
     109  double * const cell_size = World::getInstance().getDomain();
    110110
    111111  if (BG == NULL) {
     
    513513    // put into new subgraph molecule and add this to list of subgraphs
    514514    LeafWalker = new MoleculeLeafClass(LeafWalker);
    515     LeafWalker->Leaf = new molecule(elemente);
     515    LeafWalker->Leaf = World::getInstance().createMolecule();
    516516    LeafWalker->Leaf->AddCopyAtom(DFS.Root);
    517517
  • src/molecule_template.hpp

    rc695c9 r5f612ee  
    1616#endif
    1717
     18#include "atom.hpp"
    1819/********************************************** declarations *******************************/
    1920
  • src/moleculelist.cpp

    rc695c9 r5f612ee  
    77#include <cstring>
    88
     9#include "World.hpp"
    910#include "atom.hpp"
    1011#include "bond.hpp"
     
    2526/** Constructor for MoleculeListClass.
    2627 */
    27 MoleculeListClass::MoleculeListClass()
     28MoleculeListClass::MoleculeListClass(World *_world) :
     29  world(_world)
    2830{
    2931  // empty lists
     
    3941  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    4042    DoLog(4) && (Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl);
    41     delete (*ListRunner);
     43    world->destroyMolecule(*ListRunner);
    4244  }
    4345  DoLog(4) && (Log() << Verbose(4) << "Freeing ListOfMolecules." << endl);
     
    5153void MoleculeListClass::insert(molecule *mol)
    5254{
     55  OBSERVE;
    5356  mol->IndexNr = MaxIndex++;
    5457  ListOfMolecules.push_back(mol);
     58  mol->signOn(this);
    5559};
    5660
     
    136140 * \param *out output stream
    137141 */
    138 void MoleculeListClass::Enumerate(ofstream *out)
    139 {
    140   element* Elemental = NULL;
     142void MoleculeListClass::Enumerate(ostream *out)
     143{
    141144  atom *Walker = NULL;
    142   int Counts[MAX_ELEMENTS];
     145  periodentafel *periode = World::getInstance().getPeriode();
     146  std::map<atomicNumber_t,unsigned int> counts;
    143147  double size=0;
    144148  Vector Origin;
    145149
    146150  // header
    147   DoLog(0) && (Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl);
    148   DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
     151  (*out) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
     152  (*out) << "-----------------------------------------------" << endl;
    149153  if (ListOfMolecules.size() == 0)
    150     DoLog(0) && (Log() << Verbose(0) << "\tNone" << endl);
     154    (*out) << "\tNone" << endl;
    151155  else {
    152156    Origin.Zero();
    153157    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    154       // reset element counts
    155       for (int j = 0; j<MAX_ELEMENTS;j++)
    156         Counts[j] = 0;
    157158      // count atoms per element and determine size of bounding sphere
    158159      size=0.;
     
    160161      while (Walker->next != (*ListRunner)->end) {
    161162        Walker = Walker->next;
    162         Counts[Walker->type->Z]++;
     163        counts[Walker->type->getNumber()]++;
    163164        if (Walker->x.DistanceSquared(&Origin) > size)
    164165          size = Walker->x.DistanceSquared(&Origin);
    165166      }
    166167      // output Index, Name, number of atoms, chemical formula
    167       DoLog(0) && (Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t");
    168       Elemental = (*ListRunner)->elemente->end;
    169       while(Elemental->previous != (*ListRunner)->elemente->start) {
    170         Elemental = Elemental->previous;
    171         if (Counts[Elemental->Z] != 0)
    172           DoLog(0) && (Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z]);
     168      (*out) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
     169
     170      std::map<atomicNumber_t,unsigned int>::reverse_iterator iter;
     171      for(iter=counts.rbegin(); iter!=counts.rend();++iter){
     172        atomicNumber_t Z =(*iter).first;
     173        (*out) << periode->FindElement(Z)->getSymbol() << (*iter).second;
    173174      }
    174175      // Center and size
    175       DoLog(0) && (Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl);
     176      (*out) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
    176177    }
    177178  }
     
    212213  // remove src
    213214  ListOfMolecules.remove(srcmol);
    214   delete(srcmol);
     215  World::getInstance().destroyMolecule(srcmol);
    215216  return true;
    216217};
     
    341342    DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl);
    342343    if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    343       CopyAtoms[Walker->nr] = new atom(Walker);
     344      CopyAtoms[Walker->nr] = Walker->clone();
    344345      mol->AddAtom(CopyAtoms[Walker->nr]);
    345346      nr++;
     
    577578  stringstream line;
    578579  atom *Walker = NULL;
    579   element *runner = NULL;
     580  periodentafel *periode=World::getInstance().getPeriode();
    580581
    581582  // open file for the force factors
     
    587588    //output << prefix << "Forces" << endl;
    588589    for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    589       runner = (*ListRunner)->elemente->start;
    590       while (runner->next != (*ListRunner)->elemente->end) { // go through every element
    591         runner = runner->next;
    592         if ((*ListRunner)->ElementsInMolecule[runner->Z]) { // if this element got atoms
     590      periodentafel::const_iterator elemIter;
     591      for(elemIter=periode->begin();elemIter!=periode->end();++elemIter){
     592          if ((*ListRunner)->ElementsInMolecule[(*elemIter).first]) { // if this element got atoms
    593593          Walker = (*ListRunner)->start;
    594594          while (Walker->next != (*ListRunner)->end) { // go through every atom of this element
    595595            Walker = Walker->next;
    596             if (Walker->type->Z == runner->Z) {
     596            if (Walker->type->getNumber() == (*elemIter).first) {
    597597              if ((Walker->GetTrueFather() != NULL) && (Walker->GetTrueFather() != Walker)) {// if there is a rea
    598598                //Log() << Verbose(0) << "Walker is " << *Walker << " with true father " << *( Walker->GetTrueFather()) << ", it
     
    640640  ofstream output;
    641641  double cell_size_backup[6];
    642   double * const cell_size = World::get()->cell_size;
     642  double * const cell_size = World::getInstance().getDomain();
    643643
    644644  // backup cell_size
     
    756756void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    757757{
    758   molecule *mol = new molecule(periode);
     758  molecule *mol = World::getInstance().createMolecule();
    759759  atom *Walker = NULL;
    760760  atom *Advancer = NULL;
     
    781781    }
    782782    // remove the molecule
    783     delete(*MolRunner);
     783    World::getInstance().destroyMolecule(*MolRunner);
    784784    ListOfMolecules.erase(MolRunner);
    785785  }
     
    787787  // 1. dissect the molecule into connected subgraphs
    788788  if (!configuration->BG->ConstructBondGraph(mol)) {
    789     delete (mol);
     789    World::getInstance().destroyMolecule(mol);
    790790    DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
    791791    return;
     
    798798  delete(BackEdgeStack);
    799799  if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) {
    800     delete (mol);
     800    World::getInstance().destroyMolecule(mol);
    801801    DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
    802802    return;
     
    812812  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    813813  for (int i=0;i<MolCount;i++) {
    814     molecules[i] = (molecule*) new molecule(mol->elemente);
     814    molecules[i] = World::getInstance().createMolecule();
    815815    molecules[i]->ActiveFlag = true;
    816816    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     
    893893  return AtomNo;
    894894}
     895
     896/***********
     897 * Methods Moved here from the menus
     898 */
     899
     900void MoleculeListClass::flipChosen() {
     901  int j;
     902  Log() << Verbose(0) << "Enter index of molecule: ";
     903  cin >> j;
     904  for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
     905    if ((*ListRunner)->IndexNr == j)
     906      (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
     907}
     908
     909void MoleculeListClass::createNewMolecule(periodentafel *periode) {
     910  OBSERVE;
     911  molecule *mol = NULL;
     912  mol = World::getInstance().createMolecule();
     913  insert(mol);
     914};
     915
     916void MoleculeListClass::loadFromXYZ(periodentafel *periode){
     917  molecule *mol = NULL;
     918  Vector center;
     919  char filename[MAXSTRINGSIZE];
     920  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     921  mol = World::getInstance().createMolecule();
     922  do {
     923    Log() << Verbose(0) << "Enter file name: ";
     924    cin >> filename;
     925  } while (!mol->AddXYZFile(filename));
     926  mol->SetNameFromFilename(filename);
     927  // center at set box dimensions
     928  mol->CenterEdge(&center);
     929  World::getInstance().getDomain()[0] = center.x[0];
     930  World::getInstance().getDomain()[1] = 0;
     931  World::getInstance().getDomain()[2] = center.x[1];
     932  World::getInstance().getDomain()[3] = 0;
     933  World::getInstance().getDomain()[4] = 0;
     934  World::getInstance().getDomain()[5] = center.x[2];
     935  insert(mol);
     936}
     937
     938void MoleculeListClass::setMoleculeFilename() {
     939  char filename[MAXSTRINGSIZE];
     940  int nr;
     941  molecule *mol = NULL;
     942  do {
     943    Log() << Verbose(0) << "Enter index of molecule: ";
     944    cin >> nr;
     945    mol = ReturnIndex(nr);
     946  } while (mol == NULL);
     947  Log() << Verbose(0) << "Enter name: ";
     948  cin >> filename;
     949  mol->SetNameFromFilename(filename);
     950}
     951
     952void MoleculeListClass::parseXYZIntoMolecule(){
     953  char filename[MAXSTRINGSIZE];
     954  int nr;
     955  molecule *mol = NULL;
     956  mol = NULL;
     957  do {
     958   Log() << Verbose(0) << "Enter index of molecule: ";
     959   cin >> nr;
     960   mol = ReturnIndex(nr);
     961  } while (mol == NULL);
     962  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     963  do {
     964   Log() << Verbose(0) << "Enter file name: ";
     965   cin >> filename;
     966  } while (!mol->AddXYZFile(filename));
     967  mol->SetNameFromFilename(filename);
     968};
     969
     970void MoleculeListClass::eraseMolecule(){
     971  int nr;
     972  molecule *mol = NULL;
     973  Log() << Verbose(0) << "Enter index of molecule: ";
     974  cin >> nr;
     975  for(MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
     976    if (nr == (*ListRunner)->IndexNr) {
     977      mol = *ListRunner;
     978      ListOfMolecules.erase(ListRunner);
     979      World::getInstance().destroyMolecule(mol);
     980      break;
     981    }
     982};
    895983
    896984
     
    9361024  // remove the leaf itself
    9371025  if (Leaf != NULL) {
    938     delete (Leaf);
     1026    World::getInstance().destroyMolecule(Leaf);
    9391027    Leaf = NULL;
    9401028  }
  • src/periodentafel.cpp

    rc695c9 r5f612ee  
    1010#include <fstream>
    1111#include <cstring>
     12#include <cassert>
    1213
    1314#include "element.hpp"
     
    1819#include "verbose.hpp"
    1920
     21using namespace std;
     22
    2023/************************************* Functions for class periodentafel ***************************/
    2124
     
    2326 * Initialises start and end of list and resets periodentafel::checkliste to false.
    2427 */
    25 periodentafel::periodentafel() : start(new element), end(new element)
    26 {
    27   start->previous = NULL;
    28   start->next = end;
    29   end->previous = start;
    30   end->next = NULL;
    31 };
     28periodentafel::periodentafel()
     29{};
    3230
    3331/** destructor for class periodentafel
     
    3735{
    3836  CleanupPeriodtable();
    39   delete(end);
    40   delete(start);
    4137};
    4238
     
    4541 * \return true - succeeded, false - does not occur
    4642 */
    47 bool periodentafel::AddElement(element * const pointer)
    48 {
     43periodentafel::iterator periodentafel::AddElement(element * const pointer)
     44{
     45  atomicNumber_t Z = pointer->getNumber();
     46  assert(!elements.count(Z));
    4947  pointer->sort = &pointer->Z;
    50   if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
    51     DoLog(0) && (Log() << Verbose(0) << "Invalid Z number!\n");
    52   return add(pointer, end);
     48  if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
     49    DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n");
     50  pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer));
     51  return res.first;
    5352};
    5453
     
    5756 * \return true - succeeded, false - element not found
    5857 */
    59 bool periodentafel::RemoveElement(element * const pointer)
    60 {
    61   return remove(pointer, start, end);
     58void periodentafel::RemoveElement(element * const pointer)
     59{
     60  atomicNumber_t Z = pointer->getNumber();
     61  elements.erase(Z);
    6262};
    6363
     
    6565 * \return true - succeeded, false - does not occur
    6666 */
    67 bool periodentafel::CleanupPeriodtable()
    68 {
    69   return cleanup(start,end);
     67void periodentafel::CleanupPeriodtable()
     68{
     69  for(iterator iter=elements.begin();iter!=elements.end();++iter){
     70    delete(*iter).second;
     71  }
     72  elements.clear();
    7073};
    7174
     
    7578 * \return pointer to element or NULL if not found
    7679 */
    77 element * const periodentafel::FindElement(const int Z) const
    78 {
    79   element *walker = find(&Z, start,end);
    80   return(walker);
     80const element * periodentafel::FindElement(atomicNumber_t Z) const
     81{
     82  const_iterator res = elements.find(Z);
     83  return res!=elements.end()?((*res).second):0;
    8184};
    8285
     
    8689 * \return pointer to element
    8790 */
    88 element * const periodentafel::FindElement(const char * const shorthand) const
    89 {
    90   element *walker =  periodentafel::start;
    91   while (walker->next != periodentafel::end) {
    92     walker = walker->next;
    93     if (strncmp(walker->symbol, shorthand, 3) == 0)
    94       return(walker);
    95   }
    96   return (NULL);
     91const element * periodentafel::FindElement(const char * const shorthand) const
     92{
     93  element *res = 0;
     94  for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
     95    if((*iter).second->getSymbol() == shorthand){
     96      res = (*iter).second;
     97      break;
     98    }
     99  }
     100  return res;
    97101};
    98102
    99103/** Asks for element number and returns pointer to element
    100104 */
    101 element * const periodentafel::AskElement() const
    102 {
    103   element *walker = NULL;
     105const element * periodentafel::AskElement() const
     106{
     107  const element *walker = NULL;
    104108  int Z;
    105109  do {
     
    114118 * \return pointer to either present or newly created element
    115119 */
    116 element * const periodentafel::EnterElement()
    117 {
    118   element *walker = NULL;
    119   int Z = -1;
     120const element * periodentafel::EnterElement()
     121{
     122  const element *res = NULL;
     123  atomicNumber_t Z = 0;
    120124  DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl);
    121125  cin >> Z;
    122   walker = FindElement(Z);
    123   if (walker == NULL) {
     126  res = FindElement(Z);
     127  if (!res) {
     128    // TODO: make this using the constructor
     129    element *tmp;
    124130    DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl);
    125     walker = new element;
    126     walker->Z = Z;
     131    tmp = new element;
     132    tmp->Z = Z;
    127133    DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl);
    128     cin >> walker->mass;
     134    cin >> tmp->mass;
    129135    DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl);
    130     cin >> walker->name;
     136    cin >> tmp->name;
    131137    DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl);
    132     cin >> walker->symbol;
    133     periodentafel::AddElement(walker);
    134   }
    135   return(walker);
    136 };
     138    cin >> tmp->symbol;
     139    AddElement(tmp);
     140    res = tmp;
     141  }
     142  return res;
     143};
     144
     145
     146/******************** Access to iterators ****************************/
     147periodentafel::const_iterator periodentafel::begin(){
     148  return elements.begin();
     149}
     150
     151periodentafel::const_iterator periodentafel::end(){
     152  return elements.end();
     153}
     154
     155periodentafel::reverse_iterator periodentafel::rbegin(){
     156  return reverse_iterator(elements.end());
     157}
     158
     159periodentafel::reverse_iterator periodentafel::rend(){
     160  return reverse_iterator(elements.begin());
     161}
    137162
    138163/** Prints period table to given stream.
    139164 * \param output stream
    140165 */
    141 bool periodentafel::Output(ofstream * const output) const
     166bool periodentafel::Output(ostream * const output) const
    142167{
    143168  bool result = true;
    144   element *walker = start;
    145169  if (output != NULL) {
    146     while (walker->next != end) {
    147       walker = walker->next;
    148       result = result && walker->Output(output);
     170    for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){
     171      result = result && (*iter).second->Output(output);
    149172    }
    150173    return result;
     
    157180 * \param *checkliste elements table for this molecule
    158181 */
    159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const
    160 {
    161   element *walker = start;
     182bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const
     183{
    162184  bool result = true;
    163185  int No = 1;
     
    166188    *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl;
    167189    *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl;
    168     while (walker->next != end) {
    169       walker = walker->next;
    170       if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) {
    171         walker->No = No;
    172         result = result && walker->Checkout(output, No++, checkliste[walker->Z]);
     190    for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){
     191      if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) {
     192        (*iter).second->No = No;
     193        result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]);
    173194      }
    174195    }
     
    184205{
    185206  ifstream infile;
    186   double tmp;
    187207  element *ptr;
     208  map<atomicNumber_t,element*> parsedElems;
    188209  bool status = true;
    189210  bool otherstatus = true;
     
    223244      //neues->Output((ofstream *)&cout);
    224245      if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
    225         periodentafel::AddElement(neues);
     246        parsedElems[neues->getNumber()] = neues;
    226247      else {
    227248        DoLog(0) && (Log() << Verbose(0) << "Could not parse element: ");
     
    243264  if (infile != NULL) {
    244265    while (!infile.eof()) {
    245       infile >> tmp;
    246       infile >> ws;
    247       infile >> FindElement((int)tmp)->Valence;
     266      atomicNumber_t Z;
     267      infile >> Z;
     268      infile >> ws;
     269      infile >> parsedElems[Z]->Valence;
    248270      infile >> ws;
    249271      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
     
    261283  if (infile != NULL) {
    262284    while (!infile.eof()) {
    263       infile >> tmp;
    264       infile >> ws;
    265       infile >> FindElement((int)tmp)->NoValenceOrbitals;
     285      atomicNumber_t Z;
     286      infile >> Z;
     287      infile >> ws;
     288      infile >> parsedElems[Z]->NoValenceOrbitals;
    266289      infile >> ws;
    267290      //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
     
    279302  if (infile != NULL) {
    280303    while (!infile.eof()) {
    281       infile >> tmp;
    282       ptr = FindElement((int)tmp);
     304      atomicNumber_t Z;
     305      infile >> Z;
     306      ptr = parsedElems[Z];
    283307      infile >> ws;
    284308      infile >> ptr->HBondDistance[0];
     
    300324  if (infile != NULL) {
    301325    while (!infile.eof()) {
    302       infile >> tmp;
    303       ptr = FindElement((int)tmp);
     326      atomicNumber_t Z;
     327      infile >> Z;
     328      ptr = parsedElems[Z];
    304329      infile >> ws;
    305330      infile >> ptr->HBondAngle[0];
     
    313338    otherstatus = false;
    314339
    315   if (!otherstatus)
     340  if (otherstatus){
     341    map<atomicNumber_t,element*>::iterator iter;
     342    for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){
     343      AddElement((*iter).second);
     344    }
     345  }
     346  else{
    316347    DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl);
     348    map<atomicNumber_t,element*>::iterator iter;
     349    for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){
     350      AddElement((*iter).second);
     351    }
     352  }
    317353
    318354  return status;
     
    334370    f << header1 << endl;
    335371    f << header2 << endl;
    336     element *walker = periodentafel::start;
    337     while (walker->next != periodentafel::end) {
    338       walker = walker->next;
    339       result = result && walker->Output(&f);
     372    for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
     373         result = result && (*iter).second->Output(&f);
    340374    }
    341375    f.close();
  • src/periodentafel.hpp

    rc695c9 r5f612ee  
    11#ifndef PERIODENTAFEL_HPP_
    22#define PERIODENTAFEL_HPP_
    3 
    4 using namespace std;
    53
    64/*********************************************** includes ***********************************/
     
    1210
    1311#include <iostream>
     12#include <map>
     13#include <iterator>
    1414
    1515#include "defs.hpp"
     16#include "types.hpp"
    1617
    1718/****************************************** forward declarations *****************************/
     
    2526 */
    2627class periodentafel {
     28  /******* Types *********/
     29  private:
     30    typedef std::map<atomicNumber_t,element*> elementSet;
    2731  public:
    28     element *start; //!< start of element list
    29     element *end;   //!< end of element list
     32    typedef elementSet::iterator iterator;
     33    typedef elementSet::const_iterator const_iterator;
     34    typedef std::reverse_iterator<const_iterator> reverse_iterator;
     35  public:
     36
    3037    char header1[MAXSTRINGSIZE]; //!< store first header line
    3138    char header2[MAXSTRINGSIZE]; //!< store second header line
     
    3441  ~periodentafel();
    3542
    36   bool AddElement(element * const pointer);
    37   bool RemoveElement(element * const pointer);
    38   bool CleanupPeriodtable();
    39   element * const FindElement(const int Z) const;
    40   element * const FindElement(const char * const shorthand) const;
    41   element * const AskElement() const;
    42   element * const EnterElement();
    43   bool Output(ofstream * const output) const;
    44   bool Checkout(ofstream * const output, const int * const checkliste) const;
     43  iterator AddElement(element * const pointer);
     44  void RemoveElement(element * const pointer);
     45  void CleanupPeriodtable();
     46  const element *FindElement(atomicNumber_t) const;
     47  const element *FindElement(const char * const shorthand) const;
     48  const element *AskElement() const;
     49  const element *EnterElement();
     50
     51  const_iterator begin();
     52  const_iterator end();
     53  reverse_iterator rbegin();
     54  reverse_iterator rend();
     55  bool Output(std::ostream * const output) const;
     56  bool Checkout(std::ostream * const output, const int * const checkliste) const;
    4557  bool LoadPeriodentafel(const char * const path);
    4658  bool StorePeriodentafel(const char * const path) const;
    4759
    4860  private:
     61    elementSet elements;
    4962};
    5063
  • src/tesselation.cpp

    rc695c9 r5f612ee  
    49384938        }
    49394939  }
    4940   delete (DegeneratedTriangles);
     4940  delete DegeneratedTriangles;
     4941
    49414942  /// 3. Find connected endpoint candidates and put them into a polygon
    49424943  UniquePolygonSet ListofDegeneratedPolygons;
  • src/tesselationhelpers.cpp

    rc695c9 r5f612ee  
    2727  int signum;
    2828  gsl_permutation *p = gsl_permutation_alloc(A->size1);
    29   gsl_matrix *tmpA;
     29  gsl_matrix *tmpA=0;
    3030
    3131  if (inPlace)
  • src/unittests/ActOnAllUnitTest.cpp

    rc695c9 r5f612ee  
    1616#include "memoryallocator.hpp"
    1717#include "vector.hpp"
     18
     19#ifdef HAVE_TESTRUNNER
     20#include "UnitTestMain.hpp"
     21#endif /*HAVE_TESTRUNNER*/
    1822
    1923/********************************************** Test classes **************************************/
     
    4044{
    4145  VL.EmptyList();
     46  // Ref was copy constructed, hence has to be cleaned, too!
     47  Ref.EmptyList();
     48  MemoryUsageObserver::purgeInstance();
    4249};
    4350
     
    8895  VL.ActOnAll( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses );
    8996  CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
     97  Free(factors);
     98  Free(inverses);
    9099};
    91100
     
    108117  }
    109118};
    110 
    111 
    112 /********************************************** Main routine **************************************/
    113 
    114 int main(int argc, char **argv)
    115 {
    116   // Get the top level suite from the registry
    117   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    118 
    119   // Adds the test to the list of test to run
    120   CppUnit::TextUi::TestRunner runner;
    121   runner.addTest( suite );
    122 
    123   // Change the default outputter to a compiler error format outputter
    124   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    125                                                        std::cerr ) );
    126   // Run the tests.
    127   bool wasSucessful = runner.run();
    128 
    129   // Return error code 1 if the one of test failed.
    130   return wasSucessful ? 0 : 1;
    131 };
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    rc695c9 r5f612ee  
    1717#include "AnalysisCorrelationToPointUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    2425#include "periodentafel.hpp"
    2526#include "tesselation.hpp"
     27#include "World.hpp"
     28
     29#ifdef HAVE_TESTRUNNER
     30#include "UnitTestMain.hpp"
     31#endif /*HAVE_TESTRUNNER*/
    2632
    2733/********************************************** Test classes **************************************/
     
    5157
    5258  // construct periodentafel
    53   tafel = new periodentafel;
     59  tafel = World::getInstance().getPeriode();
    5460  tafel->AddElement(hydrogen);
    5561
    5662  // construct molecule (tetraeder of hydrogens)
    57   TestMolecule = new molecule(tafel);
    58   Walker = new atom();
     63  TestMolecule = World::getInstance().createMolecule();
     64  Walker = World::getInstance().createAtom();
    5965  Walker->type = hydrogen;
    6066  Walker->node->Init(1., 0., 1. );
    6167  TestMolecule->AddAtom(Walker);
    62   Walker = new atom();
     68  Walker = World::getInstance().createAtom();
    6369  Walker->type = hydrogen;
    6470  Walker->node->Init(0., 1., 1. );
    6571  TestMolecule->AddAtom(Walker);
    66   Walker = new atom();
     72  Walker = World::getInstance().createAtom();
    6773  Walker->type = hydrogen;
    6874  Walker->node->Init(1., 1., 0. );
    6975  TestMolecule->AddAtom(Walker);
    70   Walker = new atom();
     76  Walker = World::getInstance().createAtom();
    7177  Walker->type = hydrogen;
    7278  Walker->node->Init(0., 0., 0. );
     
    7682  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    7783
    78   TestList = new MoleculeListClass;
     84  TestList = World::getInstance().getMolecules();
     85  TestList->insert(TestMolecule);
    7986  TestMolecule->ActiveFlag = true;
    80   TestList->insert(TestMolecule);
    8187
    8288  // init point
     
    97103    delete(binmap);
    98104
    99   // remove
    100   delete(TestList);
    101   // note that all the atoms are cleaned by TestMolecule
    102105  delete(point);
    103   delete(tafel);
    104   // note that element is cleaned by periodentafel
     106  World::purgeInstance();
     107  MemoryUsageObserver::purgeInstance();
     108  logger::purgeInstance();
    105109};
    106110
     
    140144
    141145};
    142 
    143 /********************************************** Main routine **************************************/
    144 
    145 int main(int argc, char **argv)
    146 {
    147   // Get the top level suite from the registry
    148   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    149 
    150   // Adds the test to the list of test to run
    151   CppUnit::TextUi::TestRunner runner;
    152   runner.addTest( suite );
    153 
    154   // Change the default outputter to a compiler error format outputter
    155   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    156                                                        std::cerr ) );
    157   // Run the tests.
    158   bool wasSucessful = runner.run();
    159 
    160   // Return error code 1 if the one of test failed.
    161   return wasSucessful ? 0 : 1;
    162 };
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    rc695c9 r5f612ee  
    1717#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    2425#include "periodentafel.hpp"
    2526#include "tesselation.hpp"
     27#include "World.hpp"
     28
     29#include "Helpers/Assert.hpp"
     30
     31#ifdef HAVE_TESTRUNNER
     32#include "UnitTestMain.hpp"
     33#endif /*HAVE_TESTRUNNER*/
    2634
    2735/********************************************** Test classes **************************************/
     
    3240void AnalysisCorrelationToSurfaceUnitTest::setUp()
    3341{
     42  ASSERT_DO(Assert::Throw);
     43
    3444  atom *Walker = NULL;
    3545
     
    5565
    5666  // construct periodentafel
    57   tafel = new periodentafel;
     67  tafel = World::getInstance().getPeriode();
    5868  tafel->AddElement(hydrogen);
    5969  tafel->AddElement(carbon);
    6070
    6171  // construct molecule (tetraeder of hydrogens) base
    62   TestSurfaceMolecule = new molecule(tafel);
    63   Walker = new atom();
     72  TestSurfaceMolecule = World::getInstance().createMolecule();
     73  Walker = World::getInstance().createAtom();
    6474  Walker->type = hydrogen;
    6575  Walker->node->Init(1., 0., 1. );
    6676  TestSurfaceMolecule->AddAtom(Walker);
    67   Walker = new atom();
     77  Walker = World::getInstance().createAtom();
    6878  Walker->type = hydrogen;
    6979  Walker->node->Init(0., 1., 1. );
    7080  TestSurfaceMolecule->AddAtom(Walker);
    71   Walker = new atom();
     81  Walker = World::getInstance().createAtom();
    7282  Walker->type = hydrogen;
    7383  Walker->node->Init(1., 1., 0. );
    7484  TestSurfaceMolecule->AddAtom(Walker);
    75   Walker = new atom();
     85  Walker = World::getInstance().createAtom();
    7686  Walker->type = hydrogen;
    7787  Walker->node->Init(0., 0., 0. );
     
    8191  CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
    8292
    83   TestList = new MoleculeListClass;
     93  TestList = World::getInstance().getMolecules();
    8494  TestSurfaceMolecule->ActiveFlag = true;
    8595  TestList->insert(TestSurfaceMolecule);
     
    91101
    92102  // add outer atoms
    93   TestMolecule = new molecule(tafel);
    94   Walker = new atom();
     103  TestMolecule = World::getInstance().createMolecule();
     104  Walker = World::getInstance().createAtom();
    95105  Walker->type = carbon;
    96106  Walker->node->Init(4., 0., 4. );
    97107  TestMolecule->AddAtom(Walker);
    98   Walker = new atom();
     108  Walker = World::getInstance().createAtom();
    99109  Walker->type = carbon;
    100110  Walker->node->Init(0., 4., 4. );
    101111  TestMolecule->AddAtom(Walker);
    102   Walker = new atom();
     112  Walker = World::getInstance().createAtom();
    103113  Walker->type = carbon;
    104114  Walker->node->Init(4., 4., 0. );
    105115  TestMolecule->AddAtom(Walker);
    106116  // add inner atoms
    107   Walker = new atom();
     117  Walker = World::getInstance().createAtom();
    108118  Walker->type = carbon;
    109119  Walker->node->Init(0.5, 0.5, 0.5 );
     
    126136    delete(binmap);
    127137
    128   // remove
    129   delete(TestList);
    130138  delete(Surface);
    131139  // note that all the atoms are cleaned by TestMolecule
    132140  delete(LC);
    133   delete(tafel);
    134   // note that element is cleaned by periodentafel
     141  World::purgeInstance();
     142  MemoryUsageObserver::purgeInstance();
     143  logger::purgeInstance();
    135144};
    136145
     
    227236  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
    228237};
    229 
    230 /********************************************** Main routine **************************************/
    231 
    232 int main(int argc, char **argv)
    233 {
    234   // Get the top level suite from the registry
    235   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    236 
    237   // Adds the test to the list of test to run
    238   CppUnit::TextUi::TestRunner runner;
    239   runner.addTest( suite );
    240 
    241   // Change the default outputter to a compiler error format outputter
    242   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    243                                                        std::cerr ) );
    244   // Run the tests.
    245   bool wasSucessful = runner.run();
    246 
    247   // Return error code 1 if the one of test failed.
    248   return wasSucessful ? 0 : 1;
    249 };
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    rc695c9 r5f612ee  
    1717#include "AnalysisPairCorrelationUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    2425#include "periodentafel.hpp"
    2526#include "tesselation.hpp"
     27#include "World.hpp"
     28
     29#ifdef HAVE_TESTRUNNER
     30#include "UnitTestMain.hpp"
     31#endif /*HAVE_TESTRUNNER*/
    2632
    2733/********************************************** Test classes **************************************/
     
    5056
    5157  // construct periodentafel
    52   tafel = new periodentafel;
     58  tafel = World::getInstance().getPeriode();
    5359  tafel->AddElement(hydrogen);
    5460
    5561  // construct molecule (tetraeder of hydrogens)
    56   TestMolecule = new molecule(tafel);
    57   Walker = new atom();
     62  TestMolecule = World::getInstance().createMolecule();
     63  Walker = World::getInstance().createAtom();
    5864  Walker->type = hydrogen;
    5965  Walker->node->Init(1., 0., 1. );
    6066  TestMolecule->AddAtom(Walker);
    61   Walker = new atom();
     67  Walker = World::getInstance().createAtom();
    6268  Walker->type = hydrogen;
    6369  Walker->node->Init(0., 1., 1. );
    6470  TestMolecule->AddAtom(Walker);
    65   Walker = new atom();
     71  Walker = World::getInstance().createAtom();
    6672  Walker->type = hydrogen;
    6773  Walker->node->Init(1., 1., 0. );
    6874  TestMolecule->AddAtom(Walker);
    69   Walker = new atom();
     75  Walker = World::getInstance().createAtom();
    7076  Walker->type = hydrogen;
    7177  Walker->node->Init(0., 0., 0. );
     
    7581  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    7682
    77   TestList = new MoleculeListClass;
     83  TestList = World::getInstance().getMolecules();
    7884  TestMolecule->ActiveFlag = true;
    7985  TestList->insert(TestMolecule);
     
    9399    delete(binmap);
    94100
    95   // remove
    96   delete(TestList);
    97101  // note that all the atoms are cleaned by TestMolecule
    98   delete(tafel);
    99   // note that element is cleaned by periodentafel
     102  World::purgeInstance();
     103  MemoryUsageObserver::purgeInstance();
     104  logger::purgeInstance();
     105  errorLogger::purgeInstance();
    100106};
    101107
     
    132138  CPPUNIT_ASSERT_EQUAL( 6, tester->second );
    133139};
    134 
    135 /********************************************** Main routine **************************************/
    136 
    137 int main(int argc, char **argv)
    138 {
    139   // Get the top level suite from the registry
    140   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    141 
    142   // Adds the test to the list of test to run
    143   CppUnit::TextUi::TestRunner runner;
    144   runner.addTest( suite );
    145 
    146   // Change the default outputter to a compiler error format outputter
    147   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    148                                                        std::cerr ) );
    149   // Run the tests.
    150   bool wasSucessful = runner.run();
    151 
    152   // Return error code 1 if the one of test failed.
    153   return wasSucessful ? 0 : 1;
    154 };
  • src/unittests/CountBondsUnitTest.cpp

    rc695c9 r5f612ee  
    2424#include "molecule.hpp"
    2525#include "periodentafel.hpp"
     26#include "World.hpp"
    2627#include "CountBondsUnitTest.hpp"
     28
     29#ifdef HAVE_TESTRUNNER
     30#include "UnitTestMain.hpp"
     31#endif /*HAVE_TESTRUNNER*/
    2732
    2833/********************************************** Test classes **************************************/
     
    3540{
    3641  atom *Walker = NULL;
     42  BG = NULL;
     43  filename = NULL;
    3744
    3845  // init private all pointers to zero
     
    5764
    5865  // construct periodentafel
    59   tafel = new periodentafel;
     66  tafel = World::getInstance().getPeriode();
    6067  tafel->AddElement(hydrogen);
    6168  tafel->AddElement(oxygen);
    6269
    6370  // construct molecule (water molecule)
    64   molecules = new MoleculeListClass;
    65   TestMolecule1 = new molecule(tafel);
    66   Walker = new atom();
     71  TestMolecule1 = World::getInstance().createMolecule();
     72  Walker = World::getInstance().createAtom();
    6773  Walker->type = hydrogen;
    6874  Walker->node->Init(-0.2418, 0.9350, 0. );
    6975  TestMolecule1->AddAtom(Walker);
    70   Walker = new atom();
     76  Walker = World::getInstance().createAtom();
    7177  Walker->type = hydrogen;
    7278  Walker->node->Init(0.9658, 0., 0. );
    7379  TestMolecule1->AddAtom(Walker);
    74   Walker = new atom();
     80  Walker = World::getInstance().createAtom();
    7581  Walker->type = oxygen;
    7682  Walker->node->Init(0., 0., 0. );
    7783  TestMolecule1->AddAtom(Walker);
    78   molecules->insert(TestMolecule1);
    79 
    80   TestMolecule2 = new molecule(tafel);
    81   Walker = new atom();
     84
     85  TestMolecule2 = World::getInstance().createMolecule();
     86  Walker = World::getInstance().createAtom();
    8287  Walker->type = hydrogen;
    8388  Walker->node->Init(-0.2418, 0.9350, 0. );
    8489  TestMolecule2->AddAtom(Walker);
    85   Walker = new atom();
     90  Walker = World::getInstance().createAtom();
    8691  Walker->type = hydrogen;
    8792  Walker->node->Init(0.9658, 0., 0. );
    8893  TestMolecule2->AddAtom(Walker);
    89   Walker = new atom();
     94  Walker = World::getInstance().createAtom();
    9095  Walker->type = oxygen;
    9196  Walker->node->Init(0., 0., 0. );
    9297  TestMolecule2->AddAtom(Walker);
     98
     99  molecules = World::getInstance().getMolecules();
     100  molecules->insert(TestMolecule1);
    93101  molecules->insert(TestMolecule2);
    94102
     
    117125  delete(BG);
    118126
    119   // remove molecule
    120   delete(molecules);
    121   // note that all the atoms are cleaned by TestMolecule
    122   delete(tafel);
    123   // note that element is cleaned by periodentafel
     127  World::purgeInstance();
     128  MemoryUsageObserver::purgeInstance();
    124129};
    125130
     
    232237  TestMolecule2->Scale((const double ** const)&mirror);
    233238
    234   delete(mirror);
    235 };
    236 
    237 
    238 /********************************************** Main routine **************************************/
    239 
    240 int main(int argc, char **argv)
    241 {
    242   // Get the top level suite from the registry
    243   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    244 
    245   // Adds the test to the list of test to run
    246   CppUnit::TextUi::TestRunner runner;
    247   runner.addTest( suite );
    248 
    249   // Change the default outputter to a compiler error format outputter
    250   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    251                                                        std::cerr ) );
    252   // Run the tests.
    253   bool wasSucessful = runner.run();
    254 
    255   // Return error code 1 if the one of test failed.
    256   return wasSucessful ? 0 : 1;
    257 };
     239  delete[](mirror);
     240};
  • src/unittests/LinkedCellUnitTest.cpp

    rc695c9 r5f612ee  
    2222#include "periodentafel.hpp"
    2323#include "LinkedCellUnitTest.hpp"
     24#include "World.hpp"
     25
     26#ifdef HAVE_TESTRUNNER
     27#include "UnitTestMain.hpp"
     28#endif /*HAVE_TESTRUNNER*/
    2429
    2530/********************************************** Test classes **************************************/
     
    4651
    4752  // construct periodentafel
    48   tafel = new periodentafel;
     53  tafel = World::getInstance().getPeriode();
    4954  tafel->AddElement(hydrogen);
    5055
    5156  // construct molecule (water molecule)
    52   TestMolecule = new molecule(tafel);
     57  TestMolecule = World::getInstance().createMolecule();
    5358  for (double x=0.5;x<3;x+=1.)
    5459    for (double y=0.5;y<3;y+=1.)
    5560      for (double z=0.5;z<3;z+=1.) {
    56         Walker = new atom();
     61        Walker = World::getInstance().createAtom();
    5762        Walker->type = hydrogen;
    5863        Walker->node->Init(x, y, z );
     
    7378{
    7479  delete(LC);
    75   delete(TestMolecule);
    76   // note that all the atoms are cleaned by TestMolecule
    77   delete(tafel);
    78   // note that element is cleaned by periodentafel
     80  World::purgeInstance();
     81  MemoryUsageObserver::purgeInstance();
    7982};
    8083
     
    201204
    202205  // check internal vectors, returns false, because this atom is not in LC-list!
    203   Walker = new atom();
     206  Walker = World::getInstance().createAtom();
    204207  Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
    205208  strcpy(Walker->Name, "test");
    206209  Walker->x.Init(1,1,1);
    207210  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    208   delete(Walker);
     211  World::getInstance().destroyAtom(Walker);
    209212
    210213  // check out of bounds vectors
    211   Walker = new atom();
     214  Walker = World::getInstance().createAtom();
    212215  Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
    213216  strcpy(Walker->Name, "test");
    214217  Walker->x.Init(0,-1,0);
    215218  CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
    216   delete(Walker);
     219  World::getInstance().destroyAtom(Walker);
    217220};
    218221
     
    368371  delete(ListOfPoints);
    369372};
    370 
    371 /********************************************** Main routine **************************************/
    372 
    373 int main(int argc, char **argv)
    374 {
    375   // Get the top level suite from the registry
    376   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    377 
    378   // Adds the test to the list of test to run
    379   CppUnit::TextUi::TestRunner runner;
    380   runner.addTest( suite );
    381 
    382   // Change the default outputter to a compiler error format outputter
    383   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    384                                                        std::cerr ) );
    385   // Run the tests.
    386   bool wasSucessful = runner.run();
    387 
    388   // Return error code 1 if the one of test failed.
    389   return wasSucessful ? 0 : 1;
    390 };
    391 
  • src/unittests/Makefile.am

    rc695c9 r5f612ee  
    33AM_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
     5
     6MENUTESTS = \
     7  ActionSequenceTest
    58
    69TESTS = \
     
    1013  AnalysisCorrelationToSurfaceUnitTest \
    1114  AnalysisPairCorrelationUnitTest \
     15  atomsCalculationTest \
     16  AtomDescriptorTest \
    1217  BondGraphUnitTest \
     18  CacheableTest \
    1319  CountBondsUnitTest \
    1420  GSLMatrixSymmetricUnitTest \
     
    2026  ListOfBondsUnitTest \
    2127  LogUnitTest \
     28  manipulateAtomsTest \
    2229  MemoryUsageObserverUnitTest \
    2330  MemoryAllocatorUnitTest \
     31  MoleculeDescriptorTest \
     32  ObserverTest \
     33  SingletonTest \
    2434  StackClassUnitTest \
    2535  TesselationUnitTest \
    2636  Tesselation_BoundaryTriangleUnitTest \
    2737  Tesselation_InOutsideUnitTest \
    28   VectorUnitTest
     38  VectorUnitTest \
     39  ${MENUTESTS}
    2940 
    30 check_PROGRAMS = $(TESTS)
    31 noinst_PROGRAMS = $(TESTS)
    32 
    33 ActOnAllUnitTest_SOURCES = ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp
    34 ActOnAllUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    35 
    36 AnalysisBondsUnitTests_SOURCES = analysisbondsunittest.cpp analysisbondsunittest.hpp
    37 AnalysisBondsUnitTests_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    38 
    39 AnalysisCorrelationToPointUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp
    40 AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    41 
    42 AnalysisCorrelationToSurfaceUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp
    43 AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    44 
    45 AnalysisPairCorrelationUnitTest_SOURCES = analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    46 AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    47 
    48 BondGraphUnitTest_SOURCES = bondgraphunittest.cpp bondgraphunittest.hpp
    49 BondGraphUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    50 
    51 CountBondsUnitTest_SOURCES = CountBondsUnitTest.cpp CountBondsUnitTest.hpp
    52 CountBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    53 
    54 GSLMatrixSymmetricUnitTest_SOURCES = gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
    55 GSLMatrixSymmetricUnitTest_LDADD = ../libgslwrapper.a
    56 
    57 GSLMatrixUnitTest_SOURCES = gslmatrixunittest.cpp gslmatrixunittest.hpp
    58 GSLMatrixUnitTest_LDADD = ../libgslwrapper.a
    59 
    60 GSLVectorUnitTest_SOURCES = gslvectorunittest.cpp gslvectorunittest.hpp
    61 GSLVectorUnitTest_LDADD = ../libgslwrapper.a
    62 
    63 InfoUnitTest_SOURCES = infounittest.cpp infounittest.hpp
    64 InfoUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    65 
    66 LinearSystemOfEquationsUnitTest_SOURCES = linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp
    67 LinearSystemOfEquationsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    68 
    69 LinkedCellUnitTest_SOURCES = LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp
    70 LinkedCellUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    71 
    72 ListOfBondsUnitTest_SOURCES = listofbondsunittest.cpp listofbondsunittest.hpp
    73 ListOfBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    74 
    75 LogUnitTest_SOURCES = logunittest.cpp logunittest.hpp
    76 LogUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    77 
    78 MemoryAllocatorUnitTest_SOURCES = memoryallocatorunittest.cpp memoryallocatorunittest.hpp
    79 MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    80 
    81 MemoryUsageObserverUnitTest_SOURCES = memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
    82 MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    83 
    84 StackClassUnitTest_SOURCES = stackclassunittest.cpp stackclassunittest.hpp
    85 StackClassUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    86 
    87 TesselationUnitTest_SOURCES = tesselationunittest.cpp tesselationunittest.hpp
    88 TesselationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    89 
    90 Tesselation_BoundaryTriangleUnitTest_SOURCES = tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp
    91 Tesselation_BoundaryTriangleUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    92 
    93 Tesselation_InOutsideUnitTest_SOURCES = tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp
    94 Tesselation_InOutsideUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    95 
    96 VectorUnitTest_SOURCES = vectorunittest.cpp vectorunittest.hpp
    97 VectorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    98 
     41 
     42check_PROGRAMS = $(TESTS)
     43noinst_PROGRAMS = $(TESTS) TestRunner
     44
     45GSLLIBS = ../libgslwrapper.a
     46ALLLIBS = ../libmolecuilder.a ${GSLLIBS} $(BOOST_LIB) ${BOOST_THREAD_LIB}
     47
     48TESTSOURCES = \
     49  ActOnAllUnitTest.cpp \
     50  ActionSequenceTest.cpp \
     51  analysisbondsunittest.cpp \
     52  AnalysisCorrelationToPointUnitTest.cpp \
     53  AnalysisCorrelationToSurfaceUnitTest.cpp  \
     54  AnalysisPairCorrelationUnitTest.cpp \
     55  AtomDescriptorTest.cpp \
     56  atomsCalculationTest.cpp \
     57  bondgraphunittest.cpp \
     58  CacheableTest.cpp \
     59  CountBondsUnitTest.cpp \
     60  gslmatrixsymmetricunittest.cpp \
     61  gslmatrixunittest.cpp \
     62  gslvectorunittest.cpp \
     63  infounittest.cpp \
     64  linearsystemofequationsunittest.cpp \
     65  LinkedCellUnitTest.cpp \
     66  listofbondsunittest.cpp \
     67  logunittest.cpp \
     68  manipulateAtomsTest.cpp \
     69  memoryallocatorunittest.cpp  \
     70  memoryusageobserverunittest.cpp \
     71  MoleculeDescriptorTest.cpp \
     72  ObserverTest.cpp \
     73  SingletonTest.cpp \
     74  stackclassunittest.cpp \
     75  tesselationunittest.cpp \
     76  tesselation_boundarytriangleunittest.cpp \
     77  tesselation_insideoutsideunittest.cpp \
     78  vectorunittest.cpp
     79
     80TESTHEADERS = \
     81  ActOnAllUnitTest.hpp \
     82  ActionSequenceTest.hpp \
     83  analysisbondsunittest.hpp \
     84  AnalysisCorrelationToPointUnitTest.hpp \
     85  AnalysisCorrelationToSurfaceUnitTest.hpp  \
     86  AnalysisPairCorrelationUnitTest.hpp \
     87  AtomDescriptorTest.hpp \
     88  atomsCalculationTest.hpp \
     89  bondgraphunittest.hpp \
     90  CacheableTest.hpp \
     91  CountBondsUnitTest.hpp \
     92  gslmatrixsymmetricunittest.hpp \
     93  gslmatrixunittest.hpp \
     94  gslvectorunittest.hpp \
     95  infounittest.hpp \
     96  linearsystemofequationsunittest.hpp \
     97  LinkedCellUnitTest.hpp \
     98  listofbondsunittest.hpp \
     99  logunittest.hpp \
     100  manipulateAtomsTest.hpp \
     101  memoryallocatorunittest.hpp  \
     102  memoryusageobserverunittest.hpp \
     103  MoleculeDescriptorTest.hpp \
     104  ObserverTest.hpp \
     105  SingletonTest.hpp \
     106  stackclassunittest.hpp \
     107  tesselationunittest.hpp \
     108  tesselation_boundarytriangleunittest.hpp \
     109  tesselation_insideoutsideunittest.hpp \
     110  vectorunittest.hpp
     111 
     112
     113ActOnAllUnitTest_SOURCES = UnitTestMain.cpp ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp
     114ActOnAllUnitTest_LDADD = ${ALLLIBS}
     115
     116AnalysisBondsUnitTests_SOURCES = UnitTestMain.cpp analysisbondsunittest.cpp analysisbondsunittest.hpp
     117AnalysisBondsUnitTests_LDADD = ${ALLLIBS}
     118
     119AnalysisCorrelationToPointUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp
     120AnalysisCorrelationToPointUnitTest_LDADD = ${ALLLIBS}
     121
     122AnalysisCorrelationToSurfaceUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp
     123AnalysisCorrelationToSurfaceUnitTest_LDADD = ${ALLLIBS}
     124
     125AnalysisPairCorrelationUnitTest_SOURCES = UnitTestMain.cpp analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
     126AnalysisPairCorrelationUnitTest_LDADD = ${ALLLIBS}
     127
     128atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     129atomsCalculationTest_LDADD = ${ALLLIBS}
     130
     131BondGraphUnitTest_SOURCES = UnitTestMain.cpp bondgraphunittest.cpp bondgraphunittest.hpp
     132BondGraphUnitTest_LDADD = ${ALLLIBS}
     133
     134CountBondsUnitTest_SOURCES = UnitTestMain.cpp CountBondsUnitTest.cpp CountBondsUnitTest.hpp
     135CountBondsUnitTest_LDADD = ${ALLLIBS}
     136
     137GSLMatrixSymmetricUnitTest_SOURCES = UnitTestMain.cpp gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
     138GSLMatrixSymmetricUnitTest_LDADD = ${GSLLIBS}
     139
     140GSLMatrixUnitTest_SOURCES = UnitTestMain.cpp gslmatrixunittest.cpp gslmatrixunittest.hpp
     141GSLMatrixUnitTest_LDADD = ${GSLLIBS}
     142
     143GSLVectorUnitTest_SOURCES = UnitTestMain.cpp gslvectorunittest.cpp gslvectorunittest.hpp
     144GSLVectorUnitTest_LDADD = ${GSLLIBS}
     145
     146InfoUnitTest_SOURCES = UnitTestMain.cpp infounittest.cpp infounittest.hpp
     147InfoUnitTest_LDADD = ${ALLLIBS}
     148
     149LinearSystemOfEquationsUnitTest_SOURCES = UnitTestMain.cpp linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp
     150LinearSystemOfEquationsUnitTest_LDADD = ${ALLLIBS}
     151
     152LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp
     153LinkedCellUnitTest_LDADD = ${ALLLIBS}
     154
     155ListOfBondsUnitTest_SOURCES = UnitTestMain.cpp listofbondsunittest.cpp listofbondsunittest.hpp
     156ListOfBondsUnitTest_LDADD = ${ALLLIBS}
     157
     158LogUnitTest_SOURCES = UnitTestMain.cpp logunittest.cpp logunittest.hpp
     159LogUnitTest_LDADD = ${ALLLIBS}
     160
     161MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp
     162MemoryAllocatorUnitTest_LDADD = ${ALLLIBS}
     163
     164MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
     165MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS}
     166
     167MoleculeDescriptorTest_SOURCES = UnitTestMain.cpp MoleculeDescriptorTest.cpp MoleculeDescriptorTest.hpp
     168MoleculeDescriptorTest_LDADD = ${ALLLIBS}
     169
     170SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
     171SingletonTest_LDADD = $(BOOST_LIB) ${BOOST_THREAD_LIB}
     172
     173StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp
     174StackClassUnitTest_LDADD = ${ALLLIBS}
     175
     176TesselationUnitTest_SOURCES = UnitTestMain.cpp tesselationunittest.cpp tesselationunittest.hpp
     177TesselationUnitTest_LDADD = ${ALLLIBS}
     178
     179Tesselation_BoundaryTriangleUnitTest_SOURCES = UnitTestMain.cpp tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp
     180Tesselation_BoundaryTriangleUnitTest_LDADD = ${ALLLIBS}
     181
     182Tesselation_InOutsideUnitTest_SOURCES = UnitTestMain.cpp tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp
     183Tesselation_InOutsideUnitTest_LDADD = ${ALLLIBS}
     184
     185VectorUnitTest_SOURCES = UnitTestMain.cpp vectorunittest.cpp vectorunittest.hpp
     186VectorUnitTest_LDADD = ${ALLLIBS}
     187
     188ActionSequenceTest_SOURCES = UnitTestMain.cpp ../../../TestRunnerClient.hpp ActionSequenceTest.cpp ActionSequenceTest.hpp
     189ActionSequenceTest_LDADD = ${ALLLIBS}
     190
     191ObserverTest_SOURCES = UnitTestMain.cpp ObserverTest.cpp ObserverTest.hpp
     192ObserverTest_LDADD = ${ALLLIBS}
     193
     194CacheableTest_SOURCES = UnitTestMain.cpp CacheableTest.cpp CacheableTest.hpp
     195CacheableTest_LDADD = ${ALLLIBS}
     196
     197AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp
     198AtomDescriptorTest_LDADD = ${ALLLIBS}
     199
     200manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
     201manipulateAtomsTest_LDADD = ${ALLLIBS}
     202
     203TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
     204TestRunner_LDADD = ${ALLLIBS}
    99205
    100206#AUTOMAKE_OPTIONS = parallel-tests
  • src/unittests/analysisbondsunittest.cpp

    rc695c9 r5f612ee  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "analysis_bonds.hpp"
    1920#include "analysisbondsunittest.hpp"
     
    2425#include "molecule.hpp"
    2526#include "periodentafel.hpp"
     27
     28#ifdef HAVE_TESTRUNNER
     29#include "UnitTestMain.hpp"
     30#endif /*HAVE_TESTRUNNER*/
    2631
    2732/********************************************** Test classes **************************************/
     
    5661
    5762  // construct periodentafel
    58   tafel = new periodentafel;
     63  tafel = World::getInstance().getPeriode();
    5964  tafel->AddElement(hydrogen);
    6065  tafel->AddElement(carbon);
    6166
    6267  // construct molecule (tetraeder of hydrogens)
    63   TestMolecule = new molecule(tafel);
    64   Walker = new atom();
     68  TestMolecule = World::getInstance().createMolecule();
     69  Walker = World::getInstance().createAtom();
    6570  Walker->type = hydrogen;
    6671  Walker->node->Init(1.5, 0., 1.5 );
    6772  TestMolecule->AddAtom(Walker);
    68   Walker = new atom();
     73  Walker = World::getInstance().createAtom();
    6974  Walker->type = hydrogen;
    7075  Walker->node->Init(0., 1.5, 1.5 );
    7176  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     77  Walker = World::getInstance().createAtom();
    7378  Walker->type = hydrogen;
    7479  Walker->node->Init(1.5, 1.5, 0. );
    7580  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     81  Walker = World::getInstance().createAtom();
    7782  Walker->type = hydrogen;
    7883  Walker->node->Init(0., 0., 0. );
    7984  TestMolecule->AddAtom(Walker);
    80   Walker = new atom();
     85  Walker = World::getInstance().createAtom();
    8186  Walker->type = carbon;
    8287  Walker->node->Init(0.5, 0.5, 0.5 );
     
    112117
    113118  // remove molecule
    114   delete(TestMolecule);
     119  World::getInstance().destroyMolecule(TestMolecule);
    115120  // note that all the atoms are cleaned by TestMolecule
    116   delete(tafel);
    117   // note that element is cleaned by periodentafel
     121  World::purgeInstance();
    118122};
    119123
     
    163167  CPPUNIT_ASSERT_EQUAL( 0. , Max );
    164168};
    165 
    166 
    167 /********************************************** Main routine **************************************/
    168 
    169 int main(int argc, char **argv)
    170 {
    171   // Get the top level suite from the registry
    172   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    173 
    174   // Adds the test to the list of test to run
    175   CppUnit::TextUi::TestRunner runner;
    176   runner.addTest( suite );
    177 
    178   // Change the default outputter to a compiler error format outputter
    179   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    180                                                        std::cerr ) );
    181   // Run the tests.
    182   bool wasSucessful = runner.run();
    183 
    184   // Return error code 1 if the one of test failed.
    185   return wasSucessful ? 0 : 1;
    186 };
  • src/unittests/bondgraphunittest.cpp

    rc695c9 r5f612ee  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    2425#include "periodentafel.hpp"
    2526#include "bondgraphunittest.hpp"
     27#include "World.hpp"
     28
     29#ifdef HAVE_TESTRUNNER
     30#include "UnitTestMain.hpp"
     31#endif /*HAVE_TESTRUNNER*/
    2632
    2733/********************************************** Test classes **************************************/
     
    5662
    5763  // construct periodentafel
    58   tafel = new periodentafel;
     64  tafel = World::getInstance().getPeriode();
    5965  tafel->AddElement(hydrogen);
    6066  tafel->AddElement(carbon);
    6167
    6268  // construct molecule (tetraeder of hydrogens)
    63   TestMolecule = new molecule(tafel);
    64   Walker = new atom();
     69  TestMolecule = World::getInstance().createMolecule();
     70  Walker = World::getInstance().createAtom();
    6571  Walker->type = carbon;
    6672  Walker->node->Init(1., 0., 1. );
    6773  TestMolecule->AddAtom(Walker);
    68   Walker = new atom();
     74  Walker = World::getInstance().createAtom();
    6975  Walker->type = carbon;
    7076  Walker->node->Init(0., 1., 1. );
    7177  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     78  Walker = World::getInstance().createAtom();
    7379  Walker->type = carbon;
    7480  Walker->node->Init(1., 1., 0. );
    7581  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     82  Walker = World::getInstance().createAtom();
    7783  Walker->type = carbon;
    7884  Walker->node->Init(0., 0., 0. );
     
    103109
    104110  // remove molecule
    105   delete(TestMolecule);
    106   // note that all the atoms are cleaned by TestMolecule
    107   delete(tafel);
    108   // note that element is cleaned by periodentafel
     111  World::getInstance().destroyMolecule(TestMolecule);
     112  // note that all the atoms, molecules, the tafel and the elements
     113  // are all cleaned when the world is destroyed
     114  World::purgeInstance();
     115  MemoryUsageObserver::purgeInstance();
     116  logger::purgeInstance();
    109117};
    110118
     
    143151};
    144152
    145 
    146 /********************************************** Main routine **************************************/
    147 
    148 int main(int argc, char **argv)
    149 {
    150   // Get the top level suite from the registry
    151   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    152 
    153   // Adds the test to the list of test to run
    154   CppUnit::TextUi::TestRunner runner;
    155   runner.addTest( suite );
    156 
    157   // Change the default outputter to a compiler error format outputter
    158   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    159                                                        std::cerr ) );
    160   // Run the tests.
    161   bool wasSucessful = runner.run();
    162 
    163   // Return error code 1 if the one of test failed.
    164   return wasSucessful ? 0 : 1;
    165 };
  • src/unittests/gslmatrixsymmetricunittest.cpp

    rc695c9 r5f612ee  
    1313
    1414#include "gslmatrixsymmetricunittest.hpp"
     15
     16#ifdef HAVE_TESTRUNNER
     17#include "UnitTestMain.hpp"
     18#endif /*HAVE_TESTRUNNER*/
    1519
    1620/********************************************** Test classes **************************************/
     
    266270  CPPUNIT_ASSERT_EQUAL( -26.5, m->Determinant() );
    267271};
    268 
    269 /********************************************** Main routine **************************************/
    270 
    271 int main(int argc, char **argv)
    272 {
    273   // Get the top level suite from the registry
    274   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    275 
    276   // Adds the test to the list of test to run
    277   CppUnit::TextUi::TestRunner runner;
    278   runner.addTest( suite );
    279 
    280   // Change the default outputter to a compiler error format outputter
    281   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    282                                                        std::cerr ) );
    283   // Run the tests.
    284   bool wasSucessful = runner.run();
    285 
    286   // Return error code 1 if the one of test failed.
    287   return wasSucessful ? 0 : 1;
    288 };
  • src/unittests/gslmatrixunittest.cpp

    rc695c9 r5f612ee  
    1313
    1414#include "gslmatrixunittest.hpp"
     15
     16#ifdef HAVE_TESTRUNNER
     17#include "UnitTestMain.hpp"
     18#endif /*HAVE_TESTRUNNER*/
    1519
    1620/********************************************** Test classes **************************************/
     
    248252  CPPUNIT_ASSERT_EQUAL( false, m->IsPositiveDefinite() );
    249253};
    250 
    251 /********************************************** Main routine **************************************/
    252 
    253 int main(int argc, char **argv)
    254 {
    255   // Get the top level suite from the registry
    256   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    257 
    258   // Adds the test to the list of test to run
    259   CppUnit::TextUi::TestRunner runner;
    260   runner.addTest( suite );
    261 
    262   // Change the default outputter to a compiler error format outputter
    263   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    264                                                        std::cerr ) );
    265   // Run the tests.
    266   bool wasSucessful = runner.run();
    267 
    268   // Return error code 1 if the one of test failed.
    269   return wasSucessful ? 0 : 1;
    270 };
  • src/unittests/gslvectorunittest.cpp

    rc695c9 r5f612ee  
    1313
    1414#include "gslvectorunittest.hpp"
     15
     16#ifdef HAVE_TESTRUNNER
     17#include "UnitTestMain.hpp"
     18#endif /*HAVE_TESTRUNNER*/
    1519
    1620/********************************************** Test classes **************************************/
     
    114118};
    115119
    116 
    117120/** UnitTest for operators.
    118121 */
     
    160163  CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() );
    161164};
    162 
    163 /********************************************** Main routine **************************************/
    164 
    165 int main(int argc, char **argv)
    166 {
    167   // Get the top level suite from the registry
    168   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    169 
    170   // Adds the test to the list of test to run
    171   CppUnit::TextUi::TestRunner runner;
    172   runner.addTest( suite );
    173 
    174   // Change the default outputter to a compiler error format outputter
    175   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    176                                                        std::cerr ) );
    177   // Run the tests.
    178   bool wasSucessful = runner.run();
    179 
    180   // Return error code 1 if the one of test failed.
    181   return wasSucessful ? 0 : 1;
    182 };
  • src/unittests/infounittest.cpp

    rc695c9 r5f612ee  
    1717#include "info.hpp"
    1818#include "infounittest.hpp"
     19#include "log.hpp"
     20
     21#ifdef HAVE_TESTRUNNER
     22#include "UnitTestMain.hpp"
     23#endif /*HAVE_TESTRUNNER*/
    1924
    2025/********************************************** Test classes **************************************/
     
    3136void InfoTest::tearDown()
    3237{
     38  logger::purgeInstance();
    3339};
    3440
     
    4349  CPPUNIT_ASSERT_EQUAL( 1, test.verbosity );
    4450};
    45 
    46 
    47 /********************************************** Main routine **************************************/
    48 
    49 int main(int argc, char **argv)
    50 {
    51   // Get the top level suite from the registry
    52   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    53 
    54   // Adds the test to the list of test to run
    55   CppUnit::TextUi::TestRunner runner;
    56   runner.addTest( suite );
    57 
    58   // Change the default outputter to a compiler error format outputter
    59   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    60                                                        std::cerr ) );
    61   // Run the tests.
    62   bool wasSucessful = runner.run();
    63 
    64   // Return error code 1 if the one of test failed.
    65   return wasSucessful ? 0 : 1;
    66 };
  • src/unittests/linearsystemofequationsunittest.cpp

    rc695c9 r5f612ee  
    1515#include "linearsystemofequationsunittest.hpp"
    1616#include "vector.hpp"
     17
     18#ifdef HAVE_TESTRUNNER
     19#include "UnitTestMain.hpp"
     20#endif /*HAVE_TESTRUNNER*/
    1721
    1822/********************************************** Test classes **************************************/
     
    103107  delete[](array);
    104108};
    105 
    106 /********************************************** Main routine **************************************/
    107 
    108 int main(int argc, char **argv)
    109 {
    110   // Get the top level suite from the registry
    111   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    112 
    113   // Adds the test to the list of test to run
    114   CppUnit::TextUi::TestRunner runner;
    115   runner.addTest( suite );
    116 
    117   // Change the default outputter to a compiler error format outputter
    118   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    119                                                        std::cerr ) );
    120   // Run the tests.
    121   bool wasSucessful = runner.run();
    122 
    123   // Return error code 1 if the one of test failed.
    124   return wasSucessful ? 0 : 1;
    125 };
  • src/unittests/listofbondsunittest.cpp

    rc695c9 r5f612ee  
    1616#include "listofbondsunittest.hpp"
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    2122#include "molecule.hpp"
    2223#include "periodentafel.hpp"
     24#include "World.hpp"
     25
     26#ifdef HAVE_TESTRUNNER
     27#include "UnitTestMain.hpp"
     28#endif /*HAVE_TESTRUNNER*/
    2329
    2430/********************************************** Test classes **************************************/
     
    4551
    4652  // construct periodentafel
    47   tafel = new periodentafel;
     53  tafel = World::getInstance().getPeriode();
    4854  tafel->AddElement(hydrogen);
    4955
    5056  // construct molecule (tetraeder of hydrogens)
    51   TestMolecule = new molecule(tafel);
    52   Walker = new atom();
     57  TestMolecule = World::getInstance().createMolecule();
     58  Walker = World::getInstance().createAtom();
    5359  Walker->type = hydrogen;
    5460  Walker->node->Init(1., 0., 1. );
    5561  TestMolecule->AddAtom(Walker);
    56   Walker = new atom();
     62  Walker = World::getInstance().createAtom();
    5763  Walker->type = hydrogen;
    5864  Walker->node->Init(0., 1., 1. );
    5965  TestMolecule->AddAtom(Walker);
    60   Walker = new atom();
     66  Walker = World::getInstance().createAtom();
    6167  Walker->type = hydrogen;
    6268  Walker->node->Init(1., 1., 0. );
    6369  TestMolecule->AddAtom(Walker);
    64   Walker = new atom();
     70  Walker = World::getInstance().createAtom();
    6571  Walker->type = hydrogen;
    6672  Walker->node->Init(0., 0., 0. );
     
    7682{
    7783  // remove
    78   delete(TestMolecule);
    79   // note that all the atoms are cleaned by TestMolecule
    80   delete(tafel);
    81   // note that element is cleaned by periodentafel
     84  World::getInstance().destroyMolecule(TestMolecule);
     85  // note that all the atoms, molecules, the tafel and the elements
     86  // are all cleaned when the world is destroyed
     87  World::purgeInstance();
     88  MemoryUsageObserver::purgeInstance();
     89  logger::purgeInstance();
    8290};
    8391
     
    242250
    243251  // remove atom2
    244   delete(atom2);
     252  World::getInstance().destroyAtom(atom2);
    245253
    246254  // check bond if removed from other atom
     
    250258  CPPUNIT_ASSERT_EQUAL( TestMolecule->first->next, TestMolecule->last );
    251259};
    252 
    253 /********************************************** Main routine **************************************/
    254 
    255 int main(int argc, char **argv)
    256 {
    257   // Get the top level suite from the registry
    258   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    259 
    260   // Adds the test to the list of test to run
    261   CppUnit::TextUi::TestRunner runner;
    262   runner.addTest( suite );
    263 
    264   // Change the default outputter to a compiler error format outputter
    265   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    266                                                        std::cerr ) );
    267   // Run the tests.
    268   bool wasSucessful = runner.run();
    269 
    270   // Return error code 1 if the one of test failed.
    271   return wasSucessful ? 0 : 1;
    272 };
  • src/unittests/logunittest.cpp

    rc695c9 r5f612ee  
    1515#include "verbose.hpp"
    1616
     17#ifdef HAVE_TESTRUNNER
     18#include "UnitTestMain.hpp"
     19#endif /*HAVE_TESTRUNNER*/
     20
    1721/********************************************** Test classes **************************************/
    1822
     
    2731void LogTest::tearDown()
    2832{
     33  logger::purgeInstance();
     34  errorLogger::purgeInstance();
    2935};
    3036
     
    3440void LogTest::logTest()
    3541{
    36   logger::getInstance()->setVerbosity(2);
     42  logger::getInstance().setVerbosity(2);
    3743  DoLog(0) && (Log() << Verbose(0) << "Verbosity level is set to 2." << endl);
    3844  DoLog(0) && (Log() << Verbose(0) << "Test level 0" << endl);
     
    4854  DoeLog(4) && (eLog()<< Verbose(4) << "This should not be printed." << endl);
    4955};
    50 
    51 
    52 /********************************************** Main routine **************************************/
    53 
    54 int main(int argc, char **argv)
    55 {
    56   // Get the top level suite from the registry
    57   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    58 
    59   // Adds the test to the list of test to run
    60   CppUnit::TextUi::TestRunner runner;
    61   runner.addTest( suite );
    62 
    63   // Change the default outputter to a compiler error format outputter
    64   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    65                                                        std::cerr ) );
    66   // Run the tests.
    67   bool wasSucessful = runner.run();
    68 
    69   // Return error code 1 if the one of test failed.
    70   return wasSucessful ? 0 : 1;
    71 };
  • src/unittests/memoryallocatorunittest.cpp

    rc695c9 r5f612ee  
    1313#include "memoryallocatorunittest.hpp"
    1414#include "helpers.hpp"
     15#include "log.hpp"
    1516#include "defs.hpp"
     17
     18#ifdef HAVE_TESTRUNNER
     19#include "UnitTestMain.hpp"
     20#endif /*HAVE_TESTRUNNER*/
    1621
    1722/********************************************** Test classes **************************************/
     
    2934{
    3035  MemoryUsageObserver::getInstance()->purgeInstance();
     36  logger::purgeInstance();
    3137};
    3238
     
    102108  Free(buffer2);
    103109};
    104 
    105 
    106 /********************************************** Main routine **************************************/
    107 
    108 int main(int argc, char **argv)
    109 {
    110   // Get the top level suite from the registry
    111   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    112 
    113   // Adds the test to the list of test to run
    114   CppUnit::TextUi::TestRunner runner;
    115   runner.addTest( suite );
    116 
    117   // Change the default outputter to a compiler error format outputter
    118   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    119                                                        std::cerr ) );
    120   // Run the tests.
    121   bool wasSucessful = runner.run();
    122 
    123   // Return error code 1 if the one of test failed.
    124   return wasSucessful ? 0 : 1;
    125 };
  • src/unittests/memoryusageobserverunittest.cpp

    rc695c9 r5f612ee  
    1414#include "memoryusageobserverunittest.hpp"
    1515
     16#ifdef HAVE_TESTRUNNER
     17#include "UnitTestMain.hpp"
     18#endif /*HAVE_TESTRUNNER*/
     19
    1620/********************************************** Test classes **************************************/
    1721// Registers the fixture into the 'registry'
     
    2731{
    2832  MemoryUsageObserver::purgeInstance();
     33  logger::purgeInstance();
     34  errorLogger::purgeInstance();
    2935};
    3036
     
    7076  MemoryUsageObserver::getInstance()->removeMemory(i);
    7177  CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize());
     78  Free(i);
    7279};
    7380
     
    8087  MemoryUsageObserver::getInstance()->removeMemory(i);
    8188  CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize());
     89  Free(i);
    8290};
    8391
     
    92100  MemoryUsageObserver::getInstance()->addMemory(j, sizeof(int));
    93101  CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
     102  Free(i);
     103  Free(j);
    94104};
    95105
     
    103113  MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
    104114  CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
     115  Free(i);
    105116};
    106117
     
    114125  MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
    115126  CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory());
     127  Free(i);
    116128};
    117129
     
    125137  MemoryUsageObserver::getInstance()->removeMemory(i);
    126138  CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory());
     139  Free(i);
    127140};
    128141
     
    135148  MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
    136149  CPPUNIT_ASSERT_EQUAL(i, (int*) MemoryUsageObserver::getInstance()->getPointersToAllocatedMemory().begin()->first);
     150  Free(i);
    137151};
    138 
    139 
    140 /********************************************** Main routine **************************************/
    141 
    142 int main(int argc, char **argv)
    143 {
    144   // Get the top level suite from the registry
    145   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    146 
    147   // Adds the test to the list of test to run
    148   CppUnit::TextUi::TestRunner runner;
    149   runner.addTest( suite );
    150 
    151   // Change the default outputter to a compiler error format outputter
    152   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    153                                                        std::cerr ) );
    154   // Run the tests.
    155   bool wasSucessful = runner.run();
    156 
    157   // Return error code 1 if the one of test failed.
    158   return wasSucessful ? 0 : 1;
    159 };
  • src/unittests/stackclassunittest.cpp

    rc695c9 r5f612ee  
    1414#include "stackclassunittest.hpp"
    1515#include "log.hpp"
     16
     17#ifdef HAVE_TESTRUNNER
     18#include "UnitTestMain.hpp"
     19#endif /*HAVE_TESTRUNNER*/
    1620
    1721enum { testdimension=3 };
     
    3337  Stack->ClearStack();
    3438  delete(Stack);
     39  MemoryUsageObserver::purgeInstance();
     40  logger::purgeInstance();
    3541};
    3642
     
    6773  CPPUNIT_ASSERT_EQUAL(0, Stack->ItemCount());
    6874};
    69 
    70 
    71 /********************************************** Main routine **************************************/
    72 
    73 int main(int argc, char **argv)
    74 {
    75   // Get the top level suite from the registry
    76   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    77 
    78   // Adds the test to the list of test to run
    79   CppUnit::TextUi::TestRunner runner;
    80   runner.addTest( suite );
    81 
    82   // Change the default outputter to a compiler error format outputter
    83   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    84                                                        std::cerr ) );
    85   // Run the tests.
    86   bool wasSucessful = runner.run();
    87 
    88   // Return error code 1 if the one of test failed.
    89   return wasSucessful ? 0 : 1;
    90 };
  • src/unittests/tesselation_boundarytriangleunittest.cpp

    rc695c9 r5f612ee  
    1818#include "tesselation_boundarytriangleunittest.hpp"
    1919
     20#ifdef HAVE_TESTRUNNER
     21#include "UnitTestMain.hpp"
     22#endif /*HAVE_TESTRUNNER*/
     23
    2024#define SPHERERADIUS 2.
    2125
     
    3135
    3236  // create nodes
    33   TesselPoint *Walker = NULL;
    34   Walker = new TesselPoint;
    35   Walker->node = new Vector(0., 0., 0.);
    36   Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
    37   strcpy(Walker->Name, "1");
    38   Walker->nr = 1;
    39   points[0] = new BoundaryPointSet(Walker);
    40   Walker = new TesselPoint;
    41   Walker->node = new Vector(0., 1., 0.);
    42   Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
    43   strcpy(Walker->Name, "2");
    44   Walker->nr = 2;
    45   points[1] = new BoundaryPointSet(Walker);
    46   Walker = new TesselPoint;
    47   Walker->node = new Vector(1., 0., 0.);
    48   Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
    49   strcpy(Walker->Name, "3");
    50   Walker->nr = 3;
    51   points[2] = new BoundaryPointSet(Walker);
     37  tesselpoints[0] = new TesselPoint;
     38  tesselpoints[0]->node = new Vector(0., 0., 0.);
     39  tesselpoints[0]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
     40  strcpy(tesselpoints[0]->Name, "1");
     41  tesselpoints[0]->nr = 1;
     42  points[0] = new BoundaryPointSet(tesselpoints[0]);
     43  tesselpoints[1] = new TesselPoint;
     44  tesselpoints[1]->node = new Vector(0., 1., 0.);
     45  tesselpoints[1]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
     46  strcpy(tesselpoints[1]->Name, "2");
     47  tesselpoints[1]->nr = 2;
     48  points[1] = new BoundaryPointSet(tesselpoints[1]);
     49  tesselpoints[2] = new TesselPoint;
     50  tesselpoints[2] ->node = new Vector(1., 0., 0.);
     51  tesselpoints[2] ->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
     52  strcpy(tesselpoints[2] ->Name, "3");
     53  tesselpoints[2] ->nr = 3;
     54  points[2] = new BoundaryPointSet(tesselpoints[2] );
    5255
    5356  // create line
     
    6568{
    6669  delete(triangle);
     70  for (int i=0;i<3;++i) {
     71    // TesselPoint does not delete its vector as it only got a reference
     72    delete tesselpoints[i]->node;
     73    delete tesselpoints[i];
     74  }
    6775  MemoryUsageObserver::purgeInstance();
    6876  logger::purgeInstance();
     
    191199  CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
    192200};
    193 
    194 
    195 /********************************************** Main routine **************************************/
    196 
    197 int main(int argc, char **argv)
    198 {
    199   // Get the top level suite from the registry
    200   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    201 
    202   // Adds the test to the list of test to run
    203   CppUnit::TextUi::TestRunner runner;
    204   runner.addTest( suite );
    205 
    206   // Change the default outputter to a compiler error format outputter
    207   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    208                                                        std::cerr ) );
    209   // Run the tests.
    210   bool wasSucessful = runner.run();
    211 
    212   // Return error code 1 if the one of test failed.
    213   return wasSucessful ? 0 : 1;
    214 };
  • src/unittests/tesselation_boundarytriangleunittest.hpp

    rc695c9 r5f612ee  
    3535      class BoundaryLineSet *lines[3];
    3636      class BoundaryPointSet *points[3];
     37      class TesselPoint *tesselpoints[3];
    3738      LinkedCell::LinkedNodes Corners;
    3839};
  • src/unittests/tesselation_insideoutsideunittest.cpp

    rc695c9 r5f612ee  
    1717#include "tesselation.hpp"
    1818#include "tesselation_insideoutsideunittest.hpp"
     19
     20#ifdef HAVE_TESTRUNNER
     21#include "UnitTestMain.hpp"
     22#endif /*HAVE_TESTRUNNER*/
    1923
    2024#define SPHERERADIUS 2.
     
    161165      }
    162166};
    163 
    164 /********************************************** Main routine **************************************/
    165 
    166 int main(int argc, char **argv)
    167 {
    168   // Get the top level suite from the registry
    169   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    170 
    171   // Adds the test to the list of test to run
    172   CppUnit::TextUi::TestRunner runner;
    173   runner.addTest( suite );
    174 
    175   // Change the default outputter to a compiler error format outputter
    176   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    177                                                        std::cerr ) );
    178   // Run the tests.
    179   bool wasSucessful = runner.run();
    180 
    181   // Return error code 1 if the one of test failed.
    182   return wasSucessful ? 0 : 1;
    183 };
  • src/unittests/tesselationunittest.cpp

    rc695c9 r5f612ee  
    1818#include "tesselation.hpp"
    1919#include "tesselationunittest.hpp"
     20
     21#ifdef HAVE_TESTRUNNER
     22#include "UnitTestMain.hpp"
     23#endif /*HAVE_TESTRUNNER*/
    2024
    2125#define SPHERERADIUS 2.
     
    177181  }
    178182}
    179 
    180 /********************************************** Main routine **************************************/
    181 
    182 int main(int argc, char **argv)
    183 {
    184   // Get the top level suite from the registry
    185   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    186 
    187   // Adds the test to the list of test to run
    188   CppUnit::TextUi::TestRunner runner;
    189   runner.addTest( suite );
    190 
    191   // Change the default outputter to a compiler error format outputter
    192   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    193                                                        std::cerr ) );
    194   // Run the tests.
    195   bool wasSucessful = runner.run();
    196 
    197   // Return error code 1 if the one of test failed.
    198   return wasSucessful ? 0 : 1;
    199 };
  • src/unittests/vectorunittest.cpp

    rc695c9 r5f612ee  
    1414
    1515#include "defs.hpp"
     16#include "log.hpp"
     17#include "memoryusageobserver.hpp"
    1618#include "vector.hpp"
    1719#include "vectorunittest.hpp"
     20
     21#ifdef HAVE_TESTRUNNER
     22#include "UnitTestMain.hpp"
     23#endif /*HAVE_TESTRUNNER*/
    1824
    1925/********************************************** Test classes **************************************/
     
    3541void VectorTest::tearDown()
    3642{
     43  MemoryUsageObserver::purgeInstance();
     44  logger::purgeInstance();
     45  errorLogger::purgeInstance();
    3746};
    3847
     
    290299}
    291300
    292 
    293 /********************************************** Main routine **************************************/
    294 
    295 int main(int argc, char **argv)
    296 {
    297   // Get the top level suite from the registry
    298   CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
    299 
    300   // Adds the test to the list of test to run
    301   CppUnit::TextUi::TestRunner runner;
    302   runner.addTest( suite );
    303 
    304   // Change the default outputter to a compiler error format outputter
    305   runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
    306                                                        std::cerr ) );
    307   // Run the tests.
    308   bool wasSucessful = runner.run();
    309 
    310   // Return error code 1 if the one of test failed.
    311   return wasSucessful ? 0 : 1;
    312 };
  • src/vector.cpp

    rc695c9 r5f612ee  
    362362    return false;
    363363  }
     364  delete(M);
    364365  DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl);
    365366
     
    617618 * \return lhs + a
    618619 */
    619 Vector& operator+=(Vector& a, const Vector& b)
     620const Vector& operator+=(Vector& a, const Vector& b)
    620621{
    621622  a.AddVector(&b);
     
    628629 * \return lhs - a
    629630 */
    630 Vector& operator-=(Vector& a, const Vector& b)
     631const Vector& operator-=(Vector& a, const Vector& b)
    631632{
    632633  a.SubtractVector(&b);
     
    639640 * \return lhs.x[i] * m
    640641 */
    641 Vector& operator*=(Vector& a, const double m)
     642const Vector& operator*=(Vector& a, const double m)
    642643{
    643644  a.Scale(m);
     
    650651 * \return a + b
    651652 */
    652 Vector& operator+(const Vector& a, const Vector& b)
    653 {
    654   Vector *x = new Vector;
    655   x->CopyVector(&a);
    656   x->AddVector(&b);
    657   return *x;
     653Vector const operator+(const Vector& a, const Vector& b)
     654{
     655  Vector x(a);
     656  x.AddVector(&b);
     657  return x;
    658658};
    659659
     
    663663 * \return a - b
    664664 */
    665 Vector& operator-(const Vector& a, const Vector& b)
    666 {
    667   Vector *x = new Vector;
    668   x->CopyVector(&a);
    669   x->SubtractVector(&b);
    670   return *x;
     665Vector const operator-(const Vector& a, const Vector& b)
     666{
     667  Vector x(a);
     668  x.SubtractVector(&b);
     669  return x;
    671670};
    672671
     
    676675 * \return m * a
    677676 */
    678 Vector& operator*(const Vector& a, const double m)
    679 {
    680   Vector *x = new Vector;
    681   x->CopyVector(&a);
    682   x->Scale(m);
    683   return *x;
     677Vector const operator*(const Vector& a, const double m)
     678{
     679  Vector x(a);
     680  x.Scale(m);
     681  return x;
    684682};
    685683
     
    689687 * \return m * a
    690688 */
    691 Vector& operator*(const double m, const Vector& a )
    692 {
    693   Vector *x = new Vector;
    694   x->CopyVector(&a);
    695   x->Scale(m);
    696   return *x;
     689Vector const operator*(const double m, const Vector& a )
     690{
     691  Vector x(a);
     692  x.Scale(m);
     693  return x;
    697694};
    698695
     
    11101107void Vector::CopyVector(const Vector * const y)
    11111108{
    1112   for (int i=NDIM;i--;)
    1113     this->x[i] = y->x[i];
     1109  // check for self assignment
     1110  if(y!=this){
     1111    for (int i=NDIM;i--;)
     1112      this->x[i] = y->x[i];
     1113  }
    11141114}
    11151115
     
    11191119void Vector::CopyVector(const Vector &y)
    11201120{
    1121   for (int i=NDIM;i--;)
    1122     this->x[i] = y.x[i];
     1121  // check for self assignment
     1122  if(&y!=this) {
     1123    for (int i=NDIM;i--;)
     1124      this->x[i] = y.x[i];
     1125  }
    11231126}
    11241127
  • src/vector.hpp

    rc695c9 r5f612ee  
    8282  bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    8383  void WrapPeriodically(const double * const M, const double * const Minv);
     84
    8485};
    8586
    8687ostream & operator << (ostream& ost, const Vector &m);
    8788bool operator==(const Vector& a, const Vector& b);
    88 Vector& operator+=(Vector& a, const Vector& b);
    89 Vector& operator-=(Vector& a, const Vector& b);
    90 Vector& operator*=(Vector& a, const double m);
    91 Vector& operator*(const Vector& a, const double m);
    92 Vector& operator*(const double m, const Vector& a);
    93 Vector& operator+(const Vector& a, const Vector& b);
    94 Vector& operator-(const Vector& a, const Vector& b);
     89const Vector& operator+=(Vector& a, const Vector& b);
     90const Vector& operator-=(Vector& a, const Vector& b);
     91const Vector& operator*=(Vector& a, const double m);
     92Vector const operator*(const Vector& a, const double m);
     93Vector const operator*(const double m, const Vector& a);
     94Vector const operator+(const Vector& a, const Vector& b);
     95Vector const operator-(const Vector& a, const Vector& b);
    9596
    9697
Note: See TracChangeset for help on using the changeset viewer.