Update.
[mtp.git] / misc.h
diff --git a/misc.h b/misc.h
new file mode 100644 (file)
index 0000000..f9bc8e5
--- /dev/null
+++ b/misc.h
@@ -0,0 +1,46 @@
+
+////////////////////////////////////////////////////////////////////
+// START_IP_HEADER                                                //
+//                                                                //
+// Written by Francois Fleuret                                    //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
+//                                                                //
+// END_IP_HEADER                                                  //
+////////////////////////////////////////////////////////////////////
+
+#ifndef MISC_H
+#define MISC_H
+
+#define VERBOSE
+
+typedef float scalar_t;
+
+#ifdef DEBUG
+#define ASSERT(x) if(!(x)) {                                            \
+    std::cerr << "ASSERT FAILED IN " << __FILE__ << ":" << __LINE__ << endl; \
+    abort();                                                            \
+  }
+#else
+#define ASSERT(x)
+#endif
+
+template<class T>
+T **allocate_array(int a, int b) {
+  T *whole = new T[a * b];
+  T **array = new T *[a];
+  for(int k = 0; k < a; k++) {
+    array[k] = whole;
+    whole += b;
+  }
+  return array;
+}
+
+template<class T>
+void deallocate_array(T **array) {
+  if(array) {
+    delete[] array[0];
+    delete[] array;
+  }
+}
+
+#endif