aboutsummaryrefslogtreecommitdiff
path: root/include/std/buffer.h
blob: a1bfb0118483cf065ebddbc283cb5d1265dced31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef AMALGAM_BUFFER_H
#define AMALGAM_BUFFER_H

#include "types.h"
#include "misc.h"
#include "defs.h"

#define BUFFER_OK 0
#define BUFFER_ALLOC_FAIL -1

typedef struct {
    char* data;
    usize size;
    usize capacity;
} Buffer;

CHECK_RESULT int buffer_init(Buffer *self, struct ScopedAllocator *allocator);

/* @data can be NULL */
CHECK_RESULT int buffer_append(Buffer *self, const void *data, usize size);
void* buffer_get(Buffer *self, usize index, usize type_size);
CHECK_RESULT int buffer_pop(Buffer *self, void *data, usize size);
void* buffer_start(Buffer *self);
void* buffer_end(Buffer *self);
usize __buffer_get_size(Buffer *self, usize type_size);
#define buffer_get_size(self, type) __buffer_get_size((self), sizeof(type))

#endif