Changes in / [e6fdbe:a1510d]
- Files:
-
- 16 added
- 54 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/Doxyfile
re6fdbe ra1510d 114 114 EXCLUDE = 115 115 EXCLUDE_SYMLINKS = NO 116 EXCLUDE_PATTERNS = 116 EXCLUDE_PATTERNS = */unittests/* \ 117 */test/* 117 118 EXAMPLE_PATH = 118 119 EXAMPLE_PATTERNS = * -
src/Actions/ActionRegistry.cpp
re6fdbe ra1510d 24 24 { 25 25 map<const string,Action*>::iterator iter; 26 for(iter=actionMap.begin();iter!=actionMap.end(); iter++) {26 for(iter=actionMap.begin();iter!=actionMap.end();++iter) { 27 27 delete iter->second; 28 actionMap.erase(iter);29 28 } 29 actionMap.clear(); 30 30 } 31 31 -
src/Actions/MakroAction.cpp
re6fdbe ra1510d 23 23 { 24 24 Action* action; 25 while( action=actions->removeLastAction()){25 while((action=actions->removeLastAction())){ 26 26 delete action; 27 27 } -
src/Actions/Process.cpp
re6fdbe ra1510d 13 13 Action(_name,_doRegister), 14 14 maxSteps(_maxSteps), 15 active(false), 15 16 starts(false), 16 stops(false), 17 active(false) 17 stops(false) 18 18 {} 19 19 … … 38 38 39 39 int Process::getCurrStep(){ 40 OBSERVE; 40 41 return currStep; 42 } 43 44 void Process::setCurrStep(int _currStep){ 45 currStep = _currStep; 41 46 } 42 47 … … 47 52 return 0; 48 53 } 54 49 55 int Process::getMaxSteps(){ 50 56 return maxSteps; 51 57 } 52 58 59 void Process::setMaxSteps(int _maxSteps){ 60 maxSteps = _maxSteps; 61 } 53 62 54 63 void Process::start(){ … … 69 78 starts = false; 70 79 } 80 71 81 void Process::step(){ 72 82 OBSERVE; 73 83 currStep++; 74 84 } 85 75 86 void Process::stop(){ 76 87 stops = true; -
src/Actions/Process.hpp
re6fdbe ra1510d 29 29 bool doesStop(); 30 30 int getCurrStep(); 31 void setCurrStep(int _currStep); 31 32 float getDoneRatio(); 32 33 int getMaxSteps(); 34 void setMaxSteps(int _maxSteps); 33 35 34 36 protected: -
src/Descriptors/AtomDescriptor.cpp
re6fdbe ra1510d 19 19 using namespace std; 20 20 21 typedef map<int,atom*> atoms_t; 22 typedef atoms_t::iterator atoms_iter_t; 21 typedef World::AtomSet::iterator atoms_iter_t; 23 22 24 23 /************************ Forwarding object **************************************/ … … 68 67 } 69 68 70 atoms_t& AtomDescriptor_impl::getAtoms(){69 World::AtomSet& AtomDescriptor_impl::getAtoms(){ 71 70 return World::get()->atoms; 72 71 } 73 72 74 73 atom* AtomDescriptor_impl::find() { 75 atoms_t atoms = getAtoms();74 World::AtomSet atoms = getAtoms(); 76 75 atoms_iter_t res = find_if(atoms.begin(),atoms.end(),boost::bind(&AtomDescriptor_impl::predicate,this,_1)); 77 76 return (res!=atoms.end())?((*res).second):0; … … 80 79 vector<atom*> AtomDescriptor_impl::findAll() { 81 80 vector<atom*> res; 82 atoms_t atoms = getAtoms();81 World::AtomSet atoms = getAtoms(); 83 82 atoms_iter_t iter; 84 83 for(iter=atoms.begin();iter!=atoms.end();++iter) { … … 98 97 {} 99 98 100 bool AtomAllDescriptor_impl::predicate(std::pair< int,atom*>){99 bool AtomAllDescriptor_impl::predicate(std::pair<atomId_t,atom*>){ 101 100 return true; 102 101 } … … 112 111 {} 113 112 114 bool AtomNoneDescriptor_impl::predicate(std::pair< int,atom*>){113 bool AtomNoneDescriptor_impl::predicate(std::pair<atomId_t,atom*>){ 115 114 return false; 116 115 } … … 130 129 {} 131 130 132 bool AtomAndDescriptor_impl::predicate(std::pair< int,atom*> atom){131 bool AtomAndDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){ 133 132 return lhs->predicate(atom) && rhs->predicate(atom); 134 133 } … … 146 145 } 147 146 148 bool AtomOrDescriptor_impl::predicate(std::pair< int,atom*> atom){147 bool AtomOrDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){ 149 148 return lhs->predicate(atom) || rhs->predicate(atom); 150 149 } … … 166 165 } 167 166 168 bool AtomNotDescriptor_impl::predicate(std::pair< int,atom*> atom){167 bool AtomNotDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom){ 169 168 return !(arg->predicate(atom)); 170 169 } -
src/Descriptors/AtomDescriptor.hpp
re6fdbe ra1510d 15 15 #include "World.hpp" 16 16 17 class World; 17 18 class atom; 18 19 … … 21 22 22 23 class AtomDescriptor { 24 // close coupling to the world to allow access 23 25 friend atom* World::getAtom(AtomDescriptor descriptor); 24 26 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor); 27 friend class World::AtomIterator; 25 28 26 29 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 1 4 #include "Descriptors/AtomDescriptor.hpp" 2 5 … … 11 14 virtual ~AtomDescriptor_impl(); 12 15 13 virtual bool predicate(std::pair< int,atom*>)=0;16 virtual bool predicate(std::pair<atomId_t,atom*>)=0; 14 17 15 18 protected: 16 19 virtual atom* find(); 17 20 virtual std::vector<atom*> findAll(); 18 std::map<int,atom*>& getAtoms();21 World::AtomSet& getAtoms(); 19 22 }; 20 23 … … 25 28 AtomAllDescriptor_impl(); 26 29 virtual ~AtomAllDescriptor_impl(); 27 virtual bool predicate(std::pair< int,atom*>);30 virtual bool predicate(std::pair<atomId_t,atom*>); 28 31 }; 29 32 … … 32 35 AtomNoneDescriptor_impl(); 33 36 virtual ~AtomNoneDescriptor_impl(); 34 virtual bool predicate(std::pair< int,atom*>);37 virtual bool predicate(std::pair<atomId_t,atom*>); 35 38 }; 36 39 … … 42 45 AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 43 46 ~AtomAndDescriptor_impl(); 44 virtual bool predicate(std::pair< int,atom*>);47 virtual bool predicate(std::pair<atomId_t,atom*>); 45 48 46 49 private: … … 54 57 AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 55 58 virtual ~AtomOrDescriptor_impl(); 56 virtual bool predicate(std::pair< int,atom*>);59 virtual bool predicate(std::pair<atomId_t,atom*>); 57 60 58 61 private: … … 67 70 virtual ~AtomNotDescriptor_impl(); 68 71 69 virtual bool predicate(std::pair< int,atom*>);72 virtual bool predicate(std::pair<atomId_t,atom*>); 70 73 71 74 private: 72 75 AtomDescriptor::impl_ptr arg; 73 76 }; 77 78 #endif //ATOMDESCRIPTOR_IMPL_HPP -
src/Descriptors/AtomIdDescriptor.cpp
re6fdbe ra1510d 14 14 15 15 16 AtomIdDescriptor_impl::AtomIdDescriptor_impl( int _id) :16 AtomIdDescriptor_impl::AtomIdDescriptor_impl(atomId_t _id) : 17 17 id(_id) 18 18 {} … … 21 21 {} 22 22 23 bool AtomIdDescriptor_impl::predicate(std::pair< int,atom*> atom) {24 return atom. second->getId()==id;23 bool AtomIdDescriptor_impl::predicate(std::pair<atomId_t,atom*> atom) { 24 return atom.first==id; 25 25 } 26 26 27 AtomDescriptor AtomById( int id){27 AtomDescriptor AtomById(atomId_t id){ 28 28 return AtomDescriptor(AtomDescriptor::impl_ptr(new AtomIdDescriptor_impl(id))); 29 29 } 30 30 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); 31 atom *AtomIdDescriptor_impl::find(){ 32 World::AtomSet atoms = getAtoms(); 33 World::AtomSet::iterator res = atoms.find(id); 39 34 return (res!=atoms.end())?((*res).second):0; 40 35 } 41 36 42 vector<atom*> AtomIdDescriptor ::findAll(){37 vector<atom*> AtomIdDescriptor_impl::findAll(){ 43 38 atom *res = find(); 44 39 return (res)?(vector<atom*>(1,res)):(vector<atom*>()); 45 40 } 46 47 #endif -
src/Descriptors/AtomIdDescriptor.hpp
re6fdbe ra1510d 9 9 #define ATOMIDDESCRIPTOR_HPP_ 10 10 11 #include "defs.hpp" 11 12 #include "Descriptors/AtomDescriptor.hpp" 12 13 13 AtomDescriptor AtomById( int id);14 AtomDescriptor AtomById(atomId_t id); 14 15 15 16 #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 2 4 #include "Descriptors/AtomDescriptor_impl.hpp" 3 5 … … 5 7 { 6 8 public: 7 AtomIdDescriptor_impl( int _id);9 AtomIdDescriptor_impl(atomId_t _id); 8 10 virtual ~AtomIdDescriptor_impl(); 9 11 10 bool predicate(std::pair< int,atom*> atom);12 bool predicate(std::pair<atomId_t,atom*> atom); 11 13 12 14 protected: 13 #if 0 14 atom *find(); 15 std::vector<atom*> findAll(); 16 #endif 15 virtual atom *find(); 16 virtual std::vector<atom*> findAll(); 17 17 private: 18 int id;18 atomId_t id; 19 19 }; 20 21 #endif //ATOMIDDESCRIPTOR_IMPL_HPP -
src/Legacy/oldmenu.cpp
re6fdbe ra1510d 9 9 #include "Legacy/oldmenu.hpp" 10 10 #include "analysis_correlation.hpp" 11 #include "World.hpp" 11 12 #include "atom.hpp" 12 13 #include "bond.hpp" … … 77 78 case 'a': // absolute coordinates of atom 78 79 Log() << Verbose(0) << "Enter absolute coordinates." << endl; 79 first = new atom;80 first = World::get()->createAtom(); 80 81 first->x.AskPosition(mol->cell_size, false); 81 82 first->type = periode->AskElement(); // give type … … 84 85 85 86 case 'b': // relative coordinates of atom wrt to reference point 86 first = new atom;87 first = World::get()->createAtom(); 87 88 valid = true; 88 89 do { … … 100 101 101 102 case 'c': // relative coordinates of atom wrt to already placed atom 102 first = new atom;103 first = World::get()->createAtom(); 103 104 valid = true; 104 105 do { … … 116 117 117 118 case 'd': // two atoms, two angles and a distance 118 first = new atom;119 first = World::get()->createAtom(); 119 120 valid = true; 120 121 do { … … 216 217 217 218 case 'e': // least square distance position to a set of atoms 218 first = new atom;219 first = World::get()->createAtom(); 219 220 atoms = new (Vector*[128]); 220 221 valid = true; … … 238 239 mol->AddAtom(first); // add to molecule 239 240 } else { 240 delete first;241 World::get()->destroyAtom(first); 241 242 Log() << Verbose(0) << "Please enter at least two vectors!\n"; 242 243 } … … 736 737 Log() << Verbose(0) << "New element by atomic number Z: "; 737 738 cin >> Z; 738 first-> type = periode->FindElement(Z);739 first->setType(Z); 739 740 Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl; 740 741 } … … 781 782 x.AddVector(&y); // per factor one cell width further 782 783 for (int k=count;k--;) { // go through every atom of the original cell 783 first = new atom(); // create a new body784 first = World::get()->createAtom(); // create a new body 784 785 first->x.CopyVector(vectors[k]); // use coordinate of original atom 785 786 first->x.AddVector(&x); // translate the coordinates … … 811 812 void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration) 812 813 { 813 atom *first = NULL;814 814 Vector x,y,z,n; // coordinates for absolute point in cell volume 815 int j, axis, count, faktor;816 815 char choice; // menu choice char 817 816 molecule *mol = NULL; 818 element **Elements;819 Vector **vectors;820 817 MoleculeLeafClass *Subgraphs = NULL; 821 818 … … 1092 1089 A++; 1093 1090 } 1094 delete(mol);1091 World::get()->destroyMolecule(mol); 1095 1092 }; 1096 1093 -
src/Makefile.am
re6fdbe ra1510d 8 8 ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp 9 9 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.cpp11 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.hpp10 ACTIONSSOURCE = 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 11 ACTIONSHEADER = 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 12 12 13 13 PATTERNSOURCE = Patterns/Observer.cpp … … 29 29 LEGACYHEADER = Legacy/oldmenu.hpp 30 30 31 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp 32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp 31 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp 32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp 33 33 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 l og.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.cpp34 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 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 35 35 HEADER = ${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 36 36 … … 41 41 bin_PROGRAMS = molecuilder joiner analyzer 42 42 molecuilderdir = ${bindir} 43 #libmolecuilder_a_CXXFLAGS = -DNO_CACHING44 43 libmolecuilder_a_SOURCES = ${SOURCE} ${HEADER} 45 44 libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER} 46 45 molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db 47 46 molecuilder_LDFLAGS = $(BOOST_LDFLAGS) 48 molecuilder_CXXFLAGS = $(BOOST_CPPFLAGS)49 #molecuilder_CXXFLAGS += -DNO_CACHING50 47 molecuilder_SOURCES = builder.cpp 51 48 molecuilder_LDADD = libmolecuilder.a libgslwrapper.a $(BOOST_LIB) ${BOOST_THREAD_LIB} -
src/Menu/DisplayMenuItem.cpp
re6fdbe ra1510d 21 21 22 22 DisplayMenuItem::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) 28 28 { 29 29 } 30 30 31 31 DisplayMenuItem::~DisplayMenuItem() 32 { 33 // TODO Auto-generated destructor stub 34 } 32 {} 35 33 36 34 -
src/Menu/TextMenu.cpp
re6fdbe ra1510d 18 18 */ 19 19 TextMenu::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) 26 26 { 27 27 } -
src/Patterns/Cacheable.hpp
re6fdbe ra1510d 43 43 Cacheable<T>::Cacheable(Observable *_owner, boost::function<T()> _recalcMethod) : 44 44 owner(_owner), 45 recalcMethod(_recalcMethod),46 45 valid(false), 47 canBeUsed(true) 46 canBeUsed(true), 47 recalcMethod(_recalcMethod) 48 48 { 49 49 // we sign on with the best(=lowest) priority, so cached values are recalculated before -
src/Patterns/Observer.cpp
re6fdbe ra1510d 108 108 callees_t *callees = callTable[this]; 109 109 callees_t::iterator iter; 110 for(iter=callees->begin();iter!=callees->end(); iter++){110 for(iter=callees->begin();iter!=callees->end();++iter){ 111 111 (*iter).second->update(this); 112 112 } … … 160 160 161 161 callees_t::iterator iter; 162 for(iter=callees->begin();iter!=callees->end(); iter++){162 for(iter=callees->begin();iter!=callees->end();++iter){ 163 163 res |= ((*iter).second == target); 164 164 } … … 177 177 callees_t::iterator deliter; 178 178 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 } 182 185 } 183 186 if(callees->empty()){ … … 208 211 callees_t *callees = callTable[this]; 209 212 callees_t::iterator iter; 210 for(iter=callees->begin();iter!=callees->end(); iter++){213 for(iter=callees->begin();iter!=callees->end();++iter){ 211 214 (*iter).second->subjectKilled(this); 212 215 } -
src/UIElements/Dialog.cpp
re6fdbe ra1510d 102 102 Dialog::MoleculeQuery::MoleculeQuery(string title, molecule **_target, MoleculeListClass *_molecules) : 103 103 Query(title), 104 t arget(_target),104 tmp(0), 105 105 molecules(_molecules), 106 tmp(0) 106 target(_target) 107 107 108 {} 108 109 … … 116 117 117 118 Dialog::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) 119 123 { 120 124 tmp = new Vector(); -
src/UIElements/TextDialog.cpp
re6fdbe ra1510d 114 114 bool TextDialog::VectorTextQuery::handle() { 115 115 tmp->AskPosition(cellSize,check); 116 return true; 116 117 } -
src/UIElements/TextStatusIndicator.cpp
re6fdbe ra1510d 27 27 Process *proc; 28 28 // we are only observing Processes 29 if( proc=dynamic_cast<Process*>(subject)){29 if((proc=dynamic_cast<Process*>(subject))){ 30 30 // see what kind of progress we have to display 31 31 if(proc->getMaxSteps()>0){ -
src/Views/MethodStringView.cpp
re6fdbe ra1510d 7 7 8 8 #include "MethodStringView.hpp" 9 10 using namespace std; 9 11 10 12 MethodStringView::MethodStringView(boost::function<string()> _displayMethod) : -
src/Views/MethodStringView.hpp
re6fdbe ra1510d 19 19 { 20 20 public: 21 MethodStringView(boost::function<st ring()>);21 MethodStringView(boost::function<std::string()>); 22 22 virtual ~MethodStringView(); 23 23 24 virtual const st ring toString();24 virtual const std::string toString(); 25 25 26 26 private: 27 boost::function<st ring()> displayMethod;27 boost::function<std::string()> displayMethod; 28 28 }; 29 29 -
src/Views/StreamStringView.cpp
re6fdbe ra1510d 7 7 8 8 #include <sstream> 9 #include <iostream> 9 10 10 11 #include "StreamStringView.hpp" 11 12 12 StreamStringView::StreamStringView(boost::function<void(ofstream *)> _displayMethod) : 13 using namespace std; 14 15 StreamStringView::StreamStringView(boost::function<void(ostream *)> _displayMethod) : 13 16 StringView(), 14 17 displayMethod(_displayMethod) 15 { 16 // TODO Auto-generated constructor stub 17 18 } 18 {} 19 19 20 20 StreamStringView::~StreamStringView() 21 { 22 // TODO Auto-generated destructor stub 23 } 21 {} 24 22 25 23 const string StreamStringView::toString() { 26 24 stringstream s; 27 displayMethod( (ofstream *)&s);25 displayMethod(dynamic_cast<ostream *>(&s)); 28 26 return s.str(); 29 27 } -
src/Views/StreamStringView.hpp
re6fdbe ra1510d 10 10 11 11 #include <boost/function.hpp> 12 #include <iostream> 12 13 13 14 #include "Views/StringView.hpp" … … 24 25 { 25 26 public: 26 StreamStringView(boost::function<void( ofstream *)>);27 StreamStringView(boost::function<void(std::ostream *)>); 27 28 virtual ~StreamStringView(); 28 29 29 virtual const st ring toString();30 virtual const std::string toString(); 30 31 31 32 private: 32 boost::function<void( ofstream *)> displayMethod;33 boost::function<void(std::ostream *)> displayMethod; 33 34 }; 34 35 -
src/Views/StringView.hpp
re6fdbe ra1510d 12 12 #include "Views/View.hpp" 13 13 14 using namespace std;15 16 14 /** 17 15 * View to show something as a string … … 26 24 virtual ~StringView(); 27 25 28 virtual const st ring toString()=0;26 virtual const std::string toString()=0; 29 27 }; 30 28 -
src/World.cpp
re6fdbe ra1510d 12 12 #include "periodentafel.hpp" 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Actions/ManipulateAtomsProcess.hpp" 14 16 15 17 using namespace std; … … 28 30 } 29 31 32 vector<atom*> World::getAllAtoms(){ 33 return getAllAtoms(AllAtoms()); 34 } 35 30 36 int World::numAtoms(){ 31 37 return atoms.size(); … … 36 42 } 37 43 44 /******************** Methods to change World state *********************/ 45 38 46 molecule* World::createMolecule(){ 39 47 OBSERVE; 40 48 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; 44 54 mol->signOn(this); 45 55 return mol; 46 56 } 47 57 58 void World::destroyMolecule(molecule* mol){ 59 OBSERVE; 60 destroyMolecule(mol->getId()); 61 } 62 63 void 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 72 atom *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 83 int 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 92 void World::destroyAtom(atom* atom){ 93 OBSERVE; 94 int id = atom->getId(); 95 destroyAtom(id); 96 } 97 98 void World::destroyAtom(atomId_t id) { 99 OBSERVE; 100 atom *atom = atoms[id]; 101 assert(atom); 102 DeleteAtom(atom); 103 atoms.erase(id); 104 } 105 106 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 107 return new ManipulateAtomsProcess(op, descr,name,true); 108 } 109 110 ManipulateAtomsProcess* 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 116 void 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 131 World::AtomIterator World::getAtomIter(AtomDescriptor descr){ 132 return AtomIterator(descr,this); 133 } 134 135 World::AtomSet::iterator World::atomEnd(){ 136 return atoms.end(); 137 } 48 138 49 139 /******************************* Singleton Stuff **************************/ … … 53 143 boost::mutex World::worldLock; 54 144 55 56 57 145 World::World() : 58 146 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)) 61 152 { 62 153 molecules_deprecated->signOn(this); … … 68 159 delete molecules_deprecated; 69 160 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(); 70 171 } 71 172 … … 80 181 81 182 void World::destroy(){ 82 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise83 theWorld->destroyLegacy();84 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.85 86 183 // boost supports RAII-Style locking, so we don't need to unlock 87 184 boost::mutex::scoped_lock guard(worldLock); … … 91 188 92 189 World* World::reset(){ 93 // For legacy reasons all atoms have to be destroyed first, since unregistering would cause deadlocks otherwise94 theWorld->destroyLegacy();95 //WARNING: at this point we have a small race condition, when sombody now tries to access the world.96 97 190 World* oldWorld = 0; 98 191 { … … 114 207 // should see that it gets the updated new world 115 208 delete oldWorld; 209 return theWorld; 116 210 } 117 211 … … 121 215 return molecules_deprecated; 122 216 } 123 124 // some legacy stuff to let the World know about items created outside125 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 9 9 #define WORLD_HPP_ 10 10 11 #include < boost/thread.hpp>11 #include <string> 12 12 #include <map> 13 13 #include <vector> 14 14 #include <set> 15 15 #include <boost/thread.hpp> 16 #include <boost/shared_ptr.hpp> 17 18 #include "defs.hpp" 16 19 #include "Patterns/Observer.hpp" 17 20 #include "Patterns/Cacheable.hpp" … … 24 27 class AtomDescriptor; 25 28 class AtomDescriptor_impl; 29 class ManipulateAtomsProcess; 30 template<typename T> 31 class AtomsCalculation; 26 32 27 33 class World : public Observable 28 34 { 35 // necessary for coupling with descriptors 29 36 friend class AtomDescriptor_impl; 37 friend class AtomDescriptor; 38 39 // Actions, calculations etc associated with the World 40 friend class ManipulateAtomsProcess; 41 template<typename> friend class AtomsCalculation; 30 42 public: 43 typedef std::map<atomId_t,atom*> AtomSet; 44 typedef std::map<moleculeId_t,molecule*> MoleculeSet; 31 45 32 46 /***** getter and setter *****/ 33 47 // 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 */ 34 51 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 */ 35 57 atom* getAtom(AtomDescriptor descriptor); 58 59 /** 60 * returns a vector containing all atoms that match a given descriptor 61 */ 36 62 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 */ 37 76 int numAtoms(); 77 78 /** 79 * get the number of molecules in the World 80 */ 38 81 int numMolecules(); 39 82 40 83 /***** 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 */ 41 89 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 125 protected: 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 42 168 private: 43 169 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; 46 174 47 175 48 176 /***** singleton Stuff *****/ 49 177 public: 178 179 /** 180 * get the currently active instance of the World. 181 */ 50 182 static World* get(); 183 184 /** 185 * destroy the currently active instance of the World. 186 */ 51 187 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 */ 52 195 static World* reset(); 53 196 54 197 private: 198 /** 199 * private constructor to ensure creation of the world using 200 * the singleton pattern. 201 */ 55 202 World(); 203 204 /** 205 * private destructor to ensure destruction of the world using the 206 * singleton pattern. 207 */ 56 208 virtual ~World(); 57 209 … … 68 220 MoleculeListClass *&getMolecules(); 69 221 70 // functions used for the WorldContent template mechanism71 void registerAtom(atom *theAtom);72 void unregisterAtom(atom *theAtom);73 222 private: 74 // this function cleans up anything that cannot be cleaned while the lock is active75 // at a later point all these cleanups have to be moved to the World Class so the deadlock and76 // race condition can both be avoided.77 void destroyLegacy();78 79 223 MoleculeListClass *molecules_deprecated; 80 81 // this is needed to assign unique IDs to atoms... so far82 // IDs are not assigned upon Atom creation, so we cannot query the ID83 // during construction. By using the dummy ID we can make sure all atoms84 // are actually stored in the map and don't overwrite each other.85 int dummyId;86 224 }; 87 225 -
src/atom.cpp
re6fdbe ra1510d 20 20 /** Constructor of class atom. 21 21 */ 22 atom::atom() : previous(NULL), next(NULL), father(this), sort(&nr)23 { 24 World::get()->registerAtom(this); 22 atom::atom() : 23 previous(NULL), next(NULL), father(this), sort(&nr) 24 { 25 25 node = &x; // TesselPoint::x can only be referenced from here 26 26 }; … … 28 28 /** Constructor of class atom. 29 29 */ 30 atom::atom(atom *pointer) : previous(NULL), next(NULL), father(pointer), sort(&nr) 31 { 32 World::get()->registerAtom(this); 30 atom::atom(atom *pointer) : 31 ParticleInfo(pointer), 32 previous(NULL), next(NULL), father(pointer), sort(&nr) 33 { 33 34 type = pointer->type; // copy element of atom 34 35 x.CopyVector(&pointer->x); // copy coordination … … 38 39 }; 39 40 41 atom *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 40 56 41 57 /** Destructor of class atom. … … 43 59 atom::~atom() 44 60 { 45 World::get()->unregisterAtom(this);46 61 unlink(this); 47 62 }; … … 267 282 }; 268 283 284 World *atom::getWorld(){ 285 return world; 286 } 287 288 void atom::setWorld(World* _world){ 289 world = _world; 290 } 291 292 void atom::setId(int _id) { 293 id=_id; 294 } 295 296 int atom::getId() { 297 return id; 298 } 299 300 atom* NewAtom(){ 301 return new atom(); 302 } 303 304 void DeleteAtom(atom* atom){ 305 delete atom; 306 } -
src/atom.hpp
re6fdbe ra1510d 32 32 33 33 class Vector; 34 class World; 34 35 35 36 /********************************************** declarations *******************************/ … … 39 40 */ 40 41 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 42 friend atom* NewAtom(); 43 friend void DeleteAtom(atom*); 41 44 public: 42 45 atom *previous; //!< previous atom in molecule list … … 45 48 int *sort; //!< sort criteria 46 49 47 atom(); 48 atom(class atom *pointer); 49 virtual ~atom(); 50 virtual atom *clone(); 50 51 51 52 bool OutputIndexed(ofstream * const out, const int ElementNo, const int AtomNo, const char *comment = NULL) const; … … 67 68 bool IsInParallelepiped(const Vector offset, const double *parallelepiped) const; 68 69 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(); 69 101 private: 102 World* world; 103 int id; 70 104 }; 71 105 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 */ 111 atom* 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 */ 118 void DeleteAtom(atom*); 119 120 72 121 #endif /* ATOM_HPP_ */ -
src/atom_atominfo.cpp
re6fdbe ra1510d 6 6 */ 7 7 8 #include "periodentafel.hpp" 9 #include "World.hpp" 8 10 #include "atom_atominfo.hpp" 9 11 … … 18 20 }; 19 21 22 element *AtomInfo::getType(){ 23 return type; 24 } 25 26 void AtomInfo::setType(element* _type) { 27 type = _type; 28 } 29 30 void AtomInfo::setType(int Z) { 31 element *elem = World::get()->getPeriode()->FindElement(Z); 32 setType(elem); 33 } -
src/atom_atominfo.hpp
re6fdbe ra1510d 37 37 ~AtomInfo(); 38 38 39 element *getType(); 40 void setType(element *); 41 void setType(int); 42 39 43 private: 40 44 }; -
src/atom_particleinfo.cpp
re6fdbe ra1510d 13 13 ParticleInfo::ParticleInfo() : nr(-1), Name(NULL) {}; 14 14 15 ParticleInfo::ParticleInfo(ParticleInfo *pointer) : 16 nr(pointer->nr), 17 Name(pointer->Name) 18 {} 19 20 15 21 /** Destructor of ParticleInfo. 16 22 */ … … 19 25 Free(&Name); 20 26 }; 21 22 int ParticleInfo::getId() {23 return nr;24 }25 27 26 28 ostream & operator << (ostream &ost, const ParticleInfo &a) -
src/atom_particleinfo.hpp
re6fdbe ra1510d 31 31 32 32 ParticleInfo(); 33 ParticleInfo(ParticleInfo*); 33 34 ~ParticleInfo(); 34 35 35 36 ostream & operator << (ostream &ost) const; 36 37 virtual int getId();38 37 39 38 private: -
src/boundary.cpp
re6fdbe ra1510d 4 4 */ 5 5 6 #include "World.hpp" 6 7 #include "atom.hpp" 7 8 #include "bond.hpp" … … 800 801 { 801 802 Info FunctionInfo(__func__); 802 molecule *Filling = new molecule(filler->elemente);803 molecule *Filling = World::get()->createMolecule(); 803 804 Vector CurrentPosition; 804 805 int N[NDIM]; … … 887 888 Walker = Walker->next; 888 889 // copy atom ... 889 CopyAtoms[Walker->nr] = new atom(Walker);890 CopyAtoms[Walker->nr] = Walker->clone(); 890 891 891 892 // create atomic random translation vector ... … … 964 965 bool freeLC = false; 965 966 bool status = false; 966 CandidateForTesselation *baseline = NULL;967 CandidateForTesselation *baseline=0; 967 968 LineMap::iterator testline; 968 969 bool OneLoopWithoutSuccessFlag = true; // marks whether we went once through all baselines without finding any without two triangles -
src/builder.cpp
re6fdbe ra1510d 1432 1432 } 1433 1433 if (mol == NULL) { 1434 mol = new molecule(periode);1434 mol = World::get()->createMolecule(); 1435 1435 mol->ActiveFlag = true; 1436 1436 if (ConfigFileName != NULL) … … 1481 1481 SaveFlag = true; 1482 1482 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(); 1484 1484 first->type = periode->FindElement(atoi(argv[argptr])); 1485 1485 if (first->type != NULL) … … 1634 1634 Log() << Verbose(1) << "Filling Box with water molecules." << endl; 1635 1635 // construct water molecule 1636 molecule *filler = new molecule(periode);1636 molecule *filler = World::get()->createMolecule(); 1637 1637 molecule *Filling = NULL; 1638 1638 atom *second = NULL, *third = NULL; … … 1641 1641 // first->x.Zero(); 1642 1642 // filler->AddAtom(first); 1643 first = new atom();1643 first = World::get()->createAtom(); 1644 1644 first->type = periode->FindElement(1); 1645 1645 first->x.Init(0.441, -0.143, 0.); 1646 1646 filler->AddAtom(first); 1647 second = new atom();1647 second = World::get()->createAtom(); 1648 1648 second->type = periode->FindElement(1); 1649 1649 second->x.Init(-0.464, 1.137, 0.0); 1650 1650 filler->AddAtom(second); 1651 third = new atom();1651 third = World::get()->createAtom(); 1652 1652 third->type = periode->FindElement(8); 1653 1653 third->x.Init(-0.464, 0.177, 0.); … … 1664 1664 molecules->insert(Filling); 1665 1665 } 1666 delete(filler);1666 World::get()->destroyMolecule(filler); 1667 1667 argptr+=6; 1668 1668 } … … 2097 2097 x.AddVector(&y); // per factor one cell width further 2098 2098 for (int k=count;k--;) { // go through every atom of the original cell 2099 first = new atom(); // create a new body2099 first = World::get()->createAtom(); // create a new body 2100 2100 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2101 2101 first->x.AddVector(&x); // translate the coordinates … … 2204 2204 if(World::get()->numMolecules() == 0){ 2205 2205 mol = World::get()->createMolecule(); 2206 World::get()->getMolecules()->insert(mol); 2207 cout << "Molecule created" << endl; 2206 2208 if(mol->cell_size[0] == 0.){ 2207 2209 Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl; -
src/config.cpp
re6fdbe ra1510d 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 732 733 sprintf(keyword,"%s_%i",name, j+1); 733 734 if (repetition == 0) { 734 neues = new atom();735 neues = World::get()->createAtom(); 735 736 AtomList[i][j] = neues; 736 737 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 811 812 sprintf(keyword,"%s_%i",name, j+1); 812 813 if (repetition == 0) { 813 neues = new atom();814 neues = World::get()->createAtom(); 814 815 AtomList[i][j] = neues; 815 816 LinearList[ FileBuffer->LineMapping[FileBuffer->CurrentLine] ] = neues; … … 850 851 void config::Load(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 851 852 { 852 molecule *mol = new molecule(periode);853 molecule *mol = World::get()->createMolecule(); 853 854 ifstream *file = new ifstream(filename); 854 855 if (file == NULL) { … … 1088 1089 void config::LoadOld(const char * const filename, const string &BondGraphFileName, const periodentafel * const periode, MoleculeListClass * const &MolList) 1089 1090 { 1090 molecule *mol = new molecule(periode);1091 molecule *mol = World::get()->createMolecule(); 1091 1092 ifstream *file = new ifstream(filename); 1092 1093 if (file == NULL) { … … 1287 1288 } 1288 1289 istringstream input2(zeile); 1289 atom *neues = new atom();1290 atom *neues = World::get()->createAtom(); 1290 1291 input2 >> neues->x.x[0]; // x 1291 1292 input2 >> neues->x.x[1]; // y … … 1787 1788 char filename[MAXSTRINGSIZE]; 1788 1789 ofstream output; 1789 molecule *mol = new molecule(periode);1790 molecule *mol = World::get()->createMolecule(); 1790 1791 mol->SetNameFromFilename(ConfigFileName); 1791 1792 … … 1898 1899 } 1899 1900 1900 delete(mol);1901 World::get()->destroyMolecule(mol); 1901 1902 }; 1902 1903 -
src/datacreator.cpp
re6fdbe ra1510d 771 771 { 772 772 stringstream line(Force.Header[Force.MatrixCounter]); 773 c har *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};773 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; 774 774 string token; 775 775 … … 803 803 { 804 804 stringstream line(Force.Header[Force.MatrixCounter]); 805 c har *fillcolor[5] = {"black", "red", "blue", "green", "cyan"};805 const char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; 806 806 string token; 807 807 -
src/defs.hpp
re6fdbe ra1510d 32 32 33 33 enum Shading { white, lightgray, darkgray, black }; //!< color in Breadth-First-Search analysis 34 35 // some types that can stay abstract 36 typedef unsigned int moleculeId_t; 37 typedef unsigned int atomId_t; 34 38 35 39 //enum CutCyclicBond { KeepBond, SaturateBond }; //!< Saturation scheme either atom- or bondwise -
src/lists.hpp
re6fdbe ra1510d 9 9 #define LISTS_HPP_ 10 10 11 class atom; 12 11 13 /******************************** Some templates for list management ***********************************/ 12 14 … … 18 20 { 19 21 X *vorher = end->previous; 20 if (vorher != NULL)22 if (vorher != 0) 21 23 vorher->next = walker; 22 24 end->previous = walker; … … 31 33 template <typename X> void unlink(X *walker) 32 34 { 33 if (walker->next != NULL)35 if (walker->next != 0) 34 36 walker->next->previous = walker->previous; 35 if (walker->previous != NULL)37 if (walker->previous != 0) 36 38 walker->previous->next = walker->next; 37 walker->next = NULL;38 walker->previous= NULL;39 walker->next = 0; 40 walker->previous= 0; 39 41 }; 40 42 … … 46 48 template <typename X> bool add(X *pointer, X *end) 47 49 { 48 if (end != NULL) {50 if (end != 0) { 49 51 link(pointer, end); 50 52 } else { 51 pointer->previous = NULL;52 pointer->next = NULL;53 pointer->previous = 0; 54 pointer->next = 0; 53 55 } 54 56 return true; … … 59 61 * \param *start begin of list 60 62 * \param *end end of list 61 * \return X - if found, NULL- if not found63 * \return X - if found, 0 - if not found 62 64 */ 63 65 template <typename X, typename Y> X * find(Y *suche, X *start, X *end) … … 68 70 if (*walker->sort == *suche) return (walker); 69 71 } 70 return NULL;72 return 0; 71 73 }; 72 74 … … 77 79 template <typename X> void removewithoutcheck(X *walker) 78 80 { 79 if (walker != NULL) {81 if (walker != 0) { 80 82 unlink(walker); 81 83 delete(walker); 82 walker = NULL;84 walker = 0; 83 85 } 84 86 }; 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 */ 94 template <> void removewithoutcheck<atom>(atom *walker); 85 95 86 96 /** Removes an item from the list, checks if exists. … … 99 109 }*/ 100 110 // atom found, now unlink 101 if (walker != NULL)111 if (walker != 0) 102 112 removewithoutcheck(walker); 103 113 else … … 114 124 { 115 125 X *pointer = start->next; 116 X *walker = NULL;126 X *walker = 0; 117 127 while (pointer != end) { // go through list 118 128 walker = pointer; // mark current … … 131 141 { 132 142 X *Binder = me; 133 while(Binder->previous != NULL)143 while(Binder->previous != 0) 134 144 Binder = Binder->previous; 135 145 return Binder; … … 143 153 { 144 154 X *Binder = me; 145 while(Binder->next != NULL)155 while(Binder->next != 0) 146 156 Binder = Binder->next; 147 157 return Binder; -
src/molecule.cpp
re6fdbe ra1510d 8 8 #include <boost/bind.hpp> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 30 31 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. 31 32 */ 32 molecule::molecule(const periodentafel * const teil) : elemente(teil), start( new atom), end(new atom),33 molecule::molecule(const periodentafel * const teil) : elemente(teil), start(World::get()->createAtom()), end(World::get()->createAtom()), 33 34 first(new bond(start, end, 1, -1)), last(new bond(start, end, 1, -1)), MDSteps(0), AtomCount(0), 34 35 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) 37 40 { 38 41 // init atom chain list … … 52 55 }; 53 56 57 molecule *NewMolecule(){ 58 return new molecule(World::get()->getPeriode()); 59 } 60 54 61 /** Destructor of class molecule. 55 62 * Initialises molecule list with correctly referenced start and end, and sets molecule::last_atom to zero. … … 60 67 delete(first); 61 68 delete(last); 62 delete(end); 63 delete(start); 64 }; 65 69 end->getWorld()->destroyAtom(end); 70 start->getWorld()->destroyAtom(start); 71 }; 72 73 74 void DeleteMolecule(molecule *mol){ 75 delete mol; 76 } 66 77 67 78 // getter and setter … … 73 84 OBSERVE; 74 85 strncpy(name,_name.c_str(),MAXSTRINGSIZE); 86 } 87 88 moleculeId_t molecule::getId(){ 89 return id; 90 } 91 92 void molecule::setId(moleculeId_t _id){ 93 id =_id; 75 94 } 76 95 … … 135 154 OBSERVE; 136 155 if (pointer != NULL) { 137 atom *walker = new atom(pointer);156 atom *walker = pointer->clone(); 138 157 walker->Name = Malloc<char>(strlen(pointer->Name) + 1, "atom::atom: *Name"); 139 158 strcpy (walker->Name, pointer->Name); … … 242 261 switch(TopBond->BondDegree) { 243 262 case 1: 244 FirstOtherAtom = new atom(); // new atom263 FirstOtherAtom = World::get()->createAtom(); // new atom 245 264 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 246 265 FirstOtherAtom->v.CopyVector(&TopReplacement->v); // copy velocity … … 299 318 300 319 // create the two Hydrogens ... 301 FirstOtherAtom = new atom();302 SecondOtherAtom = new atom();320 FirstOtherAtom = World::get()->createAtom(); 321 SecondOtherAtom = World::get()->createAtom(); 303 322 FirstOtherAtom->type = elemente->FindElement(1); 304 323 SecondOtherAtom->type = elemente->FindElement(1); … … 354 373 case 3: 355 374 // 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(); 359 378 FirstOtherAtom->type = elemente->FindElement(1); 360 379 SecondOtherAtom->type = elemente->FindElement(1); … … 475 494 MDSteps++; 476 495 for(i=0;i<NumberOfAtoms;i++){ 477 Walker = new atom;496 Walker = World::get()->createAtom(); 478 497 getline(xyzfile,line,'\n'); 479 498 istringstream *item = new istringstream(line); -
src/molecule.hpp
re6fdbe ra1510d 29 29 #include <string> 30 30 31 #include "defs.hpp" 31 32 #include "graph.hpp" 32 33 #include "stackclass.hpp" … … 85 86 */ 86 87 class molecule : public PointCloud , public Observable { 88 friend molecule *NewMolecule(); 89 friend void DeleteMolecule(molecule *); 87 90 public: 88 91 double cell_size[6];//!< cell size … … 108 111 private: 109 112 Cacheable<string> formula; 113 moleculeId_t id; 114 protected: 115 molecule(const periodentafel * const teil); 116 virtual ~molecule(); 117 110 118 111 119 public: 112 molecule(const periodentafel * const teil);113 virtual ~molecule();114 115 120 //getter and setter 116 121 const std::string getName(); 122 moleculeId_t getId(); 123 void setId(moleculeId_t); 117 124 void setName(const std::string); 118 125 const std::string getFormula(); 119 126 std::string calcFormula(); 127 120 128 121 129 // re-definition of virtual functions from PointCloud … … 321 329 }; 322 330 331 molecule *NewMolecule(); 332 void DeleteMolecule(molecule* mol); 333 323 334 #include "molecule_template.hpp" 324 335 … … 330 341 int MaxIndex; 331 342 332 MoleculeListClass( );343 MoleculeListClass(World *world); 333 344 ~MoleculeListClass(); 334 345 … … 339 350 bool OutputConfigForListOfFragments(config *configuration, int *SortIndex); 340 351 int NumberOfActiveMolecules(); 341 void Enumerate(o fstream *out);352 void Enumerate(ostream *out); 342 353 void Output(ofstream *out); 343 354 void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration); … … 363 374 364 375 private: 376 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor 365 377 }; 366 378 -
src/molecule_dynamics.cpp
re6fdbe ra1510d 6 6 */ 7 7 8 #include "World.hpp" 8 9 #include "atom.hpp" 9 10 #include "config.hpp" … … 164 165 double tmp = 0.; 165 166 double result = 0.; 166 167 167 // go through every atom 168 168 atom *Runner = NULL; … … 486 486 bool status = true; 487 487 int MaxSteps = configuration.MaxOuterStep; 488 MoleculeListClass *MoleculePerStep = new MoleculeListClass( );488 MoleculeListClass *MoleculePerStep = new MoleculeListClass(World::get()); 489 489 // Get the Permutation Map by MinimiseConstrainedPotential 490 490 atom **PermutationMap = NULL; … … 506 506 Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl; 507 507 for (int step = 0; step <= MaxSteps; step++) { 508 mol = new molecule(elemente);508 mol = World::get()->createMolecule(); 509 509 MoleculePerStep->insert(mol); 510 510 Walker = start; -
src/molecule_fragmentation.cpp
re6fdbe ra1510d 8 8 #include <cstring> 9 9 10 #include "World.hpp" 10 11 #include "atom.hpp" 11 12 #include "bond.hpp" … … 675 676 //if (FragmentationToDo) { // we should always store the fragments again as coordination might have changed slightly without changing bond structure 676 677 // allocate memory for the pointer array and transmorph graphs into full molecular fragments 677 BondFragments = new MoleculeListClass( );678 BondFragments = new MoleculeListClass(World::get()); 678 679 int k=0; 679 680 for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) { … … 926 927 { 927 928 atom **SonList = Calloc<atom*>(AtomCount, "molecule::StoreFragmentFromStack: **SonList"); 928 molecule *Leaf = new molecule(elemente);929 molecule *Leaf = World::get()->createMolecule(); 929 930 930 931 // Log() << Verbose(1) << "Begin of StoreFragmentFromKeyset." << endl; -
src/moleculelist.cpp
re6fdbe ra1510d 7 7 #include <cstring> 8 8 9 #include "World.hpp" 9 10 #include "atom.hpp" 10 11 #include "bond.hpp" … … 24 25 /** Constructor for MoleculeListClass. 25 26 */ 26 MoleculeListClass::MoleculeListClass() 27 MoleculeListClass::MoleculeListClass(World *_world) : 28 world(_world) 27 29 { 28 30 // empty lists … … 38 40 for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) { 39 41 Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl; 40 delete(*ListRunner);42 world->destroyMolecule(*ListRunner); 41 43 } 42 44 Log() << Verbose(4) << "Freeing ListOfMolecules." << endl; … … 137 139 * \param *out output stream 138 140 */ 139 void MoleculeListClass::Enumerate(o fstream *out)141 void MoleculeListClass::Enumerate(ostream *out) 140 142 { 141 143 element* Elemental = NULL; … … 213 215 // remove src 214 216 ListOfMolecules.remove(srcmol); 215 delete(srcmol);217 World::get()->destroyMolecule(srcmol); 216 218 return true; 217 219 }; … … 342 344 Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl; 343 345 if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) { 344 CopyAtoms[Walker->nr] = new atom(Walker);346 CopyAtoms[Walker->nr] = Walker->clone(); 345 347 mol->AddAtom(CopyAtoms[Walker->nr]); 346 348 nr++; … … 748 750 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration) 749 751 { 750 molecule *mol = new molecule(periode);752 molecule *mol = World::get()->createMolecule(); 751 753 atom *Walker = NULL; 752 754 atom *Advancer = NULL; … … 773 775 } 774 776 // remove the molecule 775 delete(*MolRunner);777 World::get()->destroyMolecule(*MolRunner); 776 778 ListOfMolecules.erase(MolRunner); 777 779 } … … 795 797 molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules"); 796 798 for (int i=0;i<MolCount;i++) { 797 molecules[i] = (molecule*) new molecule(mol->elemente);799 molecules[i] = World::get()->createMolecule(); 798 800 molecules[i]->ActiveFlag = true; 799 801 strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE); … … 893 895 OBSERVE; 894 896 molecule *mol = NULL; 895 mol = new molecule(periode);897 mol = World::get()->createMolecule(); 896 898 insert(mol); 897 899 }; … … 902 904 char filename[MAXSTRINGSIZE]; 903 905 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl; 904 mol = new molecule(periode);906 mol = World::get()->createMolecule(); 905 907 do { 906 908 Log() << Verbose(0) << "Enter file name: "; … … 960 962 mol = *ListRunner; 961 963 ListOfMolecules.erase(ListRunner); 962 delete(mol);964 World::get()->destroyMolecule(mol); 963 965 break; 964 966 } … … 1007 1009 // remove the leaf itself 1008 1010 if (Leaf != NULL) { 1009 delete(Leaf);1011 World::get()->destroyMolecule(Leaf); 1010 1012 Leaf = NULL; 1011 1013 } -
src/tesselationhelpers.cpp
re6fdbe ra1510d 27 27 int signum; 28 28 gsl_permutation *p = gsl_permutation_alloc(A->size1); 29 gsl_matrix *tmpA ;29 gsl_matrix *tmpA=0; 30 30 31 31 if (inPlace) -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
re6fdbe ra1510d 17 17 #include "AnalysisCorrelationToPointUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 56 57 57 58 // construct periodentafel 58 tafel = new periodentafel;59 tafel = World::get()->getPeriode(); 59 60 tafel->AddElement(hydrogen); 60 61 61 62 // construct molecule (tetraeder of hydrogens) 62 TestMolecule = new molecule(tafel);63 Walker = new atom();63 TestMolecule = World::get()->createMolecule(); 64 Walker = World::get()->createAtom(); 64 65 Walker->type = hydrogen; 65 66 Walker->node->Init(1., 0., 1. ); 66 67 TestMolecule->AddAtom(Walker); 67 Walker = new atom();68 Walker = World::get()->createAtom(); 68 69 Walker->type = hydrogen; 69 70 Walker->node->Init(0., 1., 1. ); 70 71 TestMolecule->AddAtom(Walker); 71 Walker = new atom();72 Walker = World::get()->createAtom(); 72 73 Walker->type = hydrogen; 73 74 Walker->node->Init(1., 1., 0. ); 74 75 TestMolecule->AddAtom(Walker); 75 Walker = new atom();76 Walker = World::get()->createAtom(); 76 77 Walker->type = hydrogen; 77 78 Walker->node->Init(0., 0., 0. ); … … 81 82 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 82 83 83 TestList = new MoleculeListClass;84 TestList = World::get()->getMolecules(); 84 85 TestMolecule->ActiveFlag = true; 85 86 TestList->insert(TestMolecule); … … 102 103 delete(binmap); 103 104 104 // remove105 delete(TestList);106 // note that all the atoms are cleaned by TestMolecule107 105 delete(point); 108 delete(tafel);109 // note that element is cleaned by periodentafel110 106 World::destroy(); 111 107 MemoryUsageObserver::purgeInstance(); -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
re6fdbe ra1510d 17 17 #include "AnalysisCorrelationToSurfaceUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 60 61 61 62 // construct periodentafel 62 tafel = new periodentafel;63 tafel = World::get()->getPeriode(); 63 64 tafel->AddElement(hydrogen); 64 65 tafel->AddElement(carbon); 65 66 66 67 // 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(); 69 70 Walker->type = hydrogen; 70 71 Walker->node->Init(1., 0., 1. ); 71 72 TestMolecule->AddAtom(Walker); 72 Walker = new atom();73 Walker = World::get()->createAtom(); 73 74 Walker->type = hydrogen; 74 75 Walker->node->Init(0., 1., 1. ); 75 76 TestMolecule->AddAtom(Walker); 76 Walker = new atom();77 Walker = World::get()->createAtom(); 77 78 Walker->type = hydrogen; 78 79 Walker->node->Init(1., 1., 0. ); 79 80 TestMolecule->AddAtom(Walker); 80 Walker = new atom();81 Walker = World::get()->createAtom(); 81 82 Walker->type = hydrogen; 82 83 Walker->node->Init(0., 0., 0. ); … … 86 87 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 87 88 88 TestList = new MoleculeListClass;89 TestList = World::get()->getMolecules(); 89 90 TestMolecule->ActiveFlag = true; 90 91 TestList->insert(TestMolecule); … … 99 100 100 101 // add outer atoms 101 Walker = new atom();102 Walker = World::get()->createAtom(); 102 103 Walker->type = carbon; 103 104 Walker->node->Init(4., 0., 4. ); 104 105 TestMolecule->AddAtom(Walker); 105 Walker = new atom();106 Walker = World::get()->createAtom(); 106 107 Walker->type = carbon; 107 108 Walker->node->Init(0., 4., 4. ); 108 109 TestMolecule->AddAtom(Walker); 109 Walker = new atom();110 Walker = World::get()->createAtom(); 110 111 Walker->type = carbon; 111 112 Walker->node->Init(4., 4., 0. ); 112 113 TestMolecule->AddAtom(Walker); 113 114 // add inner atoms 114 Walker = new atom();115 Walker = World::get()->createAtom(); 115 116 Walker->type = carbon; 116 117 Walker->node->Init(0.5, 0.5, 0.5 ); … … 131 132 delete(binmap); 132 133 133 // remove134 delete(TestList);135 134 delete(Surface); 136 135 // note that all the atoms are cleaned by TestMolecule 137 136 delete(LC); 138 delete(tafel);139 // note that element is cleaned by periodentafel140 137 World::destroy(); 141 138 MemoryUsageObserver::purgeInstance(); -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
re6fdbe ra1510d 17 17 #include "AnalysisPairCorrelationUnitTest.hpp" 18 18 19 #include "World.hpp" 19 20 #include "atom.hpp" 20 21 #include "boundary.hpp" … … 55 56 56 57 // construct periodentafel 57 tafel = new periodentafel;58 tafel = World::get()->getPeriode(); 58 59 tafel->AddElement(hydrogen); 59 60 60 61 // construct molecule (tetraeder of hydrogens) 61 TestMolecule = new molecule(tafel);62 Walker = new atom();62 TestMolecule = World::get()->createMolecule(); 63 Walker = World::get()->createAtom(); 63 64 Walker->type = hydrogen; 64 65 Walker->node->Init(1., 0., 1. ); 65 66 TestMolecule->AddAtom(Walker); 66 Walker = new atom();67 Walker = World::get()->createAtom(); 67 68 Walker->type = hydrogen; 68 69 Walker->node->Init(0., 1., 1. ); 69 70 TestMolecule->AddAtom(Walker); 70 Walker = new atom();71 Walker = World::get()->createAtom(); 71 72 Walker->type = hydrogen; 72 73 Walker->node->Init(1., 1., 0. ); 73 74 TestMolecule->AddAtom(Walker); 74 Walker = new atom();75 Walker = World::get()->createAtom(); 75 76 Walker->type = hydrogen; 76 77 Walker->node->Init(0., 0., 0. ); … … 80 81 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 81 82 82 TestList = new MoleculeListClass;83 TestList = World::get()->getMolecules(); 83 84 TestMolecule->ActiveFlag = true; 84 85 TestList->insert(TestMolecule); … … 98 99 delete(binmap); 99 100 100 // remove101 delete(TestList);102 101 // note that all the atoms are cleaned by TestMolecule 103 delete(tafel);104 // note that element is cleaned by periodentafel105 102 World::destroy(); 106 103 MemoryUsageObserver::purgeInstance(); -
src/unittests/DescriptorUnittest.cpp
re6fdbe ra1510d 27 27 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest ); 28 28 29 // some stubs30 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 46 29 // set up and tear down 47 30 void DescriptorUnittest::setUp(){ 48 31 World::get(); 49 32 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(); 51 35 } 52 36 } 53 37 void DescriptorUnittest::tearDown(){ 54 38 World::destroy(); 55 for(int i=0;i<ATOM_COUNT;++i){56 delete atoms[i];57 }58 39 } 59 40 60 41 // 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)){ 42 bool 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)){ 64 46 std::vector<atom*>::iterator iter; 65 47 bool res=false; 66 48 for(iter=atoms.begin();iter!=atoms.end();++iter){ 67 res |= (*iter)->getId() == i ;49 res |= (*iter)->getId() == id; 68 50 } 69 51 if(!res) { 70 cout << "Atom " << i << " missing in returned list" << endl;52 cout << "Atom " << id << " missing in returned list" << endl; 71 53 return false; 72 54 } … … 91 73 void DescriptorUnittest::AtomBaseSetsTest(){ 92 74 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)); 94 76 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms)); 95 77 … … 100 82 // test Atoms from boundaries and middle of the set 101 83 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()); 108 93 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 } 109 104 // test from outside of set 110 testAtom = World::get()->getAtom(AtomById( ATOM_COUNT));105 testAtom = World::get()->getAtom(AtomById(outsideId)); 111 106 CPPUNIT_ASSERT(!testAtom); 112 107 } … … 115 110 { 116 111 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)); 118 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 119 114 } … … 121 116 { 122 117 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)); 124 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 125 120 } … … 142 137 { 143 138 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)); 145 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 146 141 } … … 148 143 // exclude and include some atoms 149 144 { 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]))); 151 146 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)); 154 149 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms)); 155 150 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); … … 157 152 158 153 { 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]))); 160 155 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()); 162 157 } 163 158 } -
src/unittests/DescriptorUnittest.hpp
re6fdbe ra1510d 33 33 private: 34 34 atom *atoms [ATOM_COUNT]; 35 int atomIds [ATOM_COUNT]; 35 36 }; 36 37 -
src/unittests/Makefile.am
re6fdbe ra1510d 30 30 CacheableTest \ 31 31 DescriptorUnittest \ 32 ${MENUTESTS} 33 32 manipulateAtomsTest \ 33 atomsCalculationTest \ 34 ${MENUTESTS} 35 36 37 34 38 35 39 check_PROGRAMS = $(TESTS) … … 60 64 tesselation_insideoutsideunittest.cpp \ 61 65 vectorunittest.cpp \ 62 ActionSequenceTest.cpp \63 66 ObserverTest.cpp \ 64 67 CacheableTest.cpp \ 65 DescriptorUnittest.cpp 68 DescriptorUnittest.cpp \ 69 manipulateAtomsTest.cpp \ 70 atomsCalculationTest.cpp \ 71 ActionSequenceTest.cpp 66 72 67 73 TESTHEADERS = \ … … 140 146 DescriptorUnittest_LDADD = ${ALLLIBS} 141 147 148 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp 149 manipulateAtomsTest_LDADD = ${ALLLIBS} 150 151 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp 152 atomsCalculationTest_LDADD = ${ALLLIBS} 153 142 154 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS) 143 155 TestRunner_LDADD = ${ALLLIBS} -
src/unittests/analysisbondsunittest.cpp
re6fdbe ra1510d 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "analysis_bonds.hpp" 19 20 #include "analysisbondsunittest.hpp" … … 60 61 61 62 // construct periodentafel 62 tafel = new periodentafel;63 tafel = World::get()->getPeriode(); 63 64 tafel->AddElement(hydrogen); 64 65 tafel->AddElement(carbon); 65 66 66 67 // construct molecule (tetraeder of hydrogens) 67 TestMolecule = new molecule(tafel);68 Walker = new atom();68 TestMolecule = World::get()->createMolecule(); 69 Walker = World::get()->createAtom(); 69 70 Walker->type = hydrogen; 70 71 Walker->node->Init(1.5, 0., 1.5 ); 71 72 TestMolecule->AddAtom(Walker); 72 Walker = new atom();73 Walker = World::get()->createAtom(); 73 74 Walker->type = hydrogen; 74 75 Walker->node->Init(0., 1.5, 1.5 ); 75 76 TestMolecule->AddAtom(Walker); 76 Walker = new atom();77 Walker = World::get()->createAtom(); 77 78 Walker->type = hydrogen; 78 79 Walker->node->Init(1.5, 1.5, 0. ); 79 80 TestMolecule->AddAtom(Walker); 80 Walker = new atom();81 Walker = World::get()->createAtom(); 81 82 Walker->type = hydrogen; 82 83 Walker->node->Init(0., 0., 0. ); 83 84 TestMolecule->AddAtom(Walker); 84 Walker = new atom();85 Walker = World::get()->createAtom(); 85 86 Walker->type = carbon; 86 87 Walker->node->Init(0.5, 0.5, 0.5 ); … … 116 117 117 118 // remove molecule 118 delete(TestMolecule);119 World::get()->destroyMolecule(TestMolecule); 119 120 // note that all the atoms are cleaned by TestMolecule 120 delete(tafel); 121 // note that element is cleaned by periodentafel 121 World::destroy(); 122 122 }; 123 123 -
src/unittests/bondgraphunittest.cpp
re6fdbe ra1510d 16 16 #include <cstring> 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 56 57 57 58 // construct periodentafel 58 tafel = new periodentafel;59 tafel = World::get()->getPeriode(); 59 60 tafel->AddElement(hydrogen); 60 61 tafel->AddElement(carbon); 61 62 62 63 // construct molecule (tetraeder of hydrogens) 63 TestMolecule = new molecule(tafel);64 Walker = new atom();64 TestMolecule = World::get()->createMolecule(); 65 Walker = World::get()->createAtom(); 65 66 Walker->type = hydrogen; 66 67 Walker->node->Init(1., 0., 1. ); 67 68 TestMolecule->AddAtom(Walker); 68 Walker = new atom();69 Walker = World::get()->createAtom(); 69 70 Walker->type = hydrogen; 70 71 Walker->node->Init(0., 1., 1. ); 71 72 TestMolecule->AddAtom(Walker); 72 Walker = new atom();73 Walker = World::get()->createAtom(); 73 74 Walker->type = hydrogen; 74 75 Walker->node->Init(1., 1., 0. ); 75 76 TestMolecule->AddAtom(Walker); 76 Walker = new atom();77 Walker = World::get()->createAtom(); 77 78 Walker->type = hydrogen; 78 79 Walker->node->Init(0., 0., 0. ); … … 101 102 102 103 // 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 107 107 World::destroy(); 108 108 MemoryUsageObserver::purgeInstance(); -
src/unittests/listofbondsunittest.cpp
re6fdbe ra1510d 16 16 #include "listofbondsunittest.hpp" 17 17 18 #include "World.hpp" 18 19 #include "atom.hpp" 19 20 #include "bond.hpp" … … 50 51 51 52 // construct periodentafel 52 tafel = new periodentafel;53 tafel = World::get()->getPeriode(); 53 54 tafel->AddElement(hydrogen); 54 55 55 56 // construct molecule (tetraeder of hydrogens) 56 TestMolecule = new molecule(tafel);57 Walker = new atom();57 TestMolecule = World::get()->createMolecule(); 58 Walker = World::get()->createAtom(); 58 59 Walker->type = hydrogen; 59 60 Walker->node->Init(1., 0., 1. ); 60 61 TestMolecule->AddAtom(Walker); 61 Walker = new atom();62 Walker = World::get()->createAtom(); 62 63 Walker->type = hydrogen; 63 64 Walker->node->Init(0., 1., 1. ); 64 65 TestMolecule->AddAtom(Walker); 65 Walker = new atom();66 Walker = World::get()->createAtom(); 66 67 Walker->type = hydrogen; 67 68 Walker->node->Init(1., 1., 0. ); 68 69 TestMolecule->AddAtom(Walker); 69 Walker = new atom();70 Walker = World::get()->createAtom(); 70 71 Walker->type = hydrogen; 71 72 Walker->node->Init(0., 0., 0. ); … … 81 82 { 82 83 // 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 87 87 World::destroy(); 88 88 MemoryUsageObserver::purgeInstance(); … … 250 250 251 251 // remove atom2 252 delete(atom2);252 World::get()->destroyAtom(atom2); 253 253 254 254 // check bond if removed from other atom
Note:
See TracChangeset
for help on using the changeset viewer.