GL Studio C++ Runtime API
timer.h
Go to the documentation of this file.
1/// \file timer.h
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/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<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#ifndef INCLUDED_DISTI_TIMER_H
40#define INCLUDED_DISTI_TIMER_H
41
42#include "disti_include.h"
43#ifdef _WIN32
44# include <windows.h>
45// Windows.h must come first
46# include <mmsystem.h>
47# include <windef.h>
48# include <winnt.h>
49#else
50# include <stdint.h>
51#endif
52
53/// Platform independent typedef for epoch time storage.
54#ifndef INT_64
55# ifndef _WIN32
56typedef uint64_t INT_64;
57# else
58typedef __int64 INT_64;
59# endif
60#endif
61
62namespace disti
63{
64/// The Timer class
65class Timer
66{
67private:
68 /// The epoch time when the timer was started.
69 /// The time of day that the time was started, or last "Reset".
70 /// Used to calculate elapsed time.
71 INT_64 _start_time;
72
73 static void AccurateSleep( unsigned long milli );
74
75public:
76 DISTI_EXPORT Timer();
77
78 virtual DISTI_EXPORT ~Timer();
79
80 /// Reset the timer so current time is the time base, reset "epoch time" to the current time.
81 DISTI_EXPORT void Reset();
82
83 /// Get the number of milliseconds elapsed since the "epoch time" began.
84 /// \return The elapsed milliseconds since the beginning of the epoch.
85 virtual DISTI_EXPORT unsigned long ElapsedMilliseconds();
86
87 /// Get the number of microseconds elapsed since the "epoch time" began.
88 /// \return The elapsed Microseconds since the beginning of the epoch.
89 virtual DISTI_EXPORT unsigned long ElapsedMicroseconds();
90
91 /// Get the number of seconds elapsed since the "epoch time" began.
92 /// \return The number of seconds since the beginning of the epoch.
93 virtual DISTI_EXPORT unsigned long ElapsedSeconds();
94
95 /// Get the number of seconds elapsed since the "epoch time" began.
96 /// \return The number of seconds elapsed since the beginning of the epoch.
97 virtual DISTI_EXPORT double ElapsedSecondsDouble();
98
99 /// Get the number of seconds elapsed since 01/01/1970, "wall clock".
100 /// \return Return the number of seconds.
101 static DISTI_EXPORT unsigned long GetCurrentTimeInSeconds();
102
103 /// Get the number of seconds elapsed since 01/01/1970,
104 /// and the number of microseconds elapsed in the current second.
105 /// \param sec Return the number of seconds elapsed since 01/01/1970
106 /// \param usec Return the fractional second in microseconds
107 static DISTI_EXPORT void GetTimeOfDay( unsigned long* sec, unsigned long* usec );
108
109 /// Get number of microseconds elapsed since 01/01/1970.
110 /// \param usec Return number of microseconds elapsed.
111 static DISTI_EXPORT void GetTimeOfDay( INT_64* usec );
112
113 /// Cause the process (or thread) to sleep for the specified number of milliseconds.
114 /// Clock time continues, this pauses the thread, not the clock.
115 /// \param milli How long to sleep in milliseconds.
116 static DISTI_EXPORT void WaitMilliseconds( unsigned long milli );
117
118 /// Cause the process (or thread) to sleep for the specified number of microseconds.
119 /// Clock time continues, this pauses the thread, not the clock.
120 /// \param micro How long to sleep im micoseconds.
121 static DISTI_EXPORT void WaitMicroseconds( unsigned long micro );
122
123 /// Get the difference between a time value and when the "epoch time" began.
124 /// \param sec Time in seconds to compare to "epoch time".
125 /// \param usec Time in microseconds to compare to "epoch time".
126 /// \return Return the difference between the time parameters, and the "epoch time", in Microseconds.
127 virtual DISTI_EXPORT unsigned long DifferenceInMicroseconds( unsigned long sec, unsigned long usec );
128
129 /// Get the difference between a time value and when the "epoch time" began.
130 /// \param sec Time in seconds to compare to "epoch time"
131 /// \param usec Time in microseconds to compare to "epoch time"
132 /// \return Return the difference between the time parameters, and the "epoch time", in Seconds
133 virtual DISTI_EXPORT double DifferenceInSeconds( unsigned long sec, unsigned long usec );
134
135 /// Create a DIS timestamp based on the current time of day.
136 /// \return Return a DIS timestamp
137 static DISTI_EXPORT unsigned long DIS_Timestamp();
138};
139
140} // namespace disti
141
142#endif
The Timer class.
Definition: timer.h:66
static void WaitMicroseconds(unsigned long micro)
virtual unsigned long ElapsedMilliseconds()
static void GetTimeOfDay(unsigned long *sec, unsigned long *usec)
static unsigned long DIS_Timestamp()
static unsigned long GetCurrentTimeInSeconds()
static void WaitMilliseconds(unsigned long milli)
void Reset()
Reset the timer so current time is the time base, reset "epoch time" to the current time.
virtual unsigned long DifferenceInMicroseconds(unsigned long sec, unsigned long usec)
virtual unsigned long ElapsedSeconds()
virtual unsigned long ElapsedMicroseconds()
virtual double ElapsedSecondsDouble()
virtual double DifferenceInSeconds(unsigned long sec, unsigned long usec)
A file for all GL Studio files to include.
Definition: bmpimage.h:46
uint64_t INT_64
Platform independent typedef for epoch time storage.
Definition: timer.h:56