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 #ifndef __DAL_VECTOR_H__
27 #define __DAL_VECTOR_H__
28
29 struct vector {
30 uint8_t *container;
31 uint32_t struct_size;
32 uint32_t count;
33 uint32_t capacity;
34 struct dc_context *ctx;
35 };
36
37 bool dal_vector_construct(
38 struct vector *vector,
39 struct dc_context *ctx,
40 uint32_t capacity,
41 uint32_t struct_size);
42
43 struct vector *dal_vector_create(
44 struct dc_context *ctx,
45 uint32_t capacity,
46 uint32_t struct_size);
47
48
49
50 struct vector *dal_vector_presized_create(
51 struct dc_context *ctx,
52 uint32_t size,
53 void *initial_value,
54 uint32_t struct_size);
55
56 void dal_vector_destruct(
57 struct vector *vector);
58
59 void dal_vector_destroy(
60 struct vector **vector);
61
62 uint32_t dal_vector_get_count(
63 const struct vector *vector);
64
65
66
67
68
69
70
71
72 bool dal_vector_insert_at(
73 struct vector *vector,
74 const void *what,
75 uint32_t position);
76
77 bool dal_vector_append(
78 struct vector *vector,
79 const void *item);
80
81
82 void *dal_vector_at_index(
83 const struct vector *vector,
84 uint32_t index);
85
86 void dal_vector_set_at_index(
87 const struct vector *vector,
88 const void *what,
89 uint32_t index);
90
91
92 struct vector *dal_vector_clone(
93 const struct vector *vector_other);
94
95
96
97
98 bool dal_vector_remove_at_index(
99 struct vector *vector,
100 uint32_t index);
101
102 uint32_t dal_vector_capacity(const struct vector *vector);
103
104 bool dal_vector_reserve(struct vector *vector, uint32_t capacity);
105
106 void dal_vector_clear(struct vector *vector);
107
108
109
110
111
112 #define DAL_VECTOR_INSERT_AT(vector_type, type_t) \
113 static bool vector_type##_vector_insert_at( \
114 struct vector *vector, \
115 type_t what, \
116 uint32_t position) \
117 { \
118 return dal_vector_insert_at(vector, what, position); \
119 }
120
121 #define DAL_VECTOR_APPEND(vector_type, type_t) \
122 static bool vector_type##_vector_append( \
123 struct vector *vector, \
124 type_t item) \
125 { \
126 return dal_vector_append(vector, item); \
127 }
128
129
130
131
132
133 #define DAL_VECTOR_AT_INDEX(vector_type, type_t) \
134 static type_t vector_type##_vector_at_index( \
135 const struct vector *vector, \
136 uint32_t index) \
137 { \
138 return dal_vector_at_index(vector, index); \
139 }
140
141 #define DAL_VECTOR_SET_AT_INDEX(vector_type, type_t) \
142 static void vector_type##_vector_set_at_index( \
143 const struct vector *vector, \
144 type_t what, \
145 uint32_t index) \
146 { \
147 dal_vector_set_at_index(vector, what, index); \
148 }
149
150 #endif