1 /*! ========================================================================
2 ** Extended Template and Library
3 ** Proc Clock Description Implementation
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
23 ** ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __ETL__CLOCK_SYSTEM_H
28 #define __ETL__CLOCK_SYSTEM_H
30 /* === H E A D E R S ======================================================= */
34 # define __sys_clock ::clock
35 # define __sys_time ::time
39 # define __sys_clock ::clock
40 # define __sys_time ::time
44 extern clock_t _clock();
45 extern time_t _time(time_t *);
46 # define CLOCKS_PER_SEC 1000
47 # define __sys_clock _clock
48 # define __sys_time _time
52 /* === M A C R O S ========================================================= */
54 /* === T Y P E D E F S ===================================================== */
56 /* === C L A S S E S & S T R U C T S ======================================= */
60 class clock_desc_sys_clock
63 typedef float value_type;
65 inline static bool realtime()
68 inline static bool proctime()
71 inline static value_type
75 inline static value_type precision()
76 { return one_second()/(value_type)CLOCKS_PER_SEC; }
78 inline static const char *description()
79 { return "ANSI C clock()"; };
82 typedef clock_t timestamp;
85 get_current_time(timestamp &time)
86 { time=__sys_clock(); }
90 { return __sys_clock(); }
93 timestamp_to_seconds(const timestamp &x)
94 { return precision()*x; }
97 seconds_to_timestamp(const value_type &x)
98 { return (timestamp)(x*(value_type)CLOCKS_PER_SEC+0.5); }
102 class clock_desc_sys_time
105 typedef float value_type;
107 inline static bool realtime()
110 inline static bool proctime()
113 inline static value_type
117 inline static value_type precision()
118 { return one_second(); }
120 inline static const char *description()
121 { return "ANSI C time()"; };
124 typedef time_t timestamp;
127 get_current_time(timestamp &time)
128 { __sys_time(&time); }
132 { return __sys_time(NULL); }
135 timestamp_to_seconds(const timestamp &x)
136 { return (value_type)x; }
139 seconds_to_timestamp(const value_type &x)
140 { return (timestamp)(x+(value_type)0.5f); }
145 /* === E N D =============================================================== */