RingBuffer is a byte-oriented, pipe memory buffer which uses the underlying space in a circular fashion. More...
Public Member Functions | |
RingBuffer () | |
Construct an empty ring buffer. | |
~RingBuffer () | |
Free the possibly used memory space. | |
unsigned int | size () const |
Return the current number of unread bytes. | |
unsigned int | buffsize () const |
Return the current number of allocated bytes. | |
void | clear () |
Reset the ring buffer to empty. | |
char * | bottom () const |
Return a pointer to the first unread element. | |
unsigned int | bottomsize () const |
Return the number of bytes available at the bottom() place. | |
void | advance (unsigned int n) |
Advance the internal read pointer n bytes, thus marking that amount of data as read. | |
void | write (const void *src, unsigned int len) |
Write len bytes into the ring buffer at the top position, the buffer will grow if necessary. | |
Private Attributes | |
char * | m_data |
pointer to allocated memory buffer | |
unsigned int | m_buffsize |
number of bytes allocated in m_data | |
unsigned int | m_size |
number of unread bytes in ring buffer | |
unsigned int | m_bottom |
bottom pointer of unread area |
RingBuffer is a byte-oriented, pipe memory buffer which uses the underlying space in a circular fashion.
The input stream is write()en into the buffer as blocks of bytes, while the buffer is reallocated with exponential growth as needed.
The first unread byte can be accessed using bottom(). The number of unread bytes at the ring buffers bottom position is queried by bottomsize(). This may not match the total number of unread bytes as returned by size(). After processing the bytes at bottom(), the unread cursor may be moved using advance().
The ring buffer has the following two states.
+------------------------------------------------------------------+ | unused | data | unused | +------------+------------------------+----------------------------+ ^ ^ m_bottom m_bottom+m_size
or
+------------------------------------------------------------------+ | more data | unused | data | +------------+--------------------------------------+--------------+ ^ ^ m_bottom+m_size m_bottom
The size of the whole buffer is m_buffsize.
Definition at line 98 of file stx-execpipe.cc.
stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::RingBuffer | ( | ) | [inline] |
Construct an empty ring buffer.
Definition at line 115 of file stx-execpipe.cc.
stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::~RingBuffer | ( | ) | [inline] |
Free the possibly used memory space.
Definition at line 122 of file stx-execpipe.cc.
void stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::advance | ( | unsigned int | n | ) | [inline] |
Advance the internal read pointer n bytes, thus marking that amount of data as read.
Definition at line 167 of file stx-execpipe.cc.
char* stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::bottom | ( | ) | const [inline] |
Return a pointer to the first unread element.
Be warned that the buffer may not be linear, thus bottom()+size() might not be valid. You have to use bottomsize().
Definition at line 150 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::bottomsize | ( | ) | const [inline] |
Return the number of bytes available at the bottom() place.
Definition at line 156 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::buffsize | ( | ) | const [inline] |
Return the current number of allocated bytes.
Definition at line 134 of file stx-execpipe.cc.
void stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::clear | ( | ) | [inline] |
Reset the ring buffer to empty.
Definition at line 140 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::size | ( | ) | const [inline] |
Return the current number of unread bytes.
Definition at line 128 of file stx-execpipe.cc.
void stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::write | ( | const void * | src, | |
unsigned int | len | |||
) | [inline] |
Write len bytes into the ring buffer at the top position, the buffer will grow if necessary.
Definition at line 179 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::m_bottom [private] |
bottom pointer of unread area
Definition at line 111 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::m_buffsize [private] |
number of bytes allocated in m_data
Definition at line 105 of file stx-execpipe.cc.
char* stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::m_data [private] |
pointer to allocated memory buffer
Definition at line 102 of file stx-execpipe.cc.
unsigned int stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::m_size [private] |
number of unread bytes in ring buffer
Definition at line 108 of file stx-execpipe.cc.