1 #ifndef NM_VECTOR_H_
2 #define NM_VECTOR_H_
3 
4 #include <stdlib.h>
5 #include <string.h>
6 
7 typedef struct {
8     size_t n_memb;  /* unit count */
9     size_t n_alloc; /* count of allocated memory in units */
10     void **data;    /* ctx */
11 } nm_vect_t;
12 
13 #define NM_INIT_VECT { 0, 0, NULL }
14 
15 typedef void (*nm_vect_ins_cb_pt)(void *unit_p, const void *ctx);
16 typedef void (*nm_vect_free_cb_pt)(void *unit_p);
17 
18 /* NOTE: If inserting C string len must include \x00 */
19 void nm_vect_insert(nm_vect_t *v, const void *data, size_t len, nm_vect_ins_cb_pt cb);
20 void nm_vect_delete(nm_vect_t *v, size_t index, nm_vect_free_cb_pt cb);
21 void *nm_vect_at(const nm_vect_t *v, size_t index);
22 void nm_vect_end_zero(nm_vect_t *v);
23 void nm_vect_free(nm_vect_t *v, nm_vect_free_cb_pt cb);
24 
nm_vect_insert_cstr(nm_vect_t * v,const char * data)25 static inline void nm_vect_insert_cstr(nm_vect_t *v, const char *data)
26 {
27     nm_vect_insert(v, data, strlen(data) + 1, NULL);
28 }
29 
30 #endif /* NM_VECTOR_H_ */
31 /* vim:set ts=4 sw=4: */
32