Line data Source code
1 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); // NOLINT 48 : OpenGroup& operator=(OpenGroup&& rhs); // NOLINT 49 : 50 : const hid_t& id() const { return group_id_; } 51 : 52 : const std::string& group_path_with_trailing_slash() const { 53 : return group_path_str_; 54 : } 55 : 56 : private: 57 : /// \cond HIDDEN_SYMBOLS 58 : std::string group_path_str_; 59 : std::vector<hid_t> group_path_; 60 : hid_t group_id_{-1}; 61 : /// \endcond 62 : }; 63 : } // namespace detail 64 : } // namespace h5