NptRingBuffer.h

00001 /*****************************************************************
00002 |
00003 |   Neptune - Ring Buffer
00004 |
00005 |   (c) 2001-2006 Gilles Boccon-Gibod
00006 |   Author: Gilles Boccon-Gibod (bok@bok.net)
00007 |
00008  ****************************************************************/
00009 
00010 #ifndef _NPT_RING_BUFFER_H_
00011 #define _NPT_RING_BUFFER_H_
00012 
00013 /*----------------------------------------------------------------------
00014 |   includes
00015 +---------------------------------------------------------------------*/
00016 #include "NptTypes.h"
00017 #include "NptReferences.h"
00018 
00019 /*----------------------------------------------------------------------
00020 |   NPT_RingBuffer
00021 +---------------------------------------------------------------------*/
00022 class NPT_RingBuffer
00023 {
00024  public:
00025     // methods
00026                   NPT_RingBuffer(NPT_Size size);
00027                   NPT_RingBuffer(void* buffer, NPT_Size size);
00028     virtual      ~NPT_RingBuffer();
00029     NPT_Size      GetSpace() const;
00030     NPT_Size      GetContiguousSpace() const;
00031     NPT_Result    Write(const void* buffer, NPT_Size byte_count);
00032     NPT_Size      GetAvailable() const;
00033     NPT_Size      GetContiguousAvailable() const;
00034     NPT_Result    Read(void* buffer, NPT_Size byte_count);
00035     unsigned char ReadByte();
00036     unsigned char PeekByte(NPT_Position offset);
00037     NPT_Result    MoveIn(NPT_Position offset);
00038     NPT_Result    MoveOut(NPT_Position offset);
00039     NPT_Result    Flush();
00040 
00041     // accessors
00042     unsigned char* GetWritePointer()  { return m_In; }
00043     unsigned char* GetReadPointer()   { return m_Out;}
00044 
00045  private:
00046     // members
00047     struct {
00048         unsigned char* start;
00049         unsigned char* end;
00050     }              m_Data;
00051     unsigned char* m_In;
00052     unsigned char* m_Out;
00053     NPT_Size       m_Size;
00054     bool           m_BufferIsLocal;
00055 };
00056 
00057 typedef NPT_Reference<NPT_RingBuffer> NPT_RingBufferReference;
00058 
00059 #endif // _NPT_RING_BUFFER_H_