Class h5stream#
Defined in File h5stream.hpp
Class Documentation#
-
class h5stream#
Minimal header-only wrapper for common HDF5 read/write operations.
The class provides utilities to create or open an HDF5 file, write/read vectors and scalar data, attach metadata attributes, and navigate groups.
Public Functions
-
h5stream() = default#
Default construct an empty HDF5 stream object.
-
inline explicit h5stream(const std::string &fileName, const std::string &rw = std::string("tr"))#
Construct and immediately open an HDF5 file.
- Parameters:
fileName – Path to the HDF5 file.
rw – Access mode. Supported values are
"tr","r","rw", and"x".
-
inline void setFileName(const H5std_string &fileName, const std::string &rw = std::string("tr"))#
Open or recreate the HDF5 file with the requested mode.
- Parameters:
fileName – Path to the file.
rw – Access mode:
"r","rw","x", or"tr".
-
template<typename T = double, template<typename...> class vec>
inline void write(const std::vector<vec<T>> &data, const H5std_string &datasetName)# Write a nested vector structure to sequential HDF5 datasets.
- Template Parameters:
T – Element type of the vector.
vec – Container type used for the nested vector.
- Parameters:
data – Vector of vectors to serialize.
datasetName – Base name for the generated datasets.
-
template<typename T = double, template<typename...> class vec = std::vector>
inline void write(const vec<T> &data, const H5std_string &datasetName)# Write a single vector to an HDF5 dataset.
- Template Parameters:
T – Element type.
vec – Container type used for the vector.
- Parameters:
data – Vector payload.
datasetName – Dataset name in the file.
-
template<typename T = double>
inline void write(const H5std_string &datasetName, const T *data, unsigned data_size)# Write a raw C-style array to an HDF5 dataset.
- Template Parameters:
T – Element type.
- Parameters:
datasetName – Dataset name in the HDF5 file.
data – Pointer to the first element.
data_size – Number of elements in the array.
-
template<typename T = double, template<typename...> class vec = std::vector>
inline void read(vec<T> &data, const H5std_string &datasetName)# Read a vector from an HDF5 dataset.
- Template Parameters:
T – Element type.
vec – Container type used for the vector.
- Parameters:
data – Output container to populate.
datasetName – Name of the dataset in the file.
-
template<typename T = double, template<typename...> class vec>
inline void read(std::vector<vec<T>> &data, const H5std_string &datasetName)# Read a nested vector structure stored as sequential datasets.
- Template Parameters:
T – Element type.
vec – Container type used for the nested vector.
- Parameters:
data – Output vector of vectors.
datasetName – Base name for the generated datasets.
-
inline void close()#
Close the currently open HDF5 file.
-
inline double fileSize() const#
Return the file size in megabytes.
- Returns:
File size in MB.
-
inline dspace getDataspace(const H5std_string &dataset_name)#
Open and wrap a dataset for attribute access.
- Parameters:
dataset_name – Name of the dataset.
- Returns:
Lightweight dataset attribute wrapper.
-
inline gspace getGroup(const H5std_string &dataset_name)#
Open and wrap a group for attribute access.
- Parameters:
dataset_name – Name of the group.
- Returns:
Lightweight group attribute wrapper.
-
inline auto createGroup(const H5std_string &group_name)#
Create a new HDF5 group.
- Parameters:
group_name – Name of the group to create.
- Returns:
Wrapper around the newly created group.
Public Members
-
H5std_string hdf5FileName#
Path to the currently open HDF5 file.
-
H5::H5File hdf5File#
Active HDF5 file handle.
Friends
-
template<typename T>
inline friend h5stream &operator<<(h5stream &out, const h5str1<T> &struct1)# Stream-style write helper for a simple HDF5 record descriptor.
- Template Parameters:
T – Type of the pointed data.
- Parameters:
out – Output stream wrapper.
struct1 – Descriptor containing the dataset name and pointer.
- Returns:
Reference to the modified stream.
-
template<typename T>
inline friend h5stream &operator>>(h5stream &out, const h5str1<T> &struct1)# Stream-style read helper for a simple HDF5 record descriptor.
- Template Parameters:
T – Type of the pointed data.
- Parameters:
out – Input stream wrapper.
struct1 – Descriptor containing the dataset name and pointer.
- Returns:
Reference to the modified stream.
-
h5stream() = default#