diff --git a/src/opt/hdf5/include/h5_content_base.h b/src/opt/hdf5/include/h5_content_base.h index dace4d6..d838ae8 100644 --- a/src/opt/hdf5/include/h5_content_base.h +++ b/src/opt/hdf5/include/h5_content_base.h @@ -38,6 +38,13 @@ namespace CNORXZ RangePtr range() const; hid_t id() const; inline bool isOpen() const { return mId != 0; } + + template + ContentBase& addAttribute(const String& name, const T& value); + DType getAttribute(const String& name) const; + bool isAttribute(const String& name) const; + String getAttributesAsString() const; + String getRecursiveAttributesAsString() const; // + all parent's attributes protected: String mName; diff --git a/src/opt/hdf5/include/h5_group.cc.h b/src/opt/hdf5/include/h5_group.cc.h index b1b1b50..033c2d2 100644 --- a/src/opt/hdf5/include/h5_group.cc.h +++ b/src/opt/hdf5/include/h5_group.cc.h @@ -3,6 +3,7 @@ #define __cxz_h5_group_cc_h__ #include "h5_group.h" +#include "xpr/for.h" namespace CNORXZ { @@ -54,6 +55,22 @@ namespace CNORXZ return *this; } + template + decltype(auto) Group::iter(F&& f) const + { + RangePtr gr = *mCont.range()->sub().begin(); + auto gi = std::make_shared>(gr); + return gi->ifor( operation(std::forward(f), mCont(gi)), NoF{} ); + } + + template + decltype(auto) Group::iterRecursive(F&& f) const + { + return iter( [&](const auto& c) { + f(c); + recursion(c, std::forward(f)); + }); + } } } diff --git a/src/opt/hdf5/include/h5_group.h b/src/opt/hdf5/include/h5_group.h index 571c752..28c6616 100644 --- a/src/opt/hdf5/include/h5_group.h +++ b/src/opt/hdf5/include/h5_group.h @@ -41,8 +41,27 @@ namespace CNORXZ template Group& addTable(const String& name, const ArrayBase>& data, const Vector& fnames); + + template + decltype(auto) iter(F&& f) const; + + template + decltype(auto) iterRecursive(F&& f) const; protected: + + template + static void recursion(const C& c, F&& f) + { + if(c->type() == ContentType::GROUP){ + auto cx = std::dynamic_pointer_cast(c); + cx->open(); + if(cx->get().range() != nullptr){ + cx->iterRecursive(std::forward(f))(); + } + } + } + MArray mCont; void mkCont(); diff --git a/src/opt/hdf5/lib/h5_file.cc b/src/opt/hdf5/lib/h5_file.cc index ec1452e..d1ba58c 100644 --- a/src/opt/hdf5/lib/h5_file.cc +++ b/src/opt/hdf5/lib/h5_file.cc @@ -67,7 +67,8 @@ namespace CNORXZ String File::path() const { - return String("/"); + //return String("/"); + return ""; } String File::filename() const diff --git a/src/opt/hdf5/tests/h5_basic_unit_test.cc b/src/opt/hdf5/tests/h5_basic_unit_test.cc index 6a3114a..a0f1ce8 100644 --- a/src/opt/hdf5/tests/h5_basic_unit_test.cc +++ b/src/opt/hdf5/tests/h5_basic_unit_test.cc @@ -39,7 +39,7 @@ namespace Group_Test() { mFileName = testh5file; - mGrps = { "gr1", "gr2" }; + //mGrps = { "gr1", "gr2", "foo", "bar", "moregroups" }; mFs = {"field1","second","real"}; Vector> v ( { {0, -6, 3.141}, @@ -53,7 +53,7 @@ namespace } String mFileName; - Vector mGrps; + //Vector mGrps; Vector mFs; MArray> mTabA; @@ -82,7 +82,15 @@ namespace h5f.open(); h5f.addGroup("gr1"); h5f.addGroup("gr2"); - EXPECT_EQ(h5f.get().size(), 2u); + h5f.addGroup("foo"); + h5f.addGroup("moregroups"); + h5f.addGroup("bar"); + h5f.getGroup("moregroups")->open().addGroup("evenmore"); + h5f.getGroup("moregroups")->getGroup("evenmore")->open().addGroup("we"); + h5f.getGroup("moregroups")->getGroup("evenmore")->addGroup("need"); + h5f.getGroup("moregroups")->getGroup("evenmore")->addGroup("more"); + h5f.getGroup("moregroups")->getGroup("evenmore")->addGroup("groups"); + EXPECT_EQ(h5f.get().size(), 5u); h5f.close(); } @@ -100,14 +108,17 @@ namespace File h5f(mFileName, true); h5f.open(); EXPECT_TRUE(h5f.ro()); - EXPECT_EQ(h5f.get().size(), 2u); + EXPECT_EQ(h5f.get().size(), 5u); EXPECT_THROW(h5f.getGroup("gr0"), std::runtime_error); auto gr1 = h5f.getGroup("gr1"); gr1->open(); auto tab = gr1->getTable("tab1"); + VCHECK(tab->path()); EXPECT_EQ(tab->fields()->size(), 3u); EXPECT_EQ(tab->records()->size(), 5u); + h5f.iter( [](const auto& c) { VCHECK(c->path()); } )(); + h5f.iterRecursive( [](const auto& c) { VCHECK(c->path()); } )(); h5f.close(); } }