Changes in src/helpers.hpp [be90f1:f66195]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/helpers.hpp
rbe90f1 rf66195 9 9 using namespace std; 10 10 11 /*********************************************** includes ***********************************/ 12 11 13 // include config.h 12 14 #ifdef HAVE_CONFIG_H … … 14 16 #endif 15 17 16 #include <iostream>17 #include <iomanip>18 18 #include <fstream> 19 #include <sstream>20 #include <math.h>21 #include <string>22 19 23 #include "defs.hpp"24 #include "verbose.hpp"25 20 #include "memoryallocator.hpp" 26 21 … … 53 48 char *FixedDigitNumber(const int FragmentNumber, const int digits); 54 49 bool IsValidNumber( const char *string); 55 static void performCriticalExit(); 50 int CompareDoubles (const void * a, const void * b); 51 double * ReturnFullMatrixforSymmetric(double *cell_size); 56 52 57 53 /********************************************** helpful template functions *********************************/ … … 115 111 }; 116 112 117 /******************************** Some templates for list management ***********************************/118 119 /** Adds linking of an item to a list.120 * \param *walker121 * \return true - adding succeeded, false - error in list122 */123 template <typename X> void link(X *walker, X *end)124 {125 X *vorher = end->previous;126 if (vorher != NULL)127 vorher->next = walker;128 end->previous = walker;129 walker->previous = vorher;130 walker->next = end;131 };132 133 /** Removes linking of an item in a list.134 * \param *walker135 * \return true - removing succeeded, false - given item not found in list136 */137 template <typename X> void unlink(X *walker)138 {139 if (walker->next != NULL)140 walker->next->previous = walker->previous;141 if (walker->previous != NULL)142 walker->previous->next = walker->next;143 };144 145 /** Adds new item before an item \a *end in a list.146 * \param *pointer item to be added147 * \param *end end of list148 * \return true - addition succeeded, false - unable to add item to list149 */150 template <typename X> bool add(X *pointer, X *end)151 {152 if (end != NULL) {153 link(pointer, end);154 } else {155 pointer->previous = NULL;156 pointer->next = NULL;157 }158 return true;159 };160 161 /** Finds item in list162 * \param *suche search criteria163 * \param *start begin of list164 * \param *end end of list165 * \return X - if found, NULL - if not found166 */167 template <typename X, typename Y> X * find(Y *suche, X *start, X *end)168 {169 X *walker = start;170 while (walker->next != end) { // go through list171 walker = walker->next; // step onward beforehand172 if (*walker->sort == *suche) return (walker);173 }174 return NULL;175 };176 177 /** Removes an item from the list without check.178 * \param *walker item to be removed179 * \return true - removing succeeded, false - given item not found in list180 */181 template <typename X> void removewithoutcheck(X *walker)182 {183 if (walker != NULL) {184 unlink(walker);185 delete(walker);186 walker = NULL;187 }188 };189 190 /** Removes an item from the list, checks if exists.191 * Checks beforehand if atom is really within molecule list.192 * \param *pointer item to be removed193 * \param *start begin of list194 * \param *end end of list195 * \return true - removing succeeded, false - given item not found in list196 */197 template <typename X> bool remove(X *pointer, X *start, X *end)198 {199 X *walker = find (pointer->sort, start, end);200 /* while (walker->next != pointer) { // search through list201 walker = walker->next;202 if (walker == end) return false; // item not found in list203 }*/204 // atom found, now unlink205 if (walker != NULL)206 removewithoutcheck(walker);207 else208 return false;209 return true;210 };211 212 /** Cleans the whole list.213 * \param *start begin of list214 * \param *end end of list215 * \return true - list was cleaned successfully, false - error in list structure216 */217 template <typename X> bool cleanup(X *start, X *end)218 {219 X *pointer = start->next;220 X *walker;221 while (pointer != end) { // go through list222 walker = pointer; // mark current223 pointer = pointer->next; // step onward beforehand224 // remove walker225 unlink(walker);226 delete(walker);227 walker = NULL;228 }229 return true;230 };231 232 /** Returns the first marker in a chain list.233 * \param *me one arbitrary item in chain list234 * \return poiner to first marker235 */236 template <typename X> X *GetFirst(X *me)237 {238 X *Binder = me;239 while(Binder->previous != NULL)240 Binder = Binder->previous;241 return Binder;242 };243 244 /** Returns the last marker in a chain list.245 * \param *me one arbitrary item in chain list246 * \return poiner to last marker247 */248 template <typename X> X *GetLast(X *me)249 {250 X *Binder = me;251 while(Binder->next != NULL)252 Binder = Binder->next;253 return Binder;254 };255 256 113 /** Frees a two-dimensional array. 257 114 * \param *ptr pointer to array … … 269 126 }; 270 127 128 template <typename T> void Increment(T *value, T inc) 129 { 130 *value += inc; 131 }; 132 133 template <typename T> void AbsoluteValue(T *value, T abs) 134 { 135 *value = abs; 136 }; 137 138 271 139 272 140
Note:
See TracChangeset
for help on using the changeset viewer.