/** \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 *********************************/ /********************************************** 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 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 *********************************/ /** 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") // this is to allow different modes of access for // maps and sets template struct _take{ Res get(T value) const; }; // if we have a set,vector etc we can directly access the result template struct _take{ static inline Res get(Res value){ return value; } }; // if we have a map we have to access the second part of // the pair template struct _take >{ static inline Res get(std::pair value){ return value.second; } }; #endif /*HELPERS_HPP_*/