TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches

Detailed Description

Specialized functions to read/write a std::tuple from/to HDF5.

The following code writes a std::tuple to an HDF5 file, reads the same tuple and outputs it to stdout:

#include <h5/h5.hpp>
#include <iostream>
#include <tuple>
int main() {
// create file in read/write mode
h5::file file("tuple.h5", 'w');
// write tuple
h5::write(file, "mytuple", std::tuple { 3.1415f, 291827ul, 'a' });
// read into tuple
std::tuple<float, unsigned long, char> tup;
h5::read(file, "mytuple", tup);
// output tuple
std::apply([](auto f, auto u, auto c) {
std::cout << "(" << f << ", " << u << ", " << c << ")" << std::endl;
}, tup);
}
A handle to an HDF5 file.
Definition file.hpp:43
T read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition generic.hpp:73
void write(group g, std::string const &key, T const &x, auto const &...args)
Generic implementation for writing a variable to an HDF5 dataset/subgroup.
Definition generic.hpp:105
Includes all relevant h5 headers.

Output:

(3.1415, 291827, a)

Contents of tuple.h5:

HDF5 "tuple.h5" {
GROUP "/" {
GROUP "mytuple" {
ATTRIBUTE "Format" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SCALAR
DATA {
(0): "PythonTupleWrap"
}
}
DATASET "0" {
DATATYPE H5T_IEEE_F32LE
DATASPACE SCALAR
DATA {
(0): 3.1415
}
}
DATASET "1" {
DATATYPE H5T_STD_U64LE
DATASPACE SCALAR
DATA {
(0): 291827
}
}
DATASET "2" {
DATATYPE H5T_STD_I8LE
DATASPACE SCALAR
DATA {
(0): 97
}
}
}
}
}

Classes

struct  h5::hdf5_format_impl< std::tuple< T... > >
 Specialization of h5::hdf5_format_impl for std::tuple. More...
 

Functions

template<typename... Ts>
void h5::h5_read (group g, std::string const &name, std::tuple< Ts... > &tup)
 Read a std::tuple from an HDF5 subgroup.
 
template<typename... Ts>
void h5::h5_write (group g, std::string const &name, std::tuple< Ts... > const &tup)
 Write a std::tuple to an HDF5 subgroup.
 

Function Documentation

◆ h5_read()

template<typename... Ts>
void h5::h5_read ( group g,
std::string const & name,
std::tuple< Ts... > & tup )

#include <h5/stl/tuple.hpp>

Read a std::tuple from an HDF5 subgroup.

Calls the specialized h5_read function for every value of the std::tuple.

Template Parameters
TsTuple types.
Parameters
gh5::group containing the subgroup.
nameName of the subgroup from which the std::tuple is read.
tupstd::tuple to read into.

Definition at line 95 of file tuple.hpp.

◆ h5_write()

template<typename... Ts>
void h5::h5_write ( group g,
std::string const & name,
std::tuple< Ts... > const & tup )

#include <h5/stl/tuple.hpp>

Write a std::tuple to an HDF5 subgroup.

Calls the specialized h5_write function for every element of the std::tuple.

Template Parameters
TsTuple types.
Parameters
gh5::group in which the subgroup is created.
nameName of the subgroup to which the std::tuple is written.
tupstd::tuple to be written.

Definition at line 78 of file tuple.hpp.