GL Studio 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) 2015 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 _TIMER_H
41 #define _TIMER_H
42 
43 #include "disti_include.h"
44 #ifdef _WIN32
45 #include <windows.h>
46 #include <windef.h>
47 #include <winnt.h>
48 #include <mmsystem.h>
49 #else
50  #include <stdint.h>
51 #endif
52 
53 #ifndef INT_64
54 #ifndef _WIN32
55  typedef uint64_t INT_64;
56 #else
57  typedef __int64 INT_64;
58 #endif
59 #endif
60 
61 namespace disti
62 {
63 
64 /** The Timer class
65  */
66 class Timer
67 {
68  private:
69 
70  /**
71  The epoch time when the timer was started. The time of
72  day that the time was started, or last "Reset". Used to calculate
73  elapsed time.
74  */
75  INT_64 _start_time;
76 
77  void AccurateSleep(unsigned long milli);
78 
79  bool _winTimerResolutionSet;
80 
81 #ifdef _WIN32
82  TIMECAPS _timeCaps;
83 #endif
84 
85  protected:
86 
87 #ifdef _WIN32
88  /** Speed of the hardware timer on windows in cycles per second
89  * This will have a value of zero if High performance timers
90  * are not available. */
91  LARGE_INTEGER performanceFreq;
92 #endif
93 
94  public:
95 
96  /** Timer constructor. */
97  DISTI_EXPORT Timer(void);
98 
99  /**
100  Reset the timer so current time is the time base, reset "epoch time" to
101  the current time
102  */
103  DISTI_EXPORT void Reset(void);
104 
105  /**
106  Get the number of milliseconds elapsed since the "epoch time" began
107  \return Return the elapsed milliseconds since the beginning of the epoch
108  */
109  virtual DISTI_EXPORT unsigned long ElapsedMilliseconds(void);
110 
111  /**
112  Get the number of microseconds elapsed since the "epoch time" began
113  \return Return the elapsed Microseconds since the beginning of the epoch
114  */
115  virtual DISTI_EXPORT unsigned long ElapsedMicroseconds(void);
116 
117  /**
118  Get the number of seconds elapsed since the "epoch time" began
119  \return Return the number of seconds since the beginning of the epoch
120  */
121  virtual DISTI_EXPORT unsigned long ElapsedSeconds(void);
122 
123  /**
124  Get the number of seconds elapsed since the "epoch time" began
125  \return The number of seconds elapsed since the beginning of the epoch
126  */
127  virtual DISTI_EXPORT double ElapsedSecondsDouble(void);
128 
129  /**
130  Get the number of seconds elapsed since 01/01/1970, "wall clock"
131  \return Return the number of seconds
132  */
133  virtual DISTI_EXPORT unsigned long GetCurrentTimeInSeconds(void);
134 
135  /**
136  Get the number of seconds elapsed since 01/01/1970,
137  and the number of microseconds elapsed in the current second
138  \param sec Return the number of seconds elapsed since 01/01/1970
139  \param usec Return the factional second in microseconds
140  */
141  virtual DISTI_EXPORT void GetTimeOfDay(unsigned long *sec,unsigned long *usec);
142 
143  /**
144  Get number of microseconds elapsed since 01/01/1970
145  \param usec Return number of microseconds elapsed
146  */
147  virtual DISTI_EXPORT void GetTimeOfDay(INT_64 *usec);
148 
149  /**
150  Cause the process (or thread) to sleep for the specified number of
151  milliseconds. Clock time continues, this pauses the thread, not
152  the clock.
153  \param milli How long to sleep in milliseconds.
154  */
155  virtual DISTI_EXPORT void WaitMilliseconds(unsigned long milli);
156 
157  /**
158  Cause the process (or thread) to sleep for the specified number of
159  microseconds. Clock time continues, this pauses the thread, not
160  the clock.
161  \param micro How long to sleep im micoseconds
162  */
163  virtual DISTI_EXPORT void WaitMicroseconds(unsigned long micro);
164 
165  /**
166  Get the difference between a time value and when the "epoch time" began
167  \param sec Time in seconds to compare to "epoch time"
168  \param usec Time in microseconds to compare to "epoch time"
169  \return Return the difference between the time parameters, and the "epoch time", in Microseconds
170  */
171  virtual DISTI_EXPORT unsigned long DifferenceInMicroseconds(unsigned long sec,unsigned long usec);
172 
173  /**
174  Get the difference between a time value and when the "epoch time" began
175  \param sec Time in seconds to compare to "epoch time"
176  \param usec Time in microseconds to compare to "epoch time"
177  \return Return the difference between the time parameters, and the "epoch time", in Seconds
178  */
179  virtual DISTI_EXPORT double DifferenceInSeconds(unsigned long sec,unsigned long usec);
180 
181  /**
182  Create a DIS timestamp based on the current time of day
183  \return Return a DIS timestamp
184  */
185  virtual DISTI_EXPORT unsigned long DIS_Timestamp(void);
186 
187  virtual DISTI_EXPORT ~Timer();
188 };
189 
190 } // namespace disti
191 
192 
193 #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)