Changes in / [6bc51d:57f5cf]


Ignore:
Files:
19 added
58 edited

Legend:

Unmodified
Added
Removed
  • doc/Doxyfile

    r6bc51d r57f5cf  
    114114EXCLUDE                =
    115115EXCLUDE_SYMLINKS       = NO
    116 EXCLUDE_PATTERNS       =
     116EXCLUDE_PATTERNS       = */unittests/* \
     117                                                 */test/*
    117118EXAMPLE_PATH           =
    118119EXAMPLE_PATTERNS       = *
  • src/Actions/ActionRegistry.cpp

    r6bc51d r57f5cf  
    2424{
    2525  map<const string,Action*>::iterator iter;
    26   for(iter=actionMap.begin();iter!=actionMap.end();iter++) {
     26  for(iter=actionMap.begin();iter!=actionMap.end();++iter) {
    2727    delete iter->second;
    28     actionMap.erase(iter);
    2928  }
     29  actionMap.clear();
    3030}
    3131
  • src/Actions/MakroAction.cpp

    r6bc51d r57f5cf  
    2323{
    2424  Action* action;
    25   while(action=actions->removeLastAction()){
     25  while((action=actions->removeLastAction())){
    2626    delete action;
    2727  }
  • src/Actions/Process.cpp

    r6bc51d r57f5cf  
    1313  Action(_name,_doRegister),
    1414  maxSteps(_maxSteps),
     15  active(false),
    1516  starts(false),
    16   stops(false),
    17   active(false)
     17  stops(false)
    1818{}
    1919
     
    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(){
     
    6473  {
    6574    OBSERVE;
    66     active = true;
    6775    currStep=0;
    6876  }
    6977  starts = false;
     78  active = true;
    7079}
     80
    7181void Process::step(){
    7282  OBSERVE;
    7383  currStep++;
    7484}
     85
    7586void Process::stop(){
     87  active=false;
    7688  stops = true;
    7789  {
    7890    OBSERVE;
    7991    currStep=0;
    80     active=false;
    8192  }
    8293  {
  • src/Actions/Process.hpp

    r6bc51d r57f5cf  
    1919#include "Actions/Action.hpp"
    2020
     21/**
     22 * A Process is an Action that might take some time and therefore has special
     23 * methods to allow communication with progress indicators. Indicators
     24 * can sign on at a global place and will be notified when any process is doing
     25 * a calculation.
     26 *
     27 * A Process has four states:
     28 *  - starting: It is in the process of setting itself up, and wants everybody to know that it will start
     29 *              the calculation soon. Indicators should set up anything they need for displaying the progress
     30 *              when they are notified by a process in this state.
     31 *  - active:   The process is currently doing it's thing and wants any indicator to know it's status, i.e.
     32 *              the percentage done.
     33 *  - stopping: The process has fullfilled it's purpose and is shutting down. Indicators recieving this status
     34 *              should also use it to shut down their indication mechanism and delete any objects allocated for
     35 *              this Process
     36 *  - inactive: This Process is currently sleeping. If a Process is sending out any signals in this state, there
     37 *              is something seriously wrong.
     38 */
    2139class Process : public Action, public Observable
    2240{
     
    2947  bool  doesStop();
    3048  int   getCurrStep();
     49  void  setCurrStep(int _currStep);
    3150  float getDoneRatio();
    3251  int   getMaxSteps();
     52  void  setMaxSteps(int _maxSteps);
    3353
    3454protected:
  • src/Descriptors/AtomDescriptor.cpp

    r6bc51d r57f5cf  
    1919using namespace std;
    2020
    21 typedef map<int,atom*> atoms_t;
    22 typedef atoms_t::iterator atoms_iter_t;
     21typedef World::AtomSet::iterator atoms_iter_t;
    2322
    2423/************************ Forwarding object **************************************/
     
    6867}
    6968
    70 atoms_t& AtomDescriptor_impl::getAtoms(){
     69World::AtomSet& AtomDescriptor_impl::getAtoms(){
    7170  return World::get()->atoms;
    7271}
    7372
    7473atom* AtomDescriptor_impl::find() {
    75   atoms_t atoms = getAtoms();
     74  World::AtomSet atoms = getAtoms();
    7675  atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor_impl::predicate,this,_1));
    7776  return (res!=atoms.end())?((*res).second):0;
     
    8079vector<atom*> AtomDescriptor_impl::findAll() {
    8180  vector<atom*> res;
    82   atoms_t atoms = getAtoms();
     81  World::AtomSet atoms = getAtoms();
    8382  atoms_iter_t iter;
    8483  for(iter=atoms.begin();iter!=atoms.end();++iter) {
     
    9897{}
    9998
    100 bool AtomAllDescriptor_impl::predicate(std::pair<int,atom*>){
     99bool AtomAllDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
    101100  return true;
    102101}
     
    112111{}
    113112
    114 bool AtomNoneDescriptor_impl::predicate(std::pair<int,atom*>){
     113bool AtomNoneDescriptor_impl::predicate(std::pair<atomId_t,atom*>){
    115114  return false;
    116115}
     
    130129{}
    131130
    132 bool AtomAndDescriptor_impl::predicate(std::pair<int,atom*> atom){
     131bool AtomAndDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
    133132  return lhs->predicate(atom) && rhs->predicate(atom);
    134133}
     
    146145}
    147146
    148 bool AtomOrDescriptor_impl::predicate(std::pair<int,atom*> atom){
     147bool AtomOrDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
    149148  return lhs->predicate(atom) || rhs->predicate(atom);
    150149}
     
    166165}
    167166
    168 bool AtomNotDescriptor_impl::predicate(std::pair<int,atom*> atom){
     167bool AtomNotDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){
    169168 return !(arg->predicate(atom));
    170169}
  • src/Descriptors/AtomDescriptor.hpp

    r6bc51d r57f5cf  
    1515#include "World.hpp"
    1616
     17class World;
    1718class atom;
    1819
     
    2021class AtomDescripter_impl;
    2122
     23/**
     24 * An AtomDescriptor describes a Set of Atoms from the World. Can be used for any method that needs to work on
     25 * a specific set of Atoms.
     26 *
     27 * This Class is implemented using the PIMPL-Idion, i.e. this class only contains an abstract structure
     28 * that forwards any request to a wrapped pointer-to-implementation. This way operators and calculations
     29 * on Descriptors are possible.
     30 *
     31 * Concrete Implementation Objects can be shared between multiple Wrappers, so make sure that
     32 * any Implementation remainst constant during lifetime.
     33 */
    2234class AtomDescriptor {
     35  // close coupling to the world to allow access
    2336  friend atom* World::getAtom(AtomDescriptor descriptor);
    2437  friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor);
     38  friend class World::AtomIterator;
    2539
    2640  friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     
    2943
    3044public:
    31   typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr;
     45  typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type
    3246
    3347  AtomDescriptor(impl_ptr);
     48
     49  /**
     50   * Copy constructor.
     51   * Takes the Implementation from the copied object and sets it's own pointer to link there.
     52   * This way the actuall implementation object is shared between copy and original
     53   */
    3454  AtomDescriptor(const AtomDescriptor&);
    3555  ~AtomDescriptor();
    3656
     57  /**
     58   * Assignment Operator.
     59   *
     60   * Implemented by setting the pointer to the new Implementation.
     61   */
    3762  AtomDescriptor &operator=(AtomDescriptor &);
    3863
    3964protected:
     65  /**
     66   * forward Method to implementation
     67   */
    4068  atom* find();
     69
     70  /**
     71   * forward Method to implementation
     72   */
    4173  std::vector<atom*> findAll();
     74
     75  /**
     76   * Return the implementation this Wrapper currently points to.
     77   * Used for copying, assignment and in Iterators over subsets of the World.
     78   */
    4279  impl_ptr get_impl() const;
    4380
     
    4683};
    4784
    48 // Functions to construct actual descriptors
     85/**
     86 * produce an Atomdescriptor that at the point of construction contains an implementation that matches all Atoms
     87 */
    4988AtomDescriptor AllAtoms();
     89
     90/**
     91 * produce an Atomdescriptor that at the point of construction contains an implementation that matches no Atoms
     92 */
    5093AtomDescriptor NoAtoms();
    5194
    52 // no true short circuit, but the test of the second descriptor wont be done
     95/**
     96 * Set Intersection for two Atomdescriptors. The resulting Atomdescriptor will only match an Atom if both
     97 * given Atomdescriptors also match. Uses short circuit inside, so the second predicate wont be called
     98 * when the first one failed.
     99 */
    53100AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     101
     102/**
     103 * Set Union for two AtomDescriptors. The resulting AtomDescriptor will match an Atom if at least one of
     104 * the two given AtomDescriptors does match. Used short circuit inside, so the second predicate wont
     105 * be called when the first one failed.
     106 */
    54107AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs);
     108
     109/**
     110 * Set inversion for an AtomDescriptor. Matches an Atom if the given AtomDescriptor did not match.
     111 */
    55112AtomDescriptor operator!(const AtomDescriptor &arg);
    56113
  • src/Descriptors/AtomDescriptor_impl.hpp

    r6bc51d r57f5cf  
     1#ifndef ATOMDESCRIPTOR_IMPL_HPP
     2#define ATOMDESCRIPTOR_IMPL_HPP
     3
    14#include "Descriptors/AtomDescriptor.hpp"
    25
    36/************************ Declarations of implementation Objects ************************/
     7
     8/**
     9 * This class implements a general Base class for AtomDescriptors using the PIMPL-Idiom
     10 *
     11 * The predicate for this class is empty and should be implemented by derived classes.
     12 * By the predicate it is described which atoms should be picked for a given descriptor.
     13 */
    414
    515class AtomDescriptor_impl
     
    1121  virtual ~AtomDescriptor_impl();
    1222
    13   virtual bool predicate(std::pair<int,atom*>)=0;
     23  /**
     24   * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms
     25   */
     26  virtual bool predicate(std::pair<atomId_t,atom*>)=0;
    1427
    1528protected:
     29
     30  /**
     31   * This method is called when the Descriptor is used to find the first matching
     32   * Atom. Walks through all Atoms and stops on the first match. Can be implemented
     33   * when the searched Atom can be found in a more efficient way. Calculated
     34   * Atomdescriptors will always use this method, so no improvement there.
     35   */
    1636  virtual atom* find();
     37
     38  /**
     39   * This method is called when the Descriptor is used to find all matching Atoms.
     40   * Walks through all Atoms and tests the predicate on each one. A vector of all
     41   * matching Atoms is returned.
     42   */
    1743  virtual std::vector<atom*> findAll();
    18   std::map<int,atom*>& getAtoms();
     44
     45  /**
     46   * This method is used internally to query the Set of Atoms from the world.
     47   * By using this method derived classes can also access the Internal World Datastructre.
     48   * Implemented in full in the Base Descriptor Implementation, so only this one method
     49   * needs to be friend with the World class.
     50   */
     51  World::AtomSet& getAtoms();
    1952};
    2053
    2154/************************** Universe and Emptyset *****************/
    2255
     56/**
     57 * A simple AtomDescriptor that will always match all Atoms present in the World.
     58 */
    2359class AtomAllDescriptor_impl : public AtomDescriptor_impl {
    2460public:
    2561  AtomAllDescriptor_impl();
    2662  virtual ~AtomAllDescriptor_impl();
    27   virtual bool predicate(std::pair<int,atom*>);
     63
     64  /**
     65   * Always returns true for any Atom
     66   */
     67  virtual bool predicate(std::pair<atomId_t,atom*>);
    2868};
    2969
     70
     71/**
     72 * An AtomDescriptor that never matches any Atom in the World.
     73 */
    3074class AtomNoneDescriptor_impl : public AtomDescriptor_impl {
    3175public:
    3276  AtomNoneDescriptor_impl();
    3377  virtual ~AtomNoneDescriptor_impl();
    34   virtual bool predicate(std::pair<int,atom*>);
     78
     79  /**
     80   * Always returns false for any Atom
     81   */
     82  virtual bool predicate(std::pair<atomId_t,atom*>);
    3583};
    3684
    3785/************************** Operator stuff ************************/
    3886
     87/**
     88 * Intersection of two AtomDescriptors
     89 */
    3990class AtomAndDescriptor_impl : public AtomDescriptor_impl
    4091{
     
    4293  AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    4394  ~AtomAndDescriptor_impl();
    44   virtual bool predicate(std::pair<int,atom*>);
     95
     96  /**
     97   * This predicate uses the predicate from the first && the predicate from the
     98   * second Descriptor to decide if an Atom should be selected.
     99   */
     100  virtual bool predicate(std::pair<atomId_t,atom*>);
    45101
    46102private:
     
    49105};
    50106
     107/**
     108 * Union of two AtomDescriptors
     109 */
    51110class AtomOrDescriptor_impl : public AtomDescriptor_impl
    52111{
     
    54113  AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    55114  virtual ~AtomOrDescriptor_impl();
    56   virtual bool predicate(std::pair<int,atom*>);
     115
     116  /**
     117   * This predicate uses the predicate form the first || the predicate from the
     118   * second Descriptor to decide if an Atom should be selected.
     119   */
     120  virtual bool predicate(std::pair<atomId_t,atom*>);
    57121
    58122private:
     
    61125};
    62126
     127/**
     128 * Set Inversion of a Descriptor
     129 */
    63130class AtomNotDescriptor_impl : public AtomDescriptor_impl
    64131{
     
    67134  virtual ~AtomNotDescriptor_impl();
    68135
    69   virtual bool predicate(std::pair<int,atom*>);
     136  /**
     137   * Opposite of the given descriptor predicate.
     138   */
     139  virtual bool predicate(std::pair<atomId_t,atom*>);
    70140
    71141private:
    72142  AtomDescriptor::impl_ptr arg;
    73143};
     144
     145#endif //ATOMDESCRIPTOR_IMPL_HPP
  • src/Descriptors/AtomIdDescriptor.cpp

    r6bc51d r57f5cf  
    1414
    1515
    16 AtomIdDescriptor_impl::AtomIdDescriptor_impl(int _id) :
     16AtomIdDescriptor_impl::AtomIdDescriptor_impl(atomId_t _id) :
    1717  id(_id)
    1818{}
     
    2121{}
    2222
    23 bool AtomIdDescriptor_impl::predicate(std::pair<int,atom*> atom) {
    24   return atom.second->getId()==id;
     23bool AtomIdDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom) {
     24  return atom.first==id;
    2525}
    2626
    27 AtomDescriptor AtomById(int id){
     27AtomDescriptor AtomById(atomId_t id){
    2828  return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomIdDescriptor_impl(id)));
    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(){
    37   map<int,atom*> atoms = getAtoms();
    38   map<int,atom*>::iterator res = atoms.find(id);
     31atom *AtomIdDescriptor_impl::find(){
     32  World::AtomSet atoms = getAtoms();
     33  World::AtomSet::iterator res = atoms.find(id);
    3934  return (res!=atoms.end())?((*res).second):0;
    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.hpp

    r6bc51d r57f5cf  
    99#define ATOMIDDESCRIPTOR_HPP_
    1010
     11#include "defs.hpp"
    1112#include "Descriptors/AtomDescriptor.hpp"
    1213
    13 AtomDescriptor AtomById(int id);
     14AtomDescriptor AtomById(atomId_t id);
    1415
    1516#endif /* ATOMIDDESCRIPTOR_HPP_ */
  • src/Descriptors/AtomIdDescriptor_impl.hpp

    r6bc51d r57f5cf  
    1 #include "Descriptors/AtomIdDescriptor.hpp"
     1#ifndef ATOMIDDESCRIPTOR_IMPL_HPP
     2#define ATOMIDDESCRIPTOR_IMPL_HPP
     3
    24#include "Descriptors/AtomDescriptor_impl.hpp"
    35
     
    57{
    68public:
    7   AtomIdDescriptor_impl(int _id);
     9  AtomIdDescriptor_impl(atomId_t _id);
    810  virtual ~AtomIdDescriptor_impl();
    911
    10   bool predicate(std::pair<int,atom*> atom);
     12  bool predicate(std::pair<atomId_t,atom*> atom);
    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:
    18   int id;
     18  atomId_t id;
    1919};
     20
     21#endif //ATOMIDDESCRIPTOR_IMPL_HPP
  • src/Legacy/oldmenu.cpp

    r6bc51d r57f5cf  
    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
     
    811812void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
    812813{
    813   atom *first = NULL;
    814814  Vector x,y,z,n; // coordinates for absolute point in cell volume
    815   int j, axis, count, faktor;
    816815  char choice;  // menu choice char
    817816  molecule *mol = NULL;
    818   element **Elements;
    819   Vector **vectors;
    820817  MoleculeLeafClass *Subgraphs = NULL;
    821818
     
    10921089    A++;
    10931090  }
    1094   delete(mol);
     1091  World::get()->destroyMolecule(mol);
    10951092};
    10961093
  • src/Makefile.am

    r6bc51d r57f5cf  
    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 Descriptors/MoleculeDescriptor.cpp
     32DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp Descriptors/MoleculeDescriptor.hpp
    3333
    34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp ChangeTracker.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp FormatParser.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 ChangeTracker.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp FormatParser.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 ChangeTracker.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp FormatParser.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
     
    4141bin_PROGRAMS = molecuilder joiner analyzer
    4242molecuilderdir = ${bindir}
    43 #libmolecuilder_a_CXXFLAGS = -DNO_CACHING
    4443libmolecuilder_a_SOURCES = ${SOURCE} ${HEADER}
    4544libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER}
    4645molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    4746molecuilder_LDFLAGS = $(BOOST_LDFLAGS)
    48 molecuilder_CXXFLAGS = $(BOOST_CPPFLAGS)
    49 #molecuilder_CXXFLAGS += -DNO_CACHING
    5047molecuilder_SOURCES = builder.cpp
    5148molecuilder_LDADD = libmolecuilder.a libgslwrapper.a $(BOOST_LIB) ${BOOST_THREAD_LIB}
  • src/Menu/DisplayMenuItem.cpp

    r6bc51d r57f5cf  
    2121
    2222DisplayMenuItem::DisplayMenuItem(Menu* _menu, StringView *_view, string _title, char _spacer, int _length ):
    23 MenuItem('\0',"",_menu),
    24 view(_view),
    25 title(_title),
    26 spacer(_spacer),
    27 length(_length)
     23  MenuItem('\0',"",_menu),
     24  view(_view),
     25  title(_title),
     26  length(_length),
     27  spacer(_spacer)
    2828{
    2929}
    3030
    3131DisplayMenuItem::~DisplayMenuItem()
    32 {
    33   // TODO Auto-generated destructor stub
    34 }
     32{}
    3533
    3634
  • src/Menu/TextMenu.cpp

    r6bc51d r57f5cf  
    1818 */
    1919TextMenu::TextMenu(ostream& _outputter, string _title, char _spacer,int _length) :
    20 outputter(_outputter),
    21 title(_title),
    22 spacer(_spacer),
    23 length(_length),
    24 quit(false),
    25 defaultItem(0)
     20  defaultItem(0),
     21  outputter(_outputter),
     22  title(_title),
     23  spacer(_spacer),
     24  length(_length),
     25  quit(false)
    2626{
    2727}
  • src/Patterns/Cacheable.hpp

    r6bc51d r57f5cf  
    4343  Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) :
    4444    owner(_owner),
    45     recalcMethod(_recalcMethod),
    4645    valid(false),
    47     canBeUsed(true)
     46    canBeUsed(true),
     47    recalcMethod(_recalcMethod)
    4848  {
    4949    // we sign on with the best(=lowest) priority, so cached values are recalculated before
  • src/Patterns/Observer.cpp

    r6bc51d r57f5cf  
    108108    callees_t *callees = callTable[this];
    109109    callees_t::iterator iter;
    110     for(iter=callees->begin();iter!=callees->end();iter++){
     110    for(iter=callees->begin();iter!=callees->end();++iter){
    111111      (*iter).second->update(this);
    112112    }
     
    160160
    161161  callees_t::iterator iter;
    162   for(iter=callees->begin();iter!=callees->end();iter++){
     162  for(iter=callees->begin();iter!=callees->end();++iter){
    163163    res |= ((*iter).second == target);
    164164  }
     
    177177  callees_t::iterator deliter;
    178178  for(iter=callees->begin();iter!=callees->end();) {
    179     deliter=iter++;
    180     if((*deliter).second == target)
    181       callees->erase(deliter);
     179    if((*iter).second == target) {
     180      callees->erase(iter++);
     181    }
     182    else {
     183      ++iter;
     184    }
    182185  }
    183186  if(callees->empty()){
     
    208211    callees_t *callees = callTable[this];
    209212    callees_t::iterator iter;
    210     for(iter=callees->begin();iter!=callees->end();iter++){
     213    for(iter=callees->begin();iter!=callees->end();++iter){
    211214      (*iter).second->subjectKilled(this);
    212215    }
  • src/Patterns/Observer.hpp

    r6bc51d r57f5cf  
    3030class Observable;
    3131
     32/**
     33 * An Observer is notified by all Observed objects, when anything changes.
     34 *
     35 * If a simple change is done to an Object the Obervable will call the update() method
     36 * of all signed on observers, passing itself as a parameter for identification. The
     37 * Observers should then react to the changes and update themselves accordingly.
     38 *
     39 * If an observed Object is destroyed it will call the subjectKilled() method
     40 * of all signed on Observers, again passing itself as a parameter for identification.
     41 * The Observers should handle the destruction of an observed Object gracefully, i.e.
     42 * set themselves inactive, display something else, etc. There is no need
     43 * to sign of from the dying object, since this will be handled by the Observable destructor.
     44 */
    3245class Observer
    3346{
     
    3851
    3952protected:
     53  /**
     54   * This method is called upon changes of the Observable
     55   */
    4056  virtual void update(Observable *publisher)=0;
     57
     58  /**
     59   * This method is called when the observed object is destroyed.
     60   */
    4161  virtual void subjectKilled(Observable *publisher)=0;
    4262};
    4363
     64/**
     65 * An Observable implements all neccessary method for being observed.
     66 *
     67 * That is, it provides methods for signing on and of from an
     68 * Observable that can be used by any observer. The actual
     69 * observer-mechanism is handled at a central static place
     70 * to avoid memory issues when many observable are around but only few
     71 * are actually observed.
     72 */
    4473class Observable : public Observer {
    4574public:
     
    4776  virtual ~Observable();
    4877
     78  /**
     79   * Sign an Observer on to this Observable. The Observer will be notified
     80   * whenever something inside the Observable changes. The Observer can
     81   * assign itself a priority for the changes in the range of -20:+20.
     82   * The Observer with lower priority will be called before the others,
     83   * same as with Unix nice-levels. This can be used when an Object
     84   * contains other objects that observe it (derived values), and these objects have
     85   * to recalculate their states before the changes should be propageted to the
     86   * UI. A default priority of 0 should be fine in most cases, since there is
     87   * ussually no need to order the update sequence.
     88   */
    4989  virtual void signOn(Observer *target, int priority=0);
     90
     91  /**
     92   * Sign of a previously signed on Observer. After this no more
     93   * updates will be recieved from that observer.
     94   */
    5095  virtual void signOff(Observer *target);
    5196
     
    76121  // Structure for RAII-Style notification
    77122protected:
     123  /**
     124   * This structure implements the Observer-mechanism RAII-Idiom.
     125   * It triggers certain functions on creation and destruction so that
     126   * Observer mechanisms can be linked to scope block.
     127   */
    78128  class _Observable_protector {
    79129  public:
  • src/UIElements/Dialog.cpp

    r6bc51d r57f5cf  
    102102Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
    103103    Query(title),
    104     target(_target),
     104    tmp(0),
    105105    molecules(_molecules),
    106     tmp(0)
     106    target(_target)
     107
    107108{}
    108109
     
    116117
    117118Dialog::VectorQuery::VectorQuery(std::string title,Vector *_target,const double *const _cellSize,bool _check) :
    118   Query(title), target(_target), cellSize(_cellSize), check(_check)
     119  Query(title),
     120  cellSize(_cellSize),
     121  check(_check),
     122  target(_target)
    119123{
    120124tmp = new Vector();
  • src/UIElements/MainWindow.hpp

    r6bc51d r57f5cf  
    2525};
    2626
     27/**
     28 * The type of menuPopulators
     29 */
    2730typedef void (*MenuMaker)(Menu*,MoleculeListClass*, config*, periodentafel*);
    2831
     32/**
     33 * This contains all Functions that are used to create the menus.
     34 * Needs a specific funtion for each menu. All populators will be called
     35 * by the UIFactory upon creation of the main menu. Thus the actuall construction
     36 * of the Menus can be kept independent of the concrete type of UI that is being
     37 * built.
     38 */
    2939struct menuPopulaters{
    3040  MenuMaker MakeEditMoleculesMenu;
  • src/UIElements/TextDialog.cpp

    r6bc51d r57f5cf  
    114114bool TextDialog::VectorTextQuery::handle() {
    115115 tmp->AskPosition(cellSize,check);
     116 return true;
    116117}
  • src/UIElements/TextStatusIndicator.cpp

    r6bc51d r57f5cf  
    2727  Process *proc;
    2828  // we are only observing Processes
    29   if(proc=dynamic_cast<Process*>(subject)){
     29  if((proc=dynamic_cast<Process*>(subject))){
    3030    // see what kind of progress we have to display
    3131    if(proc->getMaxSteps()>0){
  • src/UIElements/UIFactory.hpp

    r6bc51d r57f5cf  
    1717
    1818struct menuPopulaters;
    19 
     19/**
     20 * Abstract Factory to create any kind of User interface object needed by the programm.
     21 *
     22 * The factory can be created and has to be set to a certain type upon creation. It will then
     23 * only create UIelements of that certain type, so that all UIElements match. This way different
     24 * UIs can be handled in a concise abstract way.
     25 */
    2026class UIFactory
    2127{
     
    2531  virtual ~UIFactory();
    2632
    27   // methods for creating UIElements
     33  /**
     34   * Produce some kind of main window, of whichever type was chosen when the factory was created
     35   */
    2836  virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *)=0;
     37
     38  /**
     39   * Produce a User Interaction Dialog, that can query values from the User.
     40   * Again the type is determined upon factory creation.
     41   */
    2942  virtual Dialog* makeDialog()=0;
    3043
     
    3750
    3851public:
     52  /**
     53   * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory
     54   */
    3955  static void makeUserInterface(InterfaceTypes type);
     56
     57  /**
     58   * get the previously created factory
     59   */
    4060  static UIFactory* get();
     61
     62  /**
     63   * Destroy the created factory.
     64   *
     65   * Make sure that all UIElements that were created by the factory are destroyed before calling this method.
     66   */
    4167  static void purgeInstance();
    4268};
  • src/Views/MethodStringView.cpp

    r6bc51d r57f5cf  
    77
    88#include "MethodStringView.hpp"
     9
     10using namespace std;
    911
    1012MethodStringView::MethodStringView(boost::function<string()> _displayMethod) :
  • src/Views/MethodStringView.hpp

    r6bc51d r57f5cf  
    1919{
    2020public:
    21   MethodStringView(boost::function<string()>);
     21  MethodStringView(boost::function<std::string()>);
    2222  virtual ~MethodStringView();
    2323
    24   virtual const string toString();
     24  virtual const std::string toString();
    2525
    2626private:
    27   boost::function<string()> displayMethod;
     27  boost::function<std::string()> displayMethod;
    2828};
    2929
  • src/Views/StreamStringView.cpp

    r6bc51d r57f5cf  
    77
    88#include <sstream>
     9#include <iostream>
    910
    1011#include "StreamStringView.hpp"
    1112
    12 StreamStringView::StreamStringView(boost::function<void(ofstream *)> _displayMethod) :
     13using namespace std;
     14
     15StreamStringView::StreamStringView(boost::function<void(ostream *)> _displayMethod) :
    1316StringView(),
    1417displayMethod(_displayMethod)
    15 {
    16   // TODO Auto-generated constructor stub
    17 
    18 }
     18{}
    1919
    2020StreamStringView::~StreamStringView()
    21 {
    22   // TODO Auto-generated destructor stub
    23 }
     21{}
    2422
    2523const string StreamStringView::toString() {
    2624  stringstream s;
    27   displayMethod((ofstream *)&s);
     25  displayMethod(dynamic_cast<ostream *>(&s));
    2826  return s.str();
    2927}
  • src/Views/StreamStringView.hpp

    r6bc51d r57f5cf  
    1010
    1111#include <boost/function.hpp>
     12#include <iostream>
    1213
    1314#include "Views/StringView.hpp"
     
    2425{
    2526public:
    26   StreamStringView(boost::function<void(ofstream *)>);
     27  StreamStringView(boost::function<void(std::ostream *)>);
    2728  virtual ~StreamStringView();
    2829
    29   virtual const string toString();
     30  virtual const std::string toString();
    3031
    3132private:
    32   boost::function<void(ofstream *)> displayMethod;
     33  boost::function<void(std::ostream *)> displayMethod;
    3334};
    3435
  • src/Views/StringView.hpp

    r6bc51d r57f5cf  
    1212#include "Views/View.hpp"
    1313
    14 using namespace std;
    15 
    1614/**
    1715 * View to show something as a string
     
    2624  virtual ~StringView();
    2725
    28   virtual const string toString()=0;
     26  virtual const std::string toString()=0;
    2927};
    3028
  • src/World.cpp

    r6bc51d r57f5cf  
    1212#include "periodentafel.hpp"
    1313#include "Descriptors/AtomDescriptor.hpp"
     14#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Descriptors/MoleculeDescriptor.hpp"
     16#include "Descriptors/MoleculeDescriptor_impl.hpp"
     17#include "Actions/ManipulateAtomsProcess.hpp"
    1418
    1519using namespace std;
     
    2024}
    2125
     26// Atoms
     27
    2228atom* World::getAtom(AtomDescriptor descriptor){
    2329  return descriptor.find();
     
    2834}
    2935
     36vector<atom*> World::getAllAtoms(){
     37  return getAllAtoms(AllAtoms());
     38}
     39
    3040int World::numAtoms(){
    3141  return atoms.size();
    3242}
    3343
     44// Molecules
     45
     46molecule *World::getMolecule(MoleculeDescriptor descriptor){
     47  return descriptor.find();
     48}
     49
     50std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){
     51  return descriptor.findAll();
     52}
     53
    3454int World::numMolecules(){
    3555  return molecules_deprecated->ListOfMolecules.size();
    3656}
    3757
     58/******************** Methods to change World state *********************/
     59
    3860molecule* World::createMolecule(){
    3961  OBSERVE;
    4062  molecule *mol = NULL;
    41   mol = new molecule(periode);
    42   molecules_deprecated->insert(mol);
    43   molecules.insert(mol);
     63  mol = NewMolecule();
     64  assert(!molecules.count(currMoleculeId));
     65  mol->setId(currMoleculeId++);
     66  // store the molecule by ID
     67  molecules[mol->getId()] = mol;
    4468  mol->signOn(this);
    4569  return mol;
    4670}
    4771
     72void World::destroyMolecule(molecule* mol){
     73  OBSERVE;
     74  destroyMolecule(mol->getId());
     75}
     76
     77void World::destroyMolecule(moleculeId_t id){
     78  OBSERVE;
     79  molecule *mol = molecules[id];
     80  assert(mol);
     81  DeleteMolecule(mol);
     82  molecules.erase(id);
     83}
     84
     85
     86atom *World::createAtom(){
     87  OBSERVE;
     88  atomId_t id = getNextAtomId();
     89  atom *res = NewAtom(id);
     90  res->setWorld(this);
     91  // store the atom by ID
     92  atoms[res->getId()] = res;
     93  return res;
     94}
     95
     96int World::registerAtom(atom *atom){
     97  OBSERVE;
     98  atomId_t id = getNextAtomId();
     99  atom->setId(id);
     100  atom->setWorld(this);
     101  atoms[atom->getId()] = atom;
     102  return atom->getId();
     103}
     104
     105void World::destroyAtom(atom* atom){
     106  OBSERVE;
     107  int id = atom->getId();
     108  destroyAtom(id);
     109}
     110
     111void World::destroyAtom(atomId_t id) {
     112  OBSERVE;
     113  atom *atom = atoms[id];
     114  assert(atom);
     115  DeleteAtom(atom);
     116  atoms.erase(id);
     117  releaseAtomId(id);
     118}
     119
     120bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){
     121  OBSERVE;
     122  // in case this call did not originate from inside the atom, we redirect it,
     123  // to also let it know that it has changed
     124  if(!target){
     125    target = atoms[oldId];
     126    assert(target && "Atom with that ID not found");
     127    return target->changeId(newId);
     128  }
     129  else{
     130    if(reserveAtomId(newId)){
     131      atoms.erase(oldId);
     132      atoms.insert(pair<atomId_t,atom*>(newId,target));
     133      return true;
     134    }
     135    else{
     136      return false;
     137    }
     138  }
     139}
     140
     141ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
     142  return new ManipulateAtomsProcess(op, descr,name,true);
     143}
     144
     145ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
     146  return manipulateAtoms(op,name,AllAtoms());
     147}
     148
     149/********************* Internal Change methods for double Callback and Observer mechanism ********/
     150
     151void World::doManipulate(ManipulateAtomsProcess *proc){
     152  proc->signOn(this);
     153  {
     154    OBSERVE;
     155    proc->doManipulate(this);
     156  }
     157  proc->signOff(this);
     158}
     159/******************************* IDManagement *****************************/
     160
     161atomId_t World::getNextAtomId(){
     162  // see if we can reuse some Id
     163  if(atomIdPool.empty()){
     164    return currAtomId++;
     165  }
     166  else{
     167    // we give out the first ID from the pool
     168    atomId_t id = *(atomIdPool.begin());
     169    atomIdPool.erase(id);
     170  }
     171}
     172
     173void World::releaseAtomId(atomId_t id){
     174  atomIdPool.insert(id);
     175  // defragmentation of the pool
     176  set<atomId_t>::reverse_iterator iter;
     177  // go through all Ids in the pool that lie immediately below the border
     178  while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){
     179    atomIdPool.erase(--currAtomId);
     180  }
     181}
     182
     183bool World::reserveAtomId(atomId_t id){
     184  if(id>=currAtomId ){
     185    // add all ids between the new one and current border as available
     186    for(atomId_t pos=currAtomId; pos<id; ++pos){
     187      atomIdPool.insert(pos);
     188    }
     189    currAtomId=id+1;
     190    return true;
     191  }
     192  else if(atomIdPool.count(id)){
     193    atomIdPool.erase(id);
     194    return true;
     195  }
     196  else{
     197    // this ID could not be reserved
     198    return false;
     199  }
     200}
     201/******************************* Iterators ********************************/
     202
     203/*
     204 * Actual Implementation of the iterators can be found in WorldIterators.cpp
     205 */
     206
     207World::AtomIterator World::getAtomIter(AtomDescriptor descr){
     208  return AtomIterator(descr,this);
     209}
     210
     211World::AtomSet::iterator World::atomEnd(){
     212  return atoms.end();
     213}
     214
     215World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){
     216  return MoleculeIterator(descr,this);
     217}
     218
     219World::MoleculeSet::iterator World::moleculeEnd(){
     220  return molecules.end();
     221}
    48222
    49223/******************************* Singleton Stuff **************************/
     
    53227boost::mutex World::worldLock;
    54228
    55 
    56 
    57229World::World() :
    58230    periode(new periodentafel),
    59     molecules_deprecated(new MoleculeListClass),
    60     dummyId(0)
     231    atoms(),
     232    currAtomId(0),
     233    molecules(),
     234    currMoleculeId(0),
     235    molecules_deprecated(new MoleculeListClass(this))
    61236{
    62237  molecules_deprecated->signOn(this);
     
    68243  delete molecules_deprecated;
    69244  delete periode;
     245  MoleculeSet::iterator molIter;
     246  for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
     247    DeleteMolecule((*molIter).second);
     248  }
     249  molecules.clear();
     250  AtomSet::iterator atIter;
     251  for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
     252    DeleteAtom((*atIter).second);
     253  }
     254  atoms.clear();
    70255}
    71256
     
    80265
    81266void World::destroy(){
    82   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    83   theWorld->destroyLegacy();
    84   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    85 
    86267  // boost supports RAII-Style locking, so we don't need to unlock
    87268  boost::mutex::scoped_lock guard(worldLock);
     
    91272
    92273World* World::reset(){
    93   // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise
    94   theWorld->destroyLegacy();
    95   //WARNING: at this point we have a small race condition, when sombody now tries to access the world.
    96 
    97274  World* oldWorld = 0;
    98275  {
     
    114291  // should see that it gets the updated new world
    115292  delete oldWorld;
     293  return theWorld;
    116294}
    117295
     
    121299  return molecules_deprecated;
    122300}
    123 
    124 // some legacy stuff to let the World know about items created outside
    125 void World::registerAtom(atom *theAtom){
    126   OBSERVE;
    127   atoms[dummyId++] = theAtom;
    128 }
    129 
    130 void World::destroyLegacy(){
    131   //delete molecules_deprecated;
    132 }
    133 
    134 void World::unregisterAtom(atom *theAtom){
    135   OBSERVE;
    136   atoms.erase(theAtom->getId());
    137 }
  • src/World.hpp

    r6bc51d r57f5cf  
    99#define WORLD_HPP_
    1010
    11 #include <boost/thread.hpp>
     11#include <string>
    1212#include <map>
    1313#include <vector>
    1414#include <set>
    15 
     15#include <boost/thread.hpp>
     16#include <boost/shared_ptr.hpp>
     17
     18#include "defs.hpp"
    1619#include "Patterns/Observer.hpp"
    1720#include "Patterns/Cacheable.hpp"
     
    2427class AtomDescriptor;
    2528class AtomDescriptor_impl;
     29class MoleculeDescriptor;
     30class MoleculeDescriptor_impl;
     31class ManipulateAtomsProcess;
     32template<typename T>
     33class AtomsCalculation;
    2634
    2735class World : public Observable
    2836{
     37// necessary for coupling with descriptors
    2938friend class AtomDescriptor_impl;
     39friend class AtomDescriptor;
     40friend class MoleculeDescriptor_impl;
     41friend class MoleculeDescriptor;
     42
     43// Actions, calculations etc associated with the World
     44friend class ManipulateAtomsProcess;
     45template<typename> friend class AtomsCalculation;
    3046public:
     47  typedef std::map<atomId_t,atom*> AtomSet;
     48  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
    3149
    3250  /***** getter and setter *****/
    3351  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
     52  /**
     53   * returns the periodentafel for the world.
     54   */
    3455  periodentafel *&getPeriode();
     56
     57  /**
     58   * returns the first atom that matches a given descriptor.
     59   * Do not rely on ordering for descriptors that match more than one atom.
     60   */
    3561  atom* getAtom(AtomDescriptor descriptor);
     62
     63  /**
     64   * returns a vector containing all atoms that match a given descriptor
     65   */
    3666  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     67  std::vector<atom*> getAllAtoms();
     68
     69  /**
     70   * returns a calculation that calls a given function on all atoms matching a descriptor.
     71   * the calculation is not called at this point and can be used as an action, i.e. be stored in
     72   * menus, be kept around for later use etc.
     73   */
     74  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
     75  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
     76
     77  /**
     78   * get the number of atoms in the World
     79   */
    3780  int numAtoms();
     81
     82  /**
     83   * returns the first molecule that matches a given descriptor.
     84   * Do not rely on ordering for descriptors that match more than one molecule.
     85   */
     86  molecule *getMolecule(MoleculeDescriptor descriptor);
     87
     88  /**
     89   * returns a vector containing all molecules that match a given descriptor
     90   */
     91  std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor);
     92
     93  /**
     94   * get the number of molecules in the World
     95   */
    3896  int numMolecules();
    3997
    4098  /***** Methods to work with the World *****/
     99
     100  /**
     101   * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
     102   * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
     103   */
    41104  molecule *createMolecule();
     105
     106  void destroyMolecule(molecule*);
     107  void destroyMolecule(moleculeId_t);
     108
     109  /**
     110   * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
     111   * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
     112   */
     113  atom *createAtom();
     114
     115  /**
     116   * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
     117   * Do not re-register Atoms already known to the world since this will cause double-frees.
     118   */
     119  int registerAtom(atom*);
     120
     121  /**
     122     * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     123     * atom directly since this will leave the pointer inside the world.
     124   */
     125  void destroyAtom(atom*);
     126
     127  /**
     128   * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     129   * atom directly since this will leave the pointer inside the world.
     130   */
     131  void destroyAtom(atomId_t);
     132
     133  /**
     134   * used when changing an atom Id.
     135   * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
     136   *
     137   * Return value indicates wether the change could be done or not.
     138   */
     139  bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0);
     140
     141  /**
     142   * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
     143   * called at this time, so it can be passed around, stored inside menuItems etc.
     144   */
     145  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
     146  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
     147
     148protected:
     149  /**** Iterators to use internal data structures */
     150
     151  // Atoms
     152
     153  class AtomIterator {
     154  public:
     155    AtomIterator();
     156    AtomIterator(AtomDescriptor, World*);
     157    AtomIterator(const AtomIterator&);
     158    AtomIterator& operator=(const AtomIterator&);
     159    AtomIterator& operator++();     // prefix
     160    AtomIterator  operator++(int);  // postfix with dummy parameter
     161    bool operator==(const AtomIterator&);
     162    bool operator==(const AtomSet::iterator&);
     163    bool operator!=(const AtomIterator&);
     164    bool operator!=(const AtomSet::iterator&);
     165    atom* operator*();
     166
     167    int getCount();
     168  protected:
     169    void advanceState();
     170    AtomSet::iterator state;
     171    boost::shared_ptr<AtomDescriptor_impl>  descr;
     172    int index;
     173
     174    World* world;
     175  };
     176
     177  /**
     178   * returns an iterator over all Atoms matching a given descriptor.
     179   * used for internal purposes, like AtomProcesses and AtomCalculations.
     180   */
     181  AtomIterator getAtomIter(AtomDescriptor descr);
     182
     183  /**
     184   * returns an iterator to the end of the AtomSet. Due to overloading this iterator
     185   * can be compared to iterators produced by getAtomIter (see the mis-matching types).
     186   * Thus it can be used to detect when such an iterator is at the end of the list.
     187   * used for internal purposes, like AtomProcesses and AtomCalculations.
     188   */
     189  AtomSet::iterator atomEnd();
     190
     191  // Molecules
     192
     193  class MoleculeIterator {
     194  public:
     195    MoleculeIterator();
     196    MoleculeIterator(MoleculeDescriptor, World*);
     197    MoleculeIterator(const MoleculeIterator&);
     198    MoleculeIterator& operator=(const MoleculeIterator&);
     199    MoleculeIterator& operator++();     // prefix
     200    MoleculeIterator  operator++(int);  // postfix with dummy parameter
     201    bool operator==(const MoleculeIterator&);
     202    bool operator==(const MoleculeSet::iterator&);
     203    bool operator!=(const MoleculeIterator&);
     204    bool operator!=(const MoleculeSet::iterator&);
     205    molecule* operator*();
     206
     207    int getCount();
     208  protected:
     209    void advanceState();
     210    MoleculeSet::iterator state;
     211    boost::shared_ptr<MoleculeDescriptor_impl>  descr;
     212    int index;
     213
     214    World* world;
     215  };
     216
     217  /**
     218   * returns an iterator over all Molecules matching a given descriptor.
     219   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     220   */
     221  MoleculeIterator getMoleculeIter(MoleculeDescriptor descr);
     222
     223  /**
     224   * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator
     225   * can be compared to iterators produced by getMoleculeIter (see the mis-matching types).
     226   * Thus it can be used to detect when such an iterator is at the end of the list.
     227   * used for internal purposes, like MoleculeProcesses and MoleculeCalculations.
     228   */
     229  MoleculeSet::iterator moleculeEnd();
     230
     231
     232  /******* Internal manipulation routines for double callback and Observer mechanism ******/
     233  void doManipulate(ManipulateAtomsProcess *);
     234
    42235private:
     236
     237  atomId_t getNextAtomId();
     238  void releaseAtomId(atomId_t);
     239  bool reserveAtomId(atomId_t);
     240
    43241  periodentafel *periode;
    44   std::map<int,atom*> atoms;
    45   std::set<molecule*> molecules;
     242  AtomSet atoms;
     243  std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId
     244  atomId_t currAtomId; //!< stores the next available Id for atoms
     245  MoleculeSet molecules;
     246  moleculeId_t currMoleculeId;
    46247
    47248
    48249  /***** singleton Stuff *****/
    49250public:
     251
     252  /**
     253   * get the currently active instance of the World.
     254   */
    50255  static World* get();
     256
     257  /**
     258   * destroy the currently active instance of the World.
     259   */
    51260  static void destroy();
     261
     262  /**
     263   * destroy the currently active instance of the World and immidiately
     264   * create a new one. Use this to reset while somebody is still Observing
     265   * the world and should reset the observed instance. All observers will be
     266   * sent the subjectKille() message from the old world.
     267   */
    52268  static World* reset();
    53269
    54270private:
     271  /**
     272   * private constructor to ensure creation of the world using
     273   * the singleton pattern.
     274   */
    55275  World();
     276
     277  /**
     278   * private destructor to ensure destruction of the world using the
     279   * singleton pattern.
     280   */
    56281  virtual ~World();
    57282
     
    68293  MoleculeListClass *&getMolecules();
    69294
    70   // functions used for the WorldContent template mechanism
    71   void registerAtom(atom *theAtom);
    72   void unregisterAtom(atom *theAtom);
    73295private:
    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 
    79296  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;
    86297};
    87298
  • src/atom.cpp

    r6bc51d r57f5cf  
    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
     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
     308int 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

    r6bc51d r57f5cf  
    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(atomId_t);
     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 bool changeId(atomId_t newId);
     83
     84  /**
     85   * this function sets the Id without notifying the world. Only use it, if the world has already
     86   * gotten an ID for this Atom.
     87   */
     88   virtual void setId(atomId_t);
     89
     90  protected:
     91    /**
     92     * Protected constructor to ensure construction of atoms through the world.
     93     * see World::createAtom()
     94     */
     95    atom();
     96
     97    /**
     98     * Protected copy-constructor to ensure construction of atoms by cloning.
     99     * see atom::clone()
     100     */
     101    atom(class atom *pointer);
     102
     103    /**
     104     * Protected destructor to ensure destruction of atoms through the world.
     105     * see World::destroyAtom()
     106     */
     107    virtual ~atom();
    69108  private:
     109    World* world;
     110    atomId_t id;
    70111};
    71112
     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::createAtom() instead.
     117 */
     118atom* NewAtom(atomId_t _id);
     119
     120/**
     121* internal method used by the world. Do not use if you don't know what you are doing.
     122 * You might get burned...
     123 * Use World::destroyAtom() instead.
     124 */
     125void  DeleteAtom(atom*);
     126
     127
    72128#endif /* ATOM_HPP_ */
  • src/atom_atominfo.cpp

    r6bc51d r57f5cf  
    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

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

    r6bc51d r57f5cf  
    1313ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {};
    1414
     15ParticleInfo::ParticleInfo(ParticleInfo *pointer) :
     16    nr(pointer->nr),
     17    Name(pointer->Name)
     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

    r6bc51d r57f5cf  
    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

    r6bc51d r57f5cf  
    44 */
    55
     6#include "World.hpp"
    67#include "atom.hpp"
    78#include "bond.hpp"
     
    800801{
    801802        Info FunctionInfo(__func__);
    802   molecule *Filling = new molecule(filler->elemente);
     803  molecule *Filling = World::get()->createMolecule();
    803804  Vector CurrentPosition;
    804805  int N[NDIM];
     
    887888            Walker = Walker->next;
    888889            // copy atom ...
    889             CopyAtoms[Walker->nr] = new atom(Walker);
     890            CopyAtoms[Walker->nr] = Walker->clone();
    890891
    891892            // create atomic random translation vector ...
     
    964965  bool freeLC = false;
    965966  bool status = false;
    966   CandidateForTesselation *baseline = NULL;
     967  CandidateForTesselation *baseline=0;
    967968  LineMap::iterator testline;
    968969  bool OneLoopWithoutSuccessFlag = true;  // marks whether we went once through all baselines without finding any without two triangles
  • src/builder.cpp

    r6bc51d r57f5cf  
    14321432     }
    14331433     if (mol == NULL) {
    1434        mol = new molecule(periode);
     1434       mol = World::get()->createMolecule();
    14351435       mol->ActiveFlag = true;
    14361436       if (ConfigFileName != NULL)
     
    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)
     
    16341634                Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    16351635                // construct water molecule
    1636                 molecule *filler = new molecule(periode);
     1636                molecule *filler = World::get()->createMolecule();
    16371637                molecule *Filling = NULL;
    16381638                atom *second = NULL, *third = 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.);
     
    16641664                  molecules->insert(Filling);
    16651665                }
    1666                 delete(filler);
     1666                World::get()->destroyMolecule(filler);
    16671667                argptr+=6;
    16681668              }
     
    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
     
    22042204    if(World::get()->numMolecules() == 0){
    22052205        mol = World::get()->createMolecule();
     2206        World::get()->getMolecules()->insert(mol);
     2207        cout << "Molecule created" << endl;
    22062208        if(mol->cell_size[0] == 0.){
    22072209            Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
  • src/config.cpp

    r6bc51d r57f5cf  
    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;
     
    850851void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    851852{
    852   molecule *mol = new molecule(periode);
     853  molecule *mol = World::get()->createMolecule();
    853854  ifstream *file = new ifstream(filename);
    854855  if (file == NULL) {
     
    10881089void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList)
    10891090{
    1090   molecule *mol = new molecule(periode);
     1091  molecule *mol = World::get()->createMolecule();
    10911092  ifstream *file = new ifstream(filename);
    10921093  if (file == NULL) {
     
    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
     
    17871788  char filename[MAXSTRINGSIZE];
    17881789  ofstream output;
    1789   molecule *mol = new molecule(periode);
     1790  molecule *mol = World::get()->createMolecule();
    17901791  mol->SetNameFromFilename(ConfigFileName);
    17911792
     
    18981899  }
    18991900
    1900   delete(mol);
     1901  World::get()->destroyMolecule(mol);
    19011902};
    19021903
  • src/datacreator.cpp

    r6bc51d r57f5cf  
    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

    r6bc51d r57f5cf  
    3232
    3333enum Shading { white, lightgray, darkgray, black };  //!< color in Breadth-First-Search analysis
     34
     35// some types that can stay abstract
     36typedef unsigned int moleculeId_t;
     37typedef unsigned int atomId_t;
    3438
    3539//enum CutCyclicBond { KeepBond,  SaturateBond }; //!< Saturation scheme either atom- or bondwise
  • src/lists.hpp

    r6bc51d r57f5cf  
    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

    r6bc51d r57f5cf  
    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.),
    35   ActiveFlag(false), IndexNr(-1), last_atom(0), InternalPointer(start),
    36   formula(this,boost::bind(&molecule::calcFormula,this))
     36  ActiveFlag(false), IndexNr(-1),
     37  formula(this,boost::bind(&molecule::calcFormula,this)),
     38  last_atom(0),
     39  InternalPointer(start)
    3740{
    3841  // init atom chain list
     
    5255};
    5356
     57molecule *NewMolecule(){
     58  return new molecule(World::get()->getPeriode());
     59}
     60
    5461/** Destructor of class molecule.
    5562 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero.
     
    6067  delete(first);
    6168  delete(last);
    62   delete(end);
    63   delete(start);
    64 };
    65 
     69  end->getWorld()->destroyAtom(end);
     70  start->getWorld()->destroyAtom(start);
     71};
     72
     73
     74void DeleteMolecule(molecule *mol){
     75  delete mol;
     76}
    6677
    6778// getter and setter
     
    7384  OBSERVE;
    7485  strncpy(name,_name.c_str(),MAXSTRINGSIZE);
     86}
     87
     88moleculeId_t molecule::getId(){
     89  return id;
     90}
     91
     92void molecule::setId(moleculeId_t _id){
     93  id =_id;
    7594}
    7695
     
    135154  OBSERVE;
    136155  if (pointer != NULL) {
    137     atom *walker = new atom(pointer);
     156    atom *walker = pointer->clone();
    138157    walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name");
    139158    strcpy (walker->Name, pointer->Name);
     
    242261  switch(TopBond->BondDegree) {
    243262    case 1:
    244       FirstOtherAtom = new atom();    // new atom
     263      FirstOtherAtom = World::get()->createAtom();    // new atom
    245264      FirstOtherAtom->type = elemente->FindElement(1);  // element is Hydrogen
    246265      FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity
     
    299318
    300319      // create the two Hydrogens ...
    301       FirstOtherAtom = new atom();
    302       SecondOtherAtom = new atom();
     320      FirstOtherAtom = World::get()->createAtom();
     321      SecondOtherAtom = World::get()->createAtom();
    303322      FirstOtherAtom->type = elemente->FindElement(1);
    304323      SecondOtherAtom->type = elemente->FindElement(1);
     
    354373    case 3:
    355374      // 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();
     375      FirstOtherAtom = World::get()->createAtom();
     376      SecondOtherAtom = World::get()->createAtom();
     377      ThirdOtherAtom = World::get()->createAtom();
    359378      FirstOtherAtom->type = elemente->FindElement(1);
    360379      SecondOtherAtom->type = elemente->FindElement(1);
     
    475494    MDSteps++;
    476495  for(i=0;i<NumberOfAtoms;i++){
    477     Walker = new atom;
     496    Walker = World::get()->createAtom();
    478497    getline(xyzfile,line,'\n');
    479498    istringstream *item = new istringstream(line);
  • src/molecule.hpp

    r6bc51d r57f5cf  
    2929#include <string>
    3030
     31#include "defs.hpp"
    3132#include "graph.hpp"
    3233#include "stackclass.hpp"
     
    8586 */
    8687class molecule : public PointCloud , public Observable {
     88  friend molecule *NewMolecule();
     89  friend void DeleteMolecule(molecule *);
    8790  public:
    8891    double cell_size[6];//!< cell size
     
    108111  private:
    109112    Cacheable<string> formula;
     113    moleculeId_t id;
     114  protected:
     115    molecule(const periodentafel * const teil);
     116    virtual ~molecule();
     117
    110118
    111119public:
    112   molecule(const periodentafel * const teil);
    113   virtual ~molecule();
    114 
    115120  //getter and setter
    116121  const std::string getName();
     122  moleculeId_t getId();
     123  void setId(moleculeId_t);
    117124  void setName(const std::string);
    118125  const std::string getFormula();
    119126  std::string calcFormula();
     127
    120128
    121129  // re-definition of virtual functions from PointCloud
     
    321329};
    322330
     331molecule *NewMolecule();
     332void DeleteMolecule(molecule* mol);
     333
    323334#include "molecule_template.hpp"
    324335
     
    330341    int MaxIndex;
    331342
    332   MoleculeListClass();
     343  MoleculeListClass(World *world);
    333344  ~MoleculeListClass();
    334345
     
    339350  bool OutputConfigForListOfFragments(config *configuration, int *SortIndex);
    340351  int NumberOfActiveMolecules();
    341   void Enumerate(ofstream *out);
     352  void Enumerate(ostream *out);
    342353  void Output(ofstream *out);
    343354  void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration);
     
    363374
    364375  private:
     376  World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
    365377};
    366378
  • src/molecule_dynamics.cpp

    r6bc51d r57f5cf  
    66 */
    77
     8#include "World.hpp"
    89#include "atom.hpp"
    910#include "config.hpp"
     
    164165  double tmp = 0.;
    165166  double result = 0.;
    166 
    167167  // go through every atom
    168168  atom *Runner = NULL;
     
    486486  bool status = true;
    487487  int MaxSteps = configuration.MaxOuterStep;
    488   MoleculeListClass *MoleculePerStep = new MoleculeListClass();
     488  MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get());
    489489  // Get the Permutation Map by MinimiseConstrainedPotential
    490490  atom **PermutationMap = NULL;
     
    506506  Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
    507507  for (int step = 0; step <= MaxSteps; step++) {
    508     mol = new molecule(elemente);
     508    mol = World::get()->createMolecule();
    509509    MoleculePerStep->insert(mol);
    510510    Walker = start;
  • src/molecule_fragmentation.cpp

    r6bc51d r57f5cf  
    88#include <cstring>
    99
     10#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "bond.hpp"
     
    675676  //if (FragmentationToDo) {    // we should always store the fragments again as coordination might have changed slightly without changing bond structure
    676677  // allocate memory for the pointer array and transmorph graphs into full molecular fragments
    677   BondFragments = new MoleculeListClass();
     678  BondFragments = new MoleculeListClass(World::get());
    678679  int k=0;
    679680  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
     
    926927{
    927928  atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList");
    928   molecule *Leaf = new molecule(elemente);
     929  molecule *Leaf = World::get()->createMolecule();
    929930
    930931//  Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl;
  • src/molecule_template.hpp

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

    r6bc51d r57f5cf  
    77#include <cstring>
    88
     9#include "World.hpp"
    910#include "atom.hpp"
    1011#include "bond.hpp"
     
    2425/** Constructor for MoleculeListClass.
    2526 */
    26 MoleculeListClass::MoleculeListClass()
     27MoleculeListClass::MoleculeListClass(World *_world) :
     28  world(_world)
    2729{
    2830  // empty lists
     
    3840  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    3941    Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl;
    40     delete (*ListRunner);
     42    world->destroyMolecule(*ListRunner);
    4143  }
    4244  Log() << Verbose(4) << "Freeing ListOfMolecules." << endl;
     
    137139 * \param *out output stream
    138140 */
    139 void MoleculeListClass::Enumerate(ofstream *out)
     141void MoleculeListClass::Enumerate(ostream *out)
    140142{
    141143  element* Elemental = NULL;
     
    213215  // remove src
    214216  ListOfMolecules.remove(srcmol);
    215   delete(srcmol);
     217  World::get()->destroyMolecule(srcmol);
    216218  return true;
    217219};
     
    342344    Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
    343345    if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    344       CopyAtoms[Walker->nr] = new atom(Walker);
     346      CopyAtoms[Walker->nr] = Walker->clone();
    345347      mol->AddAtom(CopyAtoms[Walker->nr]);
    346348      nr++;
     
    748750void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
    749751{
    750   molecule *mol = new molecule(periode);
     752  molecule *mol = World::get()->createMolecule();
    751753  atom *Walker = NULL;
    752754  atom *Advancer = NULL;
     
    773775    }
    774776    // remove the molecule
    775     delete(*MolRunner);
     777    World::get()->destroyMolecule(*MolRunner);
    776778    ListOfMolecules.erase(MolRunner);
    777779  }
     
    795797  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    796798  for (int i=0;i<MolCount;i++) {
    797     molecules[i] = (molecule*) new molecule(mol->elemente);
     799    molecules[i] = World::get()->createMolecule();
    798800    molecules[i]->ActiveFlag = true;
    799801    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     
    893895  OBSERVE;
    894896  molecule *mol = NULL;
    895   mol = new molecule(periode);
     897  mol = World::get()->createMolecule();
    896898  insert(mol);
    897899};
     
    902904  char filename[MAXSTRINGSIZE];
    903905  Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
    904   mol = new molecule(periode);
     906  mol = World::get()->createMolecule();
    905907  do {
    906908    Log() << Verbose(0) << "Enter file name: ";
     
    960962      mol = *ListRunner;
    961963      ListOfMolecules.erase(ListRunner);
    962       delete(mol);
     964      World::get()->destroyMolecule(mol);
    963965      break;
    964966    }
     
    10071009  // remove the leaf itself
    10081010  if (Leaf != NULL) {
    1009     delete (Leaf);
     1011    World::get()->destroyMolecule(Leaf);
    10101012    Leaf = NULL;
    10111013  }
  • src/tesselationhelpers.cpp

    r6bc51d r57f5cf  
    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/AnalysisCorrelationToPointUnitTest.cpp

    r6bc51d r57f5cf  
    1717#include "AnalysisCorrelationToPointUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5657
    5758  // construct periodentafel
    58   tafel = new periodentafel;
     59  tafel = World::get()->getPeriode();
    5960  tafel->AddElement(hydrogen);
    6061
    6162  // construct molecule (tetraeder of hydrogens)
    62   TestMolecule = new molecule(tafel);
    63   Walker = new atom();
     63  TestMolecule = World::get()->createMolecule();
     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. );
     
    8182  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8283
    83   TestList = new MoleculeListClass;
     84  TestList = World::get()->getMolecules();
    8485  TestMolecule->ActiveFlag = true;
    8586  TestList->insert(TestMolecule);
     
    102103    delete(binmap);
    103104
    104   // remove
    105   delete(TestList);
    106   // note that all the atoms are cleaned by TestMolecule
    107105  delete(point);
    108   delete(tafel);
    109   // note that element is cleaned by periodentafel
    110106  World::destroy();
    111107  MemoryUsageObserver::purgeInstance();
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    r6bc51d r57f5cf  
    1717#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    6061
    6162  // construct periodentafel
    62   tafel = new periodentafel;
     63  tafel = World::get()->getPeriode();
    6364  tafel->AddElement(hydrogen);
    6465  tafel->AddElement(carbon);
    6566
    6667  // construct molecule (tetraeder of hydrogens) base
    67   TestMolecule = new molecule(tafel);
    68   Walker = new atom();
     68  TestMolecule = World::get()->createMolecule();
     69  Walker = World::get()->createAtom();
    6970  Walker->type = hydrogen;
    7071  Walker->node->Init(1., 0., 1. );
    7172  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     73  Walker = World::get()->createAtom();
    7374  Walker->type = hydrogen;
    7475  Walker->node->Init(0., 1., 1. );
    7576  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     77  Walker = World::get()->createAtom();
    7778  Walker->type = hydrogen;
    7879  Walker->node->Init(1., 1., 0. );
    7980  TestMolecule->AddAtom(Walker);
    80   Walker = new atom();
     81  Walker = World::get()->createAtom();
    8182  Walker->type = hydrogen;
    8283  Walker->node->Init(0., 0., 0. );
     
    8687  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8788
    88   TestList = new MoleculeListClass;
     89  TestList = World::get()->getMolecules();
    8990  TestMolecule->ActiveFlag = true;
    9091  TestList->insert(TestMolecule);
     
    99100
    100101  // add outer atoms
    101   Walker = new atom();
     102  Walker = World::get()->createAtom();
    102103  Walker->type = carbon;
    103104  Walker->node->Init(4., 0., 4. );
    104105  TestMolecule->AddAtom(Walker);
    105   Walker = new atom();
     106  Walker = World::get()->createAtom();
    106107  Walker->type = carbon;
    107108  Walker->node->Init(0., 4., 4. );
    108109  TestMolecule->AddAtom(Walker);
    109   Walker = new atom();
     110  Walker = World::get()->createAtom();
    110111  Walker->type = carbon;
    111112  Walker->node->Init(4., 4., 0. );
    112113  TestMolecule->AddAtom(Walker);
    113114  // add inner atoms
    114   Walker = new atom();
     115  Walker = World::get()->createAtom();
    115116  Walker->type = carbon;
    116117  Walker->node->Init(0.5, 0.5, 0.5 );
     
    131132    delete(binmap);
    132133
    133   // remove
    134   delete(TestList);
    135134  delete(Surface);
    136135  // note that all the atoms are cleaned by TestMolecule
    137136  delete(LC);
    138   delete(tafel);
    139   // note that element is cleaned by periodentafel
    140137  World::destroy();
    141138  MemoryUsageObserver::purgeInstance();
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    r6bc51d r57f5cf  
    1717#include "AnalysisPairCorrelationUnitTest.hpp"
    1818
     19#include "World.hpp"
    1920#include "atom.hpp"
    2021#include "boundary.hpp"
     
    5556
    5657  // construct periodentafel
    57   tafel = new periodentafel;
     58  tafel = World::get()->getPeriode();
    5859  tafel->AddElement(hydrogen);
    5960
    6061  // construct molecule (tetraeder of hydrogens)
    61   TestMolecule = new molecule(tafel);
    62   Walker = new atom();
     62  TestMolecule = World::get()->createMolecule();
     63  Walker = World::get()->createAtom();
    6364  Walker->type = hydrogen;
    6465  Walker->node->Init(1., 0., 1. );
    6566  TestMolecule->AddAtom(Walker);
    66   Walker = new atom();
     67  Walker = World::get()->createAtom();
    6768  Walker->type = hydrogen;
    6869  Walker->node->Init(0., 1., 1. );
    6970  TestMolecule->AddAtom(Walker);
    70   Walker = new atom();
     71  Walker = World::get()->createAtom();
    7172  Walker->type = hydrogen;
    7273  Walker->node->Init(1., 1., 0. );
    7374  TestMolecule->AddAtom(Walker);
    74   Walker = new atom();
     75  Walker = World::get()->createAtom();
    7576  Walker->type = hydrogen;
    7677  Walker->node->Init(0., 0., 0. );
     
    8081  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8182
    82   TestList = new MoleculeListClass;
     83  TestList = World::get()->getMolecules();
    8384  TestMolecule->ActiveFlag = true;
    8485  TestList->insert(TestMolecule);
     
    9899    delete(binmap);
    99100
    100   // remove
    101   delete(TestList);
    102101  // note that all the atoms are cleaned by TestMolecule
    103   delete(tafel);
    104   // note that element is cleaned by periodentafel
    105102  World::destroy();
    106103  MemoryUsageObserver::purgeInstance();
  • src/unittests/DescriptorUnittest.cpp

    r6bc51d r57f5cf  
    2727CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
    2828
    29 // some stubs
    30 class AtomStub : public atom {
    31 public:
    32   AtomStub(int _id) :
    33   atom(),
    34   id(_id)
    35   {}
    36 
    37   virtual int getId(){
    38     return id;
    39   }
    40 
    41 private:
    42   int id;
    43 };
    44 
    45 
    4629// set up and tear down
    4730void DescriptorUnittest::setUp(){
    4831  World::get();
    4932  for(int i=0;i<ATOM_COUNT;++i){
    50     atoms[i]= new AtomStub(i);
     33    atoms[i]= World::get()->createAtom();
     34    atomIds[i] = atoms[i]->getId();
    5135  }
    5236}
    5337void DescriptorUnittest::tearDown(){
    5438  World::destroy();
    55   for(int i=0;i<ATOM_COUNT;++i){
    56     delete atoms[i];
    57   }
    5839}
    5940
    6041// some helper functions
    61 bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
    62   for(int i=min;i<max;++i){
    63     if(!excluded.count(i)){
     42bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){
     43  for(int i=0;i<ATOM_COUNT;++i){
     44    int id = ids[i];
     45    if(!excluded.count(id)){
    6446      std::vector<atom*>::iterator iter;
    6547      bool res=false;
    6648      for(iter=atoms.begin();iter!=atoms.end();++iter){
    67         res |= (*iter)->getId() == i;
     49        res |= (*iter)->getId() == id;
    6850      }
    6951      if(!res) {
    70         cout << "Atom " << i << " missing in returned list" << endl;
     52        cout << "Atom " << id << " missing in returned list" << endl;
    7153        return false;
    7254      }
     
    9173void DescriptorUnittest::AtomBaseSetsTest(){
    9274  std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
    93   CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT));
     75  CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,atomIds));
    9476  CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
    9577
     
    10082  // test Atoms from boundaries and middle of the set
    10183  atom* testAtom;
    102   testAtom = World::get()->getAtom(AtomById(0));
    103   CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId());
    104   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2));
    105   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId());
    106   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1));
    107   CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId());
     84  testAtom = World::get()->getAtom(AtomById(atomIds[0]));
     85  CPPUNIT_ASSERT(testAtom);
     86  CPPUNIT_ASSERT_EQUAL( atomIds[0], testAtom->getId());
     87  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT/2]));
     88  CPPUNIT_ASSERT(testAtom);
     89  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtom->getId());
     90  testAtom = World::get()->getAtom(AtomById(atomIds[ATOM_COUNT-1]));
     91  CPPUNIT_ASSERT(testAtom);
     92  CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT-1], testAtom->getId());
    10893
     94  // find some ID that has not been created
     95  int outsideId =-1;
     96  bool res = false;
     97  while(!res) {
     98    ++outsideId;
     99    res = true;
     100    for(int i = 0; i < ATOM_COUNT; ++i){
     101      res &= atomIds[i]!=outsideId;
     102    }
     103  }
    109104  // test from outside of set
    110   testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
     105  testAtom = World::get()->getAtom(AtomById(outsideId));
    111106  CPPUNIT_ASSERT(!testAtom);
    112107}
     
    115110  {
    116111    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
    117     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     112    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    118113    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    119114  }
     
    121116  {
    122117    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
    123     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     118    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    124119    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    125120  }
     
    142137  {
    143138    std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
    144     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
     139    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds));
    145140    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    146141  }
     
    148143  // exclude and include some atoms
    149144  {
    150     std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2)));
     145    std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2])));
    151146    std::set<int> excluded;
    152     excluded.insert(ATOM_COUNT/2);
    153     CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded));
     147    excluded.insert(atomIds[ATOM_COUNT/2]);
     148    CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,atomIds,excluded));
    154149    CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
    155150    CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
     
    157152
    158153  {
    159     std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2)));
     154    std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(atomIds[ATOM_COUNT/2])));
    160155    CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
    161     CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());
     156    CPPUNIT_ASSERT_EQUAL( atomIds[ATOM_COUNT/2], testAtoms[0]->getId());
    162157  }
    163158}
  • src/unittests/DescriptorUnittest.hpp

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

    r6bc51d r57f5cf  
    3131  DescriptorUnittest \
    3232  MatrixUnitTest \
     33  manipulateAtomsTest \
     34  atomsCalculationTest \
    3335  ${MENUTESTS} 
    3436   
     
    6163  tesselation_insideoutsideunittest.cpp \
    6264  vectorunittest.cpp \
    63   ActionSequenceTest.cpp \
    6465  ObserverTest.cpp \
    6566  CacheableTest.cpp \
    6667  DescriptorUnittest.cpp \
    67   MatrixUnitTest.cpp   
     68  MatrixUnitTest.cpp \
     69  manipulateAtomsTest.cpp \
     70  atomsCalculationTest.cpp \
     71  ActionSequenceTest.cpp
    6872
    6973TESTHEADERS = \
     
    145149MatrixUnitTest_LDADD = ${ALLLIBS}
    146150
     151manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
     152manipulateAtomsTest_LDADD = ${ALLLIBS}
     153
     154atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     155atomsCalculationTest_LDADD = ${ALLLIBS}
     156
    147157TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    148158TestRunner_LDADD = ${ALLLIBS}
  • src/unittests/analysisbondsunittest.cpp

    r6bc51d r57f5cf  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "analysis_bonds.hpp"
    1920#include "analysisbondsunittest.hpp"
     
    6061
    6162  // construct periodentafel
    62   tafel = new periodentafel;
     63  tafel = World::get()->getPeriode();
    6364  tafel->AddElement(hydrogen);
    6465  tafel->AddElement(carbon);
    6566
    6667  // construct molecule (tetraeder of hydrogens)
    67   TestMolecule = new molecule(tafel);
    68   Walker = new atom();
     68  TestMolecule = World::get()->createMolecule();
     69  Walker = World::get()->createAtom();
    6970  Walker->type = hydrogen;
    7071  Walker->node->Init(1.5, 0., 1.5 );
    7172  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     73  Walker = World::get()->createAtom();
    7374  Walker->type = hydrogen;
    7475  Walker->node->Init(0., 1.5, 1.5 );
    7576  TestMolecule->AddAtom(Walker);
    76   Walker = new atom();
     77  Walker = World::get()->createAtom();
    7778  Walker->type = hydrogen;
    7879  Walker->node->Init(1.5, 1.5, 0. );
    7980  TestMolecule->AddAtom(Walker);
    80   Walker = new atom();
     81  Walker = World::get()->createAtom();
    8182  Walker->type = hydrogen;
    8283  Walker->node->Init(0., 0., 0. );
    8384  TestMolecule->AddAtom(Walker);
    84   Walker = new atom();
     85  Walker = World::get()->createAtom();
    8586  Walker->type = carbon;
    8687  Walker->node->Init(0.5, 0.5, 0.5 );
     
    116117
    117118  // remove molecule
    118   delete(TestMolecule);
     119  World::get()->destroyMolecule(TestMolecule);
    119120  // note that all the atoms are cleaned by TestMolecule
    120   delete(tafel);
    121   // note that element is cleaned by periodentafel
     121  World::destroy();
    122122};
    123123
  • src/unittests/bondgraphunittest.cpp

    r6bc51d r57f5cf  
    1616#include <cstring>
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5657
    5758  // construct periodentafel
    58   tafel = new periodentafel;
     59  tafel = World::get()->getPeriode();
    5960  tafel->AddElement(hydrogen);
    6061  tafel->AddElement(carbon);
    6162
    6263  // construct molecule (tetraeder of hydrogens)
    63   TestMolecule = new molecule(tafel);
    64   Walker = new atom();
     64  TestMolecule = World::get()->createMolecule();
     65  Walker = World::get()->createAtom();
    6566  Walker->type = hydrogen;
    6667  Walker->node->Init(1., 0., 1. );
    6768  TestMolecule->AddAtom(Walker);
    68   Walker = new atom();
     69  Walker = World::get()->createAtom();
    6970  Walker->type = hydrogen;
    7071  Walker->node->Init(0., 1., 1. );
    7172  TestMolecule->AddAtom(Walker);
    72   Walker = new atom();
     73  Walker = World::get()->createAtom();
    7374  Walker->type = hydrogen;
    7475  Walker->node->Init(1., 1., 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. );
     
    101102
    102103  // remove molecule
    103   delete(TestMolecule);
    104   // note that all the atoms are cleaned by TestMolecule
    105   delete(tafel);
    106   // note that element is cleaned by periodentafel
     104  World::get()->destroyMolecule(TestMolecule);
     105  // note that all the atoms, molecules, the tafel and the elements
     106  // are all cleaned when the world is destroyed
    107107  World::destroy();
    108108  MemoryUsageObserver::purgeInstance();
  • src/unittests/listofbondsunittest.cpp

    r6bc51d r57f5cf  
    1616#include "listofbondsunittest.hpp"
    1717
     18#include "World.hpp"
    1819#include "atom.hpp"
    1920#include "bond.hpp"
     
    5051
    5152  // construct periodentafel
    52   tafel = new periodentafel;
     53  tafel = World::get()->getPeriode();
    5354  tafel->AddElement(hydrogen);
    5455
    5556  // construct molecule (tetraeder of hydrogens)
    56   TestMolecule = new molecule(tafel);
    57   Walker = new atom();
     57  TestMolecule = World::get()->createMolecule();
     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. );
     
    8182{
    8283  // remove
    83   delete(TestMolecule);
    84   // note that all the atoms are cleaned by TestMolecule
    85   delete(tafel);
    86   // note that element is cleaned by periodentafel
     84  World::get()->destroyMolecule(TestMolecule);
     85  // note that all the atoms, molecules, the tafel and the elements
     86  // are all cleaned when the world is destroyed
    8787  World::destroy();
    8888  MemoryUsageObserver::purgeInstance();
     
    250250
    251251  // remove atom2
    252   delete(atom2);
     252  World::get()->destroyAtom(atom2);
    253253
    254254  // check bond if removed from other atom
Note: See TracChangeset for help on using the changeset viewer.