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

Detailed Description

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

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

#include <h5/h5.hpp>
#include <iostream>
#include <utility>
int main() {
// create file in read/write mode
h5::file file("pair.h5", 'w');
// write pair
h5::write(file, "mypair", std::pair { 3.1415f, 291827ul });
// read into pair
std::pair<float, unsigned long> p;
h5::read(file, "mypair", p);
// output pair
std::cout << "(" << p.first << ", " << p.second << ")" << std::endl;
}
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)

Contents of pair.h5:

HDF5 "pair.h5" {
GROUP "/" {
GROUP "mypair" {
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
}
}
}
}
}

Classes

struct  h5::hdf5_format_impl< std::pair< T1, T2 > >
 Specialization of h5::hdf5_format_impl for std::pair. More...
 

Functions

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

Function Documentation

◆ h5_read()

template<typename T1 , typename T2 >
void h5::h5_read ( group g,
std::string const & name,
std::pair< T1, T2 > & p )

#include <h5/stl/pair.hpp>

Read a std::pair from an HDF5 subgroup.

Calls the specialized h5_read function for both values of the std::pair.

Template Parameters
T1Value type #1.
T1Value type #2.
Parameters
gh5::group containing the subgroup.
nameName of the subgroup from which the std::pair is read.
pstd::pair to read into.

Definition at line 76 of file pair.hpp.

◆ h5_write()

template<typename T1 , typename T2 >
void h5::h5_write ( group g,
std::string const & name,
std::pair< T1, T2 > const & p )

#include <h5/stl/pair.hpp>

Write a std::pair to an HDF5 subgroup.

Calls the specialized h5_write function for both values of the std::pair.

Template Parameters
T1Value type #1.
T1Value type #2.
Parameters
gh5::group in which the subgroup is created.
nameName of the subgroup to which the std::pair is written.
pstd::pair to be written.

Definition at line 57 of file pair.hpp.