Added README.md
[mtp.git] / misc.h
1
2 /*
3  *  mtp is the ``Multi Tracked Paths'', an implementation of the
4  *  k-shortest paths algorithm for multi-target tracking.
5  *
6  *  Copyright (c) 2012 Idiap Research Institute, http://www.idiap.ch/
7  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
8  *
9  *  This file is part of mtp.
10  *
11  *  mtp is free software: you can redistribute it and/or modify it
12  *  under the terms of the GNU General Public License version 3 as
13  *  published by the Free Software Foundation.
14  *
15  *  mtp is distributed in the hope that it will be useful, but WITHOUT
16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
18  *  License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with selector.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef MISC_H
26 #define MISC_H
27
28 #include <stdlib.h>
29
30 typedef float scalar_t;
31
32 #ifdef DEBUG
33 #define ASSERT(x) if(!(x)) {                                            \
34     std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << endl; \
35     abort();                                                            \
36   }
37 #else
38 #define ASSERT(x)
39 #endif
40
41 template<class T>
42 T **allocate_array(int a, int b) {
43   T *whole = new T[a * b];
44   T **array = new T *[a];
45   for(int k = 0; k < a; k++) {
46     array[k] = whole;
47     whole += b;
48   }
49   return array;
50 }
51
52 template<class T>
53 void deallocate_array(T **array) {
54   if(array) {
55     delete[] array[0];
56     delete[] array;
57   }
58 }
59
60 #endif