oftimer.h

00001 /*
00002  *
00003  *  Copyright (C) 1997-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  ofstd
00019  *
00020  *  Author:  Joerg Riesmeier
00021  *
00022  *  Purpose: Class for measurement of time (Header)
00023  *
00024  *  Last Update:      $Author: meichel $
00025  *  Update Date:      $Date: 2005/12/08 16:06:10 $
00026  *  CVS/RCS Revision: $Revision: 1.11 $
00027  *  Status:           $State: Exp $
00028  *
00029  *  CVS/RCS Log at end of file
00030  *
00031  */
00032 
00033 
00034 #ifndef OFTIMER_H
00035 #define OFTIMER_H
00036 
00037 #include "dcmtk/config/osconfig.h"
00038 #include "dcmtk/ofstd/ofcast.h"
00039 
00040 #ifdef HAVE_WINDOWS_H
00041 #include <windows.h>
00042 #else /* UNIX */
00043 #include <sys/time.h>
00044 #endif
00045 
00046 
00047 /*---------------------*
00048  *  class declaration  *
00049  *---------------------*/
00050 
00054 class OFTimer
00055 {
00056 
00057  public:
00058 
00061     OFTimer()
00062       : Start(getTime())
00063     {
00064     }
00065     
00068     inline void reset()
00069     {
00070         Start = getTime();
00071     }
00072     
00078     inline double getDiff() const
00079     {
00080         return getTime() - Start;
00081     }
00082 
00089     inline static double getDiff(double start)
00090     {
00091         return getTime() - start;
00092     }
00093 
00098     inline static double getTime()
00099     {
00100 #ifdef HAVE_WINDOWS_H
00101         return OFstatic_cast(double, GetTickCount()) / 1000;
00102 #else /* tested on solaris */
00103         timeval c_time;
00104         gettimeofday(&c_time, NULL);
00105         return OFstatic_cast(double, c_time.tv_sec) + OFstatic_cast(double, c_time.tv_usec) / 1000000;
00106 #endif
00107     }
00108 
00109 
00110  private:
00111 
00113     double Start; 
00114 };
00115 
00116 
00117 #endif
00118 
00119 
00120 /*
00121  *
00122  * CVS/RCS Log:
00123  * $Log: oftimer.h,v $
00124  * Revision 1.11  2005/12/08 16:06:10  meichel
00125  * Changed include path schema for all DCMTK header files
00126  *
00127  * Revision 1.10  2003/12/05 10:37:41  joergr
00128  * Removed leading underscore characters from preprocessor symbols (reserved
00129  * symbols). Updated copyright date where appropriate.
00130  *
00131  * Revision 1.9  2003/07/09 13:57:43  meichel
00132  * Adapted type casts to new-style typecast operators defined in ofcast.h
00133  *
00134  * Revision 1.8  2001/06/01 15:51:36  meichel
00135  * Updated copyright header
00136  *
00137  * Revision 1.7  2000/03/08 16:36:03  meichel
00138  * Updated copyright header.
00139  *
00140  * Revision 1.6  2000/02/02 10:56:25  joergr
00141  * Removed space characters before preprocessor directives.
00142  *
00143  * Revision 1.5  1999/04/29 13:45:00  joergr
00144  * Added DOC++ comments.
00145  *
00146  * Revision 1.4  1999/04/21 13:01:44  meichel
00147  * ofstd/include/oftimer.h
00148  *
00149  * Revision 1.3  1999/02/05 14:07:23  joergr
00150  * Introduced new preprocessor definition HAVE_WINDOWS_H.
00151  *
00152  * Revision 1.2  1999/01/20 15:56:12  joergr
00153  * Minor changes to avoid compiler warnings (gcc 2.8.1 with additional
00154  * options).
00155  *
00156  * Revision 1.1  1999/01/20 14:27:02  joergr
00157  * Added class for measurement of time.
00158  *
00159  *
00160  */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5