I'd recommend an intermediate wrapper which does:
check_statuswhich can be used e.g. as:
def get_STIR_version_string():
"""Returns STIR engine version as Python str."""
- handle = pystir.cSTIR_STIR_version_string()
- check_status(handle)
- version = pyiutil.charDataFromHandle(handle)
- pyiutil.deleteDataHandle(handle)
- return version
+ handle = Handle(pystir.cSTIR_STIR_version_string())
+ return str(handle)class Handle: def __init__(self, handle, check_stack=None): check_status(handle, stack=check_stack) self.handle = handle def __int__(self): return pyiutil.intDataFromHandle(self.handle) def __bool__(self): return pyiutil.boolDataFromHandle(self.handle) def __float__(self, double=False): return (pyiutil.doubleDataFromHandle if double else pyiutil.floatDataFromHandle)(self.handle) def __str__(self): return pyiutil.charDataFromHandle(self.handle) def __abs__(self): return pyiutil.size_tDataFromHandle(self.handle) def __complex__(self, double=False): if double: return pyiutil.doubleReDataFromHandle(self.handle) + 1.j * pyiutil.doubleImDataFromHandle(self.handle) return pyiutil.floatReDataFromHandle(self.handle) + 1.j * pyiutil.floatImDataFromHandle(self.handle) def __del__(self): if self.handle is not None: pyiutil.deleteDataHandle(self.handle)
Related to #1377
/CC @evgueni-ovtchinnikov @paskino @KrisThielemans
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
sounds cool
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()