CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
h5_group.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_h5_group_cc_h__
13#define __cxz_h5_group_cc_h__
14
15#include "h5_group.h"
16#include "xpr/for.h"
17
18namespace CNORXZ
19{
20 namespace hdf5
21 {
22 template <SizeT I, typename... Ts>
23 constexpr const auto& tget(const Tuple<Ts...>& t)
24 {
25 return std::get<sizeof...(Ts)-I-1>(t);
26 }
27
28 template <SizeT I, typename... Ts>
29 constexpr auto& tget(Tuple<Ts...>& t)
30 {
31 return std::get<sizeof...(Ts)-I-1>(t);
32 }
33
34 template <SizeT N, typename... Ts>
36 {
37 const PtrId beg = reinterpret_cast<PtrId>(&t);
38 const PtrId pos = reinterpret_cast<PtrId>(&tget<i>(t));
39 return pos - beg;
40 }
41
42 template <typename... Ts>
44 {
45 auto i = this->getIndexTo(name);
46 CXZ_ASSERT((*i)->type() == ContentType::TABLE,
47 "element '" << name << "' is not of type TABLE");
48 auto tab = std::dynamic_pointer_cast<Table>( *i );
49 if(tab == nullptr){
50 auto stab = std::dynamic_pointer_cast<STable<Ts...>>(*i);
51 CXZ_ASSERT(stab != nullptr, "wrong format for table '" << name << "'");
52 return stab;
53 }
54 else {
55 (*i)->close();
56 auto stab = std::make_shared<STable<Ts...>>(name, this);
57 *i = stab;
58 return stab;
59 }
60 }
61
62 template <typename T>
64 {
65 auto i = this->getIndexTo(name);
66 CXZ_ASSERT((*i)->type() == ContentType::DSET,
67 "element '" << name << "' is not of type DSET");
68 auto dset = std::dynamic_pointer_cast<Dataset>( *i );
69 if(dset == nullptr){
70 auto sdset = std::dynamic_pointer_cast<SDataset<T>>(*i);
71 CXZ_ASSERT(sdset != nullptr, "wrong format for dataset '" << name << "'");
72 return sdset;
73 }
74 else {
75 (*i)->close();
76 auto sdset = std::make_shared<SDataset<T>>(name, this);
77 *i = sdset;
78 return sdset;
79 }
80 }
81
82 template <typename T>
83 Group& Group::addDataset(const String& name, const ArrayBase<T>& data)
84 {
85 CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
88 auto ii = getIndexTo(name);
89 auto dset = std::make_shared<SDataset<T>>(name, this);
90 dset->init(data);
91 *ii = dset;
92 return *this;
93 }
94
95 template <typename... Ts>
97 const Arr<String,sizeof...(Ts)>& fnames)
98 {
99 CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
101 mCont.extend( URangeFactory<String>( nvec ).create() );
102 auto ii = getIndexTo(name);
103 auto tab = std::make_shared<STable<Ts...>>(name, this, fnames);
104 for(auto& d: data){
106 }
107 *ii = tab;
108 return *this;
109 }
110
111 template <class F>
112 decltype(auto) Group::iter(F&& f) const
113 {
114 CXZ_ASSERT(isOpen(), "try to iterate over closed object");
115 RangePtr gr = *mCont.range()->sub().begin();
116 auto gi = std::make_shared<UIndex<String>>(gr);
117 return gi->ifor( operation(std::forward<F>(f), mCont(gi)), NoF{} );
118 }
119
120 template <class F>
121 decltype(auto) Group::iterRecursive(F&& f) const
122 {
123 return iter( [&](const auto& c) {
124 f(c);
125 recursion(c, std::forward<F>(f));
126 });
127 }
128
129 template <class F>
130 decltype(auto) Group::iter(F&& f)
131 {
132 CXZ_ASSERT(isOpen(), "try to iterate over closed object");
133 RangePtr gr = *mCont.range()->sub().begin();
134 auto gi = std::make_shared<UIndex<String>>(gr);
135 return gi->ifor( operation(std::forward<F>(f), mCont(gi)), NoF{} );
136 }
137
138 template <class F>
139 decltype(auto) Group::iterRecursive(F&& f)
140 {
141 return iter( [&](const auto& c) {
142 f(c);
143 recursion(c, std::forward<F>(f));
144 });
145 }
146 }
147}
148
149#endif
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
MArray & extend(const RangePtr &range)
Definition marray.cc.h:47
const String & name() const
Group & addDataset(const String &name, const ArrayBase< T > &data)
Definition h5_group.cc.h:83
decltype(auto) iterRecursive(F &&f) const
Sptr< Dataset > getDataset(const String &name) const
Definition h5_group.cc:118
decltype(auto) iter(F &&f) const
MArray< ContentPtr > mCont
Definition h5_group.h:148
Sptr< Table > getTable(const String &name) const
Definition h5_group.cc:110
Group & addTable(const String &name, const ArrayBase< Tuple< Ts... > > &data, const Arr< String, sizeof...(Ts)> &fnames)
Definition h5_group.cc.h:96
AIndex< ContentPtr > getIndexTo(const String &name) const
Definition h5_group.cc:233
STable & appendRecord(const Tuple< Ts... > &t)
For expressions declarations.
Group declaration.
constexpr const auto & tget(const Tuple< Ts... > &t)
Definition h5_group.cc.h:23
SizeT getTupleOffset(const Tuple< Ts... > &t, CSizeT< N > i)
Definition h5_group.cc.h:35
std::intptr_t PtrId
Definition types.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
std::integral_constant< SizeT, N > CSizeT
Definition types.h:81
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)
std::shared_ptr< T > Sptr
Definition types.h:48
constexpr decltype(auto) iter(const G &g, const F &f)
Definition iter.cc.h:34