Back to index

salome-kernel  6.5.0
Basics_Utils.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SALOME Utils : general SALOME's definitions and tools
00021 //  File   : Basics_DirUtils.hxx
00022 //  Autor  : Alexander A. BORODIN
00023 //  Module : SALOME
00024 //
00025 #ifndef _Basics_UTILS_HXX_
00026 #define _Basics_UTILS_HXX_
00027 
00028 #include "SALOME_Basics.hxx"
00029 #include <string>
00030 #include <iostream>
00031 
00032 #ifndef WIN32
00033 #include <sys/time.h>
00034 #else
00035 #include <winsock2.h>
00036 #include <windows.h>
00037 #pragma comment(lib,"winmm.lib")
00038 #endif
00039 
00040 
00041 namespace Kernel_Utils
00042 {
00043   BASICS_EXPORT std::string GetHostname();
00044 
00045   class BASICS_EXPORT Localizer
00046   {
00047   public:
00048     Localizer();
00049     ~Localizer();
00050   private:
00051     std::string myCurLocale;
00052   };
00053   
00055   enum GUIDtype {
00056     DefUserID = 1,  
00057     ObjectdID       
00058   };
00059 
00061   BASICS_EXPORT std::string GetGUID( GUIDtype );
00062 #ifndef WIN32
00063   BASICS_EXPORT void print_traceback();
00064 #endif
00065 }
00066 
00067 
00068 //
00069 // =============================================================
00070 // Helper macro for time analysis
00071 // =============================================================
00072 //
00073 #ifndef WIN32
00074 #define START_TIMING(name) static long name##tcount=0;static long name##cumul;long name##tt0; timeval name##tv; gettimeofday(&name##tv,0); \
00075                            name##tt0=name##tv.tv_usec+name##tv.tv_sec*1000000; \
00076                            if(name##tcount==0)std::cerr<<__FILE__<<":"<<__LINE__<<":"<<#name<<std::endl;
00077 
00078 #define END_TIMING(name,NUMBER) name##tcount=name##tcount+1;gettimeofday(&name##tv,0); \
00079                                 name##cumul=name##cumul+name##tv.tv_usec+name##tv.tv_sec*1000000 -name##tt0; \
00080                                 if(name##tcount==NUMBER){ \
00081                                   std::cerr <<__FILE__<<":"<<__LINE__<<":"<<#name<<" temps CPU(mus): "<< name##cumul<<std::endl; \
00082                                   name##tcount=0;name##cumul=0;}
00083 #else
00084 
00085 #define START_TIMING(name) static long name##tcount=0;static DWORD name##cumul;DWORD  name##tv;DWORD  name##tt0 = timeGetTime(); \
00086                            if(name##tcount==0)std::cerr<<__FILE__<<":"<<__LINE__<<":"<<#name<<std::endl;
00087 
00088 #define END_TIMING(name,NUMBER) name##tcount=name##tcount+1; name##tv = timeGetTime(); \
00089                                 name##cumul=name##cumul+name##tv - name##tt0; \
00090                                 if(name##tcount==NUMBER){ \
00091                                   std::cerr <<__FILE__<<":"<<__LINE__<<":"<<#name<<" temps CPU(mus): "<< name##cumul<<std::endl; \
00092                                   name##tcount=0;name##cumul=0;}
00093 #endif
00094 
00095 
00096 
00097 //
00098 // =============================================================
00099 // Macro and template functions for type conversions.
00100 // =============================================================
00101 //
00102 #include <string>
00103 #include <sstream>
00104 #include <stdlib.h>
00105 
00106 template < class T >
00107 std::string ToString(const T &arg)
00108 {
00109   std::stringstream out;
00110   out << arg;
00111   return(out.str());
00112 }
00113 
00114 template < class T >
00115 double ToDouble(const T &arg) {
00116   std::stringstream out;
00117   out << arg;
00118   double value = atof(out.str().c_str());
00119   return value;
00120 }
00121 
00122 //
00123 // =============================================================
00124 // Simple Logger macros (no dependency with SALOME)
00125 // =============================================================
00126 //
00127 #define STDLOG(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
00128 #ifdef LOG
00129 #undef LOG
00130 #endif
00131 #define LOG STDLOG
00132 
00133 
00134 #endif //_Basics_UTILS_HXX_