#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <derive-c/core.h>
#include <derive-c/panic.h>
#include <derive-c/self.h>
#include <derive-c/allocs/std.h>
Go to the source code of this file.
|
#define | ALLOC stdalloc |
| A simple vector.
|
#define | T derive_c_parameter_t |
#define | T_DELETE derive_c_parameter_t_delete |
◆ ALLOC
#define T derive_c_parameter_t |
◆ T_DELETE
#define T_DELETE derive_c_parameter_t_delete |
◆ delete()
void delete |
( |
SELF * | self | ) |
|
|
static |
Definition at line 170 of file template.h.
170 {
173 for (
size_t i = 0; i < self->
size; i++) {
175 }
177 }
178}
#define ALLOC
An allocator that prints to stdout when it allocates or frees memory.
static void free(SELF *self, void *ptr)
#define DEBUG_ASSERT(expr)
◆ empty() [1/2]
bool empty |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 202 of file template.h.
202 {
204 return iter->pos >= iter->vec->size;
205}
◆ empty() [2/2]
bool empty |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 238 of file template.h.
238 {
240 return iter->pos >= iter->vec->size;
241}
◆ get_iter()
ITER get_iter |
( |
SELF * | self | ) |
|
|
static |
Definition at line 207 of file template.h.
207 {
209 return (ITER){
210 .vec = self,
211 .pos = 0,
212 };
213}
◆ get_iter_const()
ITER_CONST get_iter_const |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 243 of file template.h.
243 {
245 return (ITER_CONST){
246 .vec = self,
247 .pos = 0,
248 };
249}
◆ new()
Definition at line 42 of file template.h.
42 {
44 .size = 0,
45 .capacity = 0,
46 .data = NULL,
47 .alloc = alloc,
48 };
49 return temp;
50}
◆ new_with_capacity()
SELF new_with_capacity |
( |
size_t | capacity, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 52 of file template.h.
52 {
57 .size = 0,
58 .capacity = capacity,
59 .data = data,
60 .alloc = alloc,
61 };
62}
static void * malloc(SELF *self, size_t size)
◆ new_with_defaults()
SELF new_with_defaults |
( |
size_t | size, |
|
|
T | default_value, |
|
|
ALLOC * | alloc ) |
|
static |
Definition at line 64 of file template.h.
64 {
66 for (
size_t i = 0; i <
size; i++) {
67 data[i] = default_value;
68 }
73 .data = data,
74 .alloc = alloc,
75 };
76}
static INDEX_TYPE size(SELF const *self)
◆ next() [1/2]
Definition at line 187 of file template.h.
187 {
189 if (iter->pos < iter->vec->size) {
190 T* item = &iter->vec->data[iter->pos];
191 iter->pos++;
192 return item;
193 }
194 return NULL;
195}
◆ next() [2/2]
T const * next |
( |
ITER_CONST * | iter | ) |
|
|
static |
Definition at line 223 of file template.h.
223 {
225 if (iter->pos < iter->vec->size) {
226 T const* item = &iter->vec->data[iter->pos];
227 iter->pos++;
228 return item;
229 }
230 return NULL;
231}
◆ pop()
Definition at line 159 of file template.h.
159 {
162 return entry;
163}
static bool try_pop(SELF *self, T *destination)
◆ position() [1/2]
size_t position |
( |
ITER const * | iter | ) |
|
|
static |
Definition at line 197 of file template.h.
197 {
199 return iter->pos;
200}
◆ position() [2/2]
size_t position |
( |
ITER_CONST const * | iter | ) |
|
|
static |
Definition at line 233 of file template.h.
233 {
235 return iter->pos;
236}
◆ push()
T * push |
( |
SELF * | self, |
|
|
T | value ) |
|
static |
Definition at line 119 of file template.h.
119 {
123 size_t new_capacity;
124 if (self->
data == NULL) {
126
127
128
129
130 new_capacity = 8;
132 } else {
133
134
135
138 }
141 self->
data = new_data;
142 }
144 *entry = value;
146 return entry;
147}
static void * realloc(SELF *self, void *ptr, size_t size)
◆ read()
T const * read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 99 of file template.h.
99 {
102 return value;
103}
static V const * try_read(SELF const *self, INDEX index)
◆ shallow_clone()
Definition at line 78 of file template.h.
78 {
82 memcpy(data, self->data, self->size *
sizeof(
T));
84 .size = self->size,
85 .capacity = self->capacity,
86 .data = data,
87 .alloc = self->alloc,
88 };
89}
◆ size()
size_t size |
( |
SELF const * | self | ) |
|
|
static |
Definition at line 165 of file template.h.
165 {
167 return self->size;
168}
◆ try_pop()
bool try_pop |
( |
SELF * | self, |
|
|
T * | destination ) |
|
static |
Definition at line 149 of file template.h.
149 {
153 *destination = self->
data[self->
size];
154 return true;
155 }
156 return false;
157}
◆ try_read()
T const * try_read |
( |
SELF const * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 91 of file template.h.
91 {
94 return &self->data[index];
95 }
96 return NULL;
97}
◆ try_write()
T * try_write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 105 of file template.h.
105 {
108 return &self->
data[index];
109 }
110 return NULL;
111}
◆ write()
T * write |
( |
SELF * | self, |
|
|
size_t | index ) |
|
static |
Definition at line 113 of file template.h.
113 {
116 return value;
117}
static V * try_write(SELF *self, INDEX index)