CUGL 2.1
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
 
Uint64 ellapsedNanos (const Timestamp &stamp)
 
Timestampoperator+= (Uint32 millis)
 
Timestampoperator-= (Uint32 millis)
 
const Timestamp operator+ (Uint32 millis) const
 
const Timestamp operator- (Uint32 millis) const
 
bool operator< (const Timestamp &other) 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

◆ Timestamp() [1/2]

cugl::Timestamp::Timestamp ( )
inline

Constructs a new time stamp.

The constructor marks the exact moment that it was created.

◆ Timestamp() [2/2]

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

◆ ellapsedMicros() [1/2]

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.

◆ ellapsedMicros() [2/2]

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.

◆ ellapsedMillis() [1/2]

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.

◆ ellapsedMillis() [2/2]

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.

◆ ellapsedNanos() [1/2]

Uint64 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.

◆ ellapsedNanos() [2/2]

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.

◆ getTime()

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

◆ mark()

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.

◆ operator+()

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

◆ operator+=()

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

◆ operator-()

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

◆ operator-=()

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

◆ operator<()

bool cugl::Timestamp::operator< ( const Timestamp other) const
inline

Returns whether this timestamp is less than another timestamp.

Parameters
otherThe timestamp to compare
Returns
whether this timestamp is less than another timestamp.

◆ operator=()

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.

◆ set()

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

◆ _time

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: