Loading...
Searching...
No Matches
simple_array.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <stdint.h>
20#include <stddef.h>
21#include <stdbool.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27typedef struct SimpleArray SimpleArray;
28
29typedef void SimpleArrayData;
30typedef void SimpleArrayElement;
31
32typedef void (*SimpleArrayInit)(SimpleArrayElement* elem);
33typedef void (*SimpleArrayReset)(SimpleArrayElement* elem);
34typedef void (*SimpleArrayCopy)(SimpleArrayElement* elem, const SimpleArrayElement* other);
35
37typedef struct {
38 SimpleArrayInit init;
39 SimpleArrayReset reset;
40 SimpleArrayCopy copy;
41 const size_t type_size;
43
51
57void simple_array_free(SimpleArray* instance);
58
68void simple_array_init(SimpleArray* instance, uint32_t count);
69
77void simple_array_reset(SimpleArray* instance);
78
87void simple_array_copy(SimpleArray* instance, const SimpleArray* other);
88
97bool simple_array_is_equal(const SimpleArray* instance, const SimpleArray* other);
98
105uint32_t simple_array_get_count(const SimpleArray* instance);
106
114SimpleArrayElement* simple_array_get(SimpleArray* instance, uint32_t index);
115
123const SimpleArrayElement* simple_array_cget(const SimpleArray* instance, uint32_t index);
124
131SimpleArrayData* simple_array_get_data(SimpleArray* instance);
132
139const SimpleArrayData* simple_array_cget_data(const SimpleArray* instance);
140
141// Standard preset configurations
142
143// Preset configuration for a byte(uint8_t) array.
144extern const SimpleArrayConfig simple_array_config_uint8_t;
145
146#ifdef __cplusplus
147}
148#endif
void simple_array_init(SimpleArray *instance, uint32_t count)
Initialise a SimpleArray instance by allocating additional space to contain the requested number of e...
Definition simple_array.c:24
const SimpleArrayElement * simple_array_cget(const SimpleArray *instance, uint32_t index)
Get a const pointer to an element contained in a SimpleArray instance.
Definition simple_array.c:107
void simple_array_free(SimpleArray *instance)
Free a SimpleArray instance and release its contents.
Definition simple_array.c:17
const SimpleArrayData * simple_array_cget_data(const SimpleArray *instance)
Get a constant pointer to the internal data of a SimpleArray instance.
Definition simple_array.c:119
SimpleArray * simple_array_alloc(const SimpleArrayConfig *config)
Allocate a SimpleArray instance with the given configuration.
Definition simple_array.c:11
void simple_array_reset(SimpleArray *instance)
Reset a SimpleArray instance and delete all of its elements.
Definition simple_array.c:41
void simple_array_copy(SimpleArray *instance, const SimpleArray *other)
Copy (duplicate) another SimpleArray instance to this one.
Definition simple_array.c:60
SimpleArrayElement * simple_array_get(SimpleArray *instance, uint32_t index)
Get a pointer to an element contained in a SimpleArray instance.
Definition simple_array.c:100
bool simple_array_is_equal(const SimpleArray *instance, const SimpleArray *other)
Check if another SimpleArray instance is equal (the same object or holds the same data) to this one.
Definition simple_array.c:83
uint32_t simple_array_get_count(const SimpleArray *instance)
Get the count of elements currently contained in a SimpleArray instance.
Definition simple_array.c:95
SimpleArrayData * simple_array_get_data(SimpleArray *instance)
Get a pointer to the internal data of a SimpleArray instance.
Definition simple_array.c:112
Simple Array configuration structure.
Definition simple_array.h:37
SimpleArrayCopy copy
Copy (custom copy-constructor) method.
Definition simple_array.h:40
SimpleArrayInit init
Initialisation (in-place constructor) method.
Definition simple_array.h:38
SimpleArrayReset reset
Reset (custom destructor) method.
Definition simple_array.h:39
Definition simple_array.c:5