#include <h5cpp/all>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
namespace {
void section(const char* title) {
}
}
int main() {
section("1. creating groups");
{
h5::lcpl_t lcpl = h5::char_encoding{H5T_CSET_UTF8}
| h5::create_intermediate_group{1};
std::cout <<
" created /sensors/imu/left and /sensors/lidar\n";
}
section("2. nested groups (group as parent)");
{
std::cout <<
" added /sensors/imu/left/{calibration, raw}\n";
}
section("3. open + existence check");
{
for (const auto& path : {"/sensors/imu/left",
"/sensors/imu/right",
"/sensors/lidar"}) {
bool present = h5::exists(fd, path);
<< " -> " << (present ? "exists" : "missing") << "\n";
if (present) {
(void)gr;
}
}
}
section("4. group attributes");
{
std::cout <<
" attached 4 attributes to /sensors/imu/left\n";
}
section("5. listing group contents");
{
std::cout <<
" ls(/) -> " << h5::ls(fd,
"/") <<
"\n";
std::cout <<
" ls(/sensors) -> " << h5::ls(fd,
"/sensors") <<
"\n";
std::cout <<
" ls(/sensors/imu) -> " << h5::ls(fd,
"/sensors/imu") <<
"\n";
std::cout <<
"\n dfs(/sensors) -> " << h5::dfs(fd,
"/sensors") <<
"\n";
std::cout <<
" bfs(/sensors) -> " << h5::bfs(fd,
"/sensors") <<
"\n";
}
section("6. links — soft, hard, external");
{
h5::link_soft("/sensors/imu/left", fd, "/shortcuts/imu_l");
h5::link_hard(fd, "/sensors/imu/left",
fd, "/shortcuts/imu_l_alias");
h5::link_external("external.h5", "/sensors/imu/left",
fd, "/external/peer");
std::cout <<
" /shortcuts -> " << h5::ls(fd,
"/shortcuts") <<
"\n";
std::cout <<
" /external -> " << h5::ls(fd,
"/external") <<
"\n";
if (h5::exists(fd, "/shortcuts/imu_l")) {
std::cout <<
" opened via soft link: /shortcuts/imu_l "
<< "(target = /sensors/imu/left)\n";
(void)followed;
}
}
section("7. move / copy / unlink");
{
h5::move(fd, "/tmp/sketch", fd, "/archive/v1");
std::cout <<
" after move: /tmp -> " << h5::ls(fd,
"/tmp") <<
"\n";
std::cout <<
" /archive -> " << h5::ls(fd,
"/archive") <<
"\n";
h5::copy(fd, "/sensors/imu/left", fd, "/archive/imu_snapshot");
std::cout <<
" after copy: /archive -> " << h5::ls(fd,
"/archive") <<
"\n";
<< h5::ls(fd, "/archive/imu_snapshot") << "\n";
h5::unlink(fd, "/shortcuts/imu_l_alias");
std::cout <<
" after unlink: /shortcuts -> " << h5::ls(fd,
"/shortcuts") <<
"\n";
std::cout <<
" /sensors/imu/left still exists: "
<< (h5::exists(fd, "/sensors/imu/left") ? "yes" : "no") << "\n";
}
section("8. error handling");
{
try {
} catch (const h5::error::io::group::create& e) {
std::cout <<
" specific: " << e.what() <<
"\n";
}
try {
} catch (const h5::error::any& e) {
std::cout <<
" umbrella: " << e.what() <<
"\n";
}
}
std::cout <<
"\nWrote everything to ./groups.h5\n";
std::cout <<
"Inspect with: h5dump -n groups.h5 (full tree)\n";
return 0;
}
h5::at_t create(const hid_t &parent, const std::string &path, args_t &&... args)
Create a new attribute of element type T on a parent HDF5 object.
Definition H5Acreate.hpp:100
T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
Read an attribute by name and return its value as type T.
Definition H5Aread.hpp:76
void awrite(const h5::at_t &attr, const T *ptr)
Low-level attribute write — copies elements from ptr into an already-open h5::at_t.
Definition H5Awrite.hpp:47
void unmute()
restores previously saved error handler with h5::mute Read on Error Handling/Exceptions
Definition H5Eall.hpp:41
void mute()
removes default error handler preventing diagnostic error messages printed for direct CAPI calls....
Definition H5Eall.hpp:28
std::enable_if_t< h5::impl::is_valid_group_parent< HID_T >::value, h5::gr_t > gcreate(const HID_T &parent, const std::string &path, const h5::lcpl_t &lcpl=h5::default_lcpl)
Creates an HDF5 group and returns a managed h5::gr_t handle.
Definition H5Gcreate.hpp:32
std::enable_if_t< h5::impl::is_valid_group_parent< HID_T >::value, h5::gr_t > gopen(const HID_T &parent, const std::string &path)
Opens an existing HDF5 group and returns a managed h5::gr_t handle.
Definition H5Gopen.hpp:20