Changes in / [6bc51d:57f5cf]
- Files:
-
- 19 added
- 58 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/Doxyfile
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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(){ … … 64 73 { 65 74 OBSERVE; 66 active = true;67 75 currStep=0; 68 76 } 69 77 starts = false; 78 active = true; 70 79 } 80 71 81 void Process::step(){ 72 82 OBSERVE; 73 83 currStep++; 74 84 } 85 75 86 void Process::stop(){ 87 active=false; 76 88 stops = true; 77 89 { 78 90 OBSERVE; 79 91 currStep=0; 80 active=false;81 92 } 82 93 { -
src/Actions/Process.hpp
r6bc51d r57f5cf 19 19 #include "Actions/Action.hpp" 20 20 21 /** 22 * A Process is an Action that might take some time and therefore has special 23 * methods to allow communication with progress indicators. Indicators 24 * can sign on at a global place and will be notified when any process is doing 25 * a calculation. 26 * 27 * A Process has four states: 28 * - starting: It is in the process of setting itself up, and wants everybody to know that it will start 29 * the calculation soon. Indicators should set up anything they need for displaying the progress 30 * when they are notified by a process in this state. 31 * - active: The process is currently doing it's thing and wants any indicator to know it's status, i.e. 32 * the percentage done. 33 * - stopping: The process has fullfilled it's purpose and is shutting down. Indicators recieving this status 34 * should also use it to shut down their indication mechanism and delete any objects allocated for 35 * this Process 36 * - inactive: This Process is currently sleeping. If a Process is sending out any signals in this state, there 37 * is something seriously wrong. 38 */ 21 39 class Process : public Action, public Observable 22 40 { … … 29 47 bool doesStop(); 30 48 int getCurrStep(); 49 void setCurrStep(int _currStep); 31 50 float getDoneRatio(); 32 51 int getMaxSteps(); 52 void setMaxSteps(int _maxSteps); 33 53 34 54 protected: -
src/Descriptors/AtomDescriptor.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 15 15 #include "World.hpp" 16 16 17 class World; 17 18 class atom; 18 19 … … 20 21 class AtomDescripter_impl; 21 22 23 /** 24 * An AtomDescriptor describes a Set of Atoms from the World. Can be used for any method that needs to work on 25 * a specific set of Atoms. 26 * 27 * This Class is implemented using the PIMPL-Idion, i.e. this class only contains an abstract structure 28 * that forwards any request to a wrapped pointer-to-implementation. This way operators and calculations 29 * on Descriptors are possible. 30 * 31 * Concrete Implementation Objects can be shared between multiple Wrappers, so make sure that 32 * any Implementation remainst constant during lifetime. 33 */ 22 34 class AtomDescriptor { 35 // close coupling to the world to allow access 23 36 friend atom* World::getAtom(AtomDescriptor descriptor); 24 37 friend std::vector<atom*> World::getAllAtoms(AtomDescriptor descriptor); 38 friend class World::AtomIterator; 25 39 26 40 friend AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); … … 29 43 30 44 public: 31 typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; 45 typedef boost::shared_ptr<AtomDescriptor_impl> impl_ptr; //!< Allow easy changes of the pointer-to-implementation type 32 46 33 47 AtomDescriptor(impl_ptr); 48 49 /** 50 * Copy constructor. 51 * Takes the Implementation from the copied object and sets it's own pointer to link there. 52 * This way the actuall implementation object is shared between copy and original 53 */ 34 54 AtomDescriptor(const AtomDescriptor&); 35 55 ~AtomDescriptor(); 36 56 57 /** 58 * Assignment Operator. 59 * 60 * Implemented by setting the pointer to the new Implementation. 61 */ 37 62 AtomDescriptor &operator=(AtomDescriptor &); 38 63 39 64 protected: 65 /** 66 * forward Method to implementation 67 */ 40 68 atom* find(); 69 70 /** 71 * forward Method to implementation 72 */ 41 73 std::vector<atom*> findAll(); 74 75 /** 76 * Return the implementation this Wrapper currently points to. 77 * Used for copying, assignment and in Iterators over subsets of the World. 78 */ 42 79 impl_ptr get_impl() const; 43 80 … … 46 83 }; 47 84 48 // Functions to construct actual descriptors 85 /** 86 * produce an Atomdescriptor that at the point of construction contains an implementation that matches all Atoms 87 */ 49 88 AtomDescriptor AllAtoms(); 89 90 /** 91 * produce an Atomdescriptor that at the point of construction contains an implementation that matches no Atoms 92 */ 50 93 AtomDescriptor NoAtoms(); 51 94 52 // no true short circuit, but the test of the second descriptor wont be done 95 /** 96 * Set Intersection for two Atomdescriptors. The resulting Atomdescriptor will only match an Atom if both 97 * given Atomdescriptors also match. Uses short circuit inside, so the second predicate wont be called 98 * when the first one failed. 99 */ 53 100 AtomDescriptor operator&&(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 101 102 /** 103 * Set Union for two AtomDescriptors. The resulting AtomDescriptor will match an Atom if at least one of 104 * the two given AtomDescriptors does match. Used short circuit inside, so the second predicate wont 105 * be called when the first one failed. 106 */ 54 107 AtomDescriptor operator||(const AtomDescriptor &lhs, const AtomDescriptor &rhs); 108 109 /** 110 * Set inversion for an AtomDescriptor. Matches an Atom if the given AtomDescriptor did not match. 111 */ 55 112 AtomDescriptor operator!(const AtomDescriptor &arg); 56 113 -
src/Descriptors/AtomDescriptor_impl.hpp
r6bc51d r57f5cf 1 #ifndef ATOMDESCRIPTOR_IMPL_HPP 2 #define ATOMDESCRIPTOR_IMPL_HPP 3 1 4 #include "Descriptors/AtomDescriptor.hpp" 2 5 3 6 /************************ Declarations of implementation Objects ************************/ 7 8 /** 9 * This class implements a general Base class for AtomDescriptors using the PIMPL-Idiom 10 * 11 * The predicate for this class is empty and should be implemented by derived classes. 12 * By the predicate it is described which atoms should be picked for a given descriptor. 13 */ 4 14 5 15 class AtomDescriptor_impl … … 11 21 virtual ~AtomDescriptor_impl(); 12 22 13 virtual bool predicate(std::pair<int,atom*>)=0; 23 /** 24 * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms 25 */ 26 virtual bool predicate(std::pair<atomId_t,atom*>)=0; 14 27 15 28 protected: 29 30 /** 31 * This method is called when the Descriptor is used to find the first matching 32 * Atom. Walks through all Atoms and stops on the first match. Can be implemented 33 * when the searched Atom can be found in a more efficient way. Calculated 34 * Atomdescriptors will always use this method, so no improvement there. 35 */ 16 36 virtual atom* find(); 37 38 /** 39 * This method is called when the Descriptor is used to find all matching Atoms. 40 * Walks through all Atoms and tests the predicate on each one. A vector of all 41 * matching Atoms is returned. 42 */ 17 43 virtual std::vector<atom*> findAll(); 18 std::map<int,atom*>& getAtoms(); 44 45 /** 46 * This method is used internally to query the Set of Atoms from the world. 47 * By using this method derived classes can also access the Internal World Datastructre. 48 * Implemented in full in the Base Descriptor Implementation, so only this one method 49 * needs to be friend with the World class. 50 */ 51 World::AtomSet& getAtoms(); 19 52 }; 20 53 21 54 /************************** Universe and Emptyset *****************/ 22 55 56 /** 57 * A simple AtomDescriptor that will always match all Atoms present in the World. 58 */ 23 59 class AtomAllDescriptor_impl : public AtomDescriptor_impl { 24 60 public: 25 61 AtomAllDescriptor_impl(); 26 62 virtual ~AtomAllDescriptor_impl(); 27 virtual bool predicate(std::pair<int,atom*>); 63 64 /** 65 * Always returns true for any Atom 66 */ 67 virtual bool predicate(std::pair<atomId_t,atom*>); 28 68 }; 29 69 70 71 /** 72 * An AtomDescriptor that never matches any Atom in the World. 73 */ 30 74 class AtomNoneDescriptor_impl : public AtomDescriptor_impl { 31 75 public: 32 76 AtomNoneDescriptor_impl(); 33 77 virtual ~AtomNoneDescriptor_impl(); 34 virtual bool predicate(std::pair<int,atom*>); 78 79 /** 80 * Always returns false for any Atom 81 */ 82 virtual bool predicate(std::pair<atomId_t,atom*>); 35 83 }; 36 84 37 85 /************************** Operator stuff ************************/ 38 86 87 /** 88 * Intersection of two AtomDescriptors 89 */ 39 90 class AtomAndDescriptor_impl : public AtomDescriptor_impl 40 91 { … … 42 93 AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 43 94 ~AtomAndDescriptor_impl(); 44 virtual bool predicate(std::pair<int,atom*>); 95 96 /** 97 * This predicate uses the predicate from the first && the predicate from the 98 * second Descriptor to decide if an Atom should be selected. 99 */ 100 virtual bool predicate(std::pair<atomId_t,atom*>); 45 101 46 102 private: … … 49 105 }; 50 106 107 /** 108 * Union of two AtomDescriptors 109 */ 51 110 class AtomOrDescriptor_impl : public AtomDescriptor_impl 52 111 { … … 54 113 AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 55 114 virtual ~AtomOrDescriptor_impl(); 56 virtual bool predicate(std::pair<int,atom*>); 115 116 /** 117 * This predicate uses the predicate form the first || the predicate from the 118 * second Descriptor to decide if an Atom should be selected. 119 */ 120 virtual bool predicate(std::pair<atomId_t,atom*>); 57 121 58 122 private: … … 61 125 }; 62 126 127 /** 128 * Set Inversion of a Descriptor 129 */ 63 130 class AtomNotDescriptor_impl : public AtomDescriptor_impl 64 131 { … … 67 134 virtual ~AtomNotDescriptor_impl(); 68 135 69 virtual bool predicate(std::pair<int,atom*>); 136 /** 137 * Opposite of the given descriptor predicate. 138 */ 139 virtual bool predicate(std::pair<atomId_t,atom*>); 70 140 71 141 private: 72 142 AtomDescriptor::impl_ptr arg; 73 143 }; 144 145 #endif //ATOMDESCRIPTOR_IMPL_HPP -
src/Descriptors/AtomIdDescriptor.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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 Descriptors/MoleculeDescriptor.cpp 32 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp Descriptors/MoleculeDescriptor.hpp 33 33 34 SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} ${PATTERNSOURCE} ${UISOURCE} ${DESCRIPTORSOURCE} ${LEGACYSOURCE} bond.cpp bondgraph.cpp boundary.cpp ChangeTracker.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp FormatParser.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp 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 ChangeTracker.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp FormatParser.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp lists.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp World.cpp WorldIterators.cpp 35 35 HEADER = ${ANALYSISHEADER} ${ATOMHEADER} ${PATTERNHEADER} ${UIHEADER} ${DESCRIPTORHEADER} ${LEGACYHEADER} bond.hpp bondgraph.hpp boundary.hpp ChangeTracker.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp FormatParser.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp World.hpp 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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/Patterns/Observer.hpp
r6bc51d r57f5cf 30 30 class Observable; 31 31 32 /** 33 * An Observer is notified by all Observed objects, when anything changes. 34 * 35 * If a simple change is done to an Object the Obervable will call the update() method 36 * of all signed on observers, passing itself as a parameter for identification. The 37 * Observers should then react to the changes and update themselves accordingly. 38 * 39 * If an observed Object is destroyed it will call the subjectKilled() method 40 * of all signed on Observers, again passing itself as a parameter for identification. 41 * The Observers should handle the destruction of an observed Object gracefully, i.e. 42 * set themselves inactive, display something else, etc. There is no need 43 * to sign of from the dying object, since this will be handled by the Observable destructor. 44 */ 32 45 class Observer 33 46 { … … 38 51 39 52 protected: 53 /** 54 * This method is called upon changes of the Observable 55 */ 40 56 virtual void update(Observable *publisher)=0; 57 58 /** 59 * This method is called when the observed object is destroyed. 60 */ 41 61 virtual void subjectKilled(Observable *publisher)=0; 42 62 }; 43 63 64 /** 65 * An Observable implements all neccessary method for being observed. 66 * 67 * That is, it provides methods for signing on and of from an 68 * Observable that can be used by any observer. The actual 69 * observer-mechanism is handled at a central static place 70 * to avoid memory issues when many observable are around but only few 71 * are actually observed. 72 */ 44 73 class Observable : public Observer { 45 74 public: … … 47 76 virtual ~Observable(); 48 77 78 /** 79 * Sign an Observer on to this Observable. The Observer will be notified 80 * whenever something inside the Observable changes. The Observer can 81 * assign itself a priority for the changes in the range of -20:+20. 82 * The Observer with lower priority will be called before the others, 83 * same as with Unix nice-levels. This can be used when an Object 84 * contains other objects that observe it (derived values), and these objects have 85 * to recalculate their states before the changes should be propageted to the 86 * UI. A default priority of 0 should be fine in most cases, since there is 87 * ussually no need to order the update sequence. 88 */ 49 89 virtual void signOn(Observer *target, int priority=0); 90 91 /** 92 * Sign of a previously signed on Observer. After this no more 93 * updates will be recieved from that observer. 94 */ 50 95 virtual void signOff(Observer *target); 51 96 … … 76 121 // Structure for RAII-Style notification 77 122 protected: 123 /** 124 * This structure implements the Observer-mechanism RAII-Idiom. 125 * It triggers certain functions on creation and destruction so that 126 * Observer mechanisms can be linked to scope block. 127 */ 78 128 class _Observable_protector { 79 129 public: -
src/UIElements/Dialog.cpp
r6bc51d r57f5cf 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/MainWindow.hpp
r6bc51d r57f5cf 25 25 }; 26 26 27 /** 28 * The type of menuPopulators 29 */ 27 30 typedef void (*MenuMaker)(Menu*,MoleculeListClass*, config*, periodentafel*); 28 31 32 /** 33 * This contains all Functions that are used to create the menus. 34 * Needs a specific funtion for each menu. All populators will be called 35 * by the UIFactory upon creation of the main menu. Thus the actuall construction 36 * of the Menus can be kept independent of the concrete type of UI that is being 37 * built. 38 */ 29 39 struct menuPopulaters{ 30 40 MenuMaker MakeEditMoleculesMenu; -
src/UIElements/TextDialog.cpp
r6bc51d r57f5cf 114 114 bool TextDialog::VectorTextQuery::handle() { 115 115 tmp->AskPosition(cellSize,check); 116 return true; 116 117 } -
src/UIElements/TextStatusIndicator.cpp
r6bc51d r57f5cf 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/UIElements/UIFactory.hpp
r6bc51d r57f5cf 17 17 18 18 struct menuPopulaters; 19 19 /** 20 * Abstract Factory to create any kind of User interface object needed by the programm. 21 * 22 * The factory can be created and has to be set to a certain type upon creation. It will then 23 * only create UIelements of that certain type, so that all UIElements match. This way different 24 * UIs can be handled in a concise abstract way. 25 */ 20 26 class UIFactory 21 27 { … … 25 31 virtual ~UIFactory(); 26 32 27 // methods for creating UIElements 33 /** 34 * Produce some kind of main window, of whichever type was chosen when the factory was created 35 */ 28 36 virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *)=0; 37 38 /** 39 * Produce a User Interaction Dialog, that can query values from the User. 40 * Again the type is determined upon factory creation. 41 */ 29 42 virtual Dialog* makeDialog()=0; 30 43 … … 37 50 38 51 public: 52 /** 53 * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory 54 */ 39 55 static void makeUserInterface(InterfaceTypes type); 56 57 /** 58 * get the previously created factory 59 */ 40 60 static UIFactory* get(); 61 62 /** 63 * Destroy the created factory. 64 * 65 * Make sure that all UIElements that were created by the factory are destroyed before calling this method. 66 */ 41 67 static void purgeInstance(); 42 68 }; -
src/Views/MethodStringView.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 12 12 #include "periodentafel.hpp" 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Descriptors/MoleculeDescriptor.hpp" 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 17 #include "Actions/ManipulateAtomsProcess.hpp" 14 18 15 19 using namespace std; … … 20 24 } 21 25 26 // Atoms 27 22 28 atom* World::getAtom(AtomDescriptor descriptor){ 23 29 return descriptor.find(); … … 28 34 } 29 35 36 vector<atom*> World::getAllAtoms(){ 37 return getAllAtoms(AllAtoms()); 38 } 39 30 40 int World::numAtoms(){ 31 41 return atoms.size(); 32 42 } 33 43 44 // Molecules 45 46 molecule *World::getMolecule(MoleculeDescriptor descriptor){ 47 return descriptor.find(); 48 } 49 50 std::vector<molecule*> World::getAllMolecules(MoleculeDescriptor descriptor){ 51 return descriptor.findAll(); 52 } 53 34 54 int World::numMolecules(){ 35 55 return molecules_deprecated->ListOfMolecules.size(); 36 56 } 37 57 58 /******************** Methods to change World state *********************/ 59 38 60 molecule* World::createMolecule(){ 39 61 OBSERVE; 40 62 molecule *mol = NULL; 41 mol = new molecule(periode); 42 molecules_deprecated->insert(mol); 43 molecules.insert(mol); 63 mol = NewMolecule(); 64 assert(!molecules.count(currMoleculeId)); 65 mol->setId(currMoleculeId++); 66 // store the molecule by ID 67 molecules[mol->getId()] = mol; 44 68 mol->signOn(this); 45 69 return mol; 46 70 } 47 71 72 void World::destroyMolecule(molecule* mol){ 73 OBSERVE; 74 destroyMolecule(mol->getId()); 75 } 76 77 void World::destroyMolecule(moleculeId_t id){ 78 OBSERVE; 79 molecule *mol = molecules[id]; 80 assert(mol); 81 DeleteMolecule(mol); 82 molecules.erase(id); 83 } 84 85 86 atom *World::createAtom(){ 87 OBSERVE; 88 atomId_t id = getNextAtomId(); 89 atom *res = NewAtom(id); 90 res->setWorld(this); 91 // store the atom by ID 92 atoms[res->getId()] = res; 93 return res; 94 } 95 96 int World::registerAtom(atom *atom){ 97 OBSERVE; 98 atomId_t id = getNextAtomId(); 99 atom->setId(id); 100 atom->setWorld(this); 101 atoms[atom->getId()] = atom; 102 return atom->getId(); 103 } 104 105 void World::destroyAtom(atom* atom){ 106 OBSERVE; 107 int id = atom->getId(); 108 destroyAtom(id); 109 } 110 111 void World::destroyAtom(atomId_t id) { 112 OBSERVE; 113 atom *atom = atoms[id]; 114 assert(atom); 115 DeleteAtom(atom); 116 atoms.erase(id); 117 releaseAtomId(id); 118 } 119 120 bool World::changeAtomId(atomId_t oldId, atomId_t newId, atom* target){ 121 OBSERVE; 122 // in case this call did not originate from inside the atom, we redirect it, 123 // to also let it know that it has changed 124 if(!target){ 125 target = atoms[oldId]; 126 assert(target && "Atom with that ID not found"); 127 return target->changeId(newId); 128 } 129 else{ 130 if(reserveAtomId(newId)){ 131 atoms.erase(oldId); 132 atoms.insert(pair<atomId_t,atom*>(newId,target)); 133 return true; 134 } 135 else{ 136 return false; 137 } 138 } 139 } 140 141 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){ 142 return new ManipulateAtomsProcess(op, descr,name,true); 143 } 144 145 ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name){ 146 return manipulateAtoms(op,name,AllAtoms()); 147 } 148 149 /********************* Internal Change methods for double Callback and Observer mechanism ********/ 150 151 void World::doManipulate(ManipulateAtomsProcess *proc){ 152 proc->signOn(this); 153 { 154 OBSERVE; 155 proc->doManipulate(this); 156 } 157 proc->signOff(this); 158 } 159 /******************************* IDManagement *****************************/ 160 161 atomId_t World::getNextAtomId(){ 162 // see if we can reuse some Id 163 if(atomIdPool.empty()){ 164 return currAtomId++; 165 } 166 else{ 167 // we give out the first ID from the pool 168 atomId_t id = *(atomIdPool.begin()); 169 atomIdPool.erase(id); 170 } 171 } 172 173 void World::releaseAtomId(atomId_t id){ 174 atomIdPool.insert(id); 175 // defragmentation of the pool 176 set<atomId_t>::reverse_iterator iter; 177 // go through all Ids in the pool that lie immediately below the border 178 while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){ 179 atomIdPool.erase(--currAtomId); 180 } 181 } 182 183 bool World::reserveAtomId(atomId_t id){ 184 if(id>=currAtomId ){ 185 // add all ids between the new one and current border as available 186 for(atomId_t pos=currAtomId; pos<id; ++pos){ 187 atomIdPool.insert(pos); 188 } 189 currAtomId=id+1; 190 return true; 191 } 192 else if(atomIdPool.count(id)){ 193 atomIdPool.erase(id); 194 return true; 195 } 196 else{ 197 // this ID could not be reserved 198 return false; 199 } 200 } 201 /******************************* Iterators ********************************/ 202 203 /* 204 * Actual Implementation of the iterators can be found in WorldIterators.cpp 205 */ 206 207 World::AtomIterator World::getAtomIter(AtomDescriptor descr){ 208 return AtomIterator(descr,this); 209 } 210 211 World::AtomSet::iterator World::atomEnd(){ 212 return atoms.end(); 213 } 214 215 World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){ 216 return MoleculeIterator(descr,this); 217 } 218 219 World::MoleculeSet::iterator World::moleculeEnd(){ 220 return molecules.end(); 221 } 48 222 49 223 /******************************* Singleton Stuff **************************/ … … 53 227 boost::mutex World::worldLock; 54 228 55 56 57 229 World::World() : 58 230 periode(new periodentafel), 59 molecules_deprecated(new MoleculeListClass), 60 dummyId(0) 231 atoms(), 232 currAtomId(0), 233 molecules(), 234 currMoleculeId(0), 235 molecules_deprecated(new MoleculeListClass(this)) 61 236 { 62 237 molecules_deprecated->signOn(this); … … 68 243 delete molecules_deprecated; 69 244 delete periode; 245 MoleculeSet::iterator molIter; 246 for(molIter=molecules.begin();molIter!=molecules.end();++molIter){ 247 DeleteMolecule((*molIter).second); 248 } 249 molecules.clear(); 250 AtomSet::iterator atIter; 251 for(atIter=atoms.begin();atIter!=atoms.end();++atIter){ 252 DeleteAtom((*atIter).second); 253 } 254 atoms.clear(); 70 255 } 71 256 … … 80 265 81 266 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 267 // boost supports RAII-Style locking, so we don't need to unlock 87 268 boost::mutex::scoped_lock guard(worldLock); … … 91 272 92 273 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 274 World* oldWorld = 0; 98 275 { … … 114 291 // should see that it gets the updated new world 115 292 delete oldWorld; 293 return theWorld; 116 294 } 117 295 … … 121 299 return molecules_deprecated; 122 300 } 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
r6bc51d r57f5cf 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 MoleculeDescriptor; 30 class MoleculeDescriptor_impl; 31 class ManipulateAtomsProcess; 32 template<typename T> 33 class AtomsCalculation; 26 34 27 35 class World : public Observable 28 36 { 37 // necessary for coupling with descriptors 29 38 friend class AtomDescriptor_impl; 39 friend class AtomDescriptor; 40 friend class MoleculeDescriptor_impl; 41 friend class MoleculeDescriptor; 42 43 // Actions, calculations etc associated with the World 44 friend class ManipulateAtomsProcess; 45 template<typename> friend class AtomsCalculation; 30 46 public: 47 typedef std::map<atomId_t,atom*> AtomSet; 48 typedef std::map<moleculeId_t,molecule*> MoleculeSet; 31 49 32 50 /***** getter and setter *****/ 33 51 // reference to pointer is used for legacy reason... reference will be removed latter to keep encapsulation of World object 52 /** 53 * returns the periodentafel for the world. 54 */ 34 55 periodentafel *&getPeriode(); 56 57 /** 58 * returns the first atom that matches a given descriptor. 59 * Do not rely on ordering for descriptors that match more than one atom. 60 */ 35 61 atom* getAtom(AtomDescriptor descriptor); 62 63 /** 64 * returns a vector containing all atoms that match a given descriptor 65 */ 36 66 std::vector<atom*> getAllAtoms(AtomDescriptor descriptor); 67 std::vector<atom*> getAllAtoms(); 68 69 /** 70 * returns a calculation that calls a given function on all atoms matching a descriptor. 71 * the calculation is not called at this point and can be used as an action, i.e. be stored in 72 * menus, be kept around for later use etc. 73 */ 74 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string,AtomDescriptor); 75 template<typename T> AtomsCalculation<T>* calcOnAtoms(boost::function<T(atom*)>,std::string); 76 77 /** 78 * get the number of atoms in the World 79 */ 37 80 int numAtoms(); 81 82 /** 83 * returns the first molecule that matches a given descriptor. 84 * Do not rely on ordering for descriptors that match more than one molecule. 85 */ 86 molecule *getMolecule(MoleculeDescriptor descriptor); 87 88 /** 89 * returns a vector containing all molecules that match a given descriptor 90 */ 91 std::vector<molecule*> getAllMolecules(MoleculeDescriptor descriptor); 92 93 /** 94 * get the number of molecules in the World 95 */ 38 96 int numMolecules(); 39 97 40 98 /***** Methods to work with the World *****/ 99 100 /** 101 * create a new molecule. This method should be used whenever any kind of molecule is needed. Assigns a unique 102 * ID to the molecule and stores it in the World for later retrieval. Do not create molecules directly. 103 */ 41 104 molecule *createMolecule(); 105 106 void destroyMolecule(molecule*); 107 void destroyMolecule(moleculeId_t); 108 109 /** 110 * Create a new atom. This method should be used whenever any atom is needed. Assigns a unique ID and stores 111 * the atom in the World. If the atom is not destroyed it will automatically be destroyed when the world ends. 112 */ 113 atom *createAtom(); 114 115 /** 116 * Registers a Atom unknown to world. Needed in some rare cases, e.g. when cloning atoms, or in some unittests. 117 * Do not re-register Atoms already known to the world since this will cause double-frees. 118 */ 119 int registerAtom(atom*); 120 121 /** 122 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 123 * atom directly since this will leave the pointer inside the world. 124 */ 125 void destroyAtom(atom*); 126 127 /** 128 * Delete some atom and erase it from the world. Use this whenever you need to destroy any atom. Do not call delete on 129 * atom directly since this will leave the pointer inside the world. 130 */ 131 void destroyAtom(atomId_t); 132 133 /** 134 * used when changing an atom Id. 135 * Unless you are calling this method from inside an atom don't fiddle with the third parameter. 136 * 137 * Return value indicates wether the change could be done or not. 138 */ 139 bool changeAtomId(atomId_t oldId, atomId_t newId, atom* target=0); 140 141 /** 142 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not 143 * called at this time, so it can be passed around, stored inside menuItems etc. 144 */ 145 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string,AtomDescriptor); 146 ManipulateAtomsProcess* manipulateAtoms(boost::function<void(atom*)>,std::string); 147 148 protected: 149 /**** Iterators to use internal data structures */ 150 151 // Atoms 152 153 class AtomIterator { 154 public: 155 AtomIterator(); 156 AtomIterator(AtomDescriptor, World*); 157 AtomIterator(const AtomIterator&); 158 AtomIterator& operator=(const AtomIterator&); 159 AtomIterator& operator++(); // prefix 160 AtomIterator operator++(int); // postfix with dummy parameter 161 bool operator==(const AtomIterator&); 162 bool operator==(const AtomSet::iterator&); 163 bool operator!=(const AtomIterator&); 164 bool operator!=(const AtomSet::iterator&); 165 atom* operator*(); 166 167 int getCount(); 168 protected: 169 void advanceState(); 170 AtomSet::iterator state; 171 boost::shared_ptr<AtomDescriptor_impl> descr; 172 int index; 173 174 World* world; 175 }; 176 177 /** 178 * returns an iterator over all Atoms matching a given descriptor. 179 * used for internal purposes, like AtomProcesses and AtomCalculations. 180 */ 181 AtomIterator getAtomIter(AtomDescriptor descr); 182 183 /** 184 * returns an iterator to the end of the AtomSet. Due to overloading this iterator 185 * can be compared to iterators produced by getAtomIter (see the mis-matching types). 186 * Thus it can be used to detect when such an iterator is at the end of the list. 187 * used for internal purposes, like AtomProcesses and AtomCalculations. 188 */ 189 AtomSet::iterator atomEnd(); 190 191 // Molecules 192 193 class MoleculeIterator { 194 public: 195 MoleculeIterator(); 196 MoleculeIterator(MoleculeDescriptor, World*); 197 MoleculeIterator(const MoleculeIterator&); 198 MoleculeIterator& operator=(const MoleculeIterator&); 199 MoleculeIterator& operator++(); // prefix 200 MoleculeIterator operator++(int); // postfix with dummy parameter 201 bool operator==(const MoleculeIterator&); 202 bool operator==(const MoleculeSet::iterator&); 203 bool operator!=(const MoleculeIterator&); 204 bool operator!=(const MoleculeSet::iterator&); 205 molecule* operator*(); 206 207 int getCount(); 208 protected: 209 void advanceState(); 210 MoleculeSet::iterator state; 211 boost::shared_ptr<MoleculeDescriptor_impl> descr; 212 int index; 213 214 World* world; 215 }; 216 217 /** 218 * returns an iterator over all Molecules matching a given descriptor. 219 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 220 */ 221 MoleculeIterator getMoleculeIter(MoleculeDescriptor descr); 222 223 /** 224 * returns an iterator to the end of the MoleculeSet. Due to overloading this iterator 225 * can be compared to iterators produced by getMoleculeIter (see the mis-matching types). 226 * Thus it can be used to detect when such an iterator is at the end of the list. 227 * used for internal purposes, like MoleculeProcesses and MoleculeCalculations. 228 */ 229 MoleculeSet::iterator moleculeEnd(); 230 231 232 /******* Internal manipulation routines for double callback and Observer mechanism ******/ 233 void doManipulate(ManipulateAtomsProcess *); 234 42 235 private: 236 237 atomId_t getNextAtomId(); 238 void releaseAtomId(atomId_t); 239 bool reserveAtomId(atomId_t); 240 43 241 periodentafel *periode; 44 std::map<int,atom*> atoms; 45 std::set<molecule*> molecules; 242 AtomSet atoms; 243 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 244 atomId_t currAtomId; //!< stores the next available Id for atoms 245 MoleculeSet molecules; 246 moleculeId_t currMoleculeId; 46 247 47 248 48 249 /***** singleton Stuff *****/ 49 250 public: 251 252 /** 253 * get the currently active instance of the World. 254 */ 50 255 static World* get(); 256 257 /** 258 * destroy the currently active instance of the World. 259 */ 51 260 static void destroy(); 261 262 /** 263 * destroy the currently active instance of the World and immidiately 264 * create a new one. Use this to reset while somebody is still Observing 265 * the world and should reset the observed instance. All observers will be 266 * sent the subjectKille() message from the old world. 267 */ 52 268 static World* reset(); 53 269 54 270 private: 271 /** 272 * private constructor to ensure creation of the world using 273 * the singleton pattern. 274 */ 55 275 World(); 276 277 /** 278 * private destructor to ensure destruction of the world using the 279 * singleton pattern. 280 */ 56 281 virtual ~World(); 57 282 … … 68 293 MoleculeListClass *&getMolecules(); 69 294 70 // functions used for the WorldContent template mechanism71 void registerAtom(atom *theAtom);72 void unregisterAtom(atom *theAtom);73 295 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 296 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 297 }; 87 298 -
src/atom.cpp
r6bc51d r57f5cf 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 bool atom::changeId(atomId_t newId){ 293 // first we move ourselves in the world 294 // the world lets us know if that succeeded 295 if(world->changeAtomId(id,newId,this)){ 296 id = newId; 297 return true; 298 } 299 else{ 300 return false; 301 } 302 } 303 304 void atom::setId(atomId_t _id) { 305 id=_id; 306 } 307 308 int atom::getId() { 309 return id; 310 } 311 312 atom* NewAtom(atomId_t _id){ 313 atom * res =new atom(); 314 res->setId(_id); 315 return res; 316 } 317 318 void DeleteAtom(atom* atom){ 319 delete atom; 320 } -
src/atom.hpp
r6bc51d r57f5cf 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(atomId_t); 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 bool changeId(atomId_t newId); 83 84 /** 85 * this function sets the Id without notifying the world. Only use it, if the world has already 86 * gotten an ID for this Atom. 87 */ 88 virtual void setId(atomId_t); 89 90 protected: 91 /** 92 * Protected constructor to ensure construction of atoms through the world. 93 * see World::createAtom() 94 */ 95 atom(); 96 97 /** 98 * Protected copy-constructor to ensure construction of atoms by cloning. 99 * see atom::clone() 100 */ 101 atom(class atom *pointer); 102 103 /** 104 * Protected destructor to ensure destruction of atoms through the world. 105 * see World::destroyAtom() 106 */ 107 virtual ~atom(); 69 108 private: 109 World* world; 110 atomId_t id; 70 111 }; 71 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::createAtom() instead. 117 */ 118 atom* NewAtom(atomId_t _id); 119 120 /** 121 * internal method used by the world. Do not use if you don't know what you are doing. 122 * You might get burned... 123 * Use World::destroyAtom() instead. 124 */ 125 void DeleteAtom(atom*); 126 127 72 128 #endif /* ATOM_HPP_ */ -
src/atom_atominfo.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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/molecule_template.hpp
r6bc51d r57f5cf 16 16 #endif 17 17 18 #include "atom.hpp" 18 19 /********************************************** declarations *******************************/ 19 20 -
src/moleculelist.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 33 33 private: 34 34 atom *atoms [ATOM_COUNT]; 35 int atomIds [ATOM_COUNT]; 35 36 }; 36 37 -
src/unittests/Makefile.am
r6bc51d r57f5cf 31 31 DescriptorUnittest \ 32 32 MatrixUnitTest \ 33 manipulateAtomsTest \ 34 atomsCalculationTest \ 33 35 ${MENUTESTS} 34 36 … … 61 63 tesselation_insideoutsideunittest.cpp \ 62 64 vectorunittest.cpp \ 63 ActionSequenceTest.cpp \64 65 ObserverTest.cpp \ 65 66 CacheableTest.cpp \ 66 67 DescriptorUnittest.cpp \ 67 MatrixUnitTest.cpp 68 MatrixUnitTest.cpp \ 69 manipulateAtomsTest.cpp \ 70 atomsCalculationTest.cpp \ 71 ActionSequenceTest.cpp 68 72 69 73 TESTHEADERS = \ … … 145 149 MatrixUnitTest_LDADD = ${ALLLIBS} 146 150 151 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp 152 manipulateAtomsTest_LDADD = ${ALLLIBS} 153 154 atomsCalculationTest_SOURCES = UnitTestMain.cpp atomsCalculationTest.cpp atomsCalculationTest.hpp 155 atomsCalculationTest_LDADD = ${ALLLIBS} 156 147 157 TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS) 148 158 TestRunner_LDADD = ${ALLLIBS} -
src/unittests/analysisbondsunittest.cpp
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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
r6bc51d r57f5cf 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.