Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/helpers.hpp

    rbe90f1 rf66195  
    99using namespace std;
    1010
     11/*********************************************** includes ***********************************/
     12
    1113// include config.h
    1214#ifdef HAVE_CONFIG_H
     
    1416#endif
    1517
    16 #include <iostream>
    17 #include <iomanip>
    1818#include <fstream>
    19 #include <sstream>
    20 #include <math.h>
    21 #include <string>
    2219
    23 #include "defs.hpp"
    24 #include "verbose.hpp"
    2520#include "memoryallocator.hpp"
    2621
     
    5348char *FixedDigitNumber(const int FragmentNumber, const int digits);
    5449bool IsValidNumber( const char *string);
    55 static void performCriticalExit();
     50int CompareDoubles (const void * a, const void * b);
     51double * ReturnFullMatrixforSymmetric(double *cell_size);
    5652
    5753/********************************************** helpful template functions *********************************/
     
    115111};
    116112
    117 /******************************** Some templates for list management ***********************************/
    118 
    119 /** Adds linking of an item to a list.
    120  * \param *walker
    121  * \return true - adding succeeded, false - error in list
    122  */
    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 *walker
    135  * \return true - removing succeeded, false - given item not found in list
    136  */
    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 added
    147  * \param *end  end of list
    148  * \return true - addition succeeded, false - unable to add item to list
    149  */
    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 list
    162  * \param *suche  search criteria
    163  * \param *start  begin of list
    164  * \param *end  end of list
    165  * \return X - if found, NULL - if not found
    166  */
    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 list
    171     walker = walker->next; // step onward beforehand
    172     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 removed
    179  * \return true - removing succeeded, false - given item not found in list
    180  */
    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 removed
    193  * \param *start  begin of list
    194  * \param *end  end of list
    195  * \return true - removing succeeded, false - given item not found in list
    196  */
    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 list
    201     walker = walker->next;
    202     if (walker == end) return false;  // item not found in list
    203   }*/
    204   // atom found, now unlink
    205   if (walker != NULL)
    206     removewithoutcheck(walker);
    207   else
    208     return false;
    209   return true;
    210 };
    211 
    212 /** Cleans the whole list.
    213  * \param *start begin of list
    214  * \param *end end of list
    215  * \return true - list was cleaned successfully, false - error in list structure
    216  */
    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 list
    222     walker = pointer; // mark current
    223     pointer = pointer->next; // step onward beforehand
    224     // remove walker
    225     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 list
    234  * \return poiner to first marker
    235  */
    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 list
    246  * \return poiner to last marker
    247  */
    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 
    256113/** Frees a two-dimensional array.
    257114 * \param *ptr pointer to array
     
    269126};
    270127
     128template <typename T> void Increment(T *value, T inc)
     129{
     130  *value += inc;
     131};
     132
     133template <typename T> void AbsoluteValue(T *value, T abs)
     134{
     135  *value = abs;
     136};
     137
     138
    271139
    272140
Note: See TracChangeset for help on using the changeset viewer.