1 | #ifndef NVIM_MAP_H |
2 | #define NVIM_MAP_H |
3 | |
4 | #include <stdbool.h> |
5 | |
6 | #include "nvim/map_defs.h" |
7 | #include "nvim/api/private/defs.h" |
8 | #include "nvim/api/private/dispatch.h" |
9 | #include "nvim/bufhl_defs.h" |
10 | #include "nvim/highlight_defs.h" |
11 | |
12 | #if defined(__NetBSD__) |
13 | # undef uint64_t |
14 | # define uint64_t uint64_t |
15 | #endif |
16 | |
17 | #define MAP_DECLS(T, U) \ |
18 | KHASH_DECLARE(T##_##U##_map, T, U) \ |
19 | \ |
20 | typedef struct { \ |
21 | khash_t(T##_##U##_map) *table; \ |
22 | } Map(T, U); \ |
23 | \ |
24 | Map(T, U) *map_##T##_##U##_new(void); \ |
25 | void map_##T##_##U##_free(Map(T, U) *map); \ |
26 | U map_##T##_##U##_get(Map(T, U) *map, T key); \ |
27 | bool map_##T##_##U##_has(Map(T, U) *map, T key); \ |
28 | T map_##T##_##U##_key(Map(T, U) *map, T key); \ |
29 | U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \ |
30 | U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \ |
31 | U map_##T##_##U##_del(Map(T, U) *map, T key); \ |
32 | void map_##T##_##U##_clear(Map(T, U) *map); |
33 | |
34 | // |
35 | // NOTE: Keys AND values must be allocated! khash.h does not make a copy. |
36 | // |
37 | MAP_DECLS(int, int) |
38 | MAP_DECLS(cstr_t, ptr_t) |
39 | MAP_DECLS(ptr_t, ptr_t) |
40 | MAP_DECLS(uint64_t, ptr_t) |
41 | MAP_DECLS(handle_T, ptr_t) |
42 | MAP_DECLS(String, MsgpackRpcRequestHandler) |
43 | MAP_DECLS(HlEntry, int) |
44 | MAP_DECLS(String, handle_T) |
45 | |
46 | #define map_new(T, U) map_##T##_##U##_new |
47 | #define map_free(T, U) map_##T##_##U##_free |
48 | #define map_get(T, U) map_##T##_##U##_get |
49 | #define map_has(T, U) map_##T##_##U##_has |
50 | #define map_key(T, U) map_##T##_##U##_key |
51 | #define map_put(T, U) map_##T##_##U##_put |
52 | #define map_ref(T, U) map_##T##_##U##_ref |
53 | #define map_del(T, U) map_##T##_##U##_del |
54 | #define map_clear(T, U) map_##T##_##U##_clear |
55 | |
56 | #define pmap_new(T) map_new(T, ptr_t) |
57 | #define pmap_free(T) map_free(T, ptr_t) |
58 | #define pmap_get(T) map_get(T, ptr_t) |
59 | #define pmap_has(T) map_has(T, ptr_t) |
60 | #define pmap_key(T) map_key(T, ptr_t) |
61 | #define pmap_put(T) map_put(T, ptr_t) |
62 | /// @see pmap_del2 |
63 | #define pmap_del(T) map_del(T, ptr_t) |
64 | #define pmap_clear(T) map_clear(T, ptr_t) |
65 | |
66 | #define map_foreach(map, key, value, block) \ |
67 | kh_foreach(map->table, key, value, block) |
68 | |
69 | #define map_foreach_value(map, value, block) \ |
70 | kh_foreach_value(map->table, value, block) |
71 | |
72 | void pmap_del2(PMap(cstr_t) *map, const char *key); |
73 | |
74 | #endif // NVIM_MAP_H |
75 | |