]> git.mxchange.org Git - simgear.git/blob - simgear/timing/timestamp.hxx
Update a few more instances of my email address.
[simgear.git] / simgear / timing / timestamp.hxx
1 /**
2  * \file timestamp.hxx
3  * Provides a class for managing a timestamp (seconds & milliseconds.)
4  */
5
6 // Written by Curtis Olson, started December 1998.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25
26
27 #ifndef _TIMESTAMP_HXX
28 #define _TIMESTAMP_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #include <simgear/compiler.h>
37
38
39 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
40 class SGTimeStamp;
41 SGTimeStamp operator + (const SGTimeStamp& t, const long& m);
42 long operator - (const SGTimeStamp& a, const SGTimeStamp& b);
43
44 /**
45  * The SGTimeStamp class allows you to mark and compare time stamps
46  * with microsecond accuracy (if your system has support for this
47  * level of accuracy.)
48  *
49  * The SGTimeStamp is useful for tracking the elapsed time of various
50  * events in your program. You can also use it to keep constistant
51  * motion across varying frame rates.
52  */
53
54 class SGTimeStamp {
55
56 private:
57
58     long seconds;
59     long usec;
60
61 public:
62
63     /** Default constructor */
64     SGTimeStamp();
65
66     /**
67      * This creates an instance of the SGTimeStamp object. When
68      * calling the constructor you may provide initial seconds an
69      * microseconds values.
70      * @param s initial seconds value
71      * @param m initial microseconds value
72      */
73     SGTimeStamp( const long s, const long m );
74     ~SGTimeStamp();
75
76     /** Update stored time to current time (seconds and microseconds) */
77     void stamp();
78
79     /** Compare two time stamps for equality */
80     SGTimeStamp& operator = ( const SGTimeStamp& t );
81
82     /**
83      * Increment the saved time by the specified number of microseconds
84      * @param t time stamp
85      * @param m microseconds increment
86      * @return new time stamp
87      */
88     friend SGTimeStamp operator + (const SGTimeStamp& t, const long& m);
89
90     /**
91      * Subtract two time stamps returning the difference in microseconds.
92      * @param a timestamp 1
93      * @param b timestame 2
94      * @return difference in microseconds
95      */
96     friend long operator - (const SGTimeStamp& a, const SGTimeStamp& b);
97
98     /** @return the saved seconds of this time stamp */
99     inline long get_seconds() const { return seconds; }
100
101     /** @return the saved microseconds of this time stamp */
102     inline long get_usec() const { return usec; }
103 };
104
105 inline SGTimeStamp::SGTimeStamp() :
106     seconds(0),
107     usec(0)
108 {
109 }
110
111 inline SGTimeStamp::SGTimeStamp( const long s, const long u ) {
112     seconds = s;
113     usec = u;
114 }
115
116 inline SGTimeStamp::~SGTimeStamp() {
117 }
118
119 inline SGTimeStamp& SGTimeStamp::operator = (const SGTimeStamp& t)
120 {
121     seconds = t.seconds;
122     usec = t.usec;
123     return *this;
124 }
125
126
127 #endif // _TIMESTAMP_HXX
128
129