Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::SampleBuffer Class Template Reference

Buffer class for input data. More...

#include <SampleBuffer.h>

Inheritance diagram for gadget::SampleBuffer:

Inheritance graph
[legend]
List of all members.

Public Types

typedef std::vector< std::vector<
DATA_TYPE > > 
buffer_t

Public Methods

 SampleBuffer ()
void addSample (const std::vector< DATA_TYPE > &dataSample)
 Add a new sample to the buffer. More...

void swapBuffers ()
 Swap the data buffers. More...

void lock ()
void unlock ()
buffer_tstableBuffer ()

Protected Methods

 SampleBuffer (const SampleBuffer &b)
void operator= (const SampleBuffer &b)

Protected Attributes

buffer_t mStableBuffer
buffer_t mReadyBuffer
vpr::Mutex mLock
 Lock to protect the buffer. More...


Detailed Description

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
class gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >

Buffer class for input data.

The SampleBuffer stores the readings from an input device.

It consists of two buffers (vectors of vectors of samples) that hold The "stable" samples and the "ready" samples.

Stable - Samples that the application is actually looking at Ready - Samples that have been completed and could be swapped over to current

ASSERTION: The buffers can be empty at the start, but after the first cycle (first time stable gets values) the Stable buffer must have at least one sample.

Parameters:
MAX_BUFFER_SIZE  - The maximum allowable size of the buffer. After it gets this large we will start throwing away old data.

Definition at line 65 of file SampleBuffer.h.


Member Typedef Documentation

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
typedef std::vector< std::vector< DATA_TYPE > > gadget::SampleBuffer::buffer_t
 

Definition at line 68 of file SampleBuffer.h.

Referenced by gadget::SampleBuffer< DigitalData >::stableBuffer.


Constructor & Destructor Documentation

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::SampleBuffer   [inline]
 

Definition at line 71 of file SampleBuffer.h.

Referenced by gadget::SampleBuffer< DigitalData >::operator=, and gadget::SampleBuffer< DigitalData >::SampleBuffer.

00072    {
00073       /* Do nothing. */ ;
00074    }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::SampleBuffer const SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE > &    b [inline, protected]
 

Definition at line 118 of file SampleBuffer.h.

00118 {;}


Member Function Documentation

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
void gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::addSample const std::vector< DATA_TYPE > &    dataSample [inline]
 

Add a new sample to the buffer.

Precondition:
Buffers must be locked before calling

Definition at line 79 of file SampleBuffer.h.

00080    {
00081       vprASSERT(mLock.test());                  // Verify that it is locked
00082       mReadyBuffer.push_back(dataSample);
00083       if(mReadyBuffer.size() > MAX_BUFFER_SIZE)
00084       {
00085          while(mReadyBuffer.size() > MAX_BUFFER_SIZE)
00086          { mReadyBuffer.erase(mReadyBuffer.begin()); }
00087       }
00088    }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
void gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::swapBuffers   [inline]
 

Swap the data buffers.

Postcondition:
If ready has values, then copy values from ready to stable if not, then stable keeps its old values
Note:
This means that until the first sample, StableBuffer is possibly empty.

Definition at line 95 of file SampleBuffer.h.

00096    {
00097    vpr::Guard<vpr::Mutex>  guard(mLock);
00098 
00099       if(!mReadyBuffer.empty())            // If Ready buffer has data
00100       {
00101          mStableBuffer = mReadyBuffer;       // Copy over the ready values
00102       }
00103 
00104       mReadyBuffer.clear();
00105    }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
void gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::lock   [inline]
 

Definition at line 107 of file SampleBuffer.h.

00108    {  mLock.acquire(); }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
void gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::unlock   [inline]
 

Definition at line 110 of file SampleBuffer.h.

00111    {  mLock.release(); }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
buffer_t& gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::stableBuffer   [inline]
 

Definition at line 113 of file SampleBuffer.h.

00114    { return mStableBuffer; }

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
void gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::operator= const SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE > &    b [inline, protected]
 

Definition at line 119 of file SampleBuffer.h.

00119 {;}


Member Data Documentation

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
buffer_t gadget::SampleBuffer::mStableBuffer [protected]
 

Definition at line 121 of file SampleBuffer.h.

Referenced by gadget::SampleBuffer< DigitalData >::stableBuffer, and gadget::SampleBuffer< DigitalData >::swapBuffers.

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
buffer_t gadget::SampleBuffer::mReadyBuffer [protected]
 

Definition at line 122 of file SampleBuffer.h.

Referenced by gadget::SampleBuffer< DigitalData >::addSample, and gadget::SampleBuffer< DigitalData >::swapBuffers.

template<class DATA_TYPE, unsigned MAX_BUFFER_SIZE = 5000>
vpr::Mutex gadget::SampleBuffer::mLock [protected]
 

Lock to protect the buffer.

Definition at line 124 of file SampleBuffer.h.

Referenced by gadget::SampleBuffer< DigitalData >::addSample, gadget::SampleBuffer< DigitalData >::lock, gadget::SampleBuffer< DigitalData >::swapBuffers, and gadget::SampleBuffer< DigitalData >::unlock.


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:27:03 2004 for Gadgeteer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002