17 DC_SCOPED(int_queue) queue = int_queue_new(stdalloc_get_ref());
20 for (
int i = 1; i <= 5; i++) {
21 int_queue_push_back(&queue, i);
26 while (int_queue_size(&queue) > 0) {
27 int value = int_queue_pop_front(&queue);
40 DC_SCOPED(int_deque) deque = int_deque_new(stdalloc_get_ref());
42 DC_LOG(log,
DC_INFO,
"push_back 10, push_back 20, pop_front");
43 int_deque_push_back(&deque, 10);
44 int_deque_push_back(&deque, 20);
45 int_deque_pop_front(&deque);
56 char* cloned_data = (
char*)malloc((
size_t)self->length);
57 memcpy(cloned_data, self->data, (
size_t)self->length);
58 return (
struct message){.data = cloned_data, .length = self->length};
63 fprintf(
stream,
"message@%p { data: \"%.*s\", length: %d }", (
void*)self, self->
length,
67#define ITEM struct message
68#define ITEM_DELETE message_delete
69#define ITEM_CLONE message_clone
70#define ITEM_DEBUG message_debug
71#define NAME message_queue
76 DC_SCOPED(message_queue) queue = message_queue_new(stdalloc_get_ref());
79 char* data1 = (
char*)malloc(5);
80 memcpy(data1,
"hello", 5);
81 struct message msg1 = {.data = data1, .length = 5};
82 message_queue_push_back(&queue, msg1);
84 char* data2 = (
char*)malloc(5);
85 memcpy(data2,
"world", 5);
86 struct message msg2 = {.data = data2, .length = 5};
87 message_queue_push_back(&queue, msg2);
95 new_global)((
NS(
DC_LOGGER, global_config)){.stream = stdout, .ansi_colours =
true},
#define DC_DEBUG(DEBUG_FN, DEBUG_PTR)
static void example_custom(DC_LOGGER *parent)
static void message_debug(struct message const *self, dc_debug_fmt fmt, FILE *stream)
static void example_queue(DC_LOGGER *parent)
static struct message message_clone(struct message const *self)
static void message_delete(struct message *self)
static void example_deque(DC_LOGGER *parent)
#define DC_SCOPED(type,...)
RAII in C. Call the destructor when the variable goes out of scope.
Debug format helpers for debug printin data structures.
#define DC_LOGGER_NEW(...)
static DC_PUBLIC FILE * stream(SELF *self)