22 const void *data; |
22 const void *data; |
23 size_t size; |
23 size_t size; |
24 } flib_constbuffer; |
24 } flib_constbuffer; |
25 |
25 |
26 /** |
26 /** |
27 * Simple variable-capacity data structure (opaque type). |
27 * Simple variable-capacity data structure that can be efficiently appended to. |
28 */ |
28 */ |
29 struct _flib_vector; |
29 struct _flib_vector; |
30 typedef struct _flib_vector *flib_vector; |
30 typedef struct _flib_vector flib_vector; |
31 |
31 |
32 /** |
32 /** |
33 * Create a new vector. Needs to be destroyed again later with flib_vector_destroy. |
33 * Create a new vector. Needs to be destroyed again later with flib_vector_destroy. |
34 * May return NULL if memory runs out. |
34 * May return NULL if memory runs out. |
35 */ |
35 */ |
36 flib_vector flib_vector_create(); |
36 flib_vector *flib_vector_create(); |
37 |
37 |
38 /** |
38 /** |
39 * Free the memory of this vector and set it to NULL. |
39 * Free the memory of this vector |
40 */ |
40 */ |
41 void flib_vector_destroy(flib_vector *vec); |
41 void flib_vector_destroy(flib_vector *vec); |
42 |
42 |
43 /** |
43 /** |
44 * Append the provided data to the end of the vector, enlarging it as required. |
44 * Append the provided data to the end of the vector, enlarging it as required. |
45 * Returns the ammount of data appended, which is either len (success) or 0 (out of memory). |
45 * Returns the ammount of data appended, which is either len (success) or 0 (out of memory). |
46 * The vector remains unchanged if an out of memory situation occurs. |
46 * The vector remains unchanged if appending fails. |
47 */ |
47 */ |
48 int flib_vector_append(flib_vector vec, const void *data, size_t len); |
48 int flib_vector_append(flib_vector *vec, const void *data, size_t len); |
49 |
49 |
50 /** |
50 /** |
51 * Return a buffer or constbuffer pointing to the current contents of the vector. |
51 * Return a pointer to the current data buffer of the vector. This pointer can |
|
52 * become invalid if the vector size or capacity is changed. |
|
53 */ |
|
54 void *flib_vector_data(flib_vector *vec); |
|
55 |
|
56 /** |
|
57 * Return the current size of the vector. |
|
58 */ |
|
59 size_t flib_vector_size(flib_vector *vec); |
|
60 |
|
61 /** |
|
62 * Return a buffer pointing to the current contents of the vector. |
52 * These will become invalid if the vector size or capacity is changed. |
63 * These will become invalid if the vector size or capacity is changed. |
53 */ |
64 */ |
54 flib_buffer flib_vector_as_buffer(flib_vector vec); |
65 flib_buffer flib_vector_as_buffer(flib_vector *vec); |
55 flib_constbuffer flib_vector_as_constbuffer(flib_vector vec); |
|
56 |
66 |
|
67 /** |
|
68 * Return a constbuffer pointing to the current contents of the vector. |
|
69 * These will become invalid if the vector size or capacity is changed. |
|
70 */ |
|
71 flib_constbuffer flib_vector_as_constbuffer(flib_vector *vec); |
57 |
72 |
58 #endif |
73 #endif |