map.h
Go to the documentation of this file.
1 #ifndef NVIM_MAP_H
2 #define NVIM_MAP_H
3 
4 #include <stdbool.h>
5 
7 #include "nvim/extmark_defs.h"
8 #include "nvim/highlight_defs.h"
9 #include "nvim/map_defs.h"
10 #include "nvim/ui_client.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  typedef struct { \
20  khash_t(T##_##U##_map) table; \
21  } Map(T, U); \
22  Map(T, U) *map_##T##_##U##_new(void); \
23  void map_##T##_##U##_free(Map(T, U) *map); \
24  void map_##T##_##U##_destroy(Map(T, U) *map); \
25  U map_##T##_##U##_get(Map(T, U) *map, T key); \
26  bool map_##T##_##U##_has(Map(T, U) *map, T key); \
27  T map_##T##_##U##_key(Map(T, U) *map, T key); \
28  U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \
29  U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \
30  U map_##T##_##U##_del(Map(T, U) *map, T key); \
31  void map_##T##_##U##_clear(Map(T, U) *map);
32 
33 //
34 // NOTE: Keys AND values must be allocated! khash.h does not make a copy.
35 //
36 MAP_DECLS(int, int)
38 MAP_DECLS(cstr_t, int)
40 MAP_DECLS(uint64_t, ptr_t)
41 MAP_DECLS(uint64_t, ssize_t)
42 MAP_DECLS(uint64_t, uint64_t)
43 MAP_DECLS(uint32_t, uint32_t)
44 
46 MAP_DECLS(HlEntry, int)
48 MAP_DECLS(String, int)
49 MAP_DECLS(int, String)
50 
52 
53 #define MAP_INIT { { 0, 0, 0, 0, NULL, NULL, NULL } }
54 #define map_init(k, v, map) do { *(map) = (Map(k, v)) MAP_INIT; } while (false)
55 
56 #define map_destroy(T, U) map_##T##_##U##_destroy
57 #define map_get(T, U) map_##T##_##U##_get
58 #define map_has(T, U) map_##T##_##U##_has
59 #define map_key(T, U) map_##T##_##U##_key
60 #define map_put(T, U) map_##T##_##U##_put
61 #define map_ref(T, U) map_##T##_##U##_ref
62 #define map_del(T, U) map_##T##_##U##_del
63 #define map_clear(T, U) map_##T##_##U##_clear
64 
65 #define map_size(map) ((map)->table.size)
66 
67 #define pmap_destroy(T) map_destroy(T, ptr_t)
68 #define pmap_get(T) map_get(T, ptr_t)
69 #define pmap_has(T) map_has(T, ptr_t)
70 #define pmap_key(T) map_key(T, ptr_t)
71 #define pmap_put(T) map_put(T, ptr_t)
72 #define pmap_ref(T) map_ref(T, ptr_t)
73 #define pmap_del(T) map_del(T, ptr_t)
75 #define pmap_clear(T) map_clear(T, ptr_t)
76 #define pmap_init(k, map) map_init(k, ptr_t, map)
77 
78 #define map_foreach(map, key, value, block) \
79  kh_foreach(&(map)->table, key, value, block)
80 
81 #define map_foreach_value(map, value, block) \
82  kh_foreach_value(&(map)->table, value, block)
83 
84 void pmap_del2(PMap(cstr_t) *map, const char *key);
85 
86 #endif // NVIM_MAP_H
ui_client.h
map_defs.h
HlEntry
Definition: highlight_defs.h:203
highlight_defs.h
key
int key
Definition: keycodes.c:571
defs.h
pmap_del2
void pmap_del2(PMap(cstr_t) *map, const char *key)
Definition: map.c:183
MAP_DECLS
#define MAP_DECLS(T, U)
Definition: map.h:17
String
Definition: defs.h:78
extmark_defs.h
ColorKey
Definition: highlight_defs.h:211
cstr_t
const typedef char * cstr_t
Definition: map_defs.h:6
ptr_t
void * ptr_t
Definition: map_defs.h:7
handle_T
int handle_T
Definition: types.h:18
ColorItem
Definition: highlight_defs.h:217
PMap
#define PMap(T)
Definition: map_defs.h:10