561a9d4e8c84c708aaba917d64a90b61081be03b
[synfig.git] / ETL / tags / stable / ETL / _clock_win32hpcount.h
1 /*! ========================================================================
2 ** Extended Template and Library
3 ** Win32 Clock Description Implementation
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
7 **
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.
12 **
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.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** This is an internal header file, included by other ETL headers.
21 ** You should not attempt to use it directly.
22 **
23 ** ========================================================================= */
24
25 /* === S T A R T =========================================================== */
26
27 #ifndef __ETL__CLOCK_WIN32HPCOUNT_H
28 #define __ETL__CLOCK_WIN32HPCOUNT_H
29
30 /* === H E A D E R S ======================================================= */
31
32 #define WIN32_LEAN_AND_MEAN
33 #include <windows.h>
34
35 /* === M A C R O S ========================================================= */
36
37 #if defined(__GNUG__) && defined(__int64)
38 #undef __int64
39 #define __int64 long long int
40 #endif
41
42 /* === T Y P E D E F S ===================================================== */
43
44 /* === C L A S S E S & S T R U C T S ======================================= */
45
46 _ETL_BEGIN_NAMESPACE
47
48 class clock_desc_win32hpcount
49 {
50 public:
51         typedef double value_type;
52
53         static bool realtime()
54         { return true; }
55
56         static bool proctime()
57         { return false; }
58
59         static value_type
60         one_second()
61         { return 1.0f; }
62
63         static value_type precision()
64         {
65                 __int64 freq;
66                 QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
67                 return one_second()/(value_type)freq;
68         }
69
70         static const char *description()
71         { return "Win32 QueryPerformanceCounter()"; };
72
73 protected:
74         typedef __int64 timestamp;
75
76         static void
77         get_current_time(timestamp &x)
78         { QueryPerformanceCounter((LARGE_INTEGER*)&x);}
79
80         static timestamp
81         get_current_time()
82         { timestamp ret; QueryPerformanceCounter((LARGE_INTEGER*)&ret); return ret; }
83
84         static value_type
85         timestamp_to_seconds(const timestamp &x)
86         { return precision()*x; }
87
88         static timestamp
89         seconds_to_timestamp(const value_type &x)
90         { return (timestamp)(x/precision()); }
91 };
92
93 _ETL_END_NAMESPACE
94
95 /* === E N D =============================================================== */
96
97 #endif
98