mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 03:16:31 +00:00
API: Refactor: Implement api/handle module
This module will be used to implement remote management of objects through the API. Object types to be registered must have a `uint64_t` field named 'handle'.
This commit is contained in:
31
src/nvim/api/private/handle.c
Normal file
31
src/nvim/api/private/handle.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#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); \
|
||||
}
|
||||
|
||||
void handle_init()
|
||||
{
|
||||
}
|
14
src/nvim/api/private/handle.h
Normal file
14
src/nvim/api/private/handle.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef NVIM_API_HANDLE_H
|
||||
#define NVIM_API_HANDLE_H
|
||||
|
||||
#include "nvim/vim.h"
|
||||
|
||||
#define HANDLE_DECLS(type, name) \
|
||||
type *handle_get_##name(uint64_t handle); \
|
||||
void handle_register_##name(type *name); \
|
||||
void handle_unregister_##name(type *name);
|
||||
|
||||
void handle_init(void);
|
||||
|
||||
#endif // NVIM_API_HANDLE_H
|
||||
|
Reference in New Issue
Block a user