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_file.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
{
template <typename... Ts>
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>
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)
{
constexpr SizeT N = sizeof...(Ts);
@ -27,35 +29,36 @@ namespace CNORXZ
CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
<< ", got: " << sizeof...(Ts));
Tuple<Ts...> x;
if(mRecords == nullptr) {
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...}); }) );
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...}); }) );
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...}); }) );
}
else {
iter<0,N>( [&](auto i) { CXZ_ASSERT
( &std::get<i>(t) - &t == mOffsets.data()[i],
"wrong offset for field " << i << ": " << &std::get<i>(t) - &t
( &std::get<i>(x) - &x == mOffsets.data()[i],
"wrong offset for field " << i << ": " << &std::get<i>(x) - &x
<< " vs " << mOffsets.data()[i] ); }, NoF{} );
iter<0,N>( [&](auto i) { CXZ_ASSERT
( sizeof(std::get<i>(t)) == mSizes.data()[i],
"wrong size for field " << i << ": " << sizeof(std::get<i>(t))
( sizeof(std::get<i>(x)) == mSizes.data()[i],
"wrong size for field " << i << ": " << sizeof(std::get<i>(x))
<< " vs " << mSizes.data()[i] ); }, NoF{} );
iter<0,N>( [&](auto i) { CXZ_ASSERT
( getTypeId(std::get<i>(t)) == mTypes.data()[i],
"wrong type for field " << i << ": " << getTypeId(std::get<i>(t))
( getTypeId(std::get<i>(x)) == mTypes.data()[i],
"wrong type for field " << i << ": " << getTypeId(std::get<i>(x))
<< " vs " << mTypes.data()[i] ); }, NoF{} );
}
}
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();
if(mRecords == nullptr){

View file

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

View file

@ -6,22 +6,38 @@ namespace CNORXZ
{
namespace hdf5
{
template <typename T, SizeT N>
inline hid_t TypeId<Arr<T,N>>::get(Arr<T,N> x)
template <typename T>
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;
}
template <typename T>
hid_t getTypeId(T x)
{
if constexpr (TypeIsNative<T>::value){
return NativeTypeId<T>::value;
}
else {
return TypeId<T>::get(x);
}
return TypeId<T>::get();
}
}

View file

@ -6,44 +6,22 @@ namespace CNORXZ
{
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 *
**************/
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>
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) :
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 nrecords = 0;
H5TBget_table_info(mParent->id(), mName.c_str(), &nfields, &nrecords);