VTK  9.4.20241109
vtkHDF5ScopedHandle.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkHDF5ScopedHandle_h
4#define vtkHDF5ScopedHandle_h
5
6#include "vtk_hdf5.h"
7
8#include <algorithm>
9
10namespace vtkHDF
11{
12VTK_ABI_NAMESPACE_BEGIN
13
17#define DefineScopedHandle(name) \
18 class ScopedH5##name##Handle \
19 { \
20 public: \
21 ScopedH5##name##Handle() \
22 : Handle(H5I_INVALID_HID) \
23 { \
24 } \
25 ScopedH5##name##Handle(ScopedH5##name##Handle&& other) noexcept \
26 { \
27 this->Handle = other.Handle; \
28 other.Handle = H5I_INVALID_HID; \
29 } \
30 ScopedH5##name##Handle& operator=(ScopedH5##name##Handle&& other) noexcept \
31 { \
32 std::swap(this->Handle, other.Handle); \
33 return *this; \
34 } \
35 ScopedH5##name##Handle(const ScopedH5##name##Handle& other) = delete; \
36 ScopedH5##name##Handle& operator=(const ScopedH5##name##Handle&) = delete; \
37 ScopedH5##name##Handle(hid_t handle) \
38 : Handle(handle) \
39 { \
40 } \
41 virtual ~ScopedH5##name##Handle() \
42 { \
43 if (this->Handle >= 0) \
44 { \
45 H5##name##close(this->Handle); \
46 } \
47 } \
48 \
49 operator hid_t() const \
50 { \
51 return this->Handle; \
52 } \
53 \
54 private: \
55 hid_t Handle; \
56 };
57
58// Defines ScopedH5AHandle closed with H5Aclose
60
61// Defines ScopedH5DHandle closed with H5Dclose
63
64// Defines ScopedH5FHandle closed with H5Fclose
66
67// Defines ScopedH5GHandle closed with H5Gclose
69
70// Defines ScopedH5PHandle closed with H5Pclose
72
73// Defines ScopedH5SHandle closed with H5Sclose
75
76// Defines ScopedH5THandle closed with H5Tclose
78
79VTK_ABI_NAMESPACE_END
80}
81
82#endif
83// VTK-HeaderTest-Exclude: vtkHDF5ScopedHandle.h
#define DefineScopedHandle(name)
RAII class for automatically closing H5 handles.