ZEDA
1.6.18
|
Macros | |
#define | zRingClass(ring_t, cell_t) |
generate ring buffer class. More... | |
#define | zRingSize(y) (y)->size |
#define | zRingBuf(y) ( (y)->buf ) |
#define | zRingElemSize(y) sizeof(*zRingBuf(y)) |
#define | zRingHead(y) ( &zRingBuf(y)[(y)->head] ) |
#define | zRingElem(y, i) ( &zRingBuf(y)[((y)->head+(i)) % (y)->size] ) |
#define | zRingSetElem(a, i, d) memcpy( zRingElem(a,i), (d), zRingElemSize(a) ) |
#define | zRingReset(y) ( (y)->head = 0 ); |
#define | zRingInit(y) |
#define | zRingAlloc(y, type, size) |
allocate an array. More... | |
#define | zRingFree(y) |
#define | zRingIncHead(y) |
#define | zRingDecHead(y) |
#define zRingClass | ( | ring_t, | |
cell_t | |||
) |
generate ring buffer class.
A macro zRingClass() can generate a new ring buffer class, which consists of the total number of elements, the current head of the ring buffer, and the pointer to the ring buffer. ring_t is the class name to be defined. cell_t is the class name of the data to be arrayed.
To allocate and free a ring buffer, use zRingAlloc() and zRingFree().
The number of elements is acquired by zRingSize(). The actual array head can be accessed by zRingBuf(). But, the ring buffer conceptually conceal the body array. zRingHead() is preferable to be used, instead. It allows to access to the data at the current head. An elements after some elements the head can be safely accessed by zRingElem() and zRingSetElem().
zRingReset() resets the head position to the actual head of the array.
To advance and get back the head, use zRingIncHead() and zRingDecHead(), respectively.
#define zRingSize | ( | y | ) | (y)->size |
#define zRingBuf | ( | y | ) | ( (y)->buf ) |
#define zRingElemSize | ( | y | ) | sizeof(*zRingBuf(y)) |
#define zRingHead | ( | y | ) | ( &zRingBuf(y)[(y)->head] ) |
#define zRingElem | ( | y, | |
i | |||
) | ( &zRingBuf(y)[((y)->head+(i)) % (y)->size] ) |
#define zRingSetElem | ( | a, | |
i, | |||
d | |||
) | memcpy( zRingElem(a,i), (d), zRingElemSize(a) ) |
#define zRingReset | ( | y | ) | ( (y)->head = 0 ); |
#define zRingInit | ( | y | ) |
#define zRingAlloc | ( | y, | |
type, | |||
size | |||
) |
#define zRingFree | ( | y | ) |
#define zRingIncHead | ( | y | ) |