update bmap python binding

This commit is contained in:
2023-11-04 21:58:58 +08:00
parent d754b2fb44
commit 2000a6ad9b
8 changed files with 1211 additions and 135 deletions

View File

@ -2,6 +2,12 @@ import ctypes, os
#region Type Defines
class BMapException(Exception):
"""
The exception thrown by BMap bindings.
"""
pass
bm_CKSTRING = ctypes.c_char_p
bm_CKSTRING_p = ctypes.POINTER(bm_CKSTRING)
bm_CKDWORD = ctypes.c_uint32
@ -69,12 +75,18 @@ except:
def is_bmap_available() -> bool:
return _g_BMapModule is not None
def _create_bmap_func(fct_name: str, fct_params: list[ctypes._CData]) -> ctypes._FuncPointer:
def _bmap_error_check(result: bm_bool, func, args):
if not bm_bool.value:
raise BMapException("BMap operation failed.")
return result
def _create_bmap_func(fct_name: str, fct_params: list[ctypes._SimpleCData]) -> ctypes._CFuncPtr:
if _g_BMapModule is None: return None
cache: ctypes._FuncPointer = getattr(_g_BMapModule, fct_name)
cache: ctypes._CFuncPtr = getattr(_g_BMapModule, fct_name)
cache.argtypes = fct_params
cache.restype = bm_bool
cache.errcheck = _bmap_error_check
return cache
#endregion