12
12
* @addtogroup SRingBuffer
14
14
* An SRingBuffer is a special data structure that is circular in nature.
15
* It only holds bytes and as such is useful when dealing with strings and
16
* other eight-bit data.
18
* If you are looking for a circular array, this is not
16
* This is not a represent for a queue, this is only for byte sized data
17
* elements, like text and such.
22
20
* The theory behind a circular structure is simple: Never have to deal with
54
53
* Create a new SRingBuffer objects.
56
* @param len The number of items to
55
* @param size The number of items to allocate space for.
56
* @param free_func The function that is used to free the data.
58
* @note It is recomended to have a big size of the buffer to make room for
59
* each item that should be stored plus a bit extra. (if you expect to
60
* have \f$n\f$ items allocate \f$n + \frac{n}{2}\f$ slots.)
60
s_ring_buffer_new (size_t len);
64
s_ring_buffer_new (size_t size);
63
67
* Free an SRingBuffer.
65
69
* @param self The SRingBuffer to free.
70
* @param free_data Set to @c TRUE to free the data.
69
74
s_ring_buffer_free (SRingBuffer * self);
77
* determine if buffer is empty.
79
84
* Add data to the front of the ringbuffer.
86
* @param err Set to TRUE on error, FALSE otherwise.
84
90
s_ring_buffer_push (SRingBuffer * self,
88
* add an item to the back of the ringbuffer.
95
* add an item to the front of the ringbuffer.
97
* @param err Set to TRUE on error, FALSE otherwise.
92
s_ring_buffer_push_back (SRingBuffer * self,
101
s_ring_buffer_push_front (SRingBuffer * self,
96
106
* Pop an item from the front of the array.
100
s_ring_buffer_pop (SRingBuffer * self);
103
* Pop the back of the array.
107
s_ring_buffer_pop_back (SRingBuffer * self);
110
* Reallocate an SRingBuffer to a now size for the internal array.
108
* @param err Set to TRUE on error, FALSE otherwise.
112
s_ring_buffer_pop (SRingBuffer * self,
116
* Pop the front of the array.
118
* @param err Set to TRUE on error, FALSE otherwise.
122
s_ring_buffer_pop_front (SRingBuffer * self,
126
* Peek at the byte at the end of the buffer.
128
* @param err Set to TRUE on error, FALSE otherwise.
132
s_ring_buffer_peek (SRingBuffer * self,
136
* Peek at the byte at the front of the buffer.
138
* @param err Set to TRUE on error, FALSE otherwise.
142
s_ring_buffer_peek_front (SRingBuffer * self,
146
* Reallocate an SRingBuffer to a new size for the internal array.
112
148
* @param self The SRingBuffer to reallocate.
113
149
* @param len The new length.
150
* @param err Set to TRUE on error, FALSE otherwise.
117
154
s_ring_buffer_realloc (SRingBuffer * self,
121
159
* Get the current length of the ring buffer.
140
178
* @param func Pointer to a function that is run on each byte.
141
179
* @param user_data Data that is provided to the function when doing the
181
* @param err Set to TRUE on error, FALSE otherwise.
145
185
* This does not use pop or push operations, and is thus the only way to keep