AutoHandle.h 953 B

123456789101112131415161718192021222324252627282930313233343536
  1. //===-- AutoHandle.h --------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_lldb_Host_windows_AutoHandle_h_
  9. #define LLDB_lldb_Host_windows_AutoHandle_h_
  10. #include "lldb/Host/windows/windows.h"
  11. namespace lldb_private {
  12. class AutoHandle {
  13. public:
  14. AutoHandle(HANDLE handle, HANDLE invalid_value = INVALID_HANDLE_VALUE)
  15. : m_handle(handle), m_invalid_value(invalid_value) {}
  16. ~AutoHandle() {
  17. if (m_handle != m_invalid_value)
  18. ::CloseHandle(m_handle);
  19. }
  20. bool IsValid() const { return m_handle != m_invalid_value; }
  21. HANDLE get() const { return m_handle; }
  22. private:
  23. HANDLE m_handle;
  24. HANDLE m_invalid_value;
  25. };
  26. }
  27. #endif