Update.
[mtp.git] / misc.h
1
2 ////////////////////////////////////////////////////////////////////
3 // START_IP_HEADER                                                //
4 //                                                                //
5 // Written by Francois Fleuret                                    //
6 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
7 //                                                                //
8 // END_IP_HEADER                                                  //
9 ////////////////////////////////////////////////////////////////////
10
11 #ifndef MISC_H
12 #define MISC_H
13
14 #define VERBOSE
15
16 typedef float scalar_t;
17
18 #ifdef DEBUG
19 #define ASSERT(x) if(!(x)) {                                            \
20     std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << endl; \
21     abort();                                                            \
22   }
23 #else
24 #define ASSERT(x)
25 #endif
26
27 template<class T>
28 T **allocate_array(int a, int b) {
29   T *whole = new T[a * b];
30   T **array = new T *[a];
31   for(int k = 0; k < a; k++) {
32     array[k] = whole;
33     whole += b;
34   }
35   return array;
36 }
37
38 template<class T>
39 void deallocate_array(T **array) {
40   if(array) {
41     delete[] array[0];
42     delete[] array;
43   }
44 }
45
46 #endif