Changes in / [0188ea:957c42]


Ignore:
Files:
16 added
32 edited

Legend:

Unmodified
Added
Removed
  • doc/Doxyfile

    r0188ea r957c42  
    114114EXCLUDE                =
    115115EXCLUDE_SYMLINKS       = NO
    116 EXCLUDE_PATTERNS       =
     116EXCLUDE_PATTERNS       = */unittests/* \
     117                                                 */test/*
    117118EXAMPLE_PATH           =
    118119EXAMPLE_PATTERNS       = *
  • src/Actions/Process.cpp

    r0188ea r957c42  
    3838
    3939int Process::getCurrStep(){
     40  OBSERVE;
    4041  return currStep;
     42}
     43
     44void Process::setCurrStep(int _currStep){
     45  currStep = _currStep;
    4146}
    4247
     
    4752    return 0;
    4853}
     54
    4955int Process::getMaxSteps(){
    5056  return maxSteps;
    5157}
    5258
     59void Process::setMaxSteps(int _maxSteps){
     60  maxSteps = _maxSteps;
     61}
    5362
    5463void Process::start(){
     
    6978  starts = false;
    7079}
     80
    7181void Process::step(){
    7282  OBSERVE;
    7383  currStep++;
    7484}
     85
    7586void Process::stop(){
    7687  stops = true;
  • src/Actions/Process.hpp

    r0188ea r957c42  
    2929  bool  doesStop();
    3030  int   getCurrStep();
     31  void  setCurrStep(int _currStep);
    3132  float getDoneRatio();
    3233  int   getMaxSteps();
     34  void  setMaxSteps(int _maxSteps);
    3335
    3436protected:
  • src/Descriptors/AtomDescriptor.hpp

    r0188ea r957c42  
    1515#include "World.hpp"
    1616
     17class World;
    1718class atom;
    1819
     
    2122
    2223class AtomDescriptor {
     24  // close coupling to the world to allow access
    2325  friend atom* World::getAtom(AtomDescriptor descriptor);
    2426  friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor);
     27  friend class World::AtomIterator;
    2528
    2629  friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
  • src/Descriptors/AtomDescriptor_impl.hpp

    r0188ea r957c42  
    1 #include "Descriptors/AtomDescriptor.hpp"
     1#ifndef ATOMDESCRIPTOR_IMPL_HPP
     2#define ATOMDESCRIPTOR_IMPL_HPP
    23
    34/************************ Declarations of implementation Objects ************************/
     
    7273  AtomDescriptor::impl_ptr arg;
    7374};
     75
     76#endif //ATOMDESCRIPTOR_IMPL_HPP
  • src/Descriptors/AtomIdDescriptor.cpp

    r0188ea r957c42  
    2222
    2323bool AtomIdDescriptor_impl::predicate(std::pair<int,atom*> atom) {
    24   return atom.second->getId()==id;
     24  return atom.first==id;
    2525}
    2626
     
    2929}
    3030
    31 #if 0
    32 
    33 // so far the lookuptable for Atoms-by-id does not work, since atoms don't get an ID upon creation.
    34 // instead of this we rely on walking through all atoms.
    35 
    36 atom *AtomIdDescriptor::find(){
     31atom *AtomIdDescriptor_impl::find(){
    3732  map<int,atom*> atoms = getAtoms();
    3833  map<int,atom*>::iterator res = atoms.find(id);
     
    4035}
    4136
    42 vector<atom*> AtomIdDescriptor::findAll(){
     37vector<atom*> AtomIdDescriptor_impl::findAll(){
    4338  atom *res = find();
    4439  return (res)?(vector<atom*>(1,res)):(vector<atom*>());
    4540}
    46 
    47 #endif
  • src/Descriptors/AtomIdDescriptor_impl.hpp

    r0188ea r957c42  
    1 #include "Descriptors/AtomIdDescriptor.hpp"
     1#ifndef ATOMIDDESCRIPTOR_IMPL_HPP
     2#define ATOMIDDESCRIPTOR_IMPL_HPP
     3
    24#include "Descriptors/AtomDescriptor_impl.hpp"
    35
     
    1113
    1214protected:
    13 #if 0
    14   atom *find();
    15   std::vector<atom*> findAll();
    16 #endif
     15  virtual atom *find();
     16  virtual std::vector<atom*> findAll();
    1717private:
    1818  int id;
    1919};
     20
     21#endif //ATOMIDDESCRIPTOR_IMPL_HPP
  • src/Legacy/oldmenu.cpp

    r0188ea r957c42  
    99#include "Legacy/oldmenu.hpp"
    1010#include "analysis_correlation.hpp"
     11#include "World.hpp"
    1112#include "atom.hpp"
    1213#include "bond.hpp"
     
    7778      case 'a': // absolute coordinates of atom
    7879        Log() << Verbose(0) << "Enter absolute coordinates." << endl;
    79         first = new atom;
     80        first = World::get()->createAtom();
    8081        first->x.AskPosition(mol->cell_size, false);
    8182        first->type = periode->AskElement();  // give type
     
    8485
    8586      case 'b': // relative coordinates of atom wrt to reference point
    86         first = new atom;
     87        first = World::get()->createAtom();
    8788        valid = true;
    8889        do {
     
    100101
    101102      case 'c': // relative coordinates of atom wrt to already placed atom
    102         first = new atom;
     103        first = World::get()->createAtom();
    103104        valid = true;
    104105        do {
     
    116117
    117118    case 'd': // two atoms, two angles and a distance
    118         first = new atom;
     119        first = World::get()->createAtom();
    119120        valid = true;
    120121        do {
     
    216217
    217218      case 'e': // least square distance position to a set of atoms
    218         first = new atom;
     219        first = World::get()->createAtom();
    219220        atoms = new (Vector*[128]);
    220221        valid = true;
     
    238239          mol->AddAtom(first);  // add to molecule
    239240        } else {
    240           delete first;
     241          World::get()->destroyAtom(first);
    241242          Log() << Verbose(0) << "Please enter at least two vectors!\n";
    242243        }
     
    736737        Log() << Verbose(0) << "New element by atomic number Z: ";
    737738        cin >> Z;
    738         first->type = periode->FindElement(Z);
     739        first->setType(Z);
    739740        Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
    740741      }
     
    781782        x.AddVector(&y); // per factor one cell width further
    782783        for (int k=count;k--;) { // go through every atom of the original cell
    783           first = new atom(); // create a new body
     784          first = World::get()->createAtom(); // create a new body
    784785          first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    785786          first->x.AddVector(&x);     // translate the coordinates
  • src/Makefile.am

    r0188ea r957c42  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    10 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ActionRegistry.cpp
    11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ActionRegistry.hpp
     10ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ManipulateAtomsProcess.cpp Actions/ActionRegistry.cpp
     11ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp
    1212
    1313PATTERNSOURCE = Patterns/Observer.cpp
     
    2929LEGACYHEADER = Legacy/oldmenu.hpp
    3030
    31 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp
    32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp
     31DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp
     32DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp
    3333
    34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} 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 vector.cpp verbose.cpp World.cpp
     34SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.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 vector.cpp verbose.cpp World.cpp WorldIterators.cpp
    3535HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} 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 vector.hpp verbose.hpp World.hpp
    3636
  • src/World.cpp

    r0188ea r957c42  
    1212#include "periodentafel.hpp"
    1313#include "Descriptors/AtomDescriptor.hpp"
     14#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Actions/ManipulateAtomsProcess.hpp"
    1416
    1517using namespace std;
     
    2830}
    2931
     32vector<atom*> World::getAllAtoms(){
     33  return getAllAtoms(AllAtoms());
     34}
     35
    3036int World::numAtoms(){
    3137  return atoms.size();
     
    3642}
    3743
     44/******************** Methods to change World state *********************/
     45
    3846molecule* World::createMolecule(){
    3947  OBSERVE;
     
    4149  mol = new molecule(periode);
    4250  molecules_deprecated->insert(mol);
    43   molecules.insert(mol);
     51  assert(!molecules.count(currMoleculeId));
     52  // store the molecule by ID
     53  molecules[currMoleculeId++] = mol;
    4454  mol->signOn(this);
    4555  return mol;
    4656}
    4757
     58
     59atom *World::createAtom(){
     60  OBSERVE;
     61  atom *res = NewAtom();
     62  assert(!atoms.count(currAtomId));
     63  res->setId(currAtomId++);
     64  res->setWorld(this);
     65  // store the atom by ID
     66  atoms[res->getId()] = res;
     67  return res;
     68}
     69
     70int World::registerAtom(atom *atom){
     71  OBSERVE;
     72  assert(!atoms.count(currAtomId));
     73  atom->setId(currAtomId++);
     74  atom->setWorld(this);
     75  atoms[atom->getId()] = atom;
     76  return atom->getId();
     77}
     78
     79void World::destroyAtom(atom* atom){
     80  OBSERVE;
     81  int id = atom->getId();
     82  destroyAtom(id);
     83}
     84
     85void World::destroyAtom(int id) {
     86  OBSERVE;
     87  atom *atom = atoms[id];
     88  assert(atom);
     89  DeleteAtom(atom);
     90  atoms.erase(id);
     91}
     92
     93ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
     94  return new ManipulateAtomsProcess(op, descr,name,true);
     95}
     96
     97ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
     98  return manipulateAtoms(op,name,AllAtoms());
     99}
     100
     101/********************* Internal Change methods for double Callback and Observer mechanism ********/
     102
     103void World::doManipulate(ManipulateAtomsProcess *proc){
     104  proc->signOn(this);
     105  {
     106    OBSERVE;
     107    proc->doManipulate(this);
     108  }
     109  proc->signOff(this);
     110}
     111
     112/******************************* Iterators ********************************/
     113
     114/*
     115 * Actual Implementation of the iterators can be found in WorldIterators.cpp
     116 */
     117
     118World::AtomIterator World::getAtomIter(AtomDescriptor descr){
     119  return AtomIterator(descr,this);
     120}
     121
     122World::AtomSet::iterator World::atomEnd(){
     123  return atoms.end();
     124}
    48125
    49126/******************************* Singleton Stuff **************************/
     
    53130boost::mutex World::worldLock;
    54131
    55 
    56 
    57132World::World() :
    58     dummyId(0),
     133    currAtomId(0),
     134    currMoleculeId(0),
    59135    periode(new periodentafel),
    60     molecules_deprecated(new MoleculeListClass)
     136    molecules_deprecated(new MoleculeListClass),
     137    atoms(),
     138    molecules()
    61139{
    62140  molecules_deprecated->signOn(this);
     
    65143World::~World()
    66144{
     145  delete molecules_deprecated;
    67146  delete periode;
     147  AtomSet::iterator iter;
     148  for(iter=atoms.begin();iter!=atoms.end();++iter){
     149    DeleteAtom((*iter).second);
     150  }
     151  atoms.clear();
    68152}
    69153
     
    78162
    79163void World::destroy(){
    80   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    81   theWorld->destroyLegacy();
    82   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    83 
    84164  // boost supports RAII-Style locking, so we don't need to unlock
    85165  boost::mutex::scoped_lock guard(worldLock);
     
    89169
    90170World* World::reset(){
    91   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    92   theWorld->destroyLegacy();
    93   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    94 
    95171  World* oldWorld = 0;
    96172  {
     
    119195  return molecules_deprecated;
    120196}
    121 
    122 // some legacy stuff to let the World know about items created outside
    123 void World::registerAtom(atom *theAtom){
    124   OBSERVE;
    125   atoms[dummyId++] = theAtom;
    126 }
    127 
    128 void World::destroyLegacy(){
    129   //delete molecules_deprecated;
    130 }
    131 
    132 void World::unregisterAtom(atom *theAtom){
    133   OBSERVE;
    134   atoms.erase(theAtom->getId());
    135 }
  • src/World.hpp

    r0188ea r957c42  
    99#define WORLD_HPP_
    1010
    11 #include <boost/thread.hpp>
     11#include <string>
    1212#include <map>
    1313#include <vector>
    1414#include <set>
     15#include <boost/thread.hpp>
     16#include <boost/shared_ptr.hpp>
     17
    1518
    1619#include "Patterns/Observer.hpp"
     
    2427class AtomDescriptor;
    2528class AtomDescriptor_impl;
     29class ManipulateAtomsProcess;
     30template<typename T>
     31class AtomsCalculation;
    2632
    2733class World : public Observable
    2834{
     35// necessary for coupling with descriptors
    2936friend class AtomDescriptor_impl;
     37friend class AtomDescriptor;
     38
     39// Actions, calculations etc associated with the World
     40friend class ManipulateAtomsProcess;
     41template<typename> friend class AtomsCalculation;
     42
     43typedef std::map<int,atom*> AtomSet;
     44typedef std::map<int,molecule*> MoleculeSet;
    3045public:
    3146
    3247  /***** getter and setter *****/
    3348  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
     49  /**
     50   * returns the periodentafel for the world.
     51   */
    3452  periodentafel *&getPeriode();
     53
     54  /**
     55   * returns the first atom that matches a given descriptor.
     56   * Do not rely on ordering for descriptors that match more than one atom.
     57   */
    3558  atom* getAtom(AtomDescriptor descriptor);
     59
     60  /**
     61   * returns a vector containing all atoms that match a given descriptor
     62   */
    3663  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     64  std::vector<atom*> getAllAtoms();
     65
     66  /**
     67   * returns a calculation that calls a given function on all atoms matching a descriptor.
     68   * the calculation is not called at this point and can be used as an action, i.e. be stored in
     69   * menus, be kept around for later use etc.
     70   */
     71  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
     72  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
     73
     74  /**
     75   * get the number of atoms in the World
     76   */
    3777  int numAtoms();
     78
     79  /**
     80   * get the number of molecules in the World
     81   */
    3882  int numMolecules();
    3983
    4084  /***** Methods to work with the World *****/
     85
     86  /**
     87   * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
     88   * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
     89   */
    4190  molecule *createMolecule();
     91
     92  /**
     93   * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
     94   * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
     95   */
     96  atom *createAtom();
     97
     98  /**
     99   * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
     100   * Do not re-register Atoms already known to the world since this will cause double-frees.
     101   */
     102  int registerAtom(atom*);
     103
     104  /**
     105     * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     106     * atom directly since this will leave the pointer inside the world.
     107   */
     108  void destroyAtom(atom*);
     109
     110  /**
     111   * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     112   * atom directly since this will leave the pointer inside the world.
     113   */
     114  void destroyAtom(int);
     115
     116  /**
     117   * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
     118   * called at this time, so it can be passed around, stored inside menuItems etc.
     119   */
     120  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
     121  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
     122
     123protected:
     124  /**** Iterators to use internal data structures */
     125  class AtomIterator {
     126  public:
     127    AtomIterator();
     128    AtomIterator(AtomDescriptor, World*);
     129    AtomIterator(const AtomIterator&);
     130    AtomIterator& operator=(const AtomIterator&);
     131    AtomIterator& operator++();     // prefix
     132    AtomIterator  operator++(int);  // postfix with dummy parameter
     133    bool operator==(const AtomIterator&);
     134    bool operator==(const AtomSet::iterator&);
     135    bool operator!=(const AtomIterator&);
     136    bool operator!=(const AtomSet::iterator&);
     137    atom* operator*();
     138
     139    int getCount();
     140  protected:
     141    void advanceState();
     142    World* world;
     143    AtomSet::iterator state;
     144    boost::shared_ptr<AtomDescriptor_impl>  descr;
     145    int index;
     146  };
     147
     148  /**
     149   * returns an iterator over all Atoms matching a given descriptor.
     150   * used for internal purposes, like AtomProcesses and AtomCalculations.
     151   */
     152  AtomIterator getAtomIter(AtomDescriptor descr);
     153
     154  /**
     155   * returns an iterator to the end of the AtomSet. Due to overloading this iterator
     156   * can be compared to iterators produced by getAtomIter (see the mis-matching types).
     157   * Thus it can be used to detect when such an iterator is at the end of the list.
     158   * used for internal purposes, like AtomProcesses and AtomCalculations.
     159   */
     160  AtomSet::iterator atomEnd();
     161
     162  /******* Internal manipulation routines for double callback and Observer mechanism ******/
     163  void doManipulate(ManipulateAtomsProcess *);
     164
    42165private:
    43166  periodentafel *periode;
    44   std::map<int,atom*> atoms;
    45   std::set<molecule*> molecules;
     167  AtomSet atoms;
     168  int currAtomId; //!< stores the next available Id for atoms
     169  MoleculeSet molecules;
     170  int currMoleculeId;
    46171
    47172
    48173  /***** singleton Stuff *****/
    49174public:
     175
     176  /**
     177   * get the currently active instance of the World.
     178   */
    50179  static World* get();
     180
     181  /**
     182   * destroy the currently active instance of the World.
     183   */
    51184  static void destroy();
     185
     186  /**
     187   * destroy the currently active instance of the World and immidiately
     188   * create a new one. Use this to reset while somebody is still Observing
     189   * the world and should reset the observed instance. All observers will be
     190   * sent the subjectKille() message from the old world.
     191   */
    52192  static World* reset();
    53193
    54194private:
     195  /**
     196   * private constructor to ensure creation of the world using
     197   * the singleton pattern.
     198   */
    55199  World();
     200
     201  /**
     202   * private destructor to ensure destruction of the world using the
     203   * singleton pattern.
     204   */
    56205  virtual ~World();
    57206
     
    68217  MoleculeListClass *&getMolecules();
    69218
    70   // functions used for the WorldContent template mechanism
    71   void registerAtom(atom *theAtom);
    72   void unregisterAtom(atom *theAtom);
    73219private:
    74   // this function cleans up anything that cannot be cleaned while the lock is active
    75   // at a later point all these cleanups have to be moved to the World Class so the deadlock and
    76   // race condition can both be avoided.
    77   void destroyLegacy();
    78 
    79220  MoleculeListClass *molecules_deprecated;
    80 
    81   // this is needed to assign unique IDs to atoms... so far
    82   // IDs are not assigned upon Atom creation, so we cannot query the ID
    83   // during construction. By using the dummy ID we can make sure all atoms
    84   // are actually stored in the map and don't overwrite each other.
    85   int dummyId;
    86221};
    87222
  • src/atom.cpp

    r0188ea r957c42  
    2020/** Constructor of class atom.
    2121 */
    22 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)
    23 {
    24   World::get()->registerAtom(this);
     22atom::atom() :
     23  previous(NULL), next(NULL), father(this), sort(&nr)
     24{
    2525  node = &x;  // TesselPoint::x can only be referenced from here
    2626};
     
    2828/** Constructor of class atom.
    2929 */
    30 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr)
    31 {
    32   World::get()->registerAtom(this);
     30atom::atom(atom *pointer) :
     31    ParticleInfo(pointer),
     32    previous(NULL), next(NULL), father(pointer), sort(&nr)
     33{
    3334  type = pointer->type;  // copy element of atom
    3435  x.CopyVector(&pointer->x); // copy coordination
     
    3839};
    3940
     41atom *atom::clone(){
     42  atom *res = new atom();
     43  res->previous=0;
     44  res->next=0;
     45  res->father = this;
     46  res->sort = &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::get()->registerAtom(res);
     53  return res;
     54}
     55
    4056
    4157/** Destructor of class atom.
     
    4359atom::~atom()
    4460{
    45   World::get()->unregisterAtom(this);
    4661  unlink(this);
    4762};
     
    267282};
    268283
     284World *atom::getWorld(){
     285  return world;
     286}
     287
     288void atom::setWorld(World* _world){
     289  world = _world;
     290}
     291
     292void atom::setId(int _id) {
     293  id=_id;
     294}
     295
     296int atom::getId() {
     297  return id;
     298}
     299
     300atom* NewAtom(){
     301  return new atom();
     302}
     303
     304void  DeleteAtom(atom* atom){
     305  delete atom;
     306}
  • src/atom.hpp

    r0188ea r957c42  
    3232
    3333class Vector;
     34class World;
    3435
    3536/********************************************** declarations *******************************/
     
    3940 */
    4041class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo {
     42  friend atom* NewAtom();
     43  friend void  DeleteAtom(atom*);
    4144  public:
    4245    atom *previous; //!< previous atom in molecule list
     
    4548    int *sort;      //!< sort criteria
    4649
    47   atom();
    48   atom(class atom *pointer);
    49   virtual ~atom();
     50  virtual atom *clone();
    5051
    5152  bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const;
     
    6768  bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const;
    6869
     70  // getter and setter
     71
     72  /**
     73   * returns the World that contains this atom.
     74   * Use this if you need to get the world without locking
     75   * the singleton for example.
     76   *
     77   */
     78  World *getWorld();
     79  void setWorld(World*);
     80
     81  virtual int getId();
     82  virtual void setId(int);
     83  protected:
     84    /**
     85     * Protected constructor to ensure construction of atoms through the world.
     86     * see World::createAtom()
     87     */
     88    atom();
     89
     90    /**
     91     * Protected copy-constructor to ensure construction of atoms by cloning.
     92     * see atom::clone()
     93     */
     94    atom(class atom *pointer);
     95
     96    /**
     97     * Protected destructor to ensure destruction of atoms through the world.
     98     * see World::destroyAtom()
     99     */
     100    virtual ~atom();
    69101  private:
     102    World* world;
     103    int id;
    70104};
    71105
     106/**
     107 * internal method used by the world. Do not use if you don't know what you are doing.
     108 * You might get burned...
     109 * Use World::createAtom() instead.
     110 */
     111atom* NewAtom();
     112
     113/**
     114* internal method used by the world. Do not use if you don't know what you are doing.
     115 * You might get burned...
     116 * Use World::destroyAtom() instead.
     117 */
     118void  DeleteAtom(atom*);
     119
     120
    72121#endif /* ATOM_HPP_ */
  • src/atom_atominfo.cpp

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

    r0188ea r957c42  
    3737  ~AtomInfo();
    3838
     39  element *getType();
     40  void setType(element *);
     41  void setType(int);
     42
    3943private:
    4044};
  • src/atom_particleinfo.cpp

    r0188ea r957c42  
    1313ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {};
    1414
     15ParticleInfo::ParticleInfo(ParticleInfo *pointer) :
     16    Name(pointer->Name),
     17    nr(pointer->nr)
     18    {}
     19
     20
    1521/** Destructor of ParticleInfo.
    1622 */
     
    1925  Free(&Name);
    2026};
    21 
    22 int ParticleInfo::getId() {
    23   return nr;
    24 }
    2527
    2628ostream & operator << (ostream &ost, const ParticleInfo &a)
  • src/atom_particleinfo.hpp

    r0188ea r957c42  
    3131
    3232  ParticleInfo();
     33  ParticleInfo(ParticleInfo*);
    3334  ~ParticleInfo();
    3435
    3536  ostream & operator << (ostream &ost) const;
    36 
    37   virtual int getId();
    3837
    3938private:
  • src/boundary.cpp

    r0188ea r957c42  
    887887            Walker = Walker->next;
    888888            // copy atom ...
    889             CopyAtoms[Walker->nr] = new atom(Walker);
     889            CopyAtoms[Walker->nr] = Walker->clone();
    890890
    891891            // create atomic random translation vector ...
  • src/builder.cpp

    r0188ea r957c42  
    14811481                SaveFlag = true;
    14821482                Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
    1483                 first = new atom;
     1483                first = World::get()->createAtom();
    14841484                first->type = periode->FindElement(atoi(argv[argptr]));
    14851485                if (first->type != NULL)
     
    16411641//                first->x.Zero();
    16421642//                filler->AddAtom(first);
    1643                 first = new atom();
     1643                first = World::get()->createAtom();
    16441644                first->type = periode->FindElement(1);
    16451645                first->x.Init(0.441, -0.143, 0.);
    16461646                filler->AddAtom(first);
    1647                 second = new atom();
     1647                second = World::get()->createAtom();
    16481648                second->type = periode->FindElement(1);
    16491649                second->x.Init(-0.464, 1.137, 0.0);
    16501650                filler->AddAtom(second);
    1651                 third = new atom();
     1651                third = World::get()->createAtom();
    16521652                third->type = periode->FindElement(8);
    16531653                third->x.Init(-0.464, 0.177, 0.);
     
    20972097                      x.AddVector(&y); // per factor one cell width further
    20982098                      for (int k=count;k--;) { // go through every atom of the original cell
    2099                         first = new atom(); // create a new body
     2099                        first = World::get()->createAtom(); // create a new body
    21002100                        first->x.CopyVector(vectors[k]);  // use coordinate of original atom
    21012101                        first->x.AddVector(&x);      // translate the coordinates
  • src/config.cpp

    r0188ea r957c42  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    732733            sprintf(keyword,"%s_%i",name, j+1);
    733734            if (repetition == 0) {
    734               neues = new atom();
     735              neues = World::get()->createAtom();
    735736              AtomList[i][j] = neues;
    736737              LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    811812          sprintf(keyword,"%s_%i",name, j+1);
    812813          if (repetition == 0) {
    813             neues = new atom();
     814            neues = World::get()->createAtom();
    814815            AtomList[i][j] = neues;
    815816            LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues;
     
    12871288        }
    12881289        istringstream input2(zeile);
    1289         atom *neues = new atom();
     1290        atom *neues = World::get()->createAtom();
    12901291        input2 >> neues->x.x[0]; // x
    12911292        input2 >> neues->x.x[1]; // y
  • src/lists.hpp

    r0188ea r957c42  
    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/molecule.cpp

    r0188ea r957c42  
    88#include <boost/bind.hpp>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    3031 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
    3132 */
    32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(new atom), end(new atom),
     33molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()),
    3334  first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0),
    3435  BondCount(0), ElementCount(0), NoNonHydrogen(0), NoNonBonds(0), NoCyclicBonds(0), BondDistance(0.),
     
    6061  delete(first);
    6162  delete(last);
    62   delete(end);
    63   delete(start);
     63  end->getWorld()->destroyAtom(end);
     64  start->getWorld()->destroyAtom(start);
    6465};
    6566
     
    135136  OBSERVE;
    136137  if (pointer != NULL) {
    137     atom *walker = new atom(pointer);
     138    atom *walker = pointer->clone();
    138139    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    139140    strcpy (walker->Name, pointer->Name);
     
    242243  switch(TopBond->BondDegree) {
    243244    case 1:
    244       FirstOtherAtom = new atom();    // new atom
     245      FirstOtherAtom = World::get()->createAtom();    // new atom
    245246      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    246247      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    299300
    300301      // create the two Hydrogens ...
    301       FirstOtherAtom = new atom();
    302       SecondOtherAtom = new atom();
     302      FirstOtherAtom = World::get()->createAtom();
     303      SecondOtherAtom = World::get()->createAtom();
    303304      FirstOtherAtom->type = elemente->FindElement(1);
    304305      SecondOtherAtom->type = elemente->FindElement(1);
     
    354355    case 3:
    355356      // take the "usual" tetraoidal angle and add the three Hydrogen in direction of the bond (height of the tetraoid)
    356       FirstOtherAtom = new atom();
    357       SecondOtherAtom = new atom();
    358       ThirdOtherAtom = new atom();
     357      FirstOtherAtom = World::get()->createAtom();
     358      SecondOtherAtom = World::get()->createAtom();
     359      ThirdOtherAtom = World::get()->createAtom();
    359360      FirstOtherAtom->type = elemente->FindElement(1);
    360361      SecondOtherAtom->type = elemente->FindElement(1);
     
    475476    MDSteps++;
    476477  for(i=0;i<NumberOfAtoms;i++){
    477     Walker = new atom;
     478    Walker = World::get()->createAtom();
    478479    getline(xyzfile,line,'\n');
    479480    istringstream *item = new istringstream(line);
  • src/moleculelist.cpp

    r0188ea r957c42  
    342342    Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
    343343    if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    344       CopyAtoms[Walker->nr] = new atom(Walker);
     344      CopyAtoms[Walker->nr] = Walker->clone();
    345345      mol->AddAtom(CopyAtoms[Walker->nr]);
    346346      nr++;
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    r0188ea r957c42  
    1717#include "AnalysisCorrelationToPointUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5657  // construct molecule (tetraeder of hydrogens)
    5758  TestMolecule = new molecule(tafel);
    58   Walker = new atom();
     59  Walker = World::get()->createAtom();
    5960  Walker->type = hydrogen;
    6061  Walker->node->Init(1., 0., 1. );
    6162  TestMolecule->AddAtom(Walker);
    62   Walker = new atom();
     63  Walker = World::get()->createAtom();
    6364  Walker->type = hydrogen;
    6465  Walker->node->Init(0., 1., 1. );
    6566  TestMolecule->AddAtom(Walker);
    66   Walker = new atom();
     67  Walker = World::get()->createAtom();
    6768  Walker->type = hydrogen;
    6869  Walker->node->Init(1., 1., 0. );
    6970  TestMolecule->AddAtom(Walker);
    70   Walker = new atom();
     71  Walker = World::get()->createAtom();
    7172  Walker->type = hydrogen;
    7273  Walker->node->Init(0., 0., 0. );
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r0188ea r957c42  
    1717#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    6162  // construct molecule (tetraeder of hydrogens) base
    6263  TestMolecule = new molecule(tafel);
    63   Walker = new atom();
     64  Walker = World::get()->createAtom();
    6465  Walker->type = hydrogen;
    6566  Walker->node->Init(1., 0., 1. );
    6667  TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
     68  Walker = World::get()->createAtom();
    6869  Walker->type = hydrogen;
    6970  Walker->node->Init(0., 1., 1. );
    7071  TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
     72  Walker = World::get()->createAtom();
    7273  Walker->type = hydrogen;
    7374  Walker->node->Init(1., 1., 0. );
    7475  TestMolecule->AddAtom(Walker);
    75   Walker = new atom();
     76  Walker = World::get()->createAtom();
    7677  Walker->type = hydrogen;
    7778  Walker->node->Init(0., 0., 0. );
     
    9495
    9596  // add outer atoms
    96   Walker = new atom();
     97  Walker = World::get()->createAtom();
    9798  Walker->type = carbon;
    9899  Walker->node->Init(4., 0., 4. );
    99100  TestMolecule->AddAtom(Walker);
    100   Walker = new atom();
     101  Walker = World::get()->createAtom();
    101102  Walker->type = carbon;
    102103  Walker->node->Init(0., 4., 4. );
    103104  TestMolecule->AddAtom(Walker);
    104   Walker = new atom();
     105  Walker = World::get()->createAtom();
    105106  Walker->type = carbon;
    106107  Walker->node->Init(4., 4., 0. );
    107108  TestMolecule->AddAtom(Walker);
    108109  // add inner atoms
    109   Walker = new atom();
     110  Walker = World::get()->createAtom();
    110111  Walker->type = carbon;
    111112  Walker->node->Init(0.5, 0.5, 0.5 );
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r0188ea r957c42  
    1717#include "AnalysisPairCorrelationUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5556  // construct molecule (tetraeder of hydrogens)
    5657  TestMolecule = new molecule(tafel);
    57   Walker = new atom();
     58  Walker = World::get()->createAtom();
    5859  Walker->type = hydrogen;
    5960  Walker->node->Init(1., 0., 1. );
    6061  TestMolecule->AddAtom(Walker);
    61   Walker = new atom();
     62  Walker = World::get()->createAtom();
    6263  Walker->type = hydrogen;
    6364  Walker->node->Init(0., 1., 1. );
    6465  TestMolecule->AddAtom(Walker);
    65   Walker = new atom();
     66  Walker = World::get()->createAtom();
    6667  Walker->type = hydrogen;
    6768  Walker->node->Init(1., 1., 0. );
    6869  TestMolecule->AddAtom(Walker);
    69   Walker = new atom();
     70  Walker = World::get()->createAtom();
    7071  Walker->type = hydrogen;
    7172  Walker->node->Init(0., 0., 0. );
  • src/unittests/DescriptorUnittest.cpp

    r0188ea r957c42  
    2222CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2323
    24 // some stubs
    25 class AtomStub : public atom {
    26 public:
    27   AtomStub(int _id) :
    28   atom(),
    29   id(_id)
    30   {}
    31 
    32   virtual int getId(){
    33     return id;
    34   }
    35 
    36 private:
    37   int id;
    38 };
    39 
    40 
    4124// set up and tear down
    4225void DescriptorUnittest::setUp(){
    4326  World::get();
    4427  for(int i=0;i<ATOM_COUNT;++i){
    45     atoms[i]= new AtomStub(i);
     28    atoms[i]= World::get()->createAtom();
     29    atomIds[i] = atoms[i]->getId();
    4630  }
    4731}
    4832void DescriptorUnittest::tearDown(){
    4933  World::destroy();
    50   for(int i=0;i<ATOM_COUNT;++i){
    51     delete atoms[i];
    52   }
    5334}
    5435
    5536// some helper functions
    56 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
    57   for(int i=min;i<max;++i){
    58     if(!excluded.count(i)){
     37bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){
     38  for(int i=0;i<ATOM_COUNT;++i){
     39    int id = ids[i];
     40    if(!excluded.count(id)){
    5941      std::vector<atom*>::iterator iter;
    6042      bool res=false;
    6143      for(iter=atoms.begin();iter!=atoms.end();++iter){
    62         res |= (*iter)->getId() == i;
     44        res |= (*iter)->getId() == id;
    6345      }
    6446      if(!res) {
    65         cout << "Atom " << i << " missing in returned list" << endl;
     47        cout << "Atom " << id << " missing in returned list" << endl;
    6648        return false;
    6749      }
     
    8668void DescriptorUnittest::AtomBaseSetsTest(){
    8769  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    88   CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT));
     70  CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds));
    8971  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    9072
     
    9577  // test Atoms from boundaries and middle of the set
    9678  atom* testAtom;
    97   testAtom = World::get()->getAtom(AtomById(0));
    98   CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId());
    99   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2));
    100   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId());
    101   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1));
    102   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId());
     79  testAtom = World::get()->getAtom(AtomById(atomIds[0]));
     80  CPPUNIT_ASSERT(testAtom);
     81  CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
     82  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));
     83  CPPUNIT_ASSERT(testAtom);
     84  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
     85  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));
     86  CPPUNIT_ASSERT(testAtom);
     87  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
    10388
     89  // find some ID that has not been created
     90  int outsideId =-1;
     91  bool res = false;
     92  while(!res) {
     93    ++outsideId;
     94    res = true;
     95    for(int i = 0; i < ATOM_COUNT; ++i){
     96      res &= atomIds[i]!=outsideId;
     97    }
     98  }
    10499  // test from outside of set
    105   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
     100  testAtom = World::get()->getAtom(AtomById(outsideId));
    106101  CPPUNIT_ASSERT(!testAtom);
    107102}
     
    110105  {
    111106    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
    112     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     107    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    113108    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    114109  }
     
    116111  {
    117112    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
    118     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     113    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    119114    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    120115  }
     
    137132  {
    138133    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
    139     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     134    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    140135    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    141136  }
     
    143138  // exclude and include some atoms
    144139  {
    145     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2)));
     140    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    146141    std::set<int> excluded;
    147     excluded.insert(ATOM_COUNT/2);
    148     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded));
     142    excluded.insert(atomIds[ATOM_COUNT/2]);
     143    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded));
    149144    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    150145    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    152147
    153148  {
    154     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2)));
     149    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    155150    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    156     CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());
     151    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
    157152  }
    158153}
  • src/unittests/DescriptorUnittest.hpp

    r0188ea r957c42  
    3333private:
    3434  atom *atoms [ATOM_COUNT];
     35  int atomIds [ATOM_COUNT];
    3536};
    3637
  • src/unittests/Makefile.am

    r0188ea r957c42  
    3030  CacheableTest \
    3131  DescriptorUnittest \
    32   ${MENUTESTS} 
    33    
     32  manipulateAtomsTest \
     33  atomsCalculationTest \
     34  ${MENUTESTS}
     35 
     36
     37     
    3438 
    3539check_PROGRAMS = $(TESTS)
     
    109113
    110114DescriptorUnittest_SOURCES = DescriptorUnittest.cpp DescriptorUnittest.hpp
    111 DescriptorUnittest_LDADD = ${ALLLIBS}
     115DescriptorUnittest_LDADD = ${ALLLIBS}
     116
     117manipulateAtomsTest_SOURCES = manipulateAtomsTest.cpp manipulateAtomsTest.hpp
     118manipulateAtomsTest_LDADD = ${ALLLIBS}
     119
     120atomsCalculationTest_SOURCES = atomsCalculationTest.cpp atomsCalculationTest.hpp
     121atomsCalculationTest_LDADD = ${ALLLIBS}
    112122
    113123#AUTOMAKE_OPTIONS = parallel-tests
  • src/unittests/analysisbondsunittest.cpp

    r0188ea r957c42  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "analysis_bonds.hpp"
    1920#include "analysisbondsunittest.hpp"
     
    6263  // construct molecule (tetraeder of hydrogens)
    6364  TestMolecule = new molecule(tafel);
    64   Walker = new atom();
     65  Walker = World::get()->createAtom();
    6566  Walker->type = hydrogen;
    6667  Walker->node->Init(1.5, 0., 1.5 );
    6768  TestMolecule->AddAtom(Walker);
    68   Walker = new atom();
     69  Walker = World::get()->createAtom();
    6970  Walker->type = hydrogen;
    7071  Walker->node->Init(0., 1.5, 1.5 );
    7172  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     73  Walker = World::get()->createAtom();
    7374  Walker->type = hydrogen;
    7475  Walker->node->Init(1.5, 1.5, 0. );
    7576  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     77  Walker = World::get()->createAtom();
    7778  Walker->type = hydrogen;
    7879  Walker->node->Init(0., 0., 0. );
    7980  TestMolecule->AddAtom(Walker);
    80   Walker = new atom();
     81  Walker = World::get()->createAtom();
    8182  Walker->type = carbon;
    8283  Walker->node->Init(0.5, 0.5, 0.5 );
  • src/unittests/bondgraphunittest.cpp

    r0188ea r957c42  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5758  // construct molecule (tetraeder of hydrogens)
    5859  TestMolecule = new molecule(tafel);
    59   Walker = new atom();
     60  Walker = World::get()->createAtom();
    6061  Walker->type = hydrogen;
    6162  Walker->node->Init(1., 0., 1. );
    6263  TestMolecule->AddAtom(Walker);
    63   Walker = new atom();
     64  Walker = World::get()->createAtom();
    6465  Walker->type = hydrogen;
    6566  Walker->node->Init(0., 1., 1. );
    6667  TestMolecule->AddAtom(Walker);
    67   Walker = new atom();
     68  Walker = World::get()->createAtom();
    6869  Walker->type = hydrogen;
    6970  Walker->node->Init(1., 1., 0. );
    7071  TestMolecule->AddAtom(Walker);
    71   Walker = new atom();
     72  Walker = World::get()->createAtom();
    7273  Walker->type = hydrogen;
    7374  Walker->node->Init(0., 0., 0. );
  • src/unittests/listofbondsunittest.cpp

    r0188ea r957c42  
    1616#include "listofbondsunittest.hpp"
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5051  // construct molecule (tetraeder of hydrogens)
    5152  TestMolecule = new molecule(tafel);
    52   Walker = new atom();
     53  Walker = World::get()->createAtom();
    5354  Walker->type = hydrogen;
    5455  Walker->node->Init(1., 0., 1. );
    5556  TestMolecule->AddAtom(Walker);
    56   Walker = new atom();
     57  Walker = World::get()->createAtom();
    5758  Walker->type = hydrogen;
    5859  Walker->node->Init(0., 1., 1. );
    5960  TestMolecule->AddAtom(Walker);
    60   Walker = new atom();
     61  Walker = World::get()->createAtom();
    6162  Walker->type = hydrogen;
    6263  Walker->node->Init(1., 1., 0. );
    6364  TestMolecule->AddAtom(Walker);
    64   Walker = new atom();
     65  Walker = World::get()->createAtom();
    6566  Walker->type = hydrogen;
    6667  Walker->node->Init(0., 0., 0. );
     
    242243
    243244  // remove atom2
    244   delete(atom2);
     245  World::get()->destroyAtom(atom2);
    245246
    246247  // check bond if removed from other atom
Note: See TracChangeset for help on using the changeset viewer.