hdf5: include cc.h files + corresp compile fixes

This commit is contained in:
Christian Zimmermann 2023-01-24 00:02:32 +01:00
parent 0db94229bf
commit 6faaf7ea15
7 changed files with 65 additions and 60 deletions

View file

@ -0,0 +1,4 @@
#include "h5_types.cc.h"
#include "h5_group.cc.h"
#include "h5_table.cc.h"

View file

@ -2,3 +2,7 @@
#include "h5_content_base.h" #include "h5_content_base.h"
#include "h5_file.h" #include "h5_file.h"
#include "h5_group.h" #include "h5_group.h"
#include "h5_table.h"
#include "h5_types.h"
#include "cnorxz_hdf5.cc.h"

View file

@ -9,14 +9,16 @@ namespace CNORXZ
{ {
namespace hdf5 namespace hdf5
{ {
template <typename... Ts>
template <class F> template <class F>
decltype(auto) iterRecords(F&& f) const decltype(auto) STable<Ts...>::iterRecords(F&& f) const
{ {
CXZ_ERROR("not implemented");
return f(0);
} }
template <typename... Ts> template <typename... Ts>
STabel<Ts...>::STabel(const String& name, const ContentBase* _parent, const RangePtr& fields) : STable<Ts...>::STable(const String& name, const ContentBase* _parent, const RangePtr& fields) :
Table(name, _parent) Table(name, _parent)
{ {
constexpr SizeT N = sizeof...(Ts); constexpr SizeT N = sizeof...(Ts);
@ -27,35 +29,36 @@ namespace CNORXZ
CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size() CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
<< ", got: " << sizeof...(Ts)); << ", got: " << sizeof...(Ts));
Tuple<Ts...> x;
if(mRecords == nullptr) { if(mRecords == nullptr) {
auto mOffsets = MArray<SizeT>( mFields, iter<0,N> auto mOffsets = MArray<SizeT>( mFields, iter<0,N>
( [&](auto i) { return &std::get<i>(t) - &t; }, ( [&](auto i) { return &std::get<i>(x) - &x; },
[](const auto&... e) { return Vector<SizeT>({e...}); }) ); [](const auto&... e) { return Vector<SizeT>({e...}); }) );
auto mSizes = MArray<SizeT>( mFields, iter<0,N> auto mSizes = MArray<SizeT>( mFields, iter<0,N>
( [&](auto i) { return sizeof(std::get<i>(t)); }, ( [&](auto i) { return sizeof(std::get<i>(x)); },
[](const auto&... e) { return Vector<SizeT>({e...}); }) ); [](const auto&... e) { return Vector<SizeT>({e...}); }) );
auto mTypes = MArray<hid_t>( mFields, iter<0,N> auto mTypes = MArray<hid_t>( mFields, iter<0,N>
( [&](auto i) { return getTypeId(std::get<i>(t)); }, ( [&](auto i) { return getTypeId(std::get<i>(x)); },
[](const auto&... e) { return Vector<hid_t>({e...}); }) ); [](const auto&... e) { return Vector<hid_t>({e...}); }) );
} }
else { else {
iter<0,N>( [&](auto i) { CXZ_ASSERT iter<0,N>( [&](auto i) { CXZ_ASSERT
( &std::get<i>(t) - &t == mOffsets.data()[i], ( &std::get<i>(x) - &x == mOffsets.data()[i],
"wrong offset for field " << i << ": " << &std::get<i>(t) - &t "wrong offset for field " << i << ": " << &std::get<i>(x) - &x
<< " vs " << mOffsets.data()[i] ); }, NoF{} ); << " vs " << mOffsets.data()[i] ); }, NoF{} );
iter<0,N>( [&](auto i) { CXZ_ASSERT iter<0,N>( [&](auto i) { CXZ_ASSERT
( sizeof(std::get<i>(t)) == mSizes.data()[i], ( sizeof(std::get<i>(x)) == mSizes.data()[i],
"wrong size for field " << i << ": " << sizeof(std::get<i>(t)) "wrong size for field " << i << ": " << sizeof(std::get<i>(x))
<< " vs " << mSizes.data()[i] ); }, NoF{} ); << " vs " << mSizes.data()[i] ); }, NoF{} );
iter<0,N>( [&](auto i) { CXZ_ASSERT iter<0,N>( [&](auto i) { CXZ_ASSERT
( getTypeId(std::get<i>(t)) == mTypes.data()[i], ( getTypeId(std::get<i>(x)) == mTypes.data()[i],
"wrong type for field " << i << ": " << getTypeId(std::get<i>(t)) "wrong type for field " << i << ": " << getTypeId(std::get<i>(x))
<< " vs " << mTypes.data()[i] ); }, NoF{} ); << " vs " << mTypes.data()[i] ); }, NoF{} );
} }
} }
template <typename... Ts> template <typename... Ts>
STabel& STabel<Ts...>::appendRecord(const Tuple<Ts...>& t) STable<Ts...>& STable<Ts...>::appendRecord(const Tuple<Ts...>& t)
{ {
RangePtr appr = CRangeFactory(1).create(); RangePtr appr = CRangeFactory(1).create();
if(mRecords == nullptr){ if(mRecords == nullptr){

View file

@ -37,14 +37,14 @@ namespace CNORXZ
}; };
template <typename... Ts> template <typename... Ts>
class STabel : public Table class STable : public Table
{ {
public: public:
DEFAULT_MEMBERS(STabel); DEFAULT_MEMBERS(STable);
STabel(const String& name, const ContentBase* _parent, const RangePtr& fields); STable(const String& name, const ContentBase* _parent, const RangePtr& fields);
Table& appendRecord(const Tuple<Ts...>& t); STable& appendRecord(const Tuple<Ts...>& t);
Table& appendRecord(const MArray<Tuple<Ts...>>& t); STable& appendRecord(const MArray<Tuple<Ts...>>& t);
template <class F> template <class F>
decltype(auto) iterRecords(F&& f) const; decltype(auto) iterRecords(F&& f) const;

View file

@ -6,22 +6,38 @@ namespace CNORXZ
{ {
namespace hdf5 namespace hdf5
{ {
template <typename T, SizeT N> template <typename T>
inline hid_t TypeId<Arr<T,N>>::get(Arr<T,N> x) inline hid_t TypeId<T>::get()
{ {
static hid_t arrtype = H5Tarray_create2(getTypeId(x[0]), 1, N); return 0;
}
inline hid_t TypeId<SizeT>::get()
{
return H5T_NATIVE_ULONG;
}
inline hid_t TypeId<Int>::get()
{
return H5T_NATIVE_INT;
}
inline hid_t TypeId<Double>::get()
{
return H5T_NATIVE_DOUBLE;
}
template <typename T, SizeT N>
inline hid_t TypeId<Arr<T,N>>::get()
{
static hid_t arrtype = H5Tarray_create2(TypeId<T>::get(), 1, N);
return arrtype; return arrtype;
} }
template <typename T> template <typename T>
hid_t getTypeId(T x) hid_t getTypeId(T x)
{ {
if constexpr (TypeIsNative<T>::value){ return TypeId<T>::get();
return NativeTypeId<T>::value;
}
else {
return TypeId<T>::get(x);
}
} }
} }

View file

@ -6,44 +6,22 @@ namespace CNORXZ
{ {
namespace hdf5 namespace hdf5
{ {
/********************
* TypeIsNative *
********************/
template <typename T>
struct TypeIsNative { static constexpr bool value = false; };
template <>
struct TypeIsNative<SizeT> { static constexpr bool value = true; };
template <typename T>
struct TypeIsNative<Int> { static constexpr bool value = true; };
template <typename T>
struct TypeIsNative<Double> { static constexpr bool value = true; };
/********************
* NativeTypeId *
********************/
template <typename T>
struct NativeTypeId { static constexpr hid_t value = 0; };
template <>
struct NativeTypeId<SizeT> { static constexpr hid_t value = H5T_NATIVE_ULONG; };
template <>
struct NativeTypeId<Int> { static constexpr hid_t value = H5T_NATIVE_INT; };
template <>
struct NativeTypeId<Double> { static constexpr hid_t value = H5T_NATIVE_DOUBLE; };
/************** /**************
* TypeId * * TypeId *
**************/ **************/
template <typename T> template <typename T>
struct TypeId<T> { static inline hid_t get() { return 0; } }; struct TypeId { static inline hid_t get(); };
template <>
struct TypeId<SizeT> { static inline hid_t get(); };
template <>
struct TypeId<Int> { static inline hid_t get(); };
template <>
struct TypeId<Double> { static inline hid_t get(); };
template <typename T, SizeT N> template <typename T, SizeT N>
struct TypeId<Arr<T,N>> { static inline hid_t get(); }; struct TypeId<Arr<T,N>> { static inline hid_t get(); };

View file

@ -9,7 +9,7 @@ namespace CNORXZ
Table::Table(const String& name, const ContentBase* _parent) : Table::Table(const String& name, const ContentBase* _parent) :
ContentBase(name, _parent) ContentBase(name, _parent)
{ {
if(H5Lexists_by_name(mParent->id(), mName.c_str(), H5P_DEFAULT)){ if(H5Lexists(mParent->id(), mName.c_str(), H5P_DEFAULT)){
hsize_t nfields = 0; hsize_t nfields = 0;
hsize_t nrecords = 0; hsize_t nrecords = 0;
H5TBget_table_info(mParent->id(), mName.c_str(), &nfields, &nrecords); H5TBget_table_info(mParent->id(), mName.c_str(), &nfields, &nrecords);