diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-23 18:10:52 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-05-23 18:10:52 -0300 |
commit | 9e95c8aa331e3872253e7a06be32103b440bc97f (patch) | |
tree | d25a81cd37939466e5b9c8b33b3566f9aefbdf49 /src/nvim/api/private/handle.c | |
parent | f1e52c496ddb89f830cdbc4f23d756131106b97f (diff) | |
parent | 6c96e42e2c18bd6ae685b5a41c69b03954aa0375 (diff) | |
download | rneovim-9e95c8aa331e3872253e7a06be32103b440bc97f.tar.gz rneovim-9e95c8aa331e3872253e7a06be32103b440bc97f.tar.bz2 rneovim-9e95c8aa331e3872253e7a06be32103b440bc97f.zip |
Merge branch 'use-uids-for-api-remote-objects'
Diffstat (limited to 'src/nvim/api/private/handle.c')
-rw-r--r-- | src/nvim/api/private/handle.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c new file mode 100644 index 0000000000..88d176fccb --- /dev/null +++ b/src/nvim/api/private/handle.c @@ -0,0 +1,40 @@ +#include <stdint.h> + +#include "nvim/vim.h" +#include "nvim/map.h" +#include "nvim/api/private/handle.h" + +#define HANDLE_INIT(name) name##_handles = map_new(uint64_t)() + +#define HANDLE_IMPL(type, name) \ + static Map(uint64_t) *name##_handles = NULL; \ + \ + type *handle_get_##name(uint64_t handle) \ + { \ + return map_get(uint64_t)(name##_handles, handle); \ + } \ + \ + void handle_register_##name(type *name) \ + { \ + assert(!name->handle); \ + name->handle = next_handle++; \ + map_put(uint64_t)(name##_handles, name->handle, name); \ + } \ + \ + void handle_unregister_##name(type *name) \ + { \ + map_del(uint64_t)(name##_handles, name->handle); \ + } + +static uint64_t next_handle = 1; + +HANDLE_IMPL(buf_T, buffer) +HANDLE_IMPL(win_T, window) +HANDLE_IMPL(tabpage_T, tabpage) + +void handle_init() +{ + HANDLE_INIT(buffer); + HANDLE_INIT(window); + HANDLE_INIT(tabpage); +} |