Changes in / [e6fdbe:a1510d]


Ignore:
Files:
16 added
54 edited

Legend:

Unmodified
Added
Removed
  • doc/Doxyfile

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

    re6fdbe ra1510d  
    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

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

    re6fdbe ra1510d  
    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(){
     
    6978  starts = false;
    7079}
     80
    7181void Process::step(){
    7282  OBSERVE;
    7383  currStep++;
    7484}
     85
    7586void Process::stop(){
    7687  stops = true;
  • src/Actions/Process.hpp

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

    re6fdbe ra1510d  
    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

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

    re6fdbe ra1510d  
     1#ifndef ATOMDESCRIPTOR_IMPL_HPP
     2#define ATOMDESCRIPTOR_IMPL_HPP
     3
    14#include "Descriptors/AtomDescriptor.hpp"
    25
     
    1114  virtual ~AtomDescriptor_impl();
    1215
    13   virtual bool predicate(std::pair<int,atom*>)=0;
     16  virtual bool predicate(std::pair<atomId_t,atom*>)=0;
    1417
    1518protected:
    1619  virtual atom* find();
    1720  virtual std::vector<atom*> findAll();
    18   std::map<int,atom*>& getAtoms();
     21  World::AtomSet& getAtoms();
    1922};
    2023
     
    2528  AtomAllDescriptor_impl();
    2629  virtual ~AtomAllDescriptor_impl();
    27   virtual bool predicate(std::pair<int,atom*>);
     30  virtual bool predicate(std::pair<atomId_t,atom*>);
    2831};
    2932
     
    3235  AtomNoneDescriptor_impl();
    3336  virtual ~AtomNoneDescriptor_impl();
    34   virtual bool predicate(std::pair<int,atom*>);
     37  virtual bool predicate(std::pair<atomId_t,atom*>);
    3538};
    3639
     
    4245  AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    4346  ~AtomAndDescriptor_impl();
    44   virtual bool predicate(std::pair<int,atom*>);
     47  virtual bool predicate(std::pair<atomId_t,atom*>);
    4548
    4649private:
     
    5457  AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs);
    5558  virtual ~AtomOrDescriptor_impl();
    56   virtual bool predicate(std::pair<int,atom*>);
     59  virtual bool predicate(std::pair<atomId_t,atom*>);
    5760
    5861private:
     
    6770  virtual ~AtomNotDescriptor_impl();
    6871
    69   virtual bool predicate(std::pair<int,atom*>);
     72  virtual bool predicate(std::pair<atomId_t,atom*>);
    7073
    7174private:
    7275  AtomDescriptor::impl_ptr arg;
    7376};
     77
     78#endif //ATOMDESCRIPTOR_IMPL_HPP
  • src/Descriptors/AtomIdDescriptor.cpp

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    88ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
    99
    10 ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ActionRegistry.cpp
    11 ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ActionRegistry.hpp
     10ACTIONSSOURCE = Actions/Action.cpp Actions/Process.cpp Actions/MethodAction.cpp Actions/ActionSequence.cpp Actions/MakroAction.cpp Actions/ErrorAction.cpp Actions/small_actions.cpp Actions/ManipulateAtomsProcess.cpp Actions/ActionRegistry.cpp
     11ACTIONSHEADER = Actions/Action.hpp Actions/Process.hpp Actions/Calculation.hpp Actions/Calculation_impl.hpp Actions/MethodAction.hpp Actions/ActionSequence.hpp Actions/MakroAction.hpp Actions/ErrorAction.hpp Actions/small_actions.hpp Actions/ManipulateAtomsProcess.hpp Actions/ActionRegistry.hpp
    1212
    1313PATTERNSOURCE = Patterns/Observer.cpp
     
    2929LEGACYHEADER = Legacy/oldmenu.hpp
    3030
    31 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp
    32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp
     31DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp
     32DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp
    3333
    34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp
     34SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp WorldIterators.cpp
    3535HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp
    3636
     
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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/UIElements/Dialog.cpp

    re6fdbe ra1510d  
    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/TextDialog.cpp

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

    re6fdbe ra1510d  
    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/Views/MethodStringView.cpp

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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    1212#include "periodentafel.hpp"
    1313#include "Descriptors/AtomDescriptor.hpp"
     14#include "Descriptors/AtomDescriptor_impl.hpp"
     15#include "Actions/ManipulateAtomsProcess.hpp"
    1416
    1517using namespace std;
     
    2830}
    2931
     32vector<atom*> World::getAllAtoms(){
     33  return getAllAtoms(AllAtoms());
     34}
     35
    3036int World::numAtoms(){
    3137  return atoms.size();
     
    3642}
    3743
     44/******************** Methods to change World state *********************/
     45
    3846molecule* World::createMolecule(){
    3947  OBSERVE;
    4048  molecule *mol = NULL;
    41   mol = new molecule(periode);
    42   molecules_deprecated->insert(mol);
    43   molecules.insert(mol);
     49  mol = NewMolecule();
     50  assert(!molecules.count(currMoleculeId));
     51  mol->setId(currMoleculeId++);
     52  // store the molecule by ID
     53  molecules[mol->getId()] = mol;
    4454  mol->signOn(this);
    4555  return mol;
    4656}
    4757
     58void World::destroyMolecule(molecule* mol){
     59  OBSERVE;
     60  destroyMolecule(mol->getId());
     61}
     62
     63void World::destroyMolecule(moleculeId_t id){
     64  OBSERVE;
     65  molecule *mol = molecules[id];
     66  assert(mol);
     67  DeleteMolecule(mol);
     68  molecules.erase(id);
     69}
     70
     71
     72atom *World::createAtom(){
     73  OBSERVE;
     74  atom *res = NewAtom();
     75  assert(!atoms.count(currAtomId));
     76  res->setId(currAtomId++);
     77  res->setWorld(this);
     78  // store the atom by ID
     79  atoms[res->getId()] = res;
     80  return res;
     81}
     82
     83int World::registerAtom(atom *atom){
     84  OBSERVE;
     85  assert(!atoms.count(currAtomId));
     86  atom->setId(currAtomId++);
     87  atom->setWorld(this);
     88  atoms[atom->getId()] = atom;
     89  return atom->getId();
     90}
     91
     92void World::destroyAtom(atom* atom){
     93  OBSERVE;
     94  int id = atom->getId();
     95  destroyAtom(id);
     96}
     97
     98void World::destroyAtom(atomId_t id) {
     99  OBSERVE;
     100  atom *atom = atoms[id];
     101  assert(atom);
     102  DeleteAtom(atom);
     103  atoms.erase(id);
     104}
     105
     106ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
     107  return new ManipulateAtomsProcess(op, descr,name,true);
     108}
     109
     110ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){
     111  return manipulateAtoms(op,name,AllAtoms());
     112}
     113
     114/********************* Internal Change methods for double Callback and Observer mechanism ********/
     115
     116void World::doManipulate(ManipulateAtomsProcess *proc){
     117  proc->signOn(this);
     118  {
     119    OBSERVE;
     120    proc->doManipulate(this);
     121  }
     122  proc->signOff(this);
     123}
     124
     125/******************************* Iterators ********************************/
     126
     127/*
     128 * Actual Implementation of the iterators can be found in WorldIterators.cpp
     129 */
     130
     131World::AtomIterator World::getAtomIter(AtomDescriptor descr){
     132  return AtomIterator(descr,this);
     133}
     134
     135World::AtomSet::iterator World::atomEnd(){
     136  return atoms.end();
     137}
    48138
    49139/******************************* Singleton Stuff **************************/
     
    53143boost::mutex World::worldLock;
    54144
    55 
    56 
    57145World::World() :
    58146    periode(new periodentafel),
    59     molecules_deprecated(new MoleculeListClass),
    60     dummyId(0)
     147    atoms(),
     148    currAtomId(0),
     149    molecules(),
     150    currMoleculeId(0),
     151    molecules_deprecated(new MoleculeListClass(this))
    61152{
    62153  molecules_deprecated->signOn(this);
     
    68159  delete molecules_deprecated;
    69160  delete periode;
     161  MoleculeSet::iterator molIter;
     162  for(molIter=molecules.begin();molIter!=molecules.end();++molIter){
     163    DeleteMolecule((*molIter).second);
     164  }
     165  molecules.clear();
     166  AtomSet::iterator atIter;
     167  for(atIter=atoms.begin();atIter!=atoms.end();++atIter){
     168    DeleteAtom((*atIter).second);
     169  }
     170  atoms.clear();
    70171}
    71172
     
    80181
    81182void 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 
    86183  // boost supports RAII-Style locking, so we don't need to unlock
    87184  boost::mutex::scoped_lock guard(worldLock);
     
    91188
    92189World* 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 
    97190  World* oldWorld = 0;
    98191  {
     
    114207  // should see that it gets the updated new world
    115208  delete oldWorld;
     209  return theWorld;
    116210}
    117211
     
    121215  return molecules_deprecated;
    122216}
    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

    re6fdbe ra1510d  
    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 ManipulateAtomsProcess;
     30template<typename T>
     31class AtomsCalculation;
    2632
    2733class World : public Observable
    2834{
     35// necessary for coupling with descriptors
    2936friend class AtomDescriptor_impl;
     37friend class AtomDescriptor;
     38
     39// Actions, calculations etc associated with the World
     40friend class ManipulateAtomsProcess;
     41template<typename> friend class AtomsCalculation;
    3042public:
     43  typedef std::map<atomId_t,atom*> AtomSet;
     44  typedef std::map<moleculeId_t,molecule*> MoleculeSet;
    3145
    3246  /***** getter and setter *****/
    3347  // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object
     48  /**
     49   * returns the periodentafel for the world.
     50   */
    3451  periodentafel *&getPeriode();
     52
     53  /**
     54   * returns the first atom that matches a given descriptor.
     55   * Do not rely on ordering for descriptors that match more than one atom.
     56   */
    3557  atom* getAtom(AtomDescriptor descriptor);
     58
     59  /**
     60   * returns a vector containing all atoms that match a given descriptor
     61   */
    3662  std::vector<atom*> getAllAtoms(AtomDescriptor descriptor);
     63  std::vector<atom*> getAllAtoms();
     64
     65  /**
     66   * returns a calculation that calls a given function on all atoms matching a descriptor.
     67   * the calculation is not called at this point and can be used as an action, i.e. be stored in
     68   * menus, be kept around for later use etc.
     69   */
     70  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor);
     71  template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string);
     72
     73  /**
     74   * get the number of atoms in the World
     75   */
    3776  int numAtoms();
     77
     78  /**
     79   * get the number of molecules in the World
     80   */
    3881  int numMolecules();
    3982
    4083  /***** Methods to work with the World *****/
     84
     85  /**
     86   * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique
     87   * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly.
     88   */
    4189  molecule *createMolecule();
     90
     91  void destroyMolecule(molecule*);
     92  void destroyMolecule(moleculeId_t);
     93
     94  /**
     95   * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores
     96   * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends.
     97   */
     98  atom *createAtom();
     99
     100  /**
     101   * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests.
     102   * Do not re-register Atoms already known to the world since this will cause double-frees.
     103   */
     104  int registerAtom(atom*);
     105
     106  /**
     107     * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     108     * atom directly since this will leave the pointer inside the world.
     109   */
     110  void destroyAtom(atom*);
     111
     112  /**
     113   * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on
     114   * atom directly since this will leave the pointer inside the world.
     115   */
     116  void destroyAtom(atomId_t);
     117
     118  /**
     119   * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not
     120   * called at this time, so it can be passed around, stored inside menuItems etc.
     121   */
     122  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor);
     123  ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string);
     124
     125protected:
     126  /**** Iterators to use internal data structures */
     127  class AtomIterator {
     128  public:
     129    AtomIterator();
     130    AtomIterator(AtomDescriptor, World*);
     131    AtomIterator(const AtomIterator&);
     132    AtomIterator& operator=(const AtomIterator&);
     133    AtomIterator& operator++();     // prefix
     134    AtomIterator  operator++(int);  // postfix with dummy parameter
     135    bool operator==(const AtomIterator&);
     136    bool operator==(const AtomSet::iterator&);
     137    bool operator!=(const AtomIterator&);
     138    bool operator!=(const AtomSet::iterator&);
     139    atom* operator*();
     140
     141    int getCount();
     142  protected:
     143    void advanceState();
     144    AtomSet::iterator state;
     145    boost::shared_ptr<AtomDescriptor_impl>  descr;
     146    int index;
     147
     148    World* world;
     149  };
     150
     151  /**
     152   * returns an iterator over all Atoms matching a given descriptor.
     153   * used for internal purposes, like AtomProcesses and AtomCalculations.
     154   */
     155  AtomIterator getAtomIter(AtomDescriptor descr);
     156
     157  /**
     158   * returns an iterator to the end of the AtomSet. Due to overloading this iterator
     159   * can be compared to iterators produced by getAtomIter (see the mis-matching types).
     160   * Thus it can be used to detect when such an iterator is at the end of the list.
     161   * used for internal purposes, like AtomProcesses and AtomCalculations.
     162   */
     163  AtomSet::iterator atomEnd();
     164
     165  /******* Internal manipulation routines for double callback and Observer mechanism ******/
     166  void doManipulate(ManipulateAtomsProcess *);
     167
    42168private:
    43169  periodentafel *periode;
    44   std::map<int,atom*> atoms;
    45   std::set<molecule*> molecules;
     170  AtomSet atoms;
     171  atomId_t currAtomId; //!< stores the next available Id for atoms
     172  MoleculeSet molecules;
     173  moleculeId_t currMoleculeId;
    46174
    47175
    48176  /***** singleton Stuff *****/
    49177public:
     178
     179  /**
     180   * get the currently active instance of the World.
     181   */
    50182  static World* get();
     183
     184  /**
     185   * destroy the currently active instance of the World.
     186   */
    51187  static void destroy();
     188
     189  /**
     190   * destroy the currently active instance of the World and immidiately
     191   * create a new one. Use this to reset while somebody is still Observing
     192   * the world and should reset the observed instance. All observers will be
     193   * sent the subjectKille() message from the old world.
     194   */
    52195  static World* reset();
    53196
    54197private:
     198  /**
     199   * private constructor to ensure creation of the world using
     200   * the singleton pattern.
     201   */
    55202  World();
     203
     204  /**
     205   * private destructor to ensure destruction of the world using the
     206   * singleton pattern.
     207   */
    56208  virtual ~World();
    57209
     
    68220  MoleculeListClass *&getMolecules();
    69221
    70   // functions used for the WorldContent template mechanism
    71   void registerAtom(atom *theAtom);
    72   void unregisterAtom(atom *theAtom);
    73222private:
    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 
    79223  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;
    86224};
    87225
  • src/atom.cpp

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

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

    re6fdbe ra1510d  
    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

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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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/moleculelist.cpp

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

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

    re6fdbe ra1510d  
    3030  CacheableTest \
    3131  DescriptorUnittest \
    32   ${MENUTESTS} 
    33    
     32  manipulateAtomsTest \
     33  atomsCalculationTest \
     34  ${MENUTESTS}
     35 
     36
     37     
    3438 
    3539check_PROGRAMS = $(TESTS)
     
    6064  tesselation_insideoutsideunittest.cpp \
    6165  vectorunittest.cpp \
    62   ActionSequenceTest.cpp \
    6366  ObserverTest.cpp \
    6467  CacheableTest.cpp \
    65   DescriptorUnittest.cpp
     68  DescriptorUnittest.cpp \
     69  manipulateAtomsTest.cpp \
     70  atomsCalculationTest.cpp \
     71  ActionSequenceTest.cpp
    6672
    6773TESTHEADERS = \
     
    140146DescriptorUnittest_LDADD = ${ALLLIBS}
    141147
     148manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp
     149manipulateAtomsTest_LDADD = ${ALLLIBS}
     150
     151atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp
     152atomsCalculationTest_LDADD = ${ALLLIBS}
     153
    142154TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    143155TestRunner_LDADD = ${ALLLIBS}
  • src/unittests/analysisbondsunittest.cpp

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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

    re6fdbe ra1510d  
    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.