From 84f18e1d5ed9c7c4ef7f1e252c18ee265c6c5f25 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 30 Jan 2024 19:18:33 +0100 Subject: [PATCH] hdf5: groups: handle paths to access sub-content objects --- src/opt/hdf5/lib/h5_group.cc | 11 ++++++++++- src/opt/hdf5/tests/h5_basic_unit_test.cc | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/opt/hdf5/lib/h5_group.cc b/src/opt/hdf5/lib/h5_group.cc index bc4bbbe..94ebe8d 100644 --- a/src/opt/hdf5/lib/h5_group.cc +++ b/src/opt/hdf5/lib/h5_group.cc @@ -75,7 +75,16 @@ namespace CNORXZ const ContentPtr& Group::get(const String& name) const { - auto i = this->getIndexTo(name); + const String delim = "/"; + const SizeT delimpos = name.find(delim); + const String thisname = name.substr(0, delimpos); + if(delimpos != String::npos and delimpos+1 < name.size()){ + const String next = name.substr(delimpos+1); + auto g = getGroup(thisname); + g->open(); + return g->get(next); + } + auto i = this->getIndexTo(thisname); return *i; } diff --git a/src/opt/hdf5/tests/h5_basic_unit_test.cc b/src/opt/hdf5/tests/h5_basic_unit_test.cc index c367ea9..f6689a3 100644 --- a/src/opt/hdf5/tests/h5_basic_unit_test.cc +++ b/src/opt/hdf5/tests/h5_basic_unit_test.cc @@ -139,6 +139,12 @@ namespace VCHECK(tab->path()); EXPECT_EQ(tab->fields()->size(), 3u); EXPECT_EQ(tab->records()->size(), 5u); + + EXPECT_THROW(h5f.getTable("moregroups/evenmore/need/tab1/a"), std::runtime_error); + auto tab2 = h5f.getTable("moregroups/evenmore/need/tab1/"); + EXPECT_EQ(tab2->fields()->size(), 3u); + EXPECT_EQ(tab2->records()->size(), 5u); + h5f.iter( [](const auto& c) { VCHECK(c->path()); } )(); h5f.iterRecursive( [](const auto& c) { VCHECK(c->path()); } )(); h5f.iterRecursive( [](const auto& c) { c->open(); VCHECK(toString(c->getRecursiveAttributes())); } )();