head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.41; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.59; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.05; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.02; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# timestamp.cxx

Go to the documentation of this file.

    00001
    00006 // Written by Curtis Olson, started December 1998.
    00007 //
    00008 // Copyright (C) 1998  Curtis L. Olson  - curt@@flightgear.org
    00009 //
    00010 // This program is free software; you can redistribute it and/or
    00011 // modify it under the terms of the GNU General Public License as
    00012 // published by the Free Software Foundation; either version 2 of the
    00013 // License, or (at your option) any later version.
    00014 //
    00015 // This program is distributed in the hope that it will be useful, but
    00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018 // General Public License for more details.
    00019 //
    00020 // You should have received a copy of the GNU General Public License
    00021 // along with this program; if not, write to the Free Software
    00022 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00023 //
    00024 // $Id: timestamp.cxx,v 1.2 2002/04/20 20:53:54 curt Exp $
    00025
    00026
    00027 #ifdef HAVE_CONFIG_H
    00028 #  include <simgear_config.h>
    00029 #endif
    00030
    00031 #ifdef HAVE_WINDOWS_H
    00032 #  include <windows.h>
    00033 #endif
    00034
    00035 #include <simgear/compiler.h>
    00036
    00037 #ifdef SG_HAVE_STD_INCLUDES
    00038 #  include <ctime>
    00039 #else
    00040 #  include <time.h>
    00041 #endif
    00042
    00043 #ifdef HAVE_SYS_TIMEB_H
    00044 #  include <sys/timeb.h> // for ftime() and struct timeb
    00045 #endif
    00046 #ifdef HAVE_UNISTD_H
    00047 #  include <unistd.h>    // for gettimeofday()
    00048 #endif
    00049 #ifdef HAVE_SYS_TIME_H
    00050 #  include <sys/time.h>  // for get/setitimer, gettimeofday, struct timeval
    00051 #endif
    00052
    00053 // -dw- want to use metrowerks time.h
    00054 #ifdef macintosh
    00055 #  include <time.h>
    00056 #  include <timer.h>
    00057 #endif
    00058
    00059 #ifdef WIN32
    00060 #  include <windows.h>
    00061 #  if defined( __CYGWIN__ ) || defined( __CYGWIN32__ )
    00062 #    define NEAR /* */
    00063 #    define FAR  /* */
    00064 #  endif
    00065 #  include <mmsystem.h>
    00066 #endif
    00067
    00068 #include "timestamp.hxx"
    00069
    00070
    00071 void SGTimeStamp::stamp() {
    00072 #if defined( WIN32 )
    00073     unsigned int t;
    00074     t = timeGetTime();
    00075     seconds = 0;
    00076     usec =  t * 1000;
    00077 #elif defined( HAVE_GETTIMEOFDAY )
    00078     struct timeval current;
    00079     struct timezone tz;
    00080     // sg_timestamp currtime;
    00081     gettimeofday(&current, &tz);
    00082     seconds = current.tv_sec;
    00083     usec = current.tv_usec;
    00084 #elif defined( HAVE_GETLOCALTIME )
    00085     SYSTEMTIME current;
    00086     GetLocalTime(&current);
    00087     seconds = current.wSecond;
    00088     usec = current.wMilliseconds * 1000;
    00089 #elif defined( HAVE_FTIME )
    00090     struct timeb current;
    00091     ftime(&current);
    00092     seconds = current.time;
    00093     usec = current.millitm * 1000;
    00094 // -dw- uses time manager
    00095 #elif defined( macintosh )
    00096     UnsignedWide ms;
    00097     Microseconds(&ms);
    00098
    00099     seconds = ms.lo / 1000000;
    00100     usec = ms.lo - ( seconds * 1000000 );
    00101 #else
    00102 # error Port me
    00103 #endif
    00104 }
    00105
    00106 // increment the time stamp by the number of microseconds (usec)
    00107 SGTimeStamp operator + (const SGTimeStamp& t, const long& m) {
    00108 #if defined( WIN32 )
    00109     return SGTimeStamp( 0, t.usec + m );
    00110 #else
    00111     return SGTimeStamp( t.seconds + ( t.usec + m ) / 1000000,
    00112                         ( t.usec + m ) % 1000000 );
    00113 #endif
    00114 }
    00115
    00116 // difference between time stamps in microseconds (usec)
    00117 long operator - (const SGTimeStamp& a, const SGTimeStamp& b)
    00118 {
    00119 #if defined( WIN32 )
    00120     return a.usec - b.usec;
    00121 #else
    00122     return 1000000 * (a.seconds - b.seconds) + (a.usec - b.usec);
    00123 #endif
    00124 }

@ 1.3 log @Oops, try again. @ text @d129 1 a129 1