dev #2
5 changed files with 68 additions and 35 deletions
|
@ -14,20 +14,21 @@ namespace CNORXZ
|
|||
{
|
||||
auto i = this->getIndexTo(name);
|
||||
auto tab = std::dynamic_pointer_cast<Table>( *i );
|
||||
CXZ_ASSERT(tab->type() == ContentType::TABLE,
|
||||
"element '" << name << "' is not of type TABLE");
|
||||
if(tab == nullptr){
|
||||
auto stab = std::dynamic_pointer_cast<STable<Ts...>>(*i);
|
||||
CXZ_ASSERT(stab != nullptr, "wrong format for table '" << name << "'");
|
||||
return stab;
|
||||
}
|
||||
else {
|
||||
const RangePtr fields = tab->fields();
|
||||
(*i)->close();
|
||||
*i = std::make_shared<STable<Ts...>>(name, this, fields);
|
||||
return *i;
|
||||
auto stab = std::make_shared<STable<Ts...>>(name, this);
|
||||
*i = stab;
|
||||
return stab;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
Group& Group::addData(const String& name, const ArrayBase<T>& data)
|
||||
{
|
||||
|
@ -38,7 +39,7 @@ namespace CNORXZ
|
|||
|
||||
template <typename... Ts>
|
||||
Group& Group::addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
||||
const Vector<String>& fnames)
|
||||
const Arr<String,sizeof...(Ts)>& fnames)
|
||||
{
|
||||
CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
|
||||
Vector<String> nvec({name});
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace CNORXZ
|
|||
|
||||
template <typename... Ts>
|
||||
Group& addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
||||
const Vector<String>& fnames);
|
||||
const Arr<String,sizeof...(Ts)>& fnames);
|
||||
|
||||
template <class F>
|
||||
decltype(auto) iter(F&& f) const;
|
||||
|
|
|
@ -18,36 +18,13 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <typename... Ts>
|
||||
STable<Ts...>::STable(const String& name, const ContentBase* _parent,
|
||||
const Vector<String>& fnames) :
|
||||
STable<Ts...>::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<FieldID> fields(fnames.size());
|
||||
for(SizeT i = 0; i != fields.size(); ++i){
|
||||
fields[i].first = i;
|
||||
fields[i].second = fnames[i];
|
||||
}
|
||||
mFields = URangeFactory<FieldID>(fields).create();
|
||||
}
|
||||
CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
|
||||
<< ", got: " << sizeof...(Ts));
|
||||
|
||||
Tuple<Ts...> x;
|
||||
if(mRecords == nullptr) {
|
||||
mOffsets = MArray<SizeT>( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTupleOffset(x, i); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
mSizes = MArray<SizeT>( mFields, iter<0,N>
|
||||
( [&](auto i) { return sizeof(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
mTypes = MArray<hid_t>( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTypeId(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<hid_t>({e...}); }) );
|
||||
}
|
||||
else {
|
||||
Tuple<Ts...> 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<i>(x))
|
||||
<< " vs " << mTypes.data()[i] ); }, NoF{} );
|
||||
}
|
||||
else {
|
||||
CXZ_ASSERT(mFields->size() == N, "expected tuple of size = " << mFields->size()
|
||||
<< ", got: " << N);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
STable<Ts...>::STable(const String& name, const ContentBase* _parent,
|
||||
const Arr<String,sizeof...(Ts)>& fnames) :
|
||||
Table(name, _parent)
|
||||
{
|
||||
initFields(fnames);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
STable<Ts...>& STable<Ts...>::initFields(const Arr<String,sizeof...(Ts)>& fnames)
|
||||
{
|
||||
constexpr SizeT N = sizeof...(Ts);
|
||||
CXZ_ASSERT(mFields == nullptr and mRecords == nullptr,
|
||||
"tried to initialize an existing table");
|
||||
|
||||
Vector<FieldID> fields(fnames.size());
|
||||
for(SizeT i = 0; i != fields.size(); ++i){
|
||||
fields[i].first = i;
|
||||
fields[i].second = fnames[i];
|
||||
}
|
||||
mFields = URangeFactory<FieldID>(fields).create();
|
||||
|
||||
Tuple<Ts...> x;
|
||||
mOffsets = MArray<SizeT>
|
||||
( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTupleOffset(x, i); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
mSizes = MArray<SizeT>
|
||||
( mFields, iter<0,N>
|
||||
( [&](auto i) { return sizeof(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
mTypes = MArray<hid_t>
|
||||
( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTypeId(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<hid_t>({e...}); }) );
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
|
@ -75,6 +94,14 @@ namespace CNORXZ
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
MArray<Tuple<Ts...>> STable<Ts...>::read()
|
||||
{
|
||||
MArray<Tuple<Ts...>> out(mRecords);
|
||||
//...!!!
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,11 @@ namespace CNORXZ
|
|||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(STable);
|
||||
STable(const String& name, const ContentBase* _parent, const Vector<String>& fnames);
|
||||
STable(const String& name, const ContentBase* _parent);
|
||||
STable(const String& name, const ContentBase* _parent,
|
||||
const Arr<String,sizeof...(Ts)>& fnames);
|
||||
|
||||
STable& initFields(const Arr<String,sizeof...(Ts)>& fnames);
|
||||
|
||||
STable& appendRecord(const Tuple<Ts...>& t);
|
||||
STable& appendRecord(const MArray<Tuple<Ts...>>& t);
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace
|
|||
String mFileName;
|
||||
//Vector<String> mGrps;
|
||||
|
||||
Vector<String> mFs;
|
||||
Arr<String,3> mFs;
|
||||
MArray<Tuple<SizeT,Int,Double>> mTabA;
|
||||
};
|
||||
|
||||
|
@ -142,13 +142,14 @@ namespace
|
|||
|
||||
TEST_F(Group_Test, ReadTable)
|
||||
{
|
||||
typedef Tuple<SizeT,Int,Double> 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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue