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 103 of file stx-execpipe.cc.
stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::RingBuffer | ( | ) | [inline] |
Construct an empty ring buffer.
Definition at line 120 of file stx-execpipe.cc.
stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::~RingBuffer | ( | ) | [inline] |
Free the possibly used memory space.
Definition at line 127 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 172 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 155 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 161 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 139 of file stx-execpipe.cc.
void stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::clear | ( | ) | [inline] |
Reset the ring buffer to empty.
Definition at line 145 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 133 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 184 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 116 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 110 of file stx-execpipe.cc.
char* stx::anonymous_namespace{stx-execpipe.cc}::RingBuffer::m_data [private] |
pointer to allocated memory buffer
Definition at line 107 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 113 of file stx-execpipe.cc.