simpletime.h
Go to the documentation of this file.
00001 //======================================================================
00028 //======================================================================
00029 
00030 #ifndef SIMPLETIME_H_
00031 #define SIMPLETIME_H_
00032 
00033 #include "sdhlibrary_settings.h"
00034 
00035 //----------------------------------------------------------------------
00036 // System Includes - include with <>
00037 //----------------------------------------------------------------------
00038 
00039 #if SDH_USE_VCC
00040 #include <sys/timeb.h>
00041 #include <time.h>
00042 #else
00043 # include <sys/time.h>
00044 #endif
00045 
00046 //----------------------------------------------------------------------
00047 // Project Includes - include with ""
00048 //----------------------------------------------------------------------
00049 
00050 #include "sdhexception.h"
00051 
00052 //----------------------------------------------------------------------
00053 // Defines, enums, unions, structs,
00054 //----------------------------------------------------------------------
00055 
00056 NAMESPACE_SDH_START
00057 
00058 
00059 //----------------------------------------------------------------------
00060 // Global variables
00061 //----------------------------------------------------------------------
00062 
00063 
00064 //----------------------------------------------------------------------
00065 // Function declarations
00066 //----------------------------------------------------------------------
00067 
00068 
00069 //----------------------------------------------------------------------
00070 // Class declarations
00071 //----------------------------------------------------------------------
00072 
00073 #if SDH_USE_VCC
00074 typedef long        tTimevalSec;
00075 typedef long        tTimevalUSec;
00076 #else
00077 typedef time_t      tTimevalSec;
00078 typedef suseconds_t tTimevalUSec;
00079 #endif
00080 
00084 class VCC_EXPORT cSimpleTime
00085 {
00086 protected:
00087 #if SDH_USE_VCC
00088     struct _timeb timebuffer;
00089 #else
00090     struct timeval a_time;
00091 #endif
00092 
00093 public:
00095     cSimpleTime()
00096     {
00097         StoreNow();
00098     }
00099     //----------------------------------------------------------------------
00100 
00101 
00103     void StoreNow( void )
00104     {
00105 #if SDH_USE_VCC
00106          _ftime64_s( &timebuffer );
00107 
00108 #else
00109          gettimeofday( &a_time, NULL );
00110 #endif
00111     }
00112     //----------------------------------------------------------------------
00113 
00115     double Elapsed( void ) const
00116     {
00117         cSimpleTime now;
00118 
00119         return Elapsed( now );
00120     }
00121     //----------------------------------------------------------------------
00122 
00123 
00125     long Elapsed_us( void ) const
00126     {
00127         cSimpleTime now;
00128 
00129         return Elapsed_us( now );
00130     }
00131     //----------------------------------------------------------------------
00132 
00133 
00134 #if SDH_USE_VCC
00135 
00136     double Elapsed( cSimpleTime const& other ) const
00137     {
00138         double seconds = double( other.timebuffer.time - timebuffer.time);
00139         double msec = double( other.timebuffer.millitm - timebuffer.millitm );
00140 
00141         return seconds + msec / 1000.0;
00142     }
00143     //----------------------------------------------------------------------
00144 
00146     long Elapsed_us( cSimpleTime const& other ) const
00147     {
00148         long seconds = long( other.timebuffer.time - timebuffer.time);
00149         long msec    = long( other.timebuffer.millitm - timebuffer.millitm );
00150 
00151         return seconds * 1000000 + msec * 1000;
00152     }
00153     //----------------------------------------------------------------------
00154 #else
00155 
00156     double Elapsed( cSimpleTime const& other ) const
00157     {
00158         double seconds = double( other.a_time.tv_sec - a_time.tv_sec );
00159         double usec = double( other.a_time.tv_usec - a_time.tv_usec );
00160 
00161         return seconds + usec / 1000000.0;
00162     }
00163     //----------------------------------------------------------------------
00164 
00166     long Elapsed_us( cSimpleTime const& other ) const
00167     {
00168         long seconds = other.a_time.tv_sec - a_time.tv_sec;
00169         long usec    = other.a_time.tv_usec - a_time.tv_usec;
00170 
00171         return seconds * 1000000 + usec;
00172     }
00173     //----------------------------------------------------------------------
00174 
00175 
00177     timeval Timeval( void )
00178     {
00179         return a_time;
00180     }
00181 #endif
00182 };
00183 
00184 
00185 NAMESPACE_SDH_END
00186 
00187 #endif
00188 
00189 
00190 //======================================================================
00191 /*
00192   Here are some settings for the emacs/xemacs editor (and can be safely ignored):
00193   (e.g. to explicitely set C++ mode for *.h header files)
00194 
00195   Local Variables:
00196   mode:C++
00197   mode:ELSE
00198   End:
00199 */
00200 //======================================================================


schunk_sdh
Author(s): Florian Weisshardt
autogenerated on Mon Oct 6 2014 07:29:15