Logo
~Apps~
~Projects~
~Contact~


Clock Class Reference

millisecond timer for debug printing More...

#include <Clock.h>

List of all members.


Public Member Functions

 Clock ()
 ~Clock ()
void PrintDiff (const std::string &="")
void Reset ()

Private Member Functions

 Clock (const Clock &)
Clockoperator= (const Clock &)

Private Attributes

timeval m_tv
timeval m_tv0
timezone m_tz
timezone m_tz0

Detailed Description

millisecond timer for debug printing

File ......... Clock.h Published .... 2005-06-14 Author ....... grymse@alhem.net

Definition at line 37 of file Clock.h.


Constructor & Destructor Documentation

Clock::Clock (  ) 

File ......... Clock.cpp Published .... 2005-06-14 Author ....... grymse@alhem.net

Definition at line 30 of file Clock.cpp.

References m_tv, m_tv0, m_tz, and m_tz0.

00031 {
00032 #ifdef _WIN32
00033         ::GetLocalTime(&m_time);
00034         ::GetLocalTime(&m_time0);
00035 #else
00036         gettimeofday(&m_tv, &m_tz);
00037         gettimeofday(&m_tv0, &m_tz0);
00038 #endif
00039 }

Clock::~Clock (  ) 

Definition at line 42 of file Clock.cpp.

00043 {
00044 }

Clock::Clock ( const Clock  )  [inline, private]

Definition at line 53 of file Clock.h.

00053 {} // copy constructor


Member Function Documentation

void Clock::PrintDiff ( const std::string &  = ""  ) 

Definition at line 47 of file Clock.cpp.

References m_tv, m_tv0, and Reset().

00048 {
00049 #ifdef _WIN32
00050         SYSTEMTIME time;
00051         SYSTEMTIME time0;
00052         ::GetLocalTime(&time);
00053         ::GetLocalTime(&time0);
00054         time.wSecond -= m_time.wSecond;
00055         if (time.wSecond < 0)
00056                 time.wSecond += 60;
00057         {
00058                 time_t t = time.wSecond * 1000 + time.wMilliseconds - m_time.wMilliseconds;
00059                 time_t s = t / 1000;
00060                 time_t m = t % 1000;
00061                 if (!str.size())
00062                         printf("Time: %d.%03d", s, m);
00063                 else
00064                         printf("Time %s: %d.%03d", str.c_str(), s, m);
00065         }
00066         time0.wSecond -= m_time0.wSecond;
00067         if (time0.wSecond < 0)
00068                 time0.wSecond += 60;
00069         {
00070                 time_t t = time0.wSecond * 1000 + time0.wMilliseconds - m_time0.wMilliseconds;
00071                 time_t s = t / 1000;
00072                 time_t m = t % 1000;
00073                 if (!str.size())
00074                         printf("Time: %d.%03d", s, m);
00075                 else
00076                         printf("Time %s: %d.%03d", str.c_str(), s, m);
00077         }
00078 #else
00079         struct timeval tv;
00080         struct timezone tz;
00081         struct timeval tv0;
00082         struct timezone tz0;
00083         gettimeofday(&tv, &tz);
00084         gettimeofday(&tv0, &tz0);
00085         tv.tv_sec -= m_tv.tv_sec;
00086         {
00087                 time_t t = tv.tv_sec * 1000000 + tv.tv_usec - m_tv.tv_usec;
00088                 time_t s = t / 1000000;
00089                 time_t u = t % 1000000;
00090                 if (!str.size())
00091                         printf("Time: %d.%06d", s, u);
00092                 else
00093                         printf("Time %s: %d.%06d", str.c_str(), s, u);
00094         }
00095         tv0.tv_sec -= m_tv0.tv_sec;
00096         {
00097                 time_t t = tv0.tv_sec * 1000000 + tv0.tv_usec - m_tv0.tv_usec;
00098                 time_t s = t / 1000000;
00099                 time_t u = t % 1000000;
00100                 if (!str.size())
00101                         printf(" / %d.%06d", s, u);
00102                 else
00103                         printf(" / %d.%06d", s, u);
00104         }
00105         printf("\n");
00106 #endif
00107         Reset();
00108 }

void Clock::Reset (  )  [inline]

Definition at line 44 of file Clock.h.

References m_tv, and m_tz.

Referenced by PrintDiff().

00044                      {
00045 #ifdef _WIN32
00046                 ::GetLocalTime(&m_time);
00047 #else
00048                 gettimeofday(&m_tv, &m_tz);
00049 #endif
00050         }

Clock& Clock::operator= ( const Clock  )  [inline, private]

Definition at line 54 of file Clock.h.

00054 { return *this; } // assignment operator


Member Data Documentation

struct timeval Clock::m_tv [read, private]

Definition at line 60 of file Clock.h.

Referenced by Clock(), PrintDiff(), and Reset().

struct timeval Clock::m_tv0 [read, private]

Definition at line 61 of file Clock.h.

Referenced by Clock(), and PrintDiff().

struct timezone Clock::m_tz [read, private]

Definition at line 62 of file Clock.h.

Referenced by Clock(), and Reset().

struct timezone Clock::m_tz0 [read, private]

Definition at line 63 of file Clock.h.

Referenced by Clock().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4