vis: also lookup Lua support files relative to the binary location
[vis.git] / map.h
blob0540fab45ff7d6a3f8f722ba9dea4e7de1a9691a
1 #ifndef MAP_H
2 #define MAP_H
4 #include <stdbool.h>
6 typedef struct Map Map;
8 /* Allocate a new map. */
9 Map *map_new(void);
10 /* Retrieves a value, or NULL if it isn't in the map */
11 void *map_get(const Map*, const char *key);
12 /* Returns the corresponding value if the given prefix is unique.
13 * Otherwise NULL, if no such prefix exists then errno is set to ENOENT. */
14 void *map_closest(const Map*, const char *prefix);
15 /* check whether the map contains the given prefix, i.e. whether it can
16 * be extended to match a key of an element stored in the map. */
17 bool map_contains(const Map*, const char *prefix);
18 /* Place a member in the map. This returns false if we run out of memory
19 * (errno = ENOMEM), or if that key already appears in the map (errno = EEXIST). */
20 bool map_put(Map*, const char *key, const void *value);
21 /* Remove a member from the map. Returns the removed entry or NULL
22 * if there was no entry found using the given key*/
23 void *map_delete(Map*, const char *key);
24 /* Copy all entries from `src' into `dest', overwrites existing entries in `dest' */
25 bool map_copy(Map *dest, Map *src);
26 /* Ordered iteration over a map, call handle for every entry. If handle
27 * returns false, the iteration will stop. */
28 void map_iterate(const Map*, bool (*handle)(const char *key, void *value, void *data), const void *data);
29 /* Return a submap matching a prefix. This returns a pointer into the
30 * original map, so don't alter the map while using the return value. */
31 const Map *map_prefix(const Map*, const char *prefix);
32 /* Test whether the map is empty i.e. contains no elements */
33 bool map_empty(const Map*);
34 /* Remove every member from the map. The map will be empty after this. */
35 void map_clear(Map*);
36 /* Release all memory associated with this map */
37 void map_free(Map*);
39 #endif