TimeStamp.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00029 //
00031 #ifndef __TIMESTAMP_H__
00032 #define __TIMESTAMP_H__
00033 
00034 #include "H3DApi.h"
00035 
00036 #ifdef WIN32
00037 #include <sys/timeb.h>
00038 #else
00039 #ifdef HAVE_SYS_TIME_H
00040 #include <sys/time.h>
00041 #else
00042 #error Compiler does not support any of the default getCurrentTime() implementations in TimeStamp.h
00043 #endif
00044 #endif
00045 #include "H3DApi.h"
00046 #include "Exception.h"
00047 
00048 
00049 namespace H3D {
00050   struct H3DAPI_API TimeStamp {
00051     H3D_API_EXCEPTION( PerformanceCounterNotSupported );
00052 
00053     TimeStamp() {
00054       time = getCurrentTime();
00055     }
00056     TimeStamp( double _time ) : time( _time ) {}
00057         
00058     static TimeStamp now() {
00059       return TimeStamp( getCurrentTime() );
00060     }
00061 
00062         
00063     operator double() const { return time; }
00064     bool operator==( const TimeStamp &arg ) const { return time==arg.time; }
00065     bool operator!=( const TimeStamp &arg ) const { return time!=arg.time; }
00066     bool operator> ( const TimeStamp &arg ) const { return time>arg.time;  }
00067     bool operator< ( const TimeStamp &arg ) const { return time<arg.time;  }
00068     bool operator>=( const TimeStamp &arg ) const { return time>=arg.time; }
00069     bool operator<=( const TimeStamp &arg ) const { return time<=arg.time; }
00070 
00071   protected:
00072     double time; // seconds since epoch
00073 
00074     static double getCurrentTime();
00075 
00076 #ifdef WIN32
00077     static bool init_done;
00078     static double start_time;
00079     static LARGE_INTEGER start_perf_count;
00080     static LARGE_INTEGER perf_freq;
00081 #endif
00082   };
00083 }
00084 
00085 
00086 #endif

Generated on Thu Aug 24 12:38:34 2006 for H3D API by  doxygen 1.4.5