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

Detailed Description

The generic functions (h5::read, h5::write, h5::read_attribute, ...) call their more specialized counterparts (h5::h5_read, h5::h5_write, h5::h5_read_attribute, ...) which find the correct implementation using ADL.

Users can define their own specialized h5_write and h5_read functions for types which are not natively supported by h5. Example 2: Write/Read a custom C++ type shows how this can be done.

Functions

template<typename T >
h5::h5_read (group g, std::string const &key)
 Generic implementation for reading from an HDF5 dataset/subgroup.
 
template<typename T >
h5::h5_read_attribute (object obj, std::string const &name)
 Generic implementation for reading an HDF5 attribute.
 
template<typename T >
h5::h5_read_attribute_from_key (group g, std::string const &key, std::string const &name)
 Generic implementation for reading an HDF5 attribute.
 
template<typename T >
h5::read (group g, std::string const &key)
 Generic implementation for reading from an HDF5 dataset/subgroup.
 
template<typename T >
void h5::read (group g, std::string const &key, T &x, auto const &...args)
 Generic implementation for reading from an HDF5 dataset/subgroup into a given variable.
 
template<typename T >
h5::read_attribute (object obj, std::string const &key)
 Generic implementation for reading an HDF5 attribute.
 
template<typename T >
void h5::read_attribute (object obj, std::string const &key, T &x)
 Generic implementation for reading an HDF5 attribute into a given variable.
 
template<typename T >
bool h5::try_read (group g, std::string const &key, T &x)
 Check if an HDF5 dataset/subgroup with the given key exists in the given parent group before performing the read.
 
template<typename T >
void h5::write (group g, std::string const &key, T const &x, auto const &...args)
 Generic implementation for writing a variable to an HDF5 dataset/subgroup.
 
template<typename T >
void h5::write_attribute (object obj, std::string const &key, T const &x)
 Generic implementation for writing a variable to an HDF5 attribute.
 

Function Documentation

◆ h5_read()

template<typename T >
T h5::h5_read ( group g,
std::string const & key )

#include <h5/generic.hpp>

Generic implementation for reading from an HDF5 dataset/subgroup.

It calls the static member function T::h5_read_construct(group, T &) in case T is not default constructible, otherwise it calls the specialized h5_read(group, std::string const &, T &) with a default constructed T object.

Template Parameters
TC++ type to be read.
Parameters
gh5::group containing the dataset/subgroup from which to read from.
keyName of the dataset/subgroup.
Returns
Data read from the dataset/subgroup.

Definition at line 51 of file generic.hpp.

◆ h5_read_attribute()

template<typename T >
T h5::h5_read_attribute ( object obj,
std::string const & name )

#include <h5/generic.hpp>

Generic implementation for reading an HDF5 attribute.

T needs to be default constructible.

Template Parameters
TC++ type to be read.
Parameters
objh5::object to which the attribute is attached.
nameName of the attribute.
Returns
Data read from the attribute.

Definition at line 120 of file generic.hpp.

◆ h5_read_attribute_from_key()

template<typename T >
T h5::h5_read_attribute_from_key ( group g,
std::string const & key,
std::string const & name )

#include <h5/generic.hpp>

Generic implementation for reading an HDF5 attribute.

It calls the specialized h5_read_attribute_from_key(object, std::string const &, std::string const &, T &) for the given T. T needs to be default constructible.

Template Parameters
TC++ type to be read.
Parameters
gh5::group containing the HDF5 object to which the attribute is attached.
keyName of the object.
nameName of the attribute.
Returns
Data read from the attribute.

Definition at line 184 of file generic.hpp.

◆ read() [1/2]

template<typename T >
T h5::read ( group g,
std::string const & key )

#include <h5/generic.hpp>

Generic implementation for reading from an HDF5 dataset/subgroup.

It simply calls h5::h5_read<T>(group, std::string const &).

Template Parameters
TC++ type to be read.
Parameters
gh5::group containing the dataset/subgroup from which to read from.
keyName of the dataset/subgroup.
Returns
Data read from the dataset/subgroup.

Definition at line 73 of file generic.hpp.

◆ read() [2/2]

template<typename T >
void h5::read ( group g,
std::string const & key,
T & x,
auto const &... args )

#include <h5/generic.hpp>

Generic implementation for reading from an HDF5 dataset/subgroup into a given variable.

It calls the specialized h5_read(group, std::string const &, T &, auto const &...) for the given T.

Template Parameters
TC++ type to be read.
Parameters
gh5::group containing the dataset/subgroup from which to read from.
keyName of the dataset/subgroup.
xVariable to read into.
argsAdditional arguments to be passed to the specialized h5_read(group, std::string const &, T &) function.

Definition at line 89 of file generic.hpp.

◆ read_attribute() [1/2]

template<typename T >
T h5::read_attribute ( object obj,
std::string const & key )

#include <h5/generic.hpp>

Generic implementation for reading an HDF5 attribute.

It simply calls h5::h5_read_attribute<T>(object, std::string const &).

Template Parameters
TC++ type to be read.
Parameters
objh5::object to which the attribute is attached.
keyName of the attribute.
Returns
Data read from the attribute.

Definition at line 137 of file generic.hpp.

◆ read_attribute() [2/2]

template<typename T >
void h5::read_attribute ( object obj,
std::string const & key,
T & x )

#include <h5/generic.hpp>

Generic implementation for reading an HDF5 attribute into a given variable.

It calls the specialized h5_read_attribute(object, std::string const &, T &) for the given T.

Template Parameters
TC++ type to be read.
Parameters
objh5::object to which the attribute is attached.
keyName of the attribute.
xVariable to read into.

Definition at line 152 of file generic.hpp.

◆ try_read()

template<typename T >
bool h5::try_read ( group g,
std::string const & key,
T & x )
inline

#include <h5/generic.hpp>

Check if an HDF5 dataset/subgroup with the given key exists in the given parent group before performing the read.

If the key exists, it simply calls the specialized h5_read(group, std::string const &, T &) for the given T, otherwise it does nothing.

Template Parameters
TC++ type to be read.
Parameters
gh5::group containing the dataset/subgroup from which to read from.
keyName of the dataset/subgroup.
xVariable to read into.
Returns
True, if the dataset/subgroup exists and reading was successful, false otherwise.

Definition at line 203 of file generic.hpp.

◆ write()

template<typename T >
void h5::write ( group g,
std::string const & key,
T const & x,
auto const &... args )

#include <h5/generic.hpp>

Generic implementation for writing a variable to an HDF5 dataset/subgroup.

It calls the specialized h5_write(group, std::string const &, T const &) for the given T.

Template Parameters
TC++ type to be written.
Parameters
gh5::group in which the dataset/subgroup is created.
keyName of the dataset/subgroup to which the variable is written.
xVariable to be written.
argsAdditional arguments to be passed to the specialized h5_write(group, std::string const &, T const &) function.

Definition at line 105 of file generic.hpp.

◆ write_attribute()

template<typename T >
void h5::write_attribute ( object obj,
std::string const & key,
T const & x )

#include <h5/generic.hpp>

Generic implementation for writing a variable to an HDF5 attribute.

It calls the specialized h5_write_attribute(object, std::string const &, T const &) for the given T.

Template Parameters
TC++ type to be read.
Parameters
objh5::object to which the attribute is attached.
keyName of the attribute to be created.
xVariable to be written.

Definition at line 167 of file generic.hpp.