dev #2

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

View file

@ -59,6 +59,7 @@ namespace CNORXZ
template <class F>
decltype(auto) Group::iter(F&& f) const
{
CXZ_ASSERT(isOpen(), "try to iterate over closed object");
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{} );
@ -76,6 +77,7 @@ namespace CNORXZ
template <class F>
decltype(auto) Group::iter(F&& f)
{
CXZ_ASSERT(isOpen(), "try to iterate over closed object");
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{} );

View file

@ -9,6 +9,16 @@ namespace CNORXZ
{
namespace hdf5
{
template <class F>
decltype(auto) Table::iterRecords(F&& f) const
{
auto ri = std::make_shared<CIndex>(mRecords);
return ri->ifor
( operation( std::forward<F>(f),
operation( [&](const SizeT pos) { return readRecord(pos); } ,
xpr(ri) ) ), NoF{} );
}
template <typename... Ts>
template <class F>
decltype(auto) STable<Ts...>::iterRecords(F&& f) const

View file

@ -31,6 +31,9 @@ namespace CNORXZ
Table& readRecords(SizeT pos, SizeT n, char* data);
MArray<DType> readRecord(SizeT pos) const;
MArray<DType> read() const;
template <class F>
decltype(auto) iterRecords(F&& f) const;
const RangePtr& fields() const;
const RangePtr& records() const;

View file

@ -174,6 +174,59 @@ namespace
}
h5f.close();
}
TEST_F(Group_Test, Read2)
{
File h5f(mFileName, true);
h5f.open();
Vector<String> paths;
Vector<String> attrs;
auto checkatt = [](const std::map<String,DType>& m,
const std::map<String,DType>& cs) {
for(const auto& c: cs){
if(m.count(c.first)){
if(m.at(c.first).str() != c.second.str()){
return false;
}
}
else {
return false;
}
}
return true;
};
std::map<String,DType> constr;
constr["wex"] = DType(Vector<Int>{7});
constr["second"] = DType(static_cast<Int>(-777));
h5f.iterRecursive( [&](const auto& c) {
if(c->type() == ContentType::TABLE) {
c->open();
auto av = c->getRecursiveAttributes();
auto cx = std::dynamic_pointer_cast<Table>(c);
SizeT cnt = 0;
cx->iterRecords( [&](const MArray<DType>& r) {
auto ax = av;
auto fi = UIndex<std::pair<SizeT,String>>(r.range()->sub(0));
for(; fi.lex() != fi.lmax().val(); ++fi) { ax[fi.meta().second] = r[fi]; }
attrs.push_back(toString(ax));
if(checkatt(ax,constr)){
paths.push_back(c->path()+"/@"+toString(cnt));
}
++cnt;
} )();
}
} )();
for(const auto& x: attrs){
VCHECK(x);
}
for(const auto& p: paths){
VCHECK(p);
}
EXPECT_EQ(paths.size(), 1u);
EXPECT_EQ(paths[0], "/moregroups/evenmore/need/tab1/@3");
h5f.close();
}
}
// check write to new file