xref: /aosp_15_r20/external/lzma/CPP/Windows/Handle.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // Windows/Handle.h
2 
3 #ifndef ZIP7_INC_WINDOWS_HANDLE_H
4 #define ZIP7_INC_WINDOWS_HANDLE_H
5 
6 #include "../Common/MyWindows.h"
7 
8 namespace NWindows {
9 
10 class CHandle  MY_UNCOPYABLE
11 {
12 protected:
13   HANDLE _handle;
14 public:
HANDLE()15   operator HANDLE() { return _handle; }
CHandle()16   CHandle(): _handle(NULL) {}
~CHandle()17   ~CHandle() { Close(); }
IsCreated()18   bool IsCreated() const { return (_handle != NULL); }
Close()19   bool Close()
20   {
21     if (_handle == NULL)
22       return true;
23     if (!::CloseHandle(_handle))
24       return false;
25     _handle = NULL;
26     return true;
27   }
Attach(HANDLE handle)28   void Attach(HANDLE handle) { _handle = handle; }
Detach()29   HANDLE Detach()
30   {
31     const HANDLE handle = _handle;
32     _handle = NULL;
33     return handle;
34   }
35 };
36 
37 }
38 
39 #endif
40