_clock_system.h

Go to the documentation of this file.
00001 
00025 /* === S T A R T =========================================================== */
00026 
00027 #ifndef __ETL__CLOCK_SYSTEM_H
00028 #define __ETL__CLOCK_SYSTEM_H
00029 
00030 /* === H E A D E R S ======================================================= */
00031 
00032 #ifndef _WIN32
00033 # include <time.h>
00034 # define __sys_clock    ::clock
00035 # define __sys_time ::time
00036 #else
00037 # ifdef __GNUG__
00038 #  include <time.h>
00039 #  define __sys_clock   ::clock
00040 #  define __sys_time    ::time
00041 # else
00042 typedef int clock_t;
00043 typedef int time_t;
00044 extern clock_t _clock();
00045 extern time_t _time(time_t *);
00046 #  define CLOCKS_PER_SEC 1000
00047 #  define __sys_clock   _clock
00048 #  define __sys_time    _time
00049 # endif
00050 #endif
00051 
00052 /* === M A C R O S ========================================================= */
00053 
00054 /* === T Y P E D E F S ===================================================== */
00055 
00056 /* === C L A S S E S & S T R U C T S ======================================= */
00057 
00058 _ETL_BEGIN_NAMESPACE
00059 
00060 class clock_desc_sys_clock
00061 {
00062 public:
00063     typedef float value_type;
00064     
00065     inline static bool realtime()
00066     { return false; }
00067 
00068     inline static bool proctime()
00069     { return true; }
00070 
00071     inline static value_type
00072     one_second()
00073     { return 1.0f; }
00074 
00075     inline static value_type precision()
00076     { return one_second()/(value_type)CLOCKS_PER_SEC; }
00077 
00078     inline static const char *description()
00079     { return "ANSI C clock()"; };
00080 
00081 protected:
00082     typedef clock_t timestamp;
00083     
00084     static void
00085     get_current_time(timestamp &time)
00086     { time=__sys_clock(); }
00087 
00088     static timestamp
00089     get_current_time()
00090     { return __sys_clock(); }
00091     
00092     static value_type
00093     timestamp_to_seconds(const timestamp &x)
00094     { return precision()*x; } 
00095 
00096     static timestamp
00097     seconds_to_timestamp(const value_type &x)
00098     { return (timestamp)(x*(value_type)CLOCKS_PER_SEC+0.5); } 
00099     
00100 };
00101 
00102 class clock_desc_sys_time
00103 {
00104 public:
00105     typedef float value_type;
00106     
00107     inline static bool realtime()
00108     { return true; }
00109 
00110     inline static bool proctime()
00111     { return false; }
00112     
00113     inline static value_type
00114     one_second()
00115     { return 1.0f; }
00116 
00117     inline static value_type precision()
00118     { return one_second(); }
00119 
00120     inline static const char *description()
00121     { return "ANSI C time()"; };
00122 
00123 protected:
00124     typedef time_t timestamp;
00125     
00126     static void
00127     get_current_time(timestamp &time)
00128     { __sys_time(&time); }
00129 
00130     static timestamp
00131     get_current_time()
00132     { return __sys_time(NULL); }
00133     
00134     static value_type
00135     timestamp_to_seconds(const timestamp &x)
00136     { return (value_type)x; } 
00137 
00138     static timestamp
00139     seconds_to_timestamp(const value_type &x)
00140     { return (timestamp)(x+(value_type)0.5f); } 
00141 };
00142 
00143 _ETL_END_NAMESPACE
00144 
00145 /* === E N D =============================================================== */
00146 
00147 #endif

Generated on Thu Jun 22 11:31:47 2006 for ETL by  doxygen 1.4.6