DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
Handle Class Reference

Scope guard for an HDF5 identifier. More...

#include <HDF5Interface.h>

Public Member Functions

 Handle (hid_t id, herr_t(*close)(hid_t)) noexcept
 Take ownership of an HDF5 identifier.
 Handle (const Handle &)=delete
 Handle (Handle &&h) noexcept
 Move constructor.
 ~Handle ()
 Destructor.
Handle & operator= (const Handle &)=delete
Handle & operator= (Handle &&h) noexcept
 Move assignment.
 operator hid_t () const noexcept
 Managed identifier.
hid_t release () noexcept
 Relinquish ownership of the identifier.
void close ()
 Close the identifier, reporting a failure.

Detailed Description

Scope guard for an HDF5 identifier.

Closes the identifier on destruction, including when the enclosing scope is left by an exception. Non-positive identifiers (invalid handles, and the H5P_DEFAULT-style constants) are never closed.

Note
A close failure during destruction is logged rather than thrown. Call ::close where the failure must be reported.

Constructor & Destructor Documentation

◆ Handle()

Handle ( hid_t id,
herr_t(* close )(hid_t) )
inlinenoexcept

Take ownership of an HDF5 identifier.

Parameters
[in]idIdentifier to manage.
[in]closeFunction releasing id, e.g. H5Dclose.

Member Function Documentation

◆ close()

void close ( )
inline

Close the identifier, reporting a failure.

Ownership is given up only once the identifier is closed, so a failure leaves it with the handle, to be closed again on destruction. Does nothing if no identifier is held.

Exceptions
std::runtime_errorif the identifier cannot be closed.

◆ release()

hid_t release ( )
inlinenoexcept

Relinquish ownership of the identifier.

Returns
The identifier, which the caller must close.

The documentation for this class was generated from the following file: