SimGear - Simulator Construction Tools
SGTimeStamp Class Reference

#include <timestamp.hxx>

Public Types

typedef int nsec_type
 
typedef long sec_type
 

Public Member Functions

 SGTimeStamp ()
 
int elapsedMSec () const
 
long get_seconds () const
 
int get_usec () const
 
const nsec_typegetNanoSeconds () const
 
const sec_typegetSeconds () const
 
SGTimeStampoperator+= (const SGTimeStamp &c)
 
SGTimeStampoperator-= (const SGTimeStamp &c)
 
void setTime (const double &seconds)
 
void setTime (sec_type sec, nsec_type nsec)
 
void stamp ()
 
double toMSecs () const
 
double toNSecs () const
 
double toSecs () const
 
double toUSecs () const
 

Static Public Member Functions

static SGTimeStamp fromMSec (nsec_type msec)
 
static SGTimeStamp fromNSec (nsec_type nsec)
 
static SGTimeStamp fromSec (int sec)
 
static SGTimeStamp fromSec (const double &sec)
 
static SGTimeStamp fromSecMSec (sec_type sec, nsec_type msec)
 
static SGTimeStamp fromSecNSec (sec_type sec, nsec_type nsec)
 
static SGTimeStamp fromSecUSec (sec_type sec, nsec_type usec)
 
static SGTimeStamp fromUSec (nsec_type usec)
 
static SGTimeStamp now ()
 
static bool sleepFor (const SGTimeStamp &reltime)
 
static bool sleepForMSec (unsigned msec)
 
static bool sleepUntil (const SGTimeStamp &abstime)
 

Private Member Functions

 SGTimeStamp (sec_type sec, nsec_type nsec)
 

Private Attributes

nsec_type _nsec
 
sec_type _sec
 

Detailed Description

The SGTimeStamp class allows you to mark and compare time stamps with nanosecond accuracy (if your system has support for this level of accuracy).

The SGTimeStamp is useful for tracking the elapsed time of various events in your program. You can also use it to keep consistent motion across varying frame rates.

Note SGTimestamp does not deliver the time of day. The content of this stamps might be, dependent on the implementation, a time to an arbitrary base time.

Definition at line 55 of file timestamp.hxx.

Member Typedef Documentation

Definition at line 58 of file timestamp.hxx.

Definition at line 57 of file timestamp.hxx.

Constructor & Destructor Documentation

SGTimeStamp::SGTimeStamp ( )
inline

Default constructor, initialize time to zero.

Definition at line 61 of file timestamp.hxx.

Referenced by fromMSec(), fromNSec(), fromSecMSec(), fromSecNSec(), fromSecUSec(), and fromUSec().

SGTimeStamp::SGTimeStamp ( sec_type  sec,
nsec_type  nsec 
)
inlineprivate

Definition at line 221 of file timestamp.hxx.

Member Function Documentation

static SGTimeStamp SGTimeStamp::fromMSec ( nsec_type  msec)
inlinestatic

Definition at line 187 of file timestamp.hxx.

Referenced by sleepForMSec().

static SGTimeStamp SGTimeStamp::fromNSec ( nsec_type  nsec)
inlinestatic

Definition at line 191 of file timestamp.hxx.

static SGTimeStamp SGTimeStamp::fromSec ( const double &  sec)
inlinestatic

Definition at line 185 of file timestamp.hxx.

static SGTimeStamp SGTimeStamp::fromSecMSec ( sec_type  sec,
nsec_type  msec 
)
inlinestatic

Create SGTimeStamps from input with given units

Definition at line 176 of file timestamp.hxx.

Referenced by sleepFor(), and sleepUntil().

static SGTimeStamp SGTimeStamp::fromSecNSec ( sec_type  sec,
nsec_type  nsec 
)
inlinestatic

Definition at line 180 of file timestamp.hxx.

Referenced by sleepUntil().

static SGTimeStamp SGTimeStamp::fromSecUSec ( sec_type  sec,
nsec_type  usec 
)
inlinestatic

Definition at line 178 of file timestamp.hxx.

Referenced by sleepFor(), and sleepUntil().

static SGTimeStamp SGTimeStamp::fromUSec ( nsec_type  usec)
inlinestatic

Definition at line 189 of file timestamp.hxx.

long SGTimeStamp::get_seconds ( ) const
inline
Returns
the saved seconds of this time stamp

Definition at line 103 of file timestamp.hxx.

