OpenGroup.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines class OpenGroup for opening groups in HDF5
6 
7 #pragma once
8 
9 #include <hdf5.h>
10 #include <string>
11 #include <vector>
12 
13 #include "IO/H5/AccessType.hpp"
14 
15 namespace h5 {
16 namespace detail {
17 /*!
18  * \ingroup HDF5Group
19  * \brief Open an H5 group
20  *
21  * Opens a group recursively on creation and closes the groups when destructed.
22  */
23 class OpenGroup {
24  public:
25  OpenGroup() = default;
26 
27  /*!
28  * \param file_id the root/base file/group id where to start opening
29  * \param group_name the full path to the group to open
30  * \param access_type either AccessType::ReadOnly or AccessType::ReadWrite
31  */
32  OpenGroup(hid_t file_id, const std::string& group_name,
33  h5::AccessType access_type);
34 
35  /// \cond HIDDEN_SYMBOLS
36  ~OpenGroup();
37  /// \endcond
38 
39  // @{
40  /// \cond HIDDEN_SYMBOLS
41  /// Copying does not make sense since the group will then be closed twice.
42  OpenGroup(const OpenGroup& /*rhs*/) = delete;
43  OpenGroup& operator=(const OpenGroup& /*rhs*/) = delete;
44  /// \endcond
45  // @}
46 
47  OpenGroup(OpenGroup&& rhs) noexcept; // NOLINT
48  OpenGroup& operator=(OpenGroup&& rhs) noexcept; // NOLINT
49 
50  const hid_t& id() const noexcept { return group_id_; }
51 
52  private:
53  /// \cond HIDDEN_SYMBOLS
54  std::vector<hid_t> group_path_;
55  hid_t group_id_{-1};
56  /// \endcond
57 };
58 } // namespace detail
59 } // namespace h5
Contains functions and classes for manipulating HDF5 files.
Definition: AccessType.cpp:10
Definition: Determinant.hpp:11
Defines enum for specifying whether the H5 file is ReadWrite or ReadOnly.
AccessType
Set the access type to the H5File.
Definition: AccessType.hpp:23