45#ifndef OPENSWMM_HDF5_UTIL_HPP
46#define OPENSWMM_HDF5_UTIL_HPP
84 Handle(
Handle&& o) noexcept : id_(o.id_), kind_(o.kind_) { o.id_ = -1; }
111 hid_t
get() const noexcept {
return id_; }
116 bool ok() const noexcept {
return id_ >= 0; }
121 explicit operator bool() const noexcept {
return ok(); }
136 void close() noexcept;
169std::
string column_units(hid_t group, const std::
string& column);
197bool has_link(hid_t loc, const std::
string& name);
211bool write_attr(hid_t loc, const std::
string& name, const std::
string& value);
221bool write_attr(hid_t loc, const std::
string& name,
double value);
231bool write_attr(hid_t loc, const std::
string& name,
int value);
243bool read_attr(hid_t loc, const std::
string& name, std::
string& out);
254bool read_attr(hid_t loc, const std::
string& name,
double& out);
265bool read_attr(hid_t loc, const std::
string& name,
int& out);
292bool write_column(hid_t group, const std::
string& name, const std::vector<
double>& values,
293 const std::
string& units =
"", const std::
string& description =
"",
294 int compression = 4);
310bool write_column(hid_t group, const std::
string& name, const std::vector<
int>& values,
311 const std::
string& units =
"", const std::
string& description =
"",
312 int compression = 4);
327bool write_column(hid_t group, const std::
string& name, const std::vector<std::
string>& values,
328 const std::
string& description =
"",
int compression = 4);
343bool read_column(hid_t group, const std::
string& name, std::vector<
double>& out);
357bool read_column(hid_t group, const std::
string& name, std::vector<
int>& out);
371bool read_column(hid_t group, const std::
string& name, std::vector<std::
string>& out);
382std::
size_t column_length(hid_t group, const std::
string& probe);
Owns an hid_t and closes it with the right H5*close on scope exit.
Definition Hdf5Util.hpp:62
bool ok() const noexcept
Test whether this owner stores a nonnegative identifier.
Definition Hdf5Util.hpp:116
~Handle()
Close any owned identifier using its stored HDF5 object kind.
Definition Hdf5Util.hpp:104
void close() noexcept
Close any owned identifier and mark this owner empty.
Definition Hdf5Util.cpp:126
Handle()=default
Construct an empty owner with identifier -1 and file close kind.
Handle & operator=(const Handle &)=delete
hid_t get() const noexcept
Inspect the owned identifier without transferring ownership.
Definition Hdf5Util.hpp:111
Handle(const Handle &)=delete
Kind
Definition Hdf5Util.hpp:64
@ Group
Definition Hdf5Util.hpp:64
@ File
Definition Hdf5Util.hpp:64
@ Dataset
Definition Hdf5Util.hpp:64
@ Attr
Definition Hdf5Util.hpp:64
@ Type
Definition Hdf5Util.hpp:64
@ Space
Definition Hdf5Util.hpp:64
@ Plist
Definition Hdf5Util.hpp:64
Handle & operator=(Handle &&o) noexcept
Close this handle and transfer ownership from another.
Definition Hdf5Util.hpp:91
Handle(hid_t id, Kind kind)
Adopt an HDF5 identifier with its matching close operation.
Definition Hdf5Util.hpp:77
Handle(Handle &&o) noexcept
Transfer identifier ownership from another handle.
Definition Hdf5Util.hpp:84
Definition Hdf5InputPlugin.cpp:34
Handle open_file_readonly(const std::string &path)
Open an existing HDF5 file for read-only access.
Definition Hdf5Util.cpp:156
Handle make_group(hid_t loc, const std::string &name)
Create (or open) a group, creating intermediate groups as needed.
Definition Hdf5Util.cpp:182
Handle open_group(hid_t loc, const std::string &name)
Open an existing HDF5 group.
Definition Hdf5Util.cpp:195
bool write_attr(hid_t loc_in, const std::string &name, const std::string &value)
Create or replace a scalar std::string attribute.
Definition Hdf5Util.cpp:226
bool read_attr(hid_t loc_in, const std::string &name, std::string &out)
Read a scalar attribute as std::string.
Definition Hdf5Util.cpp:283
std::size_t column_length(hid_t group, const std::string &probe)
Row count of a group's columns โ the length of probe, or 0 if absent.
Definition Hdf5Util.cpp:465
bool write_column(hid_t group, const std::string &name, const std::vector< double > &values, const std::string &units, const std::string &description, int compression)
Create a one-dimensional double column with optional metadata.
Definition Hdf5Util.cpp:347
std::string column_units(hid_t group, const std::string &column)
A column's units attribute, or "" when it has none.
Definition Hdf5Util.cpp:161
bool has_link(hid_t loc, const std::string &name)
True when loc contains name.
Definition Hdf5Util.cpp:200
Handle make_string_type()
A variable-length UTF-8 string type, for name columns.
Definition Hdf5Util.cpp:172
bool read_column(hid_t group, const std::string &name, std::vector< double > &out)
Read a one-dimensional column into a double vector.
Definition Hdf5Util.cpp:414