Changeset e6a9c1
- Timestamp:
- Mar 4, 2010, 10:40:52 AM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 63b56a7
- Parents:
- 6a661c (diff), 66e95e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 8 added
- 18 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Calculation.hpp
r6a661c re6a9c1 11 11 #include "Actions/Process.hpp" 12 12 13 /** 14 * A calculation is a Process that has some kind of result. 15 * 16 * This class can be used in the same way as any other Action or Process, but has some special methods 17 * for inspecting the result of the calculation. 18 */ 13 19 template<typename T> 14 20 class Calculation : public Process … … 18 24 virtual ~Calculation(); 19 25 26 /** 27 * Reimplemented call method for Action Base class. 28 * Resets the result and then redoes the calculation. Can be used to retrigger calculations 29 * from menu Items or other places. 30 */ 20 31 virtual void call(); 21 32 virtual void undo(); 22 33 virtual bool canUndo(); 23 34 35 /** 36 * Does the actual calculation and returns the result. 37 * When the calculation has been done before it is not redone, but the previous cached result is returned. 38 * Call reset to delete the cached value. 39 */ 24 40 virtual T operator()(); 41 42 /** 43 * Check if a cached result is available. 44 */ 25 45 virtual bool hasResult(); 46 47 /** 48 * Get the cached result. 49 * Fails if there is no cached result. 50 */ 26 51 virtual T getResult(); 52 53 /** 54 * Delete a previously calculated result from the cache. 55 */ 27 56 virtual void reset(); 28 57 29 58 protected: 30 59 T* result; 60 61 /** 62 * Pure virtual method for implementation of the actual calculation procedure. 63 */ 31 64 virtual T* doCalc()=0; 32 65 private: -
src/Actions/Process.cpp
r6a661c re6a9c1 72 72 { 73 73 OBSERVE; 74 active = true;75 74 currStep=0; 76 75 } 77 76 starts = false; 77 active = true; 78 78 } 79 79 … … 84 84 85 85 void Process::stop(){ 86 active=false; 86 87 stops = true; 87 88 { 88 89 OBSERVE; 89 90 currStep=0; 90 active=false;91 91 } 92 92 { -
src/Actions/Process.hpp
r6a661c re6a9c1 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 { -
src/Descriptors/AtomDescriptor.hpp
r6a661c re6a9c1 21 21 class AtomDescripter_impl; 22 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 */ 23 34 class AtomDescriptor { 24 35 // close coupling to the world to allow access … … 32 43 33 44 public: 34 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 35 46 36 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 */ 37 54 AtomDescriptor(const AtomDescriptor&); 38 55 ~AtomDescriptor(); 39 56 57 /** 58 * Assignment Operator. 59 * 60 * Implemented by setting the pointer to the new Implementation. 61 */ 40 62 AtomDescriptor &operator=(AtomDescriptor &); 41 63 42 64 protected: 65 /** 66 * forward Method to implementation 67 */ 43 68 atom* find(); 69 70 /** 71 * forward Method to implementation 72 */ 44 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 */ 45 79 impl_ptr get_impl() const; 46 80 … … 49 83 }; 50 84 51 // Functions to construct actual descriptors 85 /** 86 * produce an Atomdescriptor that at the point of construction contains an implementation that matches all Atoms 87 */ 52 88 AtomDescriptor AllAtoms(); 89 90 /** 91 * produce an Atomdescriptor that at the point of construction contains an implementation that matches no Atoms 92 */ 53 93 AtomDescriptor NoAtoms(); 54 94 55 // 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 */ 56 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 */ 57 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 */ 58 112 AtomDescriptor operator!(const AtomDescriptor &arg); 59 113 -
src/Descriptors/AtomDescriptor_impl.hpp
r6a661c re6a9c1 5 5 6 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 */ 7 14 8 15 class AtomDescriptor_impl … … 14 21 virtual ~AtomDescriptor_impl(); 15 22 23 /** 24 * Implement this abstract Method to make a concrete AtomDescriptor pick certain Atoms 25 */ 16 26 virtual bool predicate(std::pair<atomId_t,atom*>)=0; 17 27 18 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 */ 19 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 */ 20 43 virtual std::vector<atom*> findAll(); 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 */ 21 51 World::AtomSet& getAtoms(); 22 52 }; … … 24 54 /************************** Universe and Emptyset *****************/ 25 55 56 /** 57 * A simple AtomDescriptor that will always match all Atoms present in the World. 58 */ 26 59 class AtomAllDescriptor_impl : public AtomDescriptor_impl { 27 60 public: 28 61 AtomAllDescriptor_impl(); 29 62 virtual ~AtomAllDescriptor_impl(); 63 64 /** 65 * Always returns true for any Atom 66 */ 30 67 virtual bool predicate(std::pair<atomId_t,atom*>); 31 68 }; 32 69 70 71 /** 72 * An AtomDescriptor that never matches any Atom in the World. 73 */ 33 74 class AtomNoneDescriptor_impl : public AtomDescriptor_impl { 34 75 public: 35 76 AtomNoneDescriptor_impl(); 36 77 virtual ~AtomNoneDescriptor_impl(); 78 79 /** 80 * Always returns false for any Atom 81 */ 37 82 virtual bool predicate(std::pair<atomId_t,atom*>); 38 83 }; … … 40 85 /************************** Operator stuff ************************/ 41 86 87 /** 88 * Intersection of two AtomDescriptors 89 */ 42 90 class AtomAndDescriptor_impl : public AtomDescriptor_impl 43 91 { … … 45 93 AtomAndDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 46 94 ~AtomAndDescriptor_impl(); 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 */ 47 100 virtual bool predicate(std::pair<atomId_t,atom*>); 48 101 … … 52 105 }; 53 106 107 /** 108 * Union of two AtomDescriptors 109 */ 54 110 class AtomOrDescriptor_impl : public AtomDescriptor_impl 55 111 { … … 57 113 AtomOrDescriptor_impl(AtomDescriptor::impl_ptr _lhs, AtomDescriptor::impl_ptr _rhs); 58 114 virtual ~AtomOrDescriptor_impl(); 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 */ 59 120 virtual bool predicate(std::pair<atomId_t,atom*>); 60 121 … … 64 125 }; 65 126 127 /** 128 * Set Inversion of a Descriptor 129 */ 66 130 class AtomNotDescriptor_impl : public AtomDescriptor_impl 67 131 { … … 70 134 virtual ~AtomNotDescriptor_impl(); 71 135 136 /** 137 * Opposite of the given descriptor predicate. 138 */ 72 139 virtual bool predicate(std::pair<atomId_t,atom*>); 73 140 -
src/Makefile.am
r6a661c re6a9c1 41 41 QTUIMOC_TARGETS = QTMainWindow.moc.cpp QTMenu.moc.cpp QTDialog.moc.cpp QTMoleculesView.moc.cpp GLMoleculeView.moc.cpp QTStatusBar.moc.cpp 42 42 43 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp Descriptors/AtomIdDescriptor.cpp Descriptors/AtomTypeDescriptor.cpp 44 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp Descriptors/AtomIdDescriptor.hpp Descriptors/AtomTypeDescriptor.hpp 43 DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp \ 44 Descriptors/AtomIdDescriptor.cpp \ 45 Descriptors/AtomTypeDescriptor.cpp \ 46 Descriptors/MoleculeDescriptor.cpp \ 47 Descriptors/MoleculeIdDescriptor.cpp 48 49 DESCRIPTORHEADER = Descriptors/AtomDescriptor.hpp \ 50 Descriptors/AtomIdDescriptor.hpp \ 51 Descriptors/AtomTypeDescriptor.hpp \ 52 Descriptors/MoleculeDescriptor.hpp \ 53 Descriptors/MoleculeIdDescriptor.hpp 45 54 46 55 QTUISOURCE = ${QTUIMOC_TARGETS} UIElements/QT4/QTMainWindow.cpp UIElements/QT4/QTDialog.cpp UIElements/QT4/QTUIFactory.cpp Menu/QT4/QTMenu.cpp Views/QT4/QTMoleculesView.cpp Views/QT4/GLMoleculeView.cpp Views/QT4/QTStatusBar.cpp -
src/Patterns/Observer.hpp
r6a661c re6a9c1 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/MainWindow.hpp
r6a661c re6a9c1 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/UIFactory.hpp
r6a661c re6a9c1 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 { … … 30 36 virtual ~UIFactory(); 31 37 32 // methods for creating UIElements 38 /** 39 * Produce some kind of main window, of whichever type was chosen when the factory was created 40 */ 33 41 virtual MainWindow* makeMainWindow(menuPopulaters,MoleculeListClass *, config *, periodentafel *, char *)=0; 42 43 /** 44 * Produce a User Interaction Dialog, that can query values from the User. 45 * Again the type is determined upon factory creation. 46 */ 34 47 virtual Dialog* makeDialog()=0; 35 48 … … 42 55 43 56 public: 57 /** 58 * create a Factory of a certain type. From that moment on only those UIElements can be produced by the factory 59 */ 44 60 static void makeUserInterface(InterfaceTypes type); 61 62 /** 63 * get the previously created factory 64 */ 45 65 static UIFactory* get(); 66 67 /** 68 * Destroy the created factory. 69 * 70 * Make sure that all UIElements that were created by the factory are destroyed before calling this method. 71 */ 46 72 static void purgeInstance(); 47 73 }; -
src/World.cpp
r6a661c re6a9c1 13 13 #include "Descriptors/AtomDescriptor.hpp" 14 14 #include "Descriptors/AtomDescriptor_impl.hpp" 15 #include "Descriptors/MoleculeDescriptor.hpp" 16 #include "Descriptors/MoleculeDescriptor_impl.hpp" 15 17 #include "Actions/ManipulateAtomsProcess.hpp" 16 18 … … 22 24 } 23 25 26 // Atoms 27 24 28 atom* World::getAtom(AtomDescriptor descriptor){ 25 29 return descriptor.find(); … … 36 40 int World::numAtoms(){ 37 41 return atoms.size(); 42 } 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(); 38 52 } 39 53 … … 72 86 atom *World::createAtom(){ 73 87 OBSERVE; 74 atom *res = NewAtom(); 75 assert(!atoms.count(currAtomId)); 76 res->setId(currAtomId++); 88 atomId_t id = getNextAtomId(); 89 atom *res = NewAtom(id); 77 90 res->setWorld(this); 78 91 // store the atom by ID … … 83 96 int World::registerAtom(atom *atom){ 84 97 OBSERVE; 85 a ssert(!atoms.count(currAtomId));86 atom->setId( currAtomId++);98 atomId_t id = getNextAtomId(); 99 atom->setId(id); 87 100 atom->setWorld(this); 88 101 atoms[atom->getId()] = atom; … … 102 115 DeleteAtom(atom); 103 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 } 104 139 } 105 140 … … 122 157 proc->signOff(this); 123 158 } 159 /******************************* IDManagement *****************************/ 160 161 // Atoms 162 163 atomId_t World::getNextAtomId(){ 164 // see if we can reuse some Id 165 if(atomIdPool.empty()){ 166 return currAtomId++; 167 } 168 else{ 169 // we give out the first ID from the pool 170 atomId_t id = *(atomIdPool.begin()); 171 atomIdPool.erase(id); 172 } 173 } 174 175 void World::releaseAtomId(atomId_t id){ 176 atomIdPool.insert(id); 177 // defragmentation of the pool 178 set<atomId_t>::reverse_iterator iter; 179 // go through all Ids in the pool that lie immediately below the border 180 while(!atomIdPool.empty() && *(atomIdPool.rbegin())==(currAtomId-1)){ 181 atomIdPool.erase(--currAtomId); 182 } 183 } 184 185 bool World::reserveAtomId(atomId_t id){ 186 if(id>=currAtomId ){ 187 // add all ids between the new one and current border as available 188 for(atomId_t pos=currAtomId; pos<id; ++pos){ 189 atomIdPool.insert(pos); 190 } 191 currAtomId=id+1; 192 return true; 193 } 194 else if(atomIdPool.count(id)){ 195 atomIdPool.erase(id); 196 return true; 197 } 198 else{ 199 // this ID could not be reserved 200 return false; 201 } 202 } 203 204 // Molecules 124 205 125 206 /******************************* Iterators ********************************/ … … 135 216 World::AtomSet::iterator World::atomEnd(){ 136 217 return atoms.end(); 218 } 219 220 World::MoleculeIterator World::getMoleculeIter(MoleculeDescriptor descr){ 221 return MoleculeIterator(descr,this); 222 } 223 224 World::MoleculeSet::iterator World::moleculeEnd(){ 225 return molecules.end(); 137 226 } 138 227 -
src/World.hpp
r6a661c re6a9c1 27 27 class AtomDescriptor; 28 28 class AtomDescriptor_impl; 29 class MoleculeDescriptor; 30 class MoleculeDescriptor_impl; 29 31 class ManipulateAtomsProcess; 30 32 template<typename T> … … 36 38 friend class AtomDescriptor_impl; 37 39 friend class AtomDescriptor; 40 friend class MoleculeDescriptor_impl; 41 friend class MoleculeDescriptor; 38 42 39 43 // Actions, calculations etc associated with the World … … 77 81 78 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 /** 79 94 * get the number of molecules in the World 80 95 */ … … 117 132 118 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 /** 119 142 * Produces a process that calls a function on all Atoms matching a given descriptor. The process is not 120 143 * called at this time, so it can be passed around, stored inside menuItems etc. … … 125 148 protected: 126 149 /**** Iterators to use internal data structures */ 150 151 // Atoms 152 127 153 class AtomIterator { 128 154 public: … … 163 189 AtomSet::iterator atomEnd(); 164 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 165 232 /******* Internal manipulation routines for double callback and Observer mechanism ******/ 166 233 void doManipulate(ManipulateAtomsProcess *); 167 234 168 235 private: 236 237 atomId_t getNextAtomId(); 238 void releaseAtomId(atomId_t); 239 bool reserveAtomId(atomId_t); 240 169 241 periodentafel *periode; 170 242 AtomSet atoms; 243 std::set<atomId_t> atomIdPool; //<!stores the pool for all available AtomIds below currAtomId 171 244 atomId_t currAtomId; //!< stores the next available Id for atoms 172 245 MoleculeSet molecules; -
src/WorldIterators.cpp
r6a661c re6a9c1 8 8 #include "Descriptors/AtomDescriptor.hpp" 9 9 #include "Descriptors/AtomDescriptor_impl.hpp" 10 #include "Descriptors/MoleculeDescriptor.hpp" 11 #include "Descriptors/MoleculeDescriptor_impl.hpp" 10 12 #include "atom.hpp" 13 #include "molecule.hpp" 11 14 #include "World.hpp" 15 16 /********************** Atoms *************************/ 12 17 13 18 World::AtomIterator::AtomIterator(){ … … 76 81 77 82 void World::AtomIterator::advanceState(){ 83 // go forward until we have a matching atom or the end is reached 78 84 while((state!=world->atoms.end()) && (!descr->predicate(*state))){ 79 85 ++state; … … 85 91 return index; 86 92 } 93 94 /*********************************** Molecules ************************/ 95 96 World::MoleculeIterator::MoleculeIterator(){ 97 state = World::get()->moleculeEnd(); 98 } 99 100 World::MoleculeIterator::MoleculeIterator(MoleculeDescriptor _descr, World* _world) : 101 descr(_descr.get_impl()), 102 index(0), 103 world(_world) 104 { 105 state = world->molecules.begin(); 106 advanceState(); 107 } 108 109 World::MoleculeIterator::MoleculeIterator(const MoleculeIterator& rhs) : 110 state(rhs.state), 111 descr(rhs.descr), 112 index(rhs.index), 113 world(rhs.world) 114 {} 115 116 World::MoleculeIterator& World::MoleculeIterator::operator=(const MoleculeIterator& rhs) 117 { 118 if(&rhs!=this){ 119 state=rhs.state; 120 descr=rhs.descr; 121 index=rhs.index; 122 world=rhs.world; 123 } 124 return *this; 125 } 126 127 World::MoleculeIterator& World::MoleculeIterator::operator++(){ 128 ++state; 129 ++index; 130 advanceState(); 131 return *this; 132 } 133 134 World::MoleculeIterator World::MoleculeIterator::operator++(int){ 135 MoleculeIterator res(*this); 136 ++(*this); 137 return res; 138 } 139 140 bool World::MoleculeIterator::operator==(const MoleculeIterator& rhs){ 141 return state==rhs.state; 142 } 143 144 bool World::MoleculeIterator::operator==(const World::MoleculeSet::iterator& rhs){ 145 return state==rhs; 146 } 147 148 bool World::MoleculeIterator::operator!=(const MoleculeIterator& rhs){ 149 return state!=rhs.state; 150 } 151 152 bool World::MoleculeIterator::operator!=(const World::MoleculeSet::iterator& rhs){ 153 return state!=rhs; 154 } 155 156 molecule* World::MoleculeIterator::operator*(){ 157 return (*state).second; 158 } 159 160 void World::MoleculeIterator::advanceState(){ 161 while((state!=world->molecules.end()) && (!descr->predicate(*state))){ 162 ++state; 163 ++index; 164 } 165 } 166 167 int World::MoleculeIterator::getCount(){ 168 return index; 169 } 170 -
src/atom.cpp
r6a661c re6a9c1 290 290 } 291 291 292 void atom::setId(int _id) { 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) { 293 305 id=_id; 294 306 } 295 307 296 int atom::getId() {308 atomId_t atom::getId() { 297 309 return id; 298 310 } 299 311 300 atom* NewAtom(){ 301 return new atom(); 302 } 303 304 void DeleteAtom(atom* atom){ 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){ 305 319 delete atom; 306 320 } -
src/atom.hpp
r6a661c re6a9c1 40 40 */ 41 41 class atom : public TesselPoint, public TrajectoryParticle, public GraphNode, public BondedParticle, public virtual ParticleInfo, public virtual AtomInfo { 42 friend atom* NewAtom( );42 friend atom* NewAtom(atomId_t); 43 43 friend void DeleteAtom(atom*); 44 44 public: … … 79 79 void setWorld(World*); 80 80 81 virtual int getId(); 82 virtual void setId(int); 81 virtual atomId_t 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 83 90 protected: 84 91 /** … … 101 108 private: 102 109 World* world; 103 int id;110 atomId_t id; 104 111 }; 105 112 … … 109 116 * Use World::createAtom() instead. 110 117 */ 111 atom* NewAtom( );118 atom* NewAtom(atomId_t _id); 112 119 113 120 /** -
src/molecule_template.hpp
r6a661c re6a9c1 16 16 #endif 17 17 18 #include "atom.hpp" 18 19 /********************************************** declarations *******************************/ 19 20 -
src/unittests/AtomDescriptorTest.cpp
r6a661c re6a9c1 6 6 */ 7 7 8 #include " DescriptorUnittest.hpp"8 #include "AtomDescriptorTest.hpp" 9 9 10 10 #include <cppunit/CompilerOutputter.h> … … 25 25 /********************************************** Test classes **************************************/ 26 26 // Registers the fixture into the 'registry' 27 CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );27 CPPUNIT_TEST_SUITE_REGISTRATION( AtomDescriptorTest ); 28 28 29 29 // set up and tear down 30 void DescriptorUnittest::setUp(){30 void AtomDescriptorTest::setUp(){ 31 31 World::get(); 32 32 for(int i=0;i<ATOM_COUNT;++i){ 33 33 atoms[i]= World::get()->createAtom(); 34 atomIds[i] 34 atomIds[i]= atoms[i]->getId(); 35 35 } 36 36 } 37 void DescriptorUnittest::tearDown(){ 37 38 void AtomDescriptorTest::tearDown(){ 38 39 World::destroy(); 39 40 } 40 41 41 42 // some helper functions 42 bool hasAll(std::vector<atom*> atoms,int ids[ATOM_COUNT], std::set<int> excluded = std::set<int>()){43 static bool hasAllAtoms(std::vector<atom*> atoms,atomId_t ids[ATOM_COUNT], std::set<atomId_t> excluded = std::set<atomId_t>()){ 43 44 for(int i=0;i<ATOM_COUNT;++i){ 44 int id = ids[i];45 atomId_t id = ids[i]; 45 46 if(!excluded.count(id)){ 46 47 std::vector<atom*>::iterator iter; … … 58 59 } 59 60 60 bool hasNoDuplicates(std::vector<atom*> atoms){61 std::set< int> found;61 static bool hasNoDuplicateAtoms(std::vector<atom*> atoms){ 62 std::set<atomId_t> found; 62 63 std::vector<atom*>::iterator iter; 63 64 for(iter=atoms.begin();iter!=atoms.end();++iter){ … … 71 72 72 73 73 void DescriptorUnittest::AtomBaseSetsTest(){74 void AtomDescriptorTest::AtomBaseSetsTest(){ 74 75 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms()); 75 CPPUNIT_ASSERT_EQUAL( true , hasAll (allAtoms,atomIds));76 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicate s(allAtoms));76 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(allAtoms,atomIds)); 77 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(allAtoms)); 77 78 78 79 std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms()); 79 80 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty()); 80 81 } 81 void DescriptorUnittest::AtomIdTest(){82 void AtomDescriptorTest::AtomIdTest(){ 82 83 // test Atoms from boundaries and middle of the set 83 84 atom* testAtom; … … 93 94 94 95 // find some ID that has not been created 95 int outsideId =-1;96 atomId_t outsideId=0; 96 97 bool res = false; 97 while(!res) { 98 ++outsideId; 98 for(outsideId=0;!res;++outsideId) { 99 99 res = true; 100 100 for(int i = 0; i < ATOM_COUNT; ++i){ … … 106 106 CPPUNIT_ASSERT(!testAtom); 107 107 } 108 void DescriptorUnittest::AtomCalcTest(){108 void AtomDescriptorTest::AtomCalcTest(){ 109 109 // test some elementary set operations 110 110 { 111 111 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms()); 112 CPPUNIT_ASSERT_EQUAL( true , hasAll (testAtoms,atomIds));113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicate s(testAtoms));112 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 113 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); 114 114 } 115 115 116 116 { 117 117 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms()); 118 CPPUNIT_ASSERT_EQUAL( true , hasAll (testAtoms,atomIds));119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicate s(testAtoms));118 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 119 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); 120 120 } 121 121 … … 137 137 { 138 138 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms()); 139 CPPUNIT_ASSERT_EQUAL( true , hasAll (testAtoms,atomIds));140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicate s(testAtoms));139 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds)); 140 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); 141 141 } 142 142 … … 144 144 { 145 145 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(atomIds[ATOM_COUNT/2]))); 146 std::set< int> excluded;146 std::set<atomId_t> excluded; 147 147 excluded.insert(atomIds[ATOM_COUNT/2]); 148 CPPUNIT_ASSERT_EQUAL( true , hasAll (testAtoms,atomIds,excluded));149 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicate s(testAtoms));148 CPPUNIT_ASSERT_EQUAL( true , hasAllAtoms(testAtoms,atomIds,excluded)); 149 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicateAtoms(testAtoms)); 150 150 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size()); 151 151 } -
src/unittests/AtomDescriptorTest.hpp
r6a661c re6a9c1 1 1 /* 2 * DescriptorUnittest.hpp2 * AtomDescriptorTest.hpp 3 3 * 4 4 * Created on: Feb 9, 2010 … … 6 6 */ 7 7 8 #ifndef DESCRIPTORUNITTEST_HPP_9 #define DESCRIPTORUNITTEST_HPP_8 #ifndef ATOMDESCRIPTORTEST_HPP_ 9 #define ATOMDESCRIPTORTEST_HPP_ 10 10 11 11 #include <cppunit/extensions/HelperMacros.h> 12 13 #include "defs.hpp" 12 14 13 15 #define ATOM_COUNT (10) … … 15 17 class atom; 16 18 17 class DescriptorUnittest : public CppUnit::TestFixture19 class AtomDescriptorTest : public CppUnit::TestFixture 18 20 { 19 CPPUNIT_TEST_SUITE( DescriptorUnittest );21 CPPUNIT_TEST_SUITE( AtomDescriptorTest ); 20 22 CPPUNIT_TEST ( AtomBaseSetsTest ); 21 23 CPPUNIT_TEST ( AtomIdTest ); … … 33 35 private: 34 36 atom *atoms [ATOM_COUNT]; 35 int atomIds [ATOM_COUNT];37 atomId_t atomIds [ATOM_COUNT]; 36 38 }; 37 39 38 #endif /* DESCRIPTORUNITTEST_HPP_ */40 #endif /* ATOMDESCRIPTORTEST_HPP_ */ -
src/unittests/Makefile.am
r6a661c re6a9c1 13 13 AnalysisCorrelationToSurfaceUnitTest \ 14 14 AnalysisPairCorrelationUnitTest \ 15 atomsCalculationTest \ 16 AtomDescriptorTest \ 15 17 BondGraphUnitTest \ 18 CacheableTest \ 16 19 GSLMatrixSymmetricUnitTest \ 17 20 GSLMatrixUnitTest \ … … 21 24 ListOfBondsUnitTest \ 22 25 LogUnitTest \ 26 manipulateAtomsTest \ 23 27 MemoryUsageObserverUnitTest \ 24 28 MemoryAllocatorUnitTest \ 29 MoleculeDescriptorTest \ 30 ObserverTest \ 25 31 StackClassUnitTest \ 26 32 TesselationUnitTest \ … … 28 34 Tesselation_InOutsideUnitTest \ 29 35 VectorUnitTest \ 30 ObserverTest \31 CacheableTest \32 DescriptorUnittest \33 manipulateAtomsTest \34 atomsCalculationTest \35 36 ${MENUTESTS} 36 37 … … 44 45 TESTSOURCES = \ 45 46 ActOnAllUnitTest.cpp \ 47 ActionSequenceTest.cpp \ 46 48 analysisbondsunittest.cpp \ 47 49 AnalysisCorrelationToPointUnitTest.cpp \ 48 50 AnalysisCorrelationToSurfaceUnitTest.cpp \ 49 51 AnalysisPairCorrelationUnitTest.cpp \ 52 AtomDescriptorTest.cpp \ 53 atomsCalculationTest.cpp \ 50 54 bondgraphunittest.cpp \ 55 CacheableTest.cpp \ 51 56 gslmatrixsymmetricunittest.cpp \ 52 57 gslmatrixunittest.cpp \ … … 56 61 listofbondsunittest.cpp \ 57 62 logunittest.cpp \ 63 manipulateAtomsTest.cpp \ 58 64 memoryallocatorunittest.cpp \ 59 65 memoryusageobserverunittest.cpp \ 66 MoleculeDescriptorTest.cpp \ 67 ObserverTest.cpp \ 60 68 stackclassunittest.cpp \ 61 69 tesselationunittest.cpp \ 62 70 tesselation_boundarytriangleunittest.cpp \ 63 71 tesselation_insideoutsideunittest.cpp \ 64 vectorunittest.cpp \ 65 ObserverTest.cpp \ 66 CacheableTest.cpp \ 67 DescriptorUnittest.cpp \ 68 manipulateAtomsTest.cpp \ 69 atomsCalculationTest.cpp \ 70 ActionSequenceTest.cpp 72 vectorunittest.cpp 71 73 72 74 TESTHEADERS = \ … … 118 120 MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS} 119 121 122 MoleculeDescriptorTest_SOURCES = UnitTestMain.cpp MoleculeDescriptorTest.cpp MoleculeDescriptorTest.hpp 123 MoleculeDescriptorTest_LDADD = ${ALLLIBS} 124 120 125 StackClassUnitTest_SOURCES = UnitTestMain.cpp stackclassunittest.cpp stackclassunittest.hpp 121 126 StackClassUnitTest_LDADD = ${ALLLIBS} … … 142 147 CacheableTest_LDADD = ${ALLLIBS} 143 148 144 DescriptorUnittest_SOURCES = UnitTestMain.cpp DescriptorUnittest.cpp DescriptorUnittest.hpp145 DescriptorUnittest_LDADD = ${ALLLIBS}149 AtomDescriptorTest_SOURCES = UnitTestMain.cpp AtomDescriptorTest.cpp AtomDescriptorTest.hpp 150 AtomDescriptorTest_LDADD = ${ALLLIBS} 146 151 147 152 manipulateAtomsTest_SOURCES = UnitTestMain.cpp manipulateAtomsTest.cpp manipulateAtomsTest.hpp -
src/unittests/atomsCalculationTest.cpp
r6a661c re6a9c1 30 30 class AtomStub : public atom { 31 31 public: 32 AtomStub( int _id) :32 AtomStub(atomId_t _id) : 33 33 atom(), 34 34 id(_id), … … 36 36 {} 37 37 38 virtual int getId(){38 virtual atomId_t getId(){ 39 39 return id; 40 40 } … … 46 46 bool manipulated; 47 47 private: 48 int id;48 atomId_t id; 49 49 }; 50 50 -
src/unittests/manipulateAtomsTest.cpp
r6a661c re6a9c1 34 34 {} 35 35 36 virtual int getId(){36 virtual atomId_t getId(){ 37 37 return id; 38 38 } … … 44 44 bool manipulated; 45 45 private: 46 int id;46 atomId_t id; 47 47 }; 48 48
Note:
See TracChangeset
for help on using the changeset viewer.