diff --git a/src/opt/hdf5/include/h5_group.cc.h b/src/opt/hdf5/include/h5_group.cc.h
index a50c64c..f8f9971 100644
--- a/src/opt/hdf5/include/h5_group.cc.h
+++ b/src/opt/hdf5/include/h5_group.cc.h
@@ -14,19 +14,20 @@ namespace CNORXZ
{
auto i = this->getIndexTo(name);
auto tab = std::dynamic_pointer_cast
( *i );
+ CXZ_ASSERT(tab->type() == ContentType::TABLE,
+ "element '" << name << "' is not of type TABLE");
if(tab == nullptr){
auto stab = std::dynamic_pointer_cast>(*i);
CXZ_ASSERT(stab != nullptr, "wrong format for table '" << name << "'");
return stab;
}
else {
- const RangePtr fields = tab->fields();
(*i)->close();
- *i = std::make_shared>(name, this, fields);
- return *i;
+ auto stab = std::make_shared>(name, this);
+ *i = stab;
+ return stab;
}
}
-
template
Group& Group::addData(const String& name, const ArrayBase& data)
@@ -38,7 +39,7 @@ namespace CNORXZ
template
Group& Group::addTable(const String& name, const ArrayBase>& data,
- const Vector& fnames)
+ const Arr& fnames)
{
CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
Vector nvec({name});
diff --git a/src/opt/hdf5/include/h5_group.h b/src/opt/hdf5/include/h5_group.h
index afee4b1..babb886 100644
--- a/src/opt/hdf5/include/h5_group.h
+++ b/src/opt/hdf5/include/h5_group.h
@@ -40,7 +40,7 @@ namespace CNORXZ
template
Group& addTable(const String& name, const ArrayBase>& data,
- const Vector& fnames);
+ const Arr& fnames);
template
decltype(auto) iter(F&& f) const;
diff --git a/src/opt/hdf5/include/h5_table.cc.h b/src/opt/hdf5/include/h5_table.cc.h
index 5e4c4d9..2072bd6 100644
--- a/src/opt/hdf5/include/h5_table.cc.h
+++ b/src/opt/hdf5/include/h5_table.cc.h
@@ -18,36 +18,13 @@ namespace CNORXZ
}
template
- STable::STable(const String& name, const ContentBase* _parent,
- const Vector& fnames) :
+ STable::STable(const String& name, const ContentBase* _parent) :
Table(name, _parent)
{
constexpr SizeT N = sizeof...(Ts);
if(mFields == nullptr){
- CXZ_ASSERT(fnames.size() != 0, "field names have to be initialized");
- Vector fields(fnames.size());
- for(SizeT i = 0; i != fields.size(); ++i){
- fields[i].first = i;
- fields[i].second = fnames[i];
- }
- mFields = URangeFactory(fields).create();
- }
- CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
- << ", got: " << sizeof...(Ts));
- Tuple x;
- if(mRecords == nullptr) {
- mOffsets = MArray( mFields, iter<0,N>
- ( [&](auto i) { return getTupleOffset(x, i); },
- [](const auto&... e) { return Vector({e...}); }) );
- mSizes = MArray( mFields, iter<0,N>
- ( [&](auto i) { return sizeof(std::get(x)); },
- [](const auto&... e) { return Vector({e...}); }) );
- mTypes = MArray( mFields, iter<0,N>
- ( [&](auto i) { return getTypeId(std::get(x)); },
- [](const auto&... e) { return Vector({e...}); }) );
- }
- else {
+ Tuple x;
iter<0,N>( [&](auto i) { CXZ_ASSERT
( getTupleOffset(x, i) == mOffsets.data()[i],
"wrong offset for field " << i << ": " << getTupleOffset(x, i)
@@ -61,6 +38,48 @@ namespace CNORXZ
"wrong type for field " << i << ": " << getTypeId(std::get(x))
<< " vs " << mTypes.data()[i] ); }, NoF{} );
}
+ else {
+ CXZ_ASSERT(mFields->size() == N, "expected tuple of size = " << mFields->size()
+ << ", got: " << N);
+ }
+ }
+
+ template
+ STable::STable(const String& name, const ContentBase* _parent,
+ const Arr& fnames) :
+ Table(name, _parent)
+ {
+ initFields(fnames);
+ }
+
+ template
+ STable& STable::initFields(const Arr& fnames)
+ {
+ constexpr SizeT N = sizeof...(Ts);
+ CXZ_ASSERT(mFields == nullptr and mRecords == nullptr,
+ "tried to initialize an existing table");
+
+ Vector fields(fnames.size());
+ for(SizeT i = 0; i != fields.size(); ++i){
+ fields[i].first = i;
+ fields[i].second = fnames[i];
+ }
+ mFields = URangeFactory(fields).create();
+
+ Tuple x;
+ mOffsets = MArray
+ ( mFields, iter<0,N>
+ ( [&](auto i) { return getTupleOffset(x, i); },
+ [](const auto&... e) { return Vector({e...}); }) );
+ mSizes = MArray
+ ( mFields, iter<0,N>
+ ( [&](auto i) { return sizeof(std::get(x)); },
+ [](const auto&... e) { return Vector({e...}); }) );
+ mTypes = MArray
+ ( mFields, iter<0,N>
+ ( [&](auto i) { return getTypeId(std::get(x)); },
+ [](const auto&... e) { return Vector({e...}); }) );
+ return *this;
}
template
@@ -75,6 +94,14 @@ namespace CNORXZ
}
return *this;
}
+
+ template
+ MArray> STable::read()
+ {
+ MArray> out(mRecords);
+ //...!!!
+ return out;
+ }
}
}
diff --git a/src/opt/hdf5/include/h5_table.h b/src/opt/hdf5/include/h5_table.h
index 8885230..6a9497b 100644
--- a/src/opt/hdf5/include/h5_table.h
+++ b/src/opt/hdf5/include/h5_table.h
@@ -46,8 +46,12 @@ namespace CNORXZ
{
public:
DEFAULT_MEMBERS(STable);
- STable(const String& name, const ContentBase* _parent, const Vector& fnames);
+ STable(const String& name, const ContentBase* _parent);
+ STable(const String& name, const ContentBase* _parent,
+ const Arr& fnames);
+ STable& initFields(const Arr& fnames);
+
STable& appendRecord(const Tuple& t);
STable& appendRecord(const MArray>& t);
diff --git a/src/opt/hdf5/tests/h5_basic_unit_test.cc b/src/opt/hdf5/tests/h5_basic_unit_test.cc
index 1221aaa..603ba27 100644
--- a/src/opt/hdf5/tests/h5_basic_unit_test.cc
+++ b/src/opt/hdf5/tests/h5_basic_unit_test.cc
@@ -55,7 +55,7 @@ namespace
String mFileName;
//Vector mGrps;
- Vector mFs;
+ Arr mFs;
MArray> mTabA;
};
@@ -142,12 +142,13 @@ namespace
TEST_F(Group_Test, ReadTable)
{
+ typedef Tuple RecType;
+
File h5f(mFileName, true);
h5f.open();
- auto tab = h5f.getGroup("gr1")->open().getTable("tab1");
+ auto tab = h5f.getGroup("gr1")->open().getTable("tab1", RecType());
EXPECT_EQ(tab->fields()->size(), 3u);
EXPECT_EQ(tab->records()->size(), 5u);
-
}
}