RingBuffer< T > Class Template Reference

A RingBuffer for non pointers only <short description="">. More...

#include <RingBuffer.hpp>

List of all members.


Public Member Functions

 RingBuffer (int siz)
 ~RingBuffer ()
 doesn't free any memory.
void put (T &elem, int key)
get (int key, bool *found)
 returns the element and removes it from the RingBuffer.

Detailed Description

template<class T>
class RingBuffer< T >

A RingBuffer for non pointers only <short description="">.

Author:
Peter Schojer
Version:
Id
RingBuffer.hpp,v 1.4 2004/06/02 14:17:22 pschojer Exp

Definition at line 57 of file RingBuffer.hpp.


Constructor & Destructor Documentation

template<class T>
RingBuffer< T >::~RingBuffer  )  [inline]
 

doesn't free any memory.

NEVER use this for pointers! Use PointerRingBuffer Definition at line 75 of file RingBuffer.hpp.

00075 { 00076 delete[] keys;delete[] data; 00077 };


Member Function Documentation

template<class T>
T RingBuffer< T >::get int  key,
bool *  found
[inline]
 

returns the element and removes it from the RingBuffer.

Searches form the oldest element to the newest. For optimal performance get Elements in the order you inserted them! If no element is found,

Parameters:
found is set to false and an invalid element is returned
Definition at line 104 of file RingBuffer.hpp.
00104 { 00105 assert(found); 00106 // endpos always points to the next insert pos 00107 for(int i=startPos;i<endPos;i++) { 00108 if(keys[i%size]==key) { 00109 keys[i%size]=-1; 00110 *found=true; 00111 return data[i%size]; 00112 } 00113 } 00114 *found=false; 00115 return invalid; 00116 };


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