#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <derive-c/core/helpers.h>
#include <derive-c/core/panic.h>
#include <derive-c/core/self/def.h>
#include <derive-c/core/self/undef.h>
Go to the source code of this file.
|
struct | item_t |
| A queue comprised of an extendable circular buffer. More...
|
struct | SELF |
| An allocator that prints to stdout when it allocates or frees memory. More...
|
|
static void | item_delete (item_t *UNUSED(self)) |
static item_t | item_clone (item_t const *self) |
static SELF | new () |
static SELF | clone (SELF const *self) |
static ITEM const * | try_read (SELF const *self, INPLACE_TYPE index) |
static ITEM const * | read (SELF const *self, INPLACE_TYPE index) |
static ITEM * | try_write (SELF *self, INPLACE_TYPE index) |
static ITEM * | write (SELF *self, INPLACE_TYPE index) |
static ITEM * | try_push (SELF *self, ITEM item) |
static bool | try_insert_at (SELF *self, size_t at, ITEM const *items, size_t count) |
static void | remove_at (SELF *self, size_t at, size_t count) |
static ITEM * | push (SELF *self, ITEM item) |
static bool | try_pop (SELF *self, ITEM *destination) |
static ITEM | pop (SELF *self) |
static size_t | size (SELF const *self) |
static void | delete (SELF *self) |
static ITEM * | next (ITER *iter) |
static size_t | position (ITER const *iter) |
static bool | empty (ITER const *iter) |
static ITER | get_iter (SELF *self) |
static ITEM const * | next (ITER_CONST *iter) |
static size_t | position (ITER_CONST const *iter) |
static bool | empty (ITER_CONST const *iter) |
static ITER_CONST | get_iter_const (SELF const *self) |
◆ INPLACE_CAPACITY
#define INPLACE_CAPACITY 8 |
◆ INPLACE_TYPE
#define INPLACE_TYPE uint8_t |
◆ ITEM
◆ ITEM_CLONE
◆ ITEM_DELETE
◆ clone()
Definition at line 61 of file template.h.
61 {
63 new_self.
size = self->size;
66 }
67 return new_self;
68}
◆ delete()
void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 167 of file template.h.
167 {
171 }
172}
#define DEBUG_ASSERT(expr)
◆ empty() [1/2]
bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 196 of file template.h.
196 {
198 return iter->pos >= iter->vec->size;
199}
◆ empty() [2/2]
bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 233 of file template.h.
233 {
235 return iter->pos >= iter->vec->size;
236}
◆ get_iter()
ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 201 of file template.h.
201 {
203 return (ITER){
204 .vec = self,
205 .pos = 0,
206 };
207}
◆ get_iter_const()
ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 238 of file template.h.
238 {
240 return (ITER_CONST){
241 .vec = self,
242 .pos = 0,
243 };
244}
◆ item_clone()
◆ item_delete()
void item_delete |
( |
item_t * | UNUSEDself | ) |
|
|
static |
◆ new()
◆ next() [1/2]
ITEM * next |
( |
ITER * | iter | ) |
|
|
static |
Definition at line 181 of file template.h.
181 {
183 if (iter->pos < iter->vec->size) {
184 ITEM* item = &iter->vec->data[iter->pos];
185 iter->pos++;
186 return item;
187 }
188 return NULL;
189}
◆ next() [2/2]
ITEM const * next |
( |
ITER_CONST * | iter | ) |
|
|
static |
Definition at line 218 of file template.h.
218 {
220 if (iter->pos < iter->vec->size) {
221 ITEM const* item = &iter->vec->data[iter->pos];
222 iter->pos++;
223 return item;
224 }
225 return NULL;
226}
◆ pop()
Definition at line 156 of file template.h.
156 {
159 return entry;
160}
static bool try_pop(SELF *self, ITEM *destination)
◆ position() [1/2]
size_t position |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 191 of file template.h.
191 {
193 return iter->pos;
194}
◆ position() [2/2]
size_t position |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 228 of file template.h.
228 {
230 return iter->pos;
231}
◆ push()
Definition at line 140 of file template.h.
140 {
143 return slot;
144}
static ITEM * try_push(SELF *self, ITEM item)
◆ read()
Definition at line 78 of file template.h.
78 {
81 return value;
82}
static VALUE const * try_read(SELF const *self, INDEX index)
◆ remove_at()
void remove_at |
( |
SELF * | self, |
|
|
size_t | at, |
|
|
size_t | count ) |
|
static |
Definition at line 124 of file template.h.
124 {
127
128 if (count == 0) {
129 return;
130 }
131
132 for (size_t i = at; i < at + count; i++) {
134 }
135
136 memmove(&self->
data[at], &self->
data[at + count], (self->
size - (at + count)) *
sizeof(
ITEM));
138}
static INDEX_TYPE size(SELF const *self)
◆ size()
size_t size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 162 of file template.h.
162 {
164 return self->size;
165}
◆ try_insert_at()
bool try_insert_at |
( |
SELF * | self, |
|
|
size_t | at, |
|
|
ITEM const * | items, |
|
|
size_t | count ) |
|
static |
Definition at line 109 of file template.h.
109 {
113
115 return false;
116 }
117
118 memmove(&self->
data[at + count], &self->
data[at], (self->
size - at) *
sizeof(
ITEM));
119 memcpy(&self->
data[at], items, count *
sizeof(
ITEM));
121 return true;
122}
◆ try_pop()
bool try_pop |
( |
SELF * | self, |
|
|
ITEM * | destination ) |
|
static |
Definition at line 146 of file template.h.
146 {
150 *destination = self->
data[self->
size];
151 return true;
152 }
153 return false;
154}
◆ try_push()
Definition at line 98 of file template.h.
98 {
102 *slot = item;
104 return slot;
105 }
106 return NULL;
107}
◆ try_read()
Definition at line 70 of file template.h.
70 {
73 return &self->data[index];
74 }
75 return NULL;
76}
◆ try_write()
Definition at line 84 of file template.h.
84 {
87 return &self->
data[index];
88 }
89 return NULL;
90}
◆ write()
Definition at line 92 of file template.h.
92 {
95 return value;
96}
static VALUE * try_write(SELF *self, INDEX index)
◆ max_size