1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
Circular Buffers
================
A circular buffer that will automatically increase in size as necessary
as data is pushed to the front or back.
.. code:: cpp
#include <util/circlebuf.h>
Circular Buffer Structure (struct circlebuf)
--------------------------------------------
.. struct:: circlebuf
.. member:: void *circlebuf.data
.. member:: size_t circlebuf.size
.. member:: size_t circlebuf.start_pos
.. member:: size_t circlebuf.end_pos
.. member:: size_t circlebuf.capacity
Circular Buffer Inline Functions
--------------------------------
.. function:: void circlebuf_init(struct circlebuf *cb)
Initializes a circular buffer (just zeroes out the entire structure).
:param cb: The circular buffer
---------------------
.. function:: void circlebuf_free(struct circlebuf *cb)
Frees a circular buffer.
:param cb: The circular buffer
---------------------
.. function:: void circlebuf_reserve(struct circlebuf *cb, size_t capacity)
Reserves a specific amount of buffer space to ensure minimum
upsizing.
:param cb: The circular buffer
:param capacity: The new capacity, in bytes
---------------------
.. function:: void circlebuf_upsize(struct circlebuf *cb, size_t size)
Sets the current active (not just reserved) size. Any new data is
zeroed.
:param cb: The circular buffer
:param size: The new size, in bytes
---------------------
.. function:: void circlebuf_place(struct circlebuf *cb, size_t position, const void *data, size_t size)
Places data at a specific positional index (relative to the starting
point) within the circular buffer.
:param cb: The circular buffer
:param position: Positional index relative to starting point
:param data: Data to insert
:param size: Size of data to insert
---------------------
.. function:: void circlebuf_push_back(struct circlebuf *cb, const void *data, size_t size)
Pushes data to the end of the circular buffer.
:param cb: The circular buffer
:param data: Data
:param size: Size of data
---------------------
.. function:: void circlebuf_push_front(struct circlebuf *cb, const void *data, size_t size)
Pushes data to the front of the circular buffer.
:param cb: The circular buffer
:param data: Data
:param size: Size of data
---------------------
.. function:: void circlebuf_push_back_zero(struct circlebuf *cb, size_t size)
Pushes zeroed data to the end of the circular buffer.
:param cb: The circular buffer
:param size: Size
---------------------
.. function:: void circlebuf_push_front_zero(struct circlebuf *cb, size_t size)
Pushes zeroed data to the front of the circular buffer.
:param cb: The circular buffer
:param size: Size
---------------------
.. function:: void circlebuf_peek_front(struct circlebuf *cb, void *data, size_t size)
Peeks data at the front of the circular buffer.
:param cb: The circular buffer
:param data: Buffer to store data in
:param size: Size of data to retrieve
---------------------
.. function:: void circlebuf_peek_back(struct circlebuf *cb, void *data, size_t size)
Peeks data at the back of the circular buffer.
:param cb: The circular buffer
:param data: Buffer to store data in
:param size: Size of data to retrieve
---------------------
.. function:: void circlebuf_pop_front(struct circlebuf *cb, void *data, size_t size)
Pops data from the front of the circular buffer.
:param cb: The circular buffer
:param data: Buffer to store data in, or *NULL*
:param size: Size of data to retrieve
---------------------
.. function:: void circlebuf_pop_back(struct circlebuf *cb, void *data, size_t size)
Pops data from the back of the circular buffer.
:param cb: The circular buffer
:param data: Buffer to store data in, or *NULL*
:param size: Size of data to retrieve
---------------------
.. function:: void *circlebuf_data(struct circlebuf *cb, size_t idx)
Gets a direct pointer to data at a specific positional index within
the circular buffer, relative to the starting point.
:param cb: The circular buffer
:param idx: Byte index relative to the starting point
|