Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
Hdf5Handle.hpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Maikel Nadolski
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #include <hdf5.h>
22 
23 namespace fub {
24 
25 template <typename Deleter> struct H5Handle {
26  H5Handle() = default;
27  H5Handle(hid_t id) : id_{id} {}
28 
29  H5Handle(const H5Handle&) = delete;
30  H5Handle& operator=(const H5Handle&) = delete;
31 
32  H5Handle(H5Handle&& other) noexcept : id_{std::exchange(other.id_, -1)} {}
33  H5Handle& operator=(H5Handle&& other) { id_ = std::exchange(other.id_, -1); }
34 
36  if (id_ > 0) {
37  Deleter{}(id_);
38  }
39  }
40 
41  operator hid_t() const noexcept { return id_; }
42 
43  hid_t id_{};
44 };
45 
46 struct H5Fdeleter {
47  using pointer = hid_t;
48  void operator()(hid_t file) const noexcept { H5Fclose(file); }
49 };
51 
52 struct H5Sdeleter {
53  using pointer = hid_t;
54  void operator()(hid_t dataspace) const noexcept { H5Sclose(dataspace); }
55 };
57 
58 struct H5Ddeleter {
59  using pointer = hid_t;
60  void operator()(hid_t dataset) const noexcept { H5Dclose(dataset); }
61 };
63 
64 struct H5Adeleter {
65  using pointer = hid_t;
66  void operator()(hid_t attributes) const noexcept { H5Aclose(attributes); }
67 };
69 
70 struct H5Pdeleter {
71  using pointer = hid_t;
72  void operator()(hid_t properties) const noexcept { H5Pclose(properties); }
73 };
75 
76 } // namespace fub
The fub namespace.
Definition: AnyBoundaryCondition.hpp:31
Definition: Hdf5Handle.hpp:64
void operator()(hid_t attributes) const noexcept
Definition: Hdf5Handle.hpp:66
hid_t pointer
Definition: Hdf5Handle.hpp:65
Definition: Hdf5Handle.hpp:58
void operator()(hid_t dataset) const noexcept
Definition: Hdf5Handle.hpp:60
hid_t pointer
Definition: Hdf5Handle.hpp:59
Definition: Hdf5Handle.hpp:46
void operator()(hid_t file) const noexcept
Definition: Hdf5Handle.hpp:48
hid_t pointer
Definition: Hdf5Handle.hpp:47
Definition: Hdf5Handle.hpp:25
H5Handle()=default
H5Handle(const H5Handle &)=delete
H5Handle(H5Handle &&other) noexcept
Definition: Hdf5Handle.hpp:32
H5Handle & operator=(H5Handle &&other)
Definition: Hdf5Handle.hpp:33
H5Handle & operator=(const H5Handle &)=delete
hid_t id_
Definition: Hdf5Handle.hpp:43
~H5Handle()
Definition: Hdf5Handle.hpp:35
H5Handle(hid_t id)
Definition: Hdf5Handle.hpp:27
Definition: Hdf5Handle.hpp:70
void operator()(hid_t properties) const noexcept
Definition: Hdf5Handle.hpp:72
hid_t pointer
Definition: Hdf5Handle.hpp:71
Definition: Hdf5Handle.hpp:52
void operator()(hid_t dataspace) const noexcept
Definition: Hdf5Handle.hpp:54
hid_t pointer
Definition: Hdf5Handle.hpp:53