LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
gd_array.h
1#ifndef GD_ARRAY_H
2#define GD_ARRAY_H 1
3
4typedef struct gdArrayStruct {
5 unsigned int size;
6 unsigned int cnt_elements;
7 unsigned int element_size;
8 void *elements;
9} gdArray;
10typedef gdArray *gdArrayPtr;
11
12/*
13C++ Vect like for C.
14element_size is f.e. sizeof(gdPath) equivalent to
15gdPathPtr path;
16or
17gdPathPtr path[12]; for a fixed length
18
19Each function takes a pointers to the array.
20*/
21
22/* Initialize a gdArray, gdArrayarray allocation and freed is the caller's responsability */
23void gdArrayInit(gdArrayPtr array, unsigned int element_size);
24
25/* Destroy the internal data of a gdArray, gdArrayarray has to be freed by the caller */
26void gdArrayDestroy(gdArrayPtr array);
27
28/* Growth the internal data storage to be able to store the additional requested amount (of
29 * elements) */
30int gdArrayReallocBy(gdArrayPtr array, unsigned int additional);
31
32/* Reduce the elements to cnt_elements (storage will remain the same until more are
33requested) */
34void gdArrayTruncate(gdArrayPtr array, unsigned int cnt_elements);
35
36/* Append an element at the end of the array */
37int gdArrayAppend(gdArrayPtr array, const void *element);
38
39/* Append cnt_elements elements to the array.
40 *elements is the actual gdSpanPtr[12] for 12 elements */
41int gdArrayAppendMultiple(gdArrayPtr array, const void *elements, unsigned int cnt_elements);
42
43/* Returns the elements at the given index */
44void *gdArrayIndex(gdArrayPtr array, unsigned int index);
45
46/* Same as gdArrayIndex but immutable pointer */
47const void *gdArrayIndexConst(gdArrayPtr array, unsigned int index);
48
49/* Return the current storage size. Storage size is the available space, not the actual
50amount of elements stored. Use gdArrayNumElements to know the actual stored elements count */
51unsigned int gdArraySize(const gdArrayPtr array);
52unsigned int gdArrayNumElements(const gdArrayPtr array);
53
54/* Private for internal usage in gdArray */
55int gdArrayAlloc(gdArrayPtr array, unsigned int cnt_elements, void **elements);
56void *gdArrayGetData(const gdArrayPtr array);
57#endif /* GD_ARRAY_H */