dev #2

Merged
chizeta merged 32 commits from dev into main 2024-02-02 20:36:53 +01:00
5 changed files with 60 additions and 5 deletions
Showing only changes of commit d5b42c9c00 - Show all commits

View file

@ -39,6 +39,13 @@ namespace CNORXZ
hid_t id() const;
inline bool isOpen() const { return mId != 0; }
template <typename T>
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;
const ContentBase* mParent = nullptr;

View file

@ -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 <class F>
decltype(auto) Group::iter(F&& f) const
{
RangePtr gr = *mCont.range()->sub().begin();
auto gi = std::make_shared<UIndex<String>>(gr);
return gi->ifor( operation(std::forward<F>(f), mCont(gi)), NoF{} );
}
template <class F>
decltype(auto) Group::iterRecursive(F&& f) const
{
return iter( [&](const auto& c) {
f(c);
recursion(c, std::forward<F>(f));
});
}
}
}

View file

@ -42,7 +42,26 @@ namespace CNORXZ
Group& addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
const Vector<String>& fnames);
template <class F>
decltype(auto) iter(F&& f) const;
template <class F>
decltype(auto) iterRecursive(F&& f) const;
protected:
template <typename C, class F>
static void recursion(const C& c, F&& f)
{
if(c->type() == ContentType::GROUP){
auto cx = std::dynamic_pointer_cast<Group>(c);
cx->open();
if(cx->get().range() != nullptr){
cx->iterRecursive(std::forward<F>(f))();
}
}
}
MArray<ContentPtr> mCont;
void mkCont();

View file

@ -67,7 +67,8 @@ namespace CNORXZ
String File::path() const
{
return String("/");
//return String("/");
return "";
}
String File::filename() const

View file

@ -39,7 +39,7 @@ namespace
Group_Test()
{
mFileName = testh5file;
mGrps = { "gr1", "gr2" };
//mGrps = { "gr1", "gr2", "foo", "bar", "moregroups" };
mFs = {"field1","second","real"};
Vector<Tuple<SizeT,Int,Double>> v
( { {0, -6, 3.141},
@ -53,7 +53,7 @@ namespace
}
String mFileName;
Vector<String> mGrps;
//Vector<String> mGrps;
Vector<String> mFs;
MArray<Tuple<SizeT,Int,Double>> 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();
}
}