int SGTimeStamp::get_usec ( ) const
inline
Returns
the saved microseconds of this time stamp

Definition at line 106 of file timestamp.hxx.

const nsec_type& SGTimeStamp::getNanoSeconds ( ) const
inline
Returns
the saved nanoseconds of this time stamp

Definition at line 112 of file timestamp.hxx.

Referenced by operator<(), operator<<(), and operator==().

const sec_type& SGTimeStamp::getSeconds ( ) const
inline
Returns
the saved seconds of this time stamp

Definition at line 109 of file timestamp.hxx.

Referenced by operator<(), operator<<(), and operator==().

SGTimeStamp& SGTimeStamp::operator+= ( const SGTimeStamp c)
inline

Inplace addition.

Definition at line 149 of file timestamp.hxx.

SGTimeStamp& SGTimeStamp::operator-= ( const SGTimeStamp c)
inline

Inplace subtraction.

Definition at line 162 of file timestamp.hxx.

void SGTimeStamp::setTime ( const double &  seconds)
inline

Set the time from a double value

Definition at line 82 of file timestamp.hxx.

Referenced by fromSec(), and SGTimeStamp().

void SGTimeStamp::setTime ( sec_type  sec,
nsec_type  nsec 
)
inline

Set the time from a seconds/nanoseconds pair

Definition at line 90 of file timestamp.hxx.

bool SGTimeStamp::sleepFor ( const SGTimeStamp reltime)
static

Sleep for reltime.

Definition at line 223 of file timestamp.cxx.

Referenced by sleepForMSec().

static bool SGTimeStamp::sleepForMSec ( unsigned  msec)
inlinestatic

Alias for the most common use case with milliseconds.

Definition at line 213 of file timestamp.hxx.

Referenced by main(), simgear::HTTP::Client::update(), waitForComplete(), waitForFailed(), and waitForUpdateComplete().

bool SGTimeStamp::sleepUntil ( const SGTimeStamp abstime)
static

Sleep until the time of abstime is passed.

Definition at line 126 of file timestamp.cxx.

void SGTimeStamp::stamp ( )

Hmm, might reenable them at some time, but since it is not clear what the input unit of the int is, omit them for now. Use the static constructor functions where it is clear from the method name how the arguments are meant.Update stored time to current time (seconds and nanoseconds)

Definition at line 74 of file timestamp.cxx.

Referenced by elapsedMSec(), SGSubsystemGroup::incrementalInit(), main(), now(), simgear::DirGetRequest::onDone(), sleepFor(), sleepUntil(), SGPerformanceMonitor::update(), and simgear::SGTerraSync::WorkerThread::updateSyncSlot().

double SGTimeStamp::toMSecs ( ) const
inline
Returns
the value of the timestamp in milliseconds, use doubles to avoid overflow. If you need real nanosecond accuracy for time differences, build up a SGTimeStamp reference time and compare SGTimeStamps directly.

Definition at line 136 of file timestamp.hxx.

Referenced by elapsedMSec(), sleepFor(), and sleepUntil().

double SGTimeStamp::toNSecs ( ) const
inline
Returns
the value of the timestamp in nanoseconds, use doubles to avoid overflow. If you need real nanosecond accuracy for time differences, build up a SGTimeStamp reference time and compare SGTimeStamps directly.

Definition at line 120 of file timestamp.hxx.

double SGTimeStamp::toSecs ( ) const
inline
Returns
the value of the timestamp in seconds, use doubles to avoid overflow. If you need real nanosecond accuracy for time differences, build up a SGTimeStamp reference time and compare SGTimeStamps directly.

Definition at line 144 of file timestamp.hxx.

Referenced by simgear::HLAFederate::enableTimeRegulation(), simgear::HLAFederate::processMessage(), simgear::HLAFederate::setLeadTime(), simgear::HLAFederate::setTimeIncrement(), and simgear::RTI13Ambassador::toFedTime().

double SGTimeStamp::toUSecs ( ) const
inline
Returns
the value of the timestamp in microseconds, use doubles to avoid overflow. If you need real nanosecond accuracy for time differences, build up a SGTimeStamp reference time and compare SGTimeStamps directly.

Definition at line 128 of file timestamp.hxx.

Referenced by sleepFor(), sleepUntil(), and SGSubsystemGroup::update().

Member Data Documentation

nsec_type SGTimeStamp::_nsec
private
sec_type SGTimeStamp::_sec
private

The documentation for this class was generated from the following files: