ucx/map.h

changeset 48
621a4430c404
parent 46
48ca036d7d9c
child 51
1c78cd19fb6b
equal deleted inserted replaced
46:48ca036d7d9c 48:621a4430c404
5 #ifndef MAP_H 5 #ifndef MAP_H
6 #define MAP_H 6 #define MAP_H
7 7
8 #include "ucx.h" 8 #include "ucx.h"
9 #include "string.h" 9 #include "string.h"
10 #include "mempool.h"
10 #include <stdio.h> 11 #include <stdio.h>
11 12
12 #ifdef __cplusplus 13 #ifdef __cplusplus
13 extern "C" { 14 extern "C" {
14 #endif 15 #endif
18 19
19 typedef struct UcxMap UcxMap; 20 typedef struct UcxMap UcxMap;
20 typedef struct UcxKey UcxKey; 21 typedef struct UcxKey UcxKey;
21 typedef struct UcxMapElement UcxMapElement; 22 typedef struct UcxMapElement UcxMapElement;
22 typedef struct UcxMapIterator UcxMapIterator; 23 typedef struct UcxMapIterator UcxMapIterator;
24
25 /*
26 * param 1: element
27 * param 2: additional data
28 * param 3: size of encoded data will be stored here
29 * returns encoded / decoded string or NULL on failure
30 */
31 typedef void*(*ucx_map_coder)(void*,void*,size_t*);
23 32
24 struct UcxMap { 33 struct UcxMap {
25 UcxMapElement **map; 34 UcxMapElement **map;
26 size_t size; 35 size_t size;
27 size_t count; 36 size_t count;
65 UcxMapIterator ucx_map_iterator(UcxMap *map); 74 UcxMapIterator ucx_map_iterator(UcxMap *map);
66 75
67 int ucx_map_iter_next(UcxMapIterator *i, void **elm); 76 int ucx_map_iter_next(UcxMapIterator *i, void **elm);
68 77
69 /* use macros for string maps only, values are not encoded */ 78 /* use macros for string maps only, values are not encoded */
70 #define ucx_map_load(map, f) ucx_map_load_enc(map, f, NULL, NULL) 79 #define ucx_map_load(map, f, alloc) ucx_map_load_enc(map, f, alloc, NULL, NULL)
71 #define ucx_map_store(map, f) ucx_map_store_enc(map, f, NULL, NULL) 80 #define ucx_map_store(map, f) ucx_map_store_enc(map, f, NULL, NULL)
72 81
73 int ucx_map_load_enc(UcxMap *map, FILE *f, copy_func decoder, void* decdata); 82 int ucx_map_load_enc(UcxMap *map, FILE *f, UcxAllocator allocator,
83 ucx_map_coder decoder, void* decdata);
74 /* encoders shall provide null terminated strings*/ 84 /* encoders shall provide null terminated strings*/
75 int ucx_map_store_enc(UcxMap *map, FILE *f, copy_func encoder, void* encdata); 85 int ucx_map_store_enc(UcxMap *map, FILE *f,
86 ucx_map_coder encoder, void* encdata);
76 87
77 #ifdef __cplusplus 88 #ifdef __cplusplus
78 } 89 }
79 #endif 90 #endif
80 91

mercurial