source: src/lists.hpp@ 9879f6

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
Last change on this file since 9879f6 was 9879f6, checked in by Frederik Heber <heber@…>, 15 years ago

Huge Refactoring due to class molecule now being an STL container.

  • molecule::start and molecule::end were dropped. Hence, the usual construct Walker = start while (Walker->next != end) {

Walker = walker->next
...

}
was changed to
for (molecule::iterator iter = begin(); iter != end(); ++iter) {

...

}
and (*iter) used instead of Walker.

  • Two build errors remain (beside some more in folder Actions, Patterns and unittest) in molecule_pointcloud.cpp and molecule.cpp
  • lists.cpp was deleted as specialization of atom* was not needed anymore
  • link, unlink, add, remove, removewithoutcheck all are not needed for atoms anymore, just for bonds (where first, last entries remain in molecule)
  • CreateFatherLookupTable() was put back into class molecule.
  • molecule::InternalPointer is now an iterator
  • class PointCloud: GoToPrevious() and GetTerminalPoint() were dropped as not needed.
  • some new STL functions in class molecule: size(), empty(), erase(), find() and insert()
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * lists.hpp
3 *
4 * Created on: Oct 9, 2009
5 * Author: heber
6 */
7
8#ifndef LISTS_HPP_
9#define LISTS_HPP_
10
11/******************************** Some templates for list management ***********************************/
12
13/** Adds linking of an item to a list.
14 * \param *walker
15 * \return true - adding succeeded, false - error in list
16 */
17template <typename X> void link(X *walker, X *end)
18{
19 X *vorher = end->previous;
20 if (vorher != 0)
21 vorher->next = walker;
22 end->previous = walker;
23 walker->previous = vorher;
24 walker->next = end;
25};
26
27/** Removes linking of an item in a list.
28 * \param *walker
29 * \return true - removing succeeded, false - given item not found in list
30 */
31template <typename X> void unlink(X *walker)
32{
33 if (walker->next != 0)
34 walker->next->previous = walker->previous;
35 if (walker->previous != 0)
36 walker->previous->next = walker->next;
37 walker->next = 0;
38 walker->previous= 0;
39};
40
41/** Adds new item before an item \a *end in a list.
42 * \param *pointer item to be added
43 * \param *end end of list
44 * \return true - addition succeeded, false - unable to add item to list
45 */
46template <typename X> bool add(X *pointer, X *end)
47{
48 if (end != 0) {
49 link(pointer, end);
50 } else {
51 pointer->previous = 0;
52 pointer->next = 0;
53 }
54 return true;
55};
56
57/** Finds item in list
58 * \param *suche search criteria
59 * \param *start begin of list
60 * \param *end end of list
61 * \return X - if found, 0 - if not found
62 */
63template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
64{
65 X *walker = start;
66 while (walker->next != end) { // go through list
67 walker = walker->next; // step onward beforehand
68 if (*walker->sort == *suche) return (walker);
69 }
70 return 0;
71};
72
73/** Removes an item from the list without check.
74 * \param *walker item to be removed
75 * \return true - removing succeeded, false - given item not found in list
76 */
77template <typename X> void removewithoutcheck(X *walker)
78{
79 if (walker != 0) {
80 unlink(walker);
81 delete(walker);
82 walker = 0;
83 }
84};
85
86/** Removes an item from the list without check.
87 * specialized for atoms, because these have to be removed from the world as well
88 * the implementation for this declaration is in lists.cpp
89 * \param *walker item to be removed
90 * \return true - removing succeeded, false - given item not found in list
91 */
92template <> void removewithoutcheck<atom>(atom *walker);
93
94/** Removes an item from the list, checks if exists.
95 * Checks beforehand if atom is really within molecule list.
96 * \param *pointer item to be removed
97 * \param *start begin of list
98 * \param *end end of list
99 * \return true - removing succeeded, false - given item not found in list
100 */
101template <typename X> bool remove(X *pointer, X *start, X *end)
102{
103 X *walker = find (pointer->sort, start, end);
104/* while (walker->next != pointer) { // search through list
105 walker = walker->next;
106 if (walker == end) return false; // item not found in list
107 }*/
108 // atom found, now unlink
109 if (walker != 0)
110 removewithoutcheck(walker);
111 else
112 return false;
113 return true;
114};
115
116/** Cleans the whole list.
117 * \param *start begin of list
118 * \param *end end of list
119 * \return true - list was cleaned successfully, false - error in list structure
120 */
121template <typename X> bool cleanup(X *start, X *end)
122{
123 X *pointer = start->next;
124 X *walker = 0;
125 while (pointer != end) { // go through list
126 walker = pointer; // mark current
127 pointer = pointer->next; // step onward beforehand
128 // remove walker
129 removewithoutcheck(walker);
130 }
131 return true;
132};
133
134#endif /* LISTS_HPP_ */
Note: See TracBrowser for help on using the repository browser.