22 #ifndef _HDF5SERIE_INTERFACE_H_ 23 #define _HDF5SERIE_INTERFACE_H_ 25 #include <fmatvec/atom.h> 34 #define HDF5SERIE_MAXCTORPARAMETERS 5 40 mutable std::string whatMsg;
42 explicit Exception(std::string path_, std::string msg_);
44 const char* what()
const noexcept
override;
49 typedef herr_t (*CloseFunc)(hid_t id);
51 CloseFunc closeFunc{
nullptr};
54 ScopedHID(hid_t id_, CloseFunc closeFunc_) : id(id_), closeFunc(closeFunc_) {
56 throw Exception(
"<unknown>",
"Calling the HDF5 function failed.");
58 throw Exception(
"<unknown>",
"No close function defined.");
72 void reset(hid_t id_, CloseFunc closeFunc_) {
75 throw Exception(
"<unknown>",
"Calling the HDF5 function failed (during reset).");
77 throw Exception(
"<unknown>",
"No close function defined.");
94 simpleAttributeScalar,
95 simpleAttributeVector,
107 virtual void close();
108 virtual void refresh();
109 virtual void flush();
110 virtual void enableSWMR();
114 std::string getName() {
return name; }
118 template<
class Child,
class Self>
121 Container() =
default;
123 for(
auto it=childs.begin(); it!=childs.end(); ++it)
127 for(
auto it=childs.begin(); it!=childs.end(); ++it)
131 for(
auto it=childs.begin(); it!=childs.end(); ++it)
132 it->second->refresh();
135 for(
auto it=childs.begin(); it!=childs.end(); ++it)
139 if constexpr (std::is_same_v<Child, Attribute>) {
141 for(
auto it=childs.begin(); it!=childs.end(); ++it)
147 for(
auto it=childs.begin(); it!=childs.end(); ++it)
149 it->second->enableSWMR();
153 std::map<std::string, Child*> childs;
161 std::map<std::string, Child*> &childs;
163 Creator(Self *self_, std::string name_, std::map<std::string, Child*> &childs_) :
164 self(self_), name(std::move(name_)), childs(childs_) {}
166 template<
typename... Args>
167 T* operator()(Args&&... args) {
168 auto ret=childs.insert(std::pair<std::string, Child*>(name, NULL));
170 throw Exception(self->getPath(),
"A element of name "+name+
" already exists.");
172 auto* r=
new T(static_cast<Self*>(
self), name, std::forward<Args>(args)...);
183 Creator<T> createChild(
const std::string &name_) {
184 if(name_.find_first_of(
'/')!=std::string::npos)
185 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
186 return Creator<T>(static_cast<Self*>(
this), name_, childs);
190 T* openChild(
const std::string &name_) {
191 if(name_.find_first_of(
'/')!=std::string::npos)
192 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
193 std::pair<typename std::map<std::string, Child*>::iterator,
bool> ret=childs.insert(std::pair<std::string, Child*>(name_, NULL));
195 auto *o=dynamic_cast<T*>(ret.first->second);
197 std::runtime_error(
"The element "+name_+
" if of other type.");
201 auto* r=
new T(0, static_cast<Self*>(
this), name_);
217 void close()
override;
218 void refresh()
override;
219 void flush()
override;
220 void enableSWMR()
override;
223 Object *getFileAsObject();
224 Object *getAttrParent(
const std::string &path,
size_t pos);
227 Creator<T> createChildAttribute(
const std::string &path) {
229 return getFileAsObject()->createChildAttribute<T>(path.substr(1));
232 if((pos=path.find_last_of(
'/'))==std::string::npos)
233 return createChild<T>(path);
235 return getAttrParent(path, pos)->createChild<T>(path.substr(pos+1));
239 T* openChildAttribute(
const std::string &path) {
241 return getFileAsObject()->openChildAttribute<T>(path.substr(1));
244 if((pos=path.find_last_of(
'/'))==std::string::npos)
245 return openChild<T>(path);
247 return getAttrParent(path, pos)->openChild<T>(path.substr(pos+1));
249 Attribute *openChildAttribute(
const std::string &name_, ElementType *attributeType=
nullptr, hid_t *type=
nullptr);
250 std::set<std::string> getChildAttributeNames();
251 bool hasChildAttribute(
const std::string &name_);
252 GroupBase *getParent() {
return parent; }
253 File *getFile() {
return file; }
254 std::string getPath();
264 void close()
override;
265 void refresh()
override;
266 void flush()
override;
268 Object *getParent() {
return parent; }
269 File *getFile() {
return file; }
270 std::string getPath();
278 void close()
override;
279 void refresh()
override;
280 void flush()
override;
281 void enableSWMR()
override;
283 std::vector<hsize_t> getExtentDims();
Definition: interface.h:257
Definition: interface.h:36
Definition: interface.h:157
Definition: interface.h:212
Definition: interface.h:99
Definition: interface.h:47
Definition: interface.h:87
Definition: interface.h:273
hid_t getID()
Note: use the returned hid_t only temporarily since it may get invalid, at least when File::enableSWM...
Definition: interface.h:113