GL Studio C++ Runtime API
timer.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::Timer class. An OS portable timing class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2017 by The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 #ifndef INCLUDED_DISTI_TIMER_H
41 #define INCLUDED_DISTI_TIMER_H
42 
43 #include "disti_include.h"
44 #ifdef _WIN32
45 # include <windows.h>
46 // Windows.h must come first
47 # include <mmsystem.h>
48 # include <windef.h>
49 # include <winnt.h>
50 #else
51 # include <stdint.h>
52 #endif
53 
54 #ifndef INT_64
55 # ifndef _WIN32
56 typedef uint64_t INT_64;
57 # else
58 typedef __int64 INT_64;
59 # endif
60 #endif
61 
62 namespace disti
63 {
64 /** The Timer class
65  */
66 class Timer
67 {
68 private:
69  /**
70  The epoch time when the timer was started. The time of
71  day that the time was started, or last "Reset". Used to calculate
72  elapsed time.
73  */
74  INT_64 _start_time;
75 
76  void AccurateSleep( unsigned long milli );
77 
78  bool _winTimerResolutionSet;
79 
80 #ifdef _WIN32
81  TIMECAPS _timeCaps;
82 #endif
83 
84 protected:
85 #ifdef _WIN32
86  /** Speed of the hardware timer on windows in cycles per second
87  * This will have a value of zero if High performance timers
88  * are not available. */
89  LARGE_INTEGER performanceFreq;
90 #endif
91 
92 public:
93  /** Timer constructor. */
94  DISTI_EXPORT Timer( void );
95 
96  /**
97  Reset the timer so current time is the time base, reset "epoch time" to
98  the current time
99  */
100  DISTI_EXPORT void Reset( void );
101 
102  /**
103  Get the number of milliseconds elapsed since the "epoch time" began
104  \return Return the elapsed milliseconds since the beginning of the epoch
105  */
106  virtual DISTI_EXPORT unsigned long ElapsedMilliseconds( void );
107 
108  /**
109  Get the number of microseconds elapsed since the "epoch time" began
110  \return Return the elapsed Microseconds since the beginning of the epoch
111  */
112  virtual DISTI_EXPORT unsigned long ElapsedMicroseconds( void );
113 
114  /**
115  Get the number of seconds elapsed since the "epoch time" began
116  \return Return the number of seconds since the beginning of the epoch
117  */
118  virtual DISTI_EXPORT unsigned long ElapsedSeconds( void );
119 
120  /**
121  Get the number of seconds elapsed since the "epoch time" began
122  \return The number of seconds elapsed since the beginning of the epoch
123  */
124  virtual DISTI_EXPORT double ElapsedSecondsDouble( void );
125 
126  /**
127  Get the number of seconds elapsed since 01/01/1970, "wall clock"
128  \return Return the number of seconds
129  */
130  virtual DISTI_EXPORT unsigned long GetCurrentTimeInSeconds( void );
131 
132  /**
133  Get the number of seconds elapsed since 01/01/1970,
134  and the number of microseconds elapsed in the current second
135  \param sec Return the number of seconds elapsed since 01/01/1970
136  \param usec Return the factional second in microseconds
137  */
138  virtual DISTI_EXPORT void GetTimeOfDay( unsigned long* sec, unsigned long* usec );
139 
140  /**
141  Get number of microseconds elapsed since 01/01/1970
142  \param usec Return number of microseconds elapsed
143  */
144  virtual DISTI_EXPORT void GetTimeOfDay( INT_64* usec );
145 
146  /**
147  Cause the process (or thread) to sleep for the specified number of
148  milliseconds. Clock time continues, this pauses the thread, not
149  the clock.
150  \param milli How long to sleep in milliseconds.
151  */
152  virtual DISTI_EXPORT void WaitMilliseconds( unsigned long milli );
153 
154  /**
155  Cause the process (or thread) to sleep for the specified number of
156  microseconds. Clock time continues, this pauses the thread, not
157  the clock.
158  \param micro How long to sleep im micoseconds
159  */
160  virtual DISTI_EXPORT void WaitMicroseconds( unsigned long micro );
161 
162  /**
163  Get the difference between a time value and when the "epoch time" began
164  \param sec Time in seconds to compare to "epoch time"
165  \param usec Time in microseconds to compare to "epoch time"
166  \return Return the difference between the time parameters, and the "epoch time", in Microseconds
167  */
168  virtual DISTI_EXPORT unsigned long DifferenceInMicroseconds( unsigned long sec, unsigned long usec );
169 
170  /**
171  Get the difference between a time value and when the "epoch time" began
172  \param sec Time in seconds to compare to "epoch time"
173  \param usec Time in microseconds to compare to "epoch time"
174  \return Return the difference between the time parameters, and the "epoch time", in Seconds
175  */
176  virtual DISTI_EXPORT double DifferenceInSeconds( unsigned long sec, unsigned long usec );
177 
178  /**
179  Create a DIS timestamp based on the current time of day
180  \return Return a DIS timestamp
181  */
182  virtual DISTI_EXPORT unsigned long DIS_Timestamp( void );
183 
184  virtual DISTI_EXPORT ~Timer();
185 };
186 
187 } // namespace disti
188 
189 #endif
virtual unsigned long ElapsedMilliseconds(void)
virtual unsigned long DIS_Timestamp(void)
virtual void WaitMicroseconds(unsigned long micro)
virtual void GetTimeOfDay(unsigned long *sec, unsigned long *usec)
void Reset(void)
virtual void WaitMilliseconds(unsigned long milli)
A file for all GL Studio files to include.
virtual unsigned long DifferenceInMicroseconds(unsigned long sec, unsigned long usec)
virtual double ElapsedSecondsDouble(void)
Definition: timer.h:66
virtual double DifferenceInSeconds(unsigned long sec, unsigned long usec)
virtual unsigned long ElapsedMicroseconds(void)
virtual unsigned long ElapsedSeconds(void)
Definition: bmpimage.h:46
virtual unsigned long GetCurrentTimeInSeconds(void)