CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
h5_table.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_h5_table_cc_h__
13#define __cxz_h5_table_cc_h__
14
15#include "h5_table.h"
16#include "h5_type_id.h"
17
18namespace CNORXZ
19{
20 namespace hdf5
21 {
22 template <class F>
23 decltype(auto) Table::iterRecords(F&& f) const
24 {
25 auto ri = std::make_shared<CIndex>(mRecords);
26 return ri->ifor
27 ( operation( std::forward<F>(f),
28 operation( [&](const SizeT pos) { return readRecord(pos); } ,
29 xpr(ri) ) ), NoF{} );
30 }
31
32 template <typename... Ts>
33 template <class F>
34 decltype(auto) STable<Ts...>::iterRecords(F&& f) const
35 {
36 CXZ_ERROR("not implemented");
37 return f(0);
38 }
39
40 template <typename... Ts>
42 Table(name, _parent)
43 {
44 constexpr SizeT N = sizeof...(Ts);
45 if(mFields != nullptr){
46
47 CXZ_ASSERT(mFields->size() == N, "expected tuple of size = " << mFields->size()
48 << ", got: " << N);
49 Tuple<Ts...> x;
50 iter<0,N>( [&](auto i) { CXZ_ASSERT
51 ( getTupleOffset(x, i) == mOffsets.data()[i],
52 "wrong offset for field " << i << ": " << getTupleOffset(x, i)
53 << " vs " << mOffsets.data()[i] ); }, NoF{} );
54 iter<0,N>( [&](auto i) { CXZ_ASSERT
55 ( sizeof(tget<i>(x)) == mSizes.data()[i],
56 "wrong size for field " << i << ": " << sizeof(tget<i>(x))
57 << " vs " << mSizes.data()[i] ); }, NoF{} );
58 iter<0,N>( [&](auto i) { CXZ_ASSERT
60 "wrong type for field " << i
61 << ": " << H5Tget_class(getTypeId(tget<i>(x)))
62 << " vs " << mTypes.data()[i] ); }, NoF{} );
63 }
64 }
65
66 template <typename... Ts>
68 const Arr<String,sizeof...(Ts)>& fnames) :
69 Table(name, _parent)
70 {
72 }
73
74 template <typename... Ts>
76 {
77 constexpr SizeT N = sizeof...(Ts);
78 CXZ_ASSERT(mFields == nullptr and mRecords == nullptr,
79 "tried to initialize an existing table");
80
81 Vector<FieldID> fields(fnames.size());
82 for(SizeT i = 0; i != fields.size(); ++i){
83 fields[i].first = i;
84 fields[i].second = fnames[i];
85 }
86 mFields = URangeFactory<FieldID>(fields).create();
87
88 Tuple<Ts...> x;
89 mOffsets = MArray<SizeT>
90 ( mFields, iter<0,N>
91 ( [&](auto i) { return getTupleOffset(x, i); },
92 [](const auto&... e) { return Vector<SizeT>({e...}); }) );
93 mSizes = MArray<SizeT>
94 ( mFields, iter<0,N>
95 ( [&](auto i) { return sizeof(tget<i>(x)); },
96 [](const auto&... e) { return Vector<SizeT>({e...}); }) );
97 mTypes = MArray<hid_t>
98 ( mFields, iter<0,N>
99 ( [&](auto i) { return getTypeId(tget<i>(x)); },
100 [](const auto&... e) { return Vector<hid_t>({e...}); }) );
101 return *this;
102 }
103
104 template <typename... Ts>
106 {
108 if(mRecords == nullptr){
109 initTable(1, &t, sizeof(t), sizeof(t));
110 }
111 else {
113 }
114 return *this;
115 }
116
117 template <typename... Ts>
119 {
120 CXZ_ASSERT(isOpen(), "attempt to read table that has not been opened");
121 MArray<Tuple<Ts...>> out(mRecords);
122 H5TBread_table(mParent->id(), mName.c_str(), mTypesize, mOffsets.data(),
123 mSizes.data(), out.data());
124 return out;
125 }
126 }
127}
128
129#endif
#define CXZ_ERROR(errmsg)
Definition assert.h:26
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
virtual const T * data() const override
Definition marray.cc.h:65
STable(const String &name, const ContentBase *_parent)
Definition h5_table.cc.h:41
MArray< Tuple< Ts... > > read() const
STable & appendRecord(const Tuple< Ts... > &t)
STable & initFields(const Arr< String, sizeof...(Ts)> &fnames)
Definition h5_table.cc.h:75
MArray< SizeT > mSizes
Definition h5_table.h:105
Table & appendRecords(SizeT n, const void *data)
Definition h5_table.cc:137
decltype(auto) iterRecords(F &&f) const
Definition h5_table.cc.h:23
MArray< hid_t > mTypes
Definition h5_table.h:107
MArray< SizeT > mOffsets
Definition h5_table.h:106
Table declaration.
TypeId template declaration.
hid_t getTypeId(T x)
SizeT getTupleOffset(const Tuple< Ts... > &t, CSizeT< N > i)
Definition h5_group.cc.h:35
std::string String
Definition types.h:42
uint64_t SizeT
Definition types.h:38
Sptr< RangeBase > RangePtr
Definition types.h:157
std::vector< T, Allocator< T > > Vector
Definition types.h:310
decltype(auto) xpr(const Sptr< I > &i)
Sptr< Range > rangeCast(const RangePtr r)
std::tuple< T... > Tuple
Definition types.h:60
std::array< T, N > Arr
Definition types.h:45
constexpr decltype(auto) operation(F &&f, const Ops &... ops)