mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
clang cant compile the handle_raii class because it thinks INVALID_HANDLE_VALUE is not a constexpr
Make a standalone class for it instead of inheriting generic_raii
This commit is contained in:
parent
2d386d87da
commit
69656be428
@ -59,11 +59,36 @@ class scoped_com_initializer { // {{{
|
||||
#define INITIALIZE_COM_IN_FUNCTION scoped_com_initializer com; if (!com) return com.set_python_error();
|
||||
|
||||
static inline void co_task_mem_free(void* m) { CoTaskMemFree(m); }
|
||||
typedef generic_raii<wchar_t*, co_task_mem_free, static_cast<wchar_t*>(NULL)> com_wchar_raii;
|
||||
static inline void handle_destructor(HANDLE p) { CloseHandle(p); }
|
||||
typedef generic_raii<HANDLE, handle_destructor, INVALID_HANDLE_VALUE> handle_raii;
|
||||
typedef generic_raii<wchar_t*, co_task_mem_free> com_wchar_raii;
|
||||
static inline void mapping_destructor(void *p) { UnmapViewOfFile(p); }
|
||||
typedef generic_raii<void*, mapping_destructor, static_cast<void*>(NULL)> mapping_raii;
|
||||
typedef generic_raii<void*, mapping_destructor> mapping_raii;
|
||||
|
||||
class handle_raii {
|
||||
private:
|
||||
handle_raii( const handle_raii & ) noexcept;
|
||||
handle_raii & operator=( const handle_raii & ) noexcept ;
|
||||
|
||||
protected:
|
||||
HANDLE handle;
|
||||
|
||||
public:
|
||||
explicit handle_raii(HANDLE h = INVALID_HANDLE_VALUE) noexcept : handle(h) {}
|
||||
~handle_raii() noexcept { release(); }
|
||||
|
||||
void release() noexcept {
|
||||
if (handle != INVALID_HANDLE_VALUE) {
|
||||
HANDLE temp = handle;
|
||||
handle = INVALID_HANDLE_VALUE;
|
||||
CloseHandle(temp);
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE ptr() noexcept { return handle; }
|
||||
HANDLE detach() noexcept { HANDLE ans = handle; handle = INVALID_HANDLE_VALUE; return ans; }
|
||||
void attach(HANDLE val) noexcept { release(); handle = val; }
|
||||
explicit operator bool() const noexcept { return handle != INVALID_HANDLE_VALUE; }
|
||||
};
|
||||
|
||||
|
||||
struct prop_variant : PROPVARIANT {
|
||||
prop_variant(VARTYPE vt=VT_EMPTY) noexcept : PROPVARIANT{} { PropVariantInit(this); this->vt = vt; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user