CUGL
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::Timestamp Class Reference

#include <CUTimestamp.h>

Public Member Functions

 Timestamp ()
 
 Timestamp (const Timestamp &stamp)
 
const Timestampoperator= (const Timestamp &stamp)
 
const Timestampset (const Timestamp &stamp)
 
void mark ()
 
timestamp_t getTime () const
 
Uint64 ellapsedMillis (const Timestamp &stamp) const
 
Uint64 ellapsedMicros (const Timestamp &stamp) const
 
long ellapsedNanos (const Timestamp &stamp)
 
Timestampoperator+= (Uint32 millis)
 
Timestampoperator-= (Uint32 millis)
 
const Timestamp operator+ (Uint32 millis) const
 
const Timestamp operator- (Uint32 millis) const
 

Static Public Member Functions

static Uint64 ellapsedMillis (const Timestamp &start, const Timestamp &end)
 
static Uint64 ellapsedMicros (const Timestamp &start, const Timestamp &end)
 
static Uint64 ellapsedNanos (const Timestamp &start, const Timestamp &end)
 

Protected Attributes

timestamp_t _time
 

Detailed Description

Class to mark a moment in time.

The advantage of using this class over timestamp_t is that it has many built-in methods for converting the timestamp to milliseconds, nanoseconds, and so on. It is a lot easier to use this class that to use the more arcane chrono package in C++.

While this is a class, this is meant to be created on the stack. Therefore there is no support for shared pointers or initialization like in our other, more heavy-weight classes.

Constructor & Destructor Documentation

cugl::Timestamp::Timestamp ( )
inline

Constructs a new time stamp.

The constructor marks the exact moment that it was created.

cugl::Timestamp::Timestamp ( const Timestamp stamp)
inline

Constructs a copy of the given time stamp.

The constructor does not mark the time it copies, but instead uses the value taken from stamp.

Parameters
stampThe time stamp to copy

Member Function Documentation

static Uint64 cugl::Timestamp::ellapsedMicros ( const Timestamp start,
const Timestamp end 
)
inlinestatic

Returns the ellapsed time between the given two timestamps.

The value is returned in microseconds.

Parameters
startThe start time
endThe finish time
Returns
the ellapsed time between the given two timestamps.
Uint64 cugl::Timestamp::ellapsedMicros ( const Timestamp stamp) const
inline

Returns the ellapsed time from the provided time.

This method measures the time from stamp until the current time. Hence the current time is the end of the interval.

The value is returned in microseconds.

Parameters
stampThe start time
Returns
the ellapsed time from the provided time.
static Uint64 cugl::Timestamp::ellapsedMillis ( const Timestamp start,
const Timestamp end 
)
inlinestatic

Returns the ellapsed time between the given two timestamps.

The value is returned in milliseconds.

Parameters
startThe start time
endThe finish time
Returns
the ellapsed time between the given two timestamps.
Uint64 cugl::Timestamp::ellapsedMillis ( const Timestamp stamp) const
inline

Returns the ellapsed time from the provided time.

This method measures the time from stamp until the current time. Hence the current time is the end of the interval.

The value is returned in milliseconds.

Parameters
stampThe start time
Returns
the ellapsed time from the provided time.
static Uint64 cugl::Timestamp::ellapsedNanos ( const Timestamp start,
const Timestamp end 
)
inlinestatic

Returns the ellapsed time between the given two timestamps.

The value is returned in nanoseconds.

Parameters
startThe start time
endThe finish time
Returns
the ellapsed time between the given two timestamps.
long cugl::Timestamp::ellapsedNanos ( const Timestamp stamp)
inline

Returns the ellapsed time from the provided time.

This method measures the time from stamp until the current time. Hence the current time is the end of the interval.

The value is returned in nanoseconds.

Parameters
stampThe start time
Returns
the ellapsed time from the provided time.
timestamp_t cugl::Timestamp::getTime ( ) const
inline

Returns the current time stamp in its internal format

This format is not much use by itself. It only allows you to use functions in chrono not supported by this class. For most purposes you should used one of the ellapsed methods instead.

Returns
the current time stamp in its internal format
void cugl::Timestamp::mark ( )
inline

Sets this time stamp to be the current moment in time.

The previous value of this time stamp will be erased.

const Timestamp cugl::Timestamp::operator+ ( Uint32  millis) const
inline

Returns a copy of this time stamp incremented by the number of milliseconds

While we can support timestamps more accurate than milliseconds, SDL events only mark time increments at the millisecond level. As this is the primary reason for incrementing a time stamp by a integer value, we only support milliseconds for this operation.

Parameters
millisThe number of milliseconds to increment
Returns
a copy of this time stamp incremented by the number of milliseconds
Timestamp& cugl::Timestamp::operator+= ( Uint32  millis)
inline

Increments this time stamp by the given number of milliseconds

While we can support timestamps more accurate than milliseconds, SDL events only mark time increments at the millisecond level. As this is the primary reason for incrementing a time stamp by a integer value, we only support milliseconds for this operation.

Parameters
millisThe number of milliseconds to increment
Returns
a reference to this time stamp for chaining
const Timestamp cugl::Timestamp::operator- ( Uint32  millis) const
inline

Returns a copy of this time stamp decremented by the number of milliseconds

While we can support timestamps more accurate than milliseconds, SDL events only mark time increments at the millisecond level. As this is the primary reason for incrementing a time stamp by a integer value, we only support milliseconds for this operation.

Parameters
millisThe number of milliseconds to decrement
Returns
a copy of this time stamp decremented by the number of milliseconds
Timestamp& cugl::Timestamp::operator-= ( Uint32  millis)
inline

Decrements this time stamp by the given number of milliseconds

While we can support timestamps more accurate than milliseconds, SDL events only mark time increments at the millisecond level. As this is the primary reason for incrementing a time stamp by a integer value, we only support milliseconds for this operation.

Parameters
millisThe number of milliseconds to decrement
Returns
a reference to this time stamp for chaining
const Timestamp& cugl::Timestamp::operator= ( const Timestamp stamp)
inline

Sets this time stamp to be a copy of stamp.

This operator does not mark the time it copies, but instead uses the value taken from stamp.

Parameters
stampThe time stamp to copy
Returns
a reference to this timestamp for chaining.
const Timestamp& cugl::Timestamp::set ( const Timestamp stamp)
inline

Sets this time stamp to be a copy of stamp.

This operator does not mark the time it copies, but instead uses the value taken from stamp.

Parameters
stampThe time stamp to copy
Returns
a reference to this timestamp for chaining.

Member Data Documentation

timestamp_t cugl::Timestamp::_time
protected

The current timestamp using the steady clock from chrono.


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