wavelength 1.0.0
Loading...
Searching...
No Matches
ringbuffer.h
Go to the documentation of this file.
1#pragma once
2
13public:
22 explicit RingBuffer(unsigned int size);
23
30 virtual ~RingBuffer();
31
42 virtual void Write(const void *data, unsigned int size, bool endOfStream);
43
45 virtual void Notify() = 0;
46
53 virtual void Reset();
54
63 bool IsFinished() const;
64
72 unsigned int ContiguousFree() const;
73
81 bool IsFull() const;
82
90 bool IsEmpty() const;
91
102 void *Read(unsigned int maxSize, unsigned int *size);
103
112 void Release(void **block);
113
121 unsigned int FreeSpace() const;
122
131 unsigned int Used(bool *endOfStream) const;
132
140
148 bool EndOfStream() const;
149
150protected:
151 unsigned int mSize;
152 char *mBuffer;
153 char *mRead;
154 char *mWrite;
155 char *mEnd;
158 unsigned int mReserve;
159};
virtual void Write(const void *data, unsigned int size, bool endOfStream)
Record the end-of-stream flag and append bytes, wrapping at mEnd.
bool mEndOfStream
Definition ringbuffer.h:157
virtual void Notify()=0
Report the free space to the writer when it has changed.
char * mEnd
Definition ringbuffer.h:155
void * Read(unsigned int maxSize, unsigned int *size)
Notify the writer, then return the next contiguous block of at most maxSize bytes.
void Release(void **block)
Consume the block Read() returned and notify the writer.
unsigned int mSize
Definition ringbuffer.h:151
char * mPendingRead
Definition ringbuffer.h:156
virtual ~RingBuffer()
Free the buffer.
bool IsFull() const
Report whether ContiguousFree() is zero.
RingBuffer(unsigned int size)
Allocate and clear a buffer of size bytes, rounded down to whole words, with both pointers at its sta...
unsigned int ContiguousFree() const
Report the space the writer can fill without wrapping, less the reserve.
unsigned int FreeSpace() const
Report the free space, less the reserve.
unsigned int Used(bool *endOfStream) const
Report the bytes written and not yet read.
bool IsFinished() const
Report whether the stream has ended and every byte has been read.
char * mWrite
Definition ringbuffer.h:154
virtual void Reset()
Discard every byte by moving both pointers to the start of the buffer.
char * mRead
Definition ringbuffer.h:153
bool EndOfStream() const
Report the end-of-stream flag.
unsigned int mReserve
Definition ringbuffer.h:158
void ClearEndOfStream()
Clear the end-of-stream flag.
bool IsEmpty() const
Report whether every written byte has been read.
char * mBuffer
Definition ringbuffer.h:152