From 484aad71f66d5a757c4aa15117258dd6b854ed56 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Thu, 25 Jul 2024 14:15:14 +0200 Subject: [PATCH] Add private DataSpace (named) ctor `fromId`. Certain HDF5 API creates data spaces, in order to use this API, we need to be able to create `HighFive::DataSpace` from an HID. --- include/highfive/H5DataSpace.hpp | 17 +++++++++++++++++ include/highfive/bits/H5Dataspace_misc.hpp | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/include/highfive/H5DataSpace.hpp b/include/highfive/H5DataSpace.hpp index 463648507..6c98d4c99 100644 --- a/include/highfive/H5DataSpace.hpp +++ b/include/highfive/H5DataSpace.hpp @@ -19,6 +19,14 @@ namespace HighFive { +namespace detail { +/// @brief Create a HighFive::DataSpace from an HID, without incrementing the id. +/// +/// @note This is internal API and subject to change. +/// @internal +DataSpace make_data_space(hid_t hid); +} // namespace detail + /// \brief Class representing the space (dimensions) of a DataSet /// /// \code{.cpp} @@ -254,9 +262,18 @@ class DataSpace: public Object { protected: DataSpace() = default; + static DataSpace fromId(hid_t hid) { + DataSpace space; + space._hid = hid; + + return space; + } + friend class Attribute; friend class File; friend class DataSet; + + friend DataSpace detail::make_data_space(hid_t hid); }; } // namespace HighFive diff --git a/include/highfive/bits/H5Dataspace_misc.hpp b/include/highfive/bits/H5Dataspace_misc.hpp index 4382c14c1..706dfd2fc 100644 --- a/include/highfive/bits/H5Dataspace_misc.hpp +++ b/include/highfive/bits/H5Dataspace_misc.hpp @@ -21,6 +21,12 @@ namespace HighFive { +namespace detail { +DataSpace make_data_space(hid_t hid) { + return DataSpace::fromId(hid); +} +} // namespace detail + inline DataSpace::DataSpace(const std::vector& dims) : DataSpace(dims.begin(), dims.end()) {}