OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
openswmm::h5io::Handle Class Reference

Owns an hid_t and closes it with the right H5*close on scope exit. More...

#include <Hdf5Util.hpp>

Collaboration diagram for openswmm::h5io::Handle:

Public Types

enum class  Kind {
  File ,
  Group ,
  Dataset ,
  Space ,
  Type ,
  Attr ,
  Plist
}
 

Public Member Functions

 Handle ()=default
 Construct an empty owner with identifier -1 and file close kind.
 
 Handle (hid_t id, Kind kind)
 Adopt an HDF5 identifier with its matching close operation.
 
 Handle (const Handle &)=delete
 
Handle & operator= (const Handle &)=delete
 
 Handle (Handle &&o) noexcept
 Transfer identifier ownership from another handle.
 
Handle & operator= (Handle &&o) noexcept
 Close this handle and transfer ownership from another.
 
 ~Handle ()
 Close any owned identifier using its stored HDF5 object kind.
 
hid_t get () const noexcept
 Inspect the owned identifier without transferring ownership.
 
bool ok () const noexcept
 Test whether this owner stores a nonnegative identifier.
 
 operator bool () const noexcept
 Test whether this owner contains an identifier.
 
void close () noexcept
 Close any owned identifier and mark this owner empty.
 

Detailed Description

Owns an hid_t and closes it with the right H5*close on scope exit.

HDF5 identifiers are not RAII and leak silently: a missed H5Dclose keeps the whole file object alive, so H5Fclose "succeeds" while flushing nothing.

Member Enumeration Documentation

◆ Kind

enum class openswmm::h5io::Handle::Kind
strong
Enumerator
File 
Group 
Dataset 
Space 
Type 
Attr 
Plist 

Constructor & Destructor Documentation

◆ Handle() [1/4]

openswmm::h5io::Handle::Handle ( )
default

Construct an empty owner with identifier -1 and file close kind.

Here is the caller graph for this function:

◆ Handle() [2/4]

openswmm::h5io::Handle::Handle ( hid_t id,
Kind kind )
inline

Adopt an HDF5 identifier with its matching close operation.

Parameters
[in]idOwned identifier, or a negative value for an empty owner.
[in]kindClose-function category matching id; not validated.
Note
The caller must relinquish independent ownership of nonnegative id. Identifiers must come from the engine's HDF5 library instance.

◆ Handle() [3/4]

openswmm::h5io::Handle::Handle ( const Handle & )
delete
Here is the call graph for this function:

◆ Handle() [4/4]

openswmm::h5io::Handle::Handle ( Handle && o)
inlinenoexcept

Transfer identifier ownership from another handle.

Parameters
[in,out]oSource owner; left empty with get() == -1.
Here is the call graph for this function:

◆ ~Handle()

openswmm::h5io::Handle::~Handle ( )
inline

Close any owned identifier using its stored HDF5 object kind.

Note
Close errors are ignored and no exception is thrown.
Here is the call graph for this function:

Member Function Documentation

◆ close()

void openswmm::h5io::Handle::close ( )
noexcept

Close any owned identifier and mark this owner empty.

Defined OUT OF LINE on purpose. HDF5 is PRIVATE-linked into the engine with hidden symbols, so a consumer that also linked its own copy would have two HDF5 instances with separate global state — the crash the CMake comments at src/engine/CMakeLists.txt warn about. Keeping every H5* call inside the engine means a caller needs these headers but not the library, and ids never cross between instances.

Calls the matching H5*close within the engine's privately linked HDF5 instance, preventing identifiers from crossing between independent library instances. Repeated calls on an empty owner do nothing.

Note
HDF5 close failures are ignored and the identifier is discarded anyway.
Here is the caller graph for this function:

◆ get()

hid_t openswmm::h5io::Handle::get ( ) const
inlinenoexcept

Inspect the owned identifier without transferring ownership.

Returns
Borrowed identifier, or -1 when empty. It must not be closed by the caller and remains usable only until this owner closes or moves it.
Here is the caller graph for this function:

◆ ok()

bool openswmm::h5io::Handle::ok ( ) const
inlinenoexcept

Test whether this owner stores a nonnegative identifier.

Returns
True when get() >= 0. Does not query HDF5 for identifier validity.
Here is the caller graph for this function:

◆ operator bool()

openswmm::h5io::Handle::operator bool ( ) const
inlineexplicitnoexcept

Test whether this owner contains an identifier.

Returns
The result of ok(); ownership is unchanged.
Here is the call graph for this function:

◆ operator=() [1/2]

Handle & openswmm::h5io::Handle::operator= ( const Handle & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

Handle & openswmm::h5io::Handle::operator= ( Handle && o)
inlinenoexcept

Close this handle and transfer ownership from another.

Parameters
[in,out]oSource owner; left empty unless this is self-assignment.
Returns
Reference to this owner. Self-assignment preserves its identifier.
Note
Close failures are ignored, as in close().
Here is the call graph for this function:

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