/** \file helpers.hpp * * Declaration of some auxiliary functions for memory dis-/allocation and so on */ #ifndef HELPERS_HPP_ #define HELPERS_HPP_ using namespace std; /*********************************************** includes ***********************************/ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include "defs.hpp" #include "log.hpp" #include "memoryallocator.hpp" /********************************************** definitions *********************************/ // some algebraic matrix stuff double RDET3(const double a[NDIM*NDIM]); double RDET2(const double a[4]); double RDET2(const double a0, const double a1, const double a2, const double a3); /********************************************** helpful functions *********************************/ // taken out of TREMOLO /*@-namechecks@*/ #ifndef __GNUC__ # undef __attribute__ # define __attribute__(x) #endif /*@=namechecks@*/ /* Behandelt aufgetretene Fehler. error ist der Fehlertyp(enum Errors) void *SpecialData ist ein untypisierter Zeiger auf Spezielle Daten zur Fehlerbehandlung. Man koennte auch noch einen Zeiger auf eine Funktion uebergeben */ extern void /*@exits@*/ debug(const char *output); //__attribute__ ((__return__)); #define debug(data) debug_in((data), __FILE__, __LINE__) extern void /*@exits@*/ debug_in(const char *output, const char *file, const int line); //__attribute__ ((__return__)); double ask_value(const char *text); bool check_bounds(double *x, double *cell_size); void bound(double *b, double lower_bound, double upper_bound); int pot(int base, int n); int CountLinesinFile(ifstream &InputFile); char *FixedDigitNumber(const int FragmentNumber, const int digits); bool IsValidNumber( const char *string); int CompareDoubles (const void * a, const void * b); double * ReturnFullMatrixforSymmetric(const double * const cell_size); double * InverseMatrix(const double * const A); void performCriticalExit(); /********************************************** helpful template functions *********************************/ /** Flips two values. * \param x first value * \param y second value */ template void flip(T &x, T &y) { T tmp; tmp = x; x = y; y = tmp; }; /** returns greater of the two values. * \param x first value * \param y second value * \return greater of the two (by operator>()) */ template T Max(T x, T y) { if (x > y) return x; else return y; }; /** returns smaller of the two values. * \param x first value * \param y second value * \return smaller of the two (by operator<()) */ template T Min(T x, T y) { if (x < y) return x; else return y; }; /** Frees a two-dimensional array. * \param *ptr pointer to array * \param dim first dim of array */ template void Free2DArray(X **ptr, int dim) { int i; if (ptr != NULL) { for(i=dim;i--;) if (ptr[i] != NULL) free(ptr[i]); free(ptr); } }; template void Increment(T *value, T *inc) { *value += *inc; }; template void AbsoluteValue(T *value, T *abs) { *value = *abs; }; template void IncrementalAbsoluteValue(T *value, T *abs) { *value = *abs; (*abs) += 1; }; #define PLURAL_S(v) (((v)==1)?"":"s") #endif /*HELPERS_HPP_*/