source: src/lists.hpp@ 796aa6

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 796aa6 was d3347e, checked in by Tillmann Crueger <crueger@…>, 15 years ago

FIX: repaired compiler problems for latest refactoring

  • 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
11class atom;
12
13/******************************** Some templates for list management ***********************************/
14
15/** Adds linking of an item to a list.
16 * \param *walker
17 * \return true - adding succeeded, false - error in list
18 */
19template <typename X> void link(X *walker, X *end)
20{
21 X *vorher = end->previous;
22 if (vorher != 0)
23 vorher->next = walker;
24 end->previous = walker;
25 walker->previous = vorher;
26 walker->next = end;
27};
28
29/** Removes linking of an item in a list.
30 * \param *walker
31 * \return true - removing succeeded, false - given item not found in list
32 */
33template <typename X> void unlink(X *walker)
34{
35 if (walker->next != 0)
36 walker->next->previous = walker->previous;
37 if (walker->previous != 0)
38 walker->previous->next = walker->next;
39 walker->next = 0;
40 walker->previous= 0;
41};
42
43/** Adds new item before an item \a *end in a list.
44 * \param *pointer item to be added
45 * \param *end end of list
46 * \return true - addition succeeded, false - unable to add item to list
47 */
48template <typename X> bool add(X *pointer, X *end)
49{
50 if (end != 0) {
51 link(pointer, end);
52 } else {
53 pointer->previous = 0;
54 pointer->next = 0;
55 }
56 return true;
57};
58
59/** Finds item in list
60 * \param *suche search criteria
61 * \param *start begin of list
62 * \param *end end of list
63 * \return X - if found, 0 - if not found
64 */
65template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
66{
67 X *walker = start;
68 while (walker->next != end) { // go through list
69 walker = walker->next; // step onward beforehand
70 if (*walker->sort == *suche) return (walker);
71 }
72 return 0;
73};
74
75/** Removes an item from the list without check.
76 * \param *walker item to be removed
77 * \return true - removing succeeded, false - given item not found in list
78 */
79template <typename X> void removewithoutcheck(X *walker)
80{
81 if (walker != 0) {
82 unlink(walker);
83 delete(walker);
84 walker = 0;
85 }
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 */
94template <> void removewithoutcheck<atom>(atom *walker);
95
96/** Removes an item from the list, checks if exists.
97 * Checks beforehand if atom is really within molecule list.
98 * \param *pointer item to be removed
99 * \param *start begin of list
100 * \param *end end of list
101 * \return true - removing succeeded, false - given item not found in list
102 */
103template <typename X> bool remove(X *pointer, X *start, X *end)
104{
105 X *walker = find (pointer->sort, start, end);
106/* while (walker->next != pointer) { // search through list
107 walker = walker->next;
108 if (walker == end) return false; // item not found in list
109 }*/
110 // atom found, now unlink
111 if (walker != 0)
112 removewithoutcheck(walker);
113 else
114 return false;
115 return true;
116};
117
118/** Cleans the whole list.
119 * \param *start begin of list
120 * \param *end end of list
121 * \return true - list was cleaned successfully, false - error in list structure
122 */
123template <typename X> bool cleanup(X *start, X *end)
124{
125 X *pointer = start->next;
126 X *walker = 0;
127 while (pointer != end) { // go through list
128 walker = pointer; // mark current
129 pointer = pointer->next; // step onward beforehand
130 // remove walker
131 removewithoutcheck(walker);
132 }
133 return true;
134};
135
136#endif /* LISTS_HPP_ */
Note: See TracBrowser for help on using the repository browser.