Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / Basics / Basics_Utils.hxx
index 43f4173df95c134b28f708da4b486d526887cf72..507217dbe1251f2a6b08ea2cfa255ff72db4adb2 100644 (file)
 
 #include <string>
 #include <iostream>
+#ifndef WIN32
 #include <sys/time.h>
+#else
+#include <sys/timeb.h>
+#endif
+
 
 namespace Kernel_Utils
 {
@@ -57,6 +62,13 @@ namespace Kernel_Utils
 #endif
 }
 
+
+//
+// =============================================================
+// Helper macro for time analysis
+// =============================================================
+//
+
 #define START_TIMING(name) static long name##tcount=0;static long name##cumul;long name##tt0; timeval name##tv; gettimeofday(&name##tv,0); \
                            name##tt0=name##tv.tv_usec+name##tv.tv_sec*1000000; \
                            if(name##tcount==0)std::cerr<<__FILE__<<":"<<__LINE__<<":"<<#name<<std::endl;
@@ -67,4 +79,42 @@ namespace Kernel_Utils
                                   std::cerr <<__FILE__<<":"<<__LINE__<<":"<<#name<<" temps CPU(mus): "<< name##cumul<<std::endl; \
                                   name##tcount=0;name##cumul=0;}
 
+
+//
+// =============================================================
+// Macro and template functions for type conversions.
+// =============================================================
+//
+#include <string>
+#include <sstream>
+#include <stdlib.h>
+
+template < class T >
+std::string ToString(const T &arg)
+{
+  std::stringstream out;
+  out << arg;
+  return(out.str());
+}
+
+template < class T >
+double ToDouble(const T &arg) {
+  std::stringstream out;
+  out << arg;
+  double value = atof(out.str().c_str());
+  return value;
+}
+
+//
+// =============================================================
+// Simple Logger macros (no dependency with SALOME)
+// =============================================================
+//
+#define STDLOG(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
+#ifdef LOG
+#undef LOG
+#endif
+#define LOG STDLOG
+
+
 #endif //_Basics_UTILS_HXX_