Support Forum       G3D Web Page     
Classes | Public Member Functions | List of all members
G3D::TimeQueue< T > Class Template Reference


Dynamic queue that works with timestamps to allow simulating latency. More...

Public Member Functions

void clear (bool freeStorage=true)
 
Removes all elements (invoking their destructors). More...
 
bool contains (const T &e) const
 
Returns true if the given element is in the queue. More...
 
bool empty () const
 
void enqueue (const T &e, RealTime time)
 
pushBack More...
 
void fastClear ()
 Clear without freeing the underlying array. More...
 
bool getPopBack (RealTime time, T &value)
 
Remove the last element from the queue if its time stamp is less than or equal to and return true, otherwise return false. More...
 
bool getPopFront (RealTime time, T &value)
 
Remove the first element from the queue if its time stamp is less than or equal to and return true, otherwise return false. More...
 
const T & last () const
 Returns the back element. More...
 
T & last ()
 
int length () const
 
Number of elements in the queue. More...
 
T & operator[] (int n)
 
Performs bounds checks in debug mode More...
 
const T & operator[] (int n) const
 
Performs bounds checks in debug mode More...
 
void pushBack (const T &e, RealTime time)
 
Insert a new element at the end of the queue that must emerge no earlier than More...
 
void pushFront (const T &e, RealTime time)
 
Insert a new element into the front of the queue that must emerge no earlier than (a traditional queue only uses pushBack). More...
 
int size () const
 Number of elements in the queue. More...
 

Detailed Description

template<class T>
class G3D::TimeQueue< T >


Dynamic queue that works with timestamps to allow simulating latency.

Faster than std::deque for objects with constructors.

Typical use:

TimeQueue<Event> eventQueue;
...
eventQueue.pushBack(newEvent, System::time() + latency);
...
Event e;
while (eventQueue.getPopFront(System::time(), e)) {
...
}
See also
Queue, ThreadsafeQueue

Member Function Documentation

◆ clear()

template<class T >
void G3D::TimeQueue< T >::clear ( bool  freeStorage = true)
inline


Removes all elements (invoking their destructors).

Parameters
freeStorageIf false, the underlying array is not deallocated (allowing fast push in the future), however, the size of the Queue is reported as zero.

Referenced by G3D::TimeQueue< T >::fastClear().

◆ contains()

template<class T >
bool G3D::TimeQueue< T >::contains ( const T &  e) const
inline


Returns true if the given element is in the queue.

◆ empty()

template<class T >
bool G3D::TimeQueue< T >::empty ( ) const
inline

◆ enqueue()

template<class T >
void G3D::TimeQueue< T >::enqueue ( const T &  e,
RealTime  time 
)
inline


pushBack

◆ fastClear()

template<class T >
void G3D::TimeQueue< T >::fastClear ( )
inline

Clear without freeing the underlying array.

◆ getPopBack()

template<class T >
bool G3D::TimeQueue< T >::getPopBack ( RealTime  time,
T &  value 
)
inline


Remove the last element from the queue if its time stamp is less than or equal to and return true, otherwise return false.

◆ getPopFront()

template<class T >
bool G3D::TimeQueue< T >::getPopFront ( RealTime  time,
T &  value 
)
inline


Remove the first element from the queue if its time stamp is less than or equal to and return true, otherwise return false.

◆ last() [1/2]

template<class T >
const T& G3D::TimeQueue< T >::last ( ) const
inline

Returns the back element.

◆ last() [2/2]

template<class T >
T& G3D::TimeQueue< T >::last ( )
inline

◆ length()

template<class T >
int G3D::TimeQueue< T >::length ( ) const
inline


Number of elements in the queue.

None may be available for popping based on the time.

◆ operator[]() [1/2]

template<class T >
T& G3D::TimeQueue< T >::operator[] ( int  n)
inline


Performs bounds checks in debug mode

◆ operator[]() [2/2]

template<class T >
const T& G3D::TimeQueue< T >::operator[] ( int  n) const
inline


Performs bounds checks in debug mode

◆ pushBack()

template<class T >
void G3D::TimeQueue< T >::pushBack ( const T &  e,
RealTime  time 
)
inline


Insert a new element at the end of the queue that must emerge no earlier than

◆ pushFront()

template<class T >
void G3D::TimeQueue< T >::pushFront ( const T &  e,
RealTime  time 
)
inline


Insert a new element into the front of the queue that must emerge no earlier than (a traditional queue only uses pushBack).

If you push an event with a time later than the first event in the queue it will block subsequent events until that time is used with popFront().

◆ size()

template<class T >
int G3D::TimeQueue< T >::size ( ) const
inline

Number of elements in the queue.

None may be available for popping based on the time.

Referenced by G3D::TimeQueue< T >::contains(), G3D::TimeQueue< T >::empty(), G3D::TimeQueue< T >::last(), and G3D::TimeQueue< T >::length().


documentation generated on Wed Nov 24 2021 08:02:01 using doxygen 1.8.15