coll  0.1.0-alpha.1
A collections library
coll_arraylist.h
Go to the documentation of this file.
1 #ifndef ___ARRAYLIST_H___
2 #define ___ARRAYLIST_H___
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdlib.h>
9 #include <stdint.h>
10 
11 #ifdef LUA_ENABLED
12 
13 #include <lua.h>
14 #include <lauxlib.h>
15 #include <lualib.h>
16 
17 #endif //LUA_ENABLED
18 
19 #ifdef APR_ENABLED
20 
21 #include <apr.h>
22 #include <apr_pools.h>
23 
24 #endif //APR_ENABLED
25 
48 #define ARRAYLIST_DEFAULT_SIZE 50
49 
50 #define E_ARRAYLIST_UNABLE_TO_ALLOCATE_ARRAY 1
51 #define E_ARRAYLIST_INDEX_BEYOND_CAPACITY 2
52 #define E_ARRAYLIST_INDEX_NOT_FOUND 3
53 
54 #define MAX_VOIDPTR_ALLOCATE (SIZE_MAX / sizeof(void*))
55 
56 typedef void (arraylist_free_function)(void* data);
57 
58 #ifdef LUA_ENABLED
59 typedef void (arraylist_item_to_lua_object)(lua_State* L, int index, void* data);
60 #endif //LUA_ENABLED
61 
80 typedef struct arraylist_t {
81  size_t capacity;
82  size_t size;
83  arraylist_free_function* free_fn;
84 #ifdef LUA_ENABLED
85  arraylist_item_to_lua_object* convert_to_lua;
86 #endif //LUA_ENABLED
87 #ifdef APR_ENABLED
88  apr_pool_t* pool;
89 #endif //APR_ENABLED
90  void** array;
92 
100 int arraylist_new(arraylist** l, arraylist_free_function* free_fn);
101 
110 int arraylist_new_with_capacity(arraylist** l, size_t capacity, arraylist_free_function* free_fn);
111 
112 #ifdef LUA_ENABLED
113 
120 void set_lua_convertor(arraylist* l, arraylist_item_to_lua_object* convert_to_lua);
121 
129 void convert_to_lua_array(arraylist* list, lua_State* L);
130 
131 #endif //LUA_ENABLED
132 
139 size_t arraylist_length(arraylist* l);
140 
158 int arraylist_insert(arraylist* l, size_t loc, void* item);
159 
172 int arraylist_add(arraylist* l, void* item);
173 
186 int arraylist_set(arraylist* l, size_t loc, void* item);
187 
196 void* arraylist_get(arraylist* l, size_t loc);
197 
203 void arraylist_clear(arraylist* l);
204 
213 int arraylist_delete(arraylist* l, size_t loc);
214 
221 void arraylist_free(arraylist* l);
222 
223 //TODO: reconsider function to return string, instead of print
230 void arraylist_print(arraylist* l, void (*item_print)(void* item));
231 
232 #ifdef APR_ENABLED
233 
234 int arraylist_apr_new(arraylist** l, apr_pool_t* pool, arraylist_free_function* free_fn);
235 int arraylist_apr_new_with_capacity(arraylist** l, apr_pool_t* pool, size_t capacity, arraylist_free_function* free_fn);
236 void arraylist_apr_free(arraylist* l);
237 
238 #endif //APR_ENABLED
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif /* ___ARRAYLIST_H___ */
void * arraylist_get(arraylist *l, size_t loc)
Definition: coll_arraylist.c:242
int arraylist_insert(arraylist *l, size_t loc, void *item)
Definition: coll_arraylist.c:189
int arraylist_delete(arraylist *l, size_t loc)
Definition: coll_arraylist.c:266
size_t arraylist_length(arraylist *l)
Definition: coll_arraylist.c:110
void arraylist_clear(arraylist *l)
Definition: coll_arraylist.c:254
struct arraylist_t arraylist
void arraylist_print(arraylist *l, void(*item_print)(void *item))
Definition: coll_arraylist.c:321
int arraylist_add(arraylist *l, void *item)
Definition: coll_arraylist.c:216
int arraylist_new_with_capacity(arraylist **l, size_t capacity, arraylist_free_function *free_fn)
Definition: coll_arraylist.c:10
int arraylist_new(arraylist **l, arraylist_free_function *free_fn)
Definition: coll_arraylist.c:5
int arraylist_set(arraylist *l, size_t loc, void *item)
Definition: coll_arraylist.c:221
void arraylist_free(arraylist *l)
Definition: coll_arraylist.c:287
Definition: coll_arraylist.h:80