Debian Codegraph @

terps/scott/ai_uk/ringbuffer.h

raw symbols SCIP
1 //
2 // ringbuffer.h
3 // part of ScottFree, an interpreter for adventures in Scott Adams format
4 //
5 // Created by Petter Sjölund on 2022-03-04.
6 //
7
8 #ifndef ringbuffer_h
9 #define ringbuffer_h
10
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include <stdlib.h>
14
15 // Opaque circular buffer structure
16 typedef struct circular_buf_t circular_buf_t;
17 // Handle type, the way users interact with the API
18 typedef circular_buf_t *cbuf_handle_t;
19
20 /// Pass in a storage buffer and size
21 /// Returns a circular buffer handle
22 cbuf_handle_t circular_buf_init(uint8_t *buffer, size_t size);
23
24 /// Free a circular buffer structure.
25 /// Does not free data buffer; owner is responsible for that
26 void circular_buf_free(cbuf_handle_t me);
27
28 /// Reset the circular buffer to empty, head == tail
29 void circular_buf_reset(cbuf_handle_t me);
30
31 /// Rejects new data if the buffer is full
32 /// Returns 0 on success, -1 if buffer is full
33 int circular_buf_putXY(cbuf_handle_t me, uint8_t x, uint8_t y);
34
35 /// Retrieve a value from the buffer
36 /// Returns 0 on success, -1 if the buffer is empty
37 int circular_buf_getXY(cbuf_handle_t me, uint8_t *x, uint8_t *y);
38
39 /// Returns true if the buffer is empty
40 bool circular_buf_empty(cbuf_handle_t me);
41
42 /// Returns true if the buffer is full
43 bool circular_buf_full(cbuf_handle_t me);
44
45 #endif /* ringbuffer_h */