source: src/lists.hpp@ 9df680

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 9df680 was 56f73b, checked in by Frederik Heber <heber@…>, 14 years ago

Added config.h also to all header files, code check test ascertain this in the future.

  • as we want to use config.h to pass stuff such as MEMDEBUG, NDEBUG, LOG_OBSERVER, we have to make sure that it is present in each and every file.
  • split up CodeChecks/testsuite.at: each test has its own .at file.
  • Property mode set to 100644
File size: 3.6 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// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
17class atom;
18
19/******************************** Some templates for list management ***********************************/
20
21/** Adds linking of an item to a list.
22 * \param *walker
23 * \return true - adding succeeded, false - error in list
24 */
25template <typename X> void link(X *walker, X *end)
26{
27 X *vorher = end->previous;
28 if (vorher != 0)
29 vorher->next = walker;
30 end->previous = walker;
31 walker->previous = vorher;
32 walker->next = end;
33};
34
35/** Removes linking of an item in a list.
36 * \param *walker
37 * \return true - removing succeeded, false - given item not found in list
38 */
39template <typename X> void unlink(X *walker)
40{
41 if (walker->next != 0)
42 walker->next->previous = walker->previous;
43 if (walker->previous != 0)
44 walker->previous->next = walker->next;
45 walker->next = 0;
46 walker->previous= 0;
47};
48
49/** Adds new item before an item \a *end in a list.
50 * \param *pointer item to be added
51 * \param *end end of list
52 * \return true - addition succeeded, false - unable to add item to list
53 */
54template <typename X> bool add(X *pointer, X *end)
55{
56 if (end != 0) {
57 link(pointer, end);
58 } else {
59 pointer->previous = 0;
60 pointer->next = 0;
61 }
62 return true;
63};
64
65/** Finds item in list
66 * \param *suche search criteria
67 * \param *start begin of list
68 * \param *end end of list
69 * \return X - if found, 0 - if not found
70 */
71template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
72{
73 X *walker = start;
74 while (walker->next != end) { // go through list
75 walker = walker->next; // step onward beforehand
76 if (*walker->sort == *suche) return (walker);
77 }
78 return 0;
79};
80
81/** Removes an item from the list without check.
82 * \param *walker item to be removed
83 * \return true - removing succeeded, false - given item not found in list
84 */
85template <typename X> void removewithoutcheck(X *walker)
86{
87 if (walker != 0) {
88 unlink(walker);
89 delete(walker);
90 walker = 0;
91 }
92};
93
94/** Removes an item from the list without check.
95 * specialized for atoms, because these have to be removed from the world as well
96 * the implementation for this declaration is in lists.cpp
97 * \param *walker item to be removed
98 * \return true - removing succeeded, false - given item not found in list
99 */
100template <> void removewithoutcheck<atom>(atom *walker);
101
102/** Removes an item from the list, checks if exists.
103 * Checks beforehand if atom is really within molecule list.
104 * \param *pointer item to be removed
105 * \param *start begin of list
106 * \param *end end of list
107 * \return true - removing succeeded, false - given item not found in list
108 */
109template <typename X> bool remove(X *pointer, X *start, X *end)
110{
111 X *walker = find (pointer->sort, start, end);
112/* while (walker->next != pointer) { // search through list
113 walker = walker->next;
114 if (walker == end) return false; // item not found in list
115 }*/
116 // atom found, now unlink
117 if (walker != 0)
118 removewithoutcheck(walker);
119 else
120 return false;
121 return true;
122};
123
124/** Cleans the whole list.
125 * \param *start begin of list
126 * \param *end end of list
127 * \return true - list was cleaned successfully, false - error in list structure
128 */
129template <typename X> bool cleanup(X *start, X *end)
130{
131 X *pointer = start->next;
132 X *walker = 0;
133 while (pointer != end) { // go through list
134 walker = pointer; // mark current
135 pointer = pointer->next; // step onward beforehand
136 // remove walker
137 removewithoutcheck(walker);
138 }
139 return true;
140};
141
142#endif /* LISTS_HPP_ */
Note: See TracBrowser for help on using the repository browser.