]> git.mxchange.org Git - simgear.git/blob - simgear/timing/timestamp.hxx
Don't waste space with too huge stl containers.
[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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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
75     /** Update stored time to current time (seconds and microseconds) */
76     void stamp();
77
78     /**
79      * Increment the saved time by the specified number of microseconds
80      * @param t time stamp
81      * @param m microseconds increment
82      * @return new time stamp
83      */
84     friend SGTimeStamp operator + (const SGTimeStamp& t, const long& m);
85
86     /**
87      * Subtract two time stamps returning the difference in microseconds.
88      * @param a timestamp 1
89      * @param b timestame 2
90      * @return difference in microseconds
91      */
92     friend long operator - (const SGTimeStamp& a, const SGTimeStamp& b);
93
94     /** @return the saved seconds of this time stamp */
95     inline long get_seconds() const { return seconds; }
96
97     /** @return the saved microseconds of this time stamp */
98     inline long get_usec() const { return usec; }
99 };
100
101 inline SGTimeStamp::SGTimeStamp() :
102     seconds(0),
103     usec(0)
104 {
105 }
106
107 inline SGTimeStamp::SGTimeStamp( const long s, const long u ) {
108     seconds = s;
109     usec = u;
110 }
111
112 #endif // _TIMESTAMP_HXX
113
114