]> Creatis software - clitk.git/blobdiff - common/clitkCommon.h
Moved from repository clitk.private to tools
[clitk.git] / common / clitkCommon.h
index 31f28dc40637bd95e91dfec7974f23183edd43ac..2f5b26f1173b3e5e94999816031695c13cb2afc4 100644 (file)
 #if defined(unix) || defined(__APPLE__)
 #  include <sys/time.h>
 #  include <sys/resource.h>
-#elif defined(WIN32)
+#elif defined(_WIN32)
 #  include <windows.h>
+#  include <stdint.h>
 #endif
 
+#define VTK_EXCLUDE_STRSTREAM_HEADERS
+
 //--------------------------------------------------------------------
 namespace clitk {
 
   typedef unsigned char uchar;
   typedef unsigned short ushort;
   typedef unsigned int uint;
+  
+#define CLITK_TRY_CATCH_EXIT(func) \
+  try { \
+    func; \
+  } \
+  catch (const itk::ExceptionObject& e) { \
+    e.Print(std::cout); \
+    exit(-1);\
+  } \
+  catch (const std::exception& e) { \
+    std::cout << e.what() << std::endl; \
+    exit(-2);\
+  } \
+  catch (...) { \
+    std::cout << "Unknown excpetion" << std::endl; \
+    exit(-3); \
+  }
+    
 
   //--------------------------------------------------------------------
   // when everything goes wrong
@@ -209,6 +230,18 @@ namespace clitk {
   //--------------------------------------------------------------------
   void PrintMemoryUsed();
 
+  //--------------------------------------------------------------------
+  // Convert a map to a vector
+  template <typename M, typename V> 
+  void MapToVecFirst(const M & m, V & v);
+  template <typename M, typename V> 
+  void MapToVecSecond(const M & m, V & v);
+
+  //--------------------------------------------------------------------
+  // Find/replace string
+  template<class T>
+  int inline findAndReplace(T& source, const T& find, const T& replace);
+
 #include "clitkCommon.txx"
 
 } // end namespace