Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
vector.h
Go to the documentation of this file.
1/**
2 * @file vector.h
3 *
4 * @brief creates and outlines a dynamic array type and its functions
5*/
6
7#ifndef ARC_STD_VECTOR_H_
8#define ARC_STD_VECTOR_H_
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14#include "arc/std/bool.h"
15#include <stdint.h>
16
17/**
18 * @addtogroup ARC_Vector
19 * Additional documentation for group 'ARC_Vector'
20 * @{
21*/
22
23/**
24 * @brief a dynamic array type
25*/
26typedef struct ARC_Vector ARC_Vector;
27
28/**
29 * @brief a callback that allows the user to define a way to check the data stored in a vector for a match
30 *
31 * @param[in] dataA the first data to check
32 * @param[in] dataB the second data to check
33 *
34 * @return ARC_True when dataA == dataB, and ARC_False otherwise
35*/
36typedef ARC_Bool (* ARC_Vector_CompareDataFn)(void *dataA, void *dataB);
37
38/**
39 * @brief a callback that cleans up memory when it is removed from the vector
40 *
41 * @param[in] data the item to destroy
42*/
43typedef void (* ARC_Vector_DestroyDataFn)(void *data);
44
45/**
46 * @brief creates an ARC_Vector which is an "expandable" array
47 *
48 * @note for this basic implementation, the array will double in size every time the capacity is hit
49 * @note the array will also half in size when the array is only half filled
50 *
51 * @param[out] vector ARC_Vector to initialize
52 * @param[in] compareDataFn a callback that checks if data stored in the array matches,
53 * if set to NULL and ARC_Vector_Remove is called, the pointer addresses will be compared
54 * @param[in] destroyDataFn a callback that frees an item on remove or clear, can be set to NULL to do nothing
55*/
57
58/**
59 * @brief destroys an ARC_Vector
60 *
61 * @note this will not free the items stored in the vector
62 * @note please make sure to clear and free the children before destroying an ARC_Vector
63 *
64 * @param[in] vector ARC_Vector to free
65*/
67
68/**
69 * @brief adds an item to an ARC_Vector
70 *
71 * @note this will error if you add more than 4,294,967,295 items (the max value of an unsigned int 32)
72 *
73 * @param[in] vector ARC_Vector to add to
74 * @param[in] data data that is being added
75*/
76void ARC_Vector_Add(ARC_Vector *vector, void *data);
77
78/**
79 * @brief removes an item from a matching item in an ARC_Vector
80 *
81 * @note this function uses the ARC_Vector_CompareDataFn that the ARC_Vector was created with
82 * @note this function will not throw an error if there is no match
83 * @note this function will call ARC_Vector_RemoveIndex, so it's notes are also applicable to this function
84 *
85 * @param[in] vector ARC_Vector to remove from
86 * @param[in] data matching data to remove
87*/
88void ARC_Vector_Remove(ARC_Vector *vector, void *data);
89
90/**
91 * @brief removes an item from an ARC_Vector at an index
92 *
93 * @note this function will error if trying to remove an index that is outside the bounds of the ARC_Vector
94 * @note this function will use ARC_Vector_DeleteDataFn if it was set in the ARC_Vector_Create function
95 *
96 * @param[in] vector ARC_Vector to remove from
97 * @param[in] index position of data to remove
98*/
99void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index);
100
101/**
102 * @brief clears all items from a vector
103 *
104 * @note this function will call ARC_Vector_RemoveIndex, so it's notes are also applicable to this function
105 *
106 * @param[in] vector ARC_Vector to clear
107*/
109
110/**
111 * @brief gets the current size of an ARC_Vector as an unsigned 32 bit integer
112 *
113 * @param[in] vector ARC_Vector to get current size from
114 *
115 * @return the current size as a unsigned 32 bit integer
116*/
118
119/**
120 * @brief gets an item from an ARC_Vector at a position index
121 *
122 * @note this function will error if trying to get an index that is outside the bounds of the ARC_Vector
123 *
124 * @param[in] vector ARC_Vector to get data from
125 * @param[in] index position of data to get
126 *
127 * @return a void * item, or NULL on error
128*/
129void *ARC_Vector_Get(ARC_Vector *vector, uint32_t index);
130
131/*! @} */
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif // !ARC_STD_VECTOR_H_
#define ARC_Bool
Definition bool.h:10
void(* ARC_Vector_DestroyDataFn)(void *data)
a callback that cleans up memory when it is removed from the vector
Definition vector.h:43
uint32_t ARC_Vector_GetSize(ARC_Vector *vector)
gets the current size of an ARC_Vector as an unsigned 32 bit integer
void * ARC_Vector_Get(ARC_Vector *vector, uint32_t index)
gets an item from an ARC_Vector at a position index
struct ARC_Vector ARC_Vector
a dynamic array type
Definition vector.h:26
void ARC_Vector_Add(ARC_Vector *vector, void *data)
adds an item to an ARC_Vector
ARC_Bool(* ARC_Vector_CompareDataFn)(void *dataA, void *dataB)
a callback that allows the user to define a way to check the data stored in a vector for a match
Definition vector.h:36
void ARC_Vector_Remove(ARC_Vector *vector, void *data)
removes an item from a matching item in an ARC_Vector
void ARC_Vector_Destroy(ARC_Vector *vector)
destroys an ARC_Vector
void ARC_Vector_RemoveIndex(ARC_Vector *vector, uint32_t index)
removes an item from an ARC_Vector at an index
void ARC_Vector_Clear(ARC_Vector *vector)
clears all items from a vector
void ARC_Vector_Create(ARC_Vector **vector, ARC_Vector_CompareDataFn *compareDataFn, ARC_Vector_DestroyDataFn *destroyDataFn)
creates an ARC_Vector which is an "expandable" array