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