123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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)
- --------------------------------------------
- .. type:: 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
|