3 * Provides a class for managing a timestamp (seconds & milliseconds.)
6 // Written by Curtis Olson, started December 1998.
8 // Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
27 #ifndef _TIMESTAMP_HXX
28 #define _TIMESTAMP_HXX
32 # error This library requires C++
36 #include <simgear/compiler.h>
39 // MSVC++ 6.0 kuldge - Need forward declaration of friends.
41 SGTimeStamp operator + (const SGTimeStamp& t, const long& m);
42 long operator - (const SGTimeStamp& a, const SGTimeStamp& b);
45 * The SGTimeStamp class allows you to mark and compare time stamps
46 * with microsecond accuracy (if your system has support for this
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.
63 /** Default constructor */
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
73 SGTimeStamp( const long s, const long m );
76 /** Update stored time to current time (seconds and microseconds) */
79 /** Compare two time stamps for equality */
80 SGTimeStamp& operator = ( const SGTimeStamp& t );
83 * Increment the saved time by the specified number of microseconds
85 * @param m microseconds increment
86 * @return new time stamp
88 friend SGTimeStamp operator + (const SGTimeStamp& t, const long& m);
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
96 friend long operator - (const SGTimeStamp& a, const SGTimeStamp& b);
98 /** @return the saved seconds of this time stamp */
99 inline long get_seconds() const { return seconds; }
101 /** @return the saved microseconds of this time stamp */
102 inline long get_usec() const { return usec; }
105 inline SGTimeStamp::SGTimeStamp() :
111 inline SGTimeStamp::SGTimeStamp( const long s, const long u ) {
116 inline SGTimeStamp::~SGTimeStamp() {
119 inline SGTimeStamp& SGTimeStamp::operator = (const SGTimeStamp& t)
127 #endif // _TIMESTAMP_HXX