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();
109 virtual void refresh();
110 virtual void flush();
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)
135 for(
auto it=childs.begin(); it!=childs.end(); ++it)
136 it->second->refresh();
139 for(
auto it=childs.begin(); it!=childs.end(); ++it)
142 std::map<std::string, Child*> childs;
150 std::map<std::string, Child*> &childs;
152 Creator(Self *self_, std::string name_, std::map<std::string, Child*> &childs_) :
153 self(self_), name(std::move(name_)), childs(childs_) {}
155 template<
typename... Args>
156 T* operator()(Args&&... args) {
157 auto ret=childs.insert(std::pair<std::string, Child*>(name, NULL));
159 throw Exception(self->getPath(),
"A element of name "+name+
" already exists.");
161 auto* r=
new T(static_cast<Self*>(
self), name, std::forward<Args>(args)...);
172 Creator<T> createChild(
const std::string &name_) {
173 if(name_.find_first_of(
'/')!=std::string::npos)
174 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
175 return Creator<T>(static_cast<Self*>(
this), name_, childs);
179 T* openChild(
const std::string &name_) {
180 if(name_.find_first_of(
'/')!=std::string::npos)
181 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
182 std::pair<typename std::map<std::string, Child*>::iterator,
bool> ret=childs.insert(std::pair<std::string, Child*>(name_, NULL));
184 auto *o=dynamic_cast<T*>(ret.first->second);
186 std::runtime_error(
"The element "+name_+
" if of other type.");
190 auto* r=
new T(0, static_cast<Self*>(
this), name_);
206 void close()
override;
207 void open()
override;
208 void refresh()
override;
209 void flush()
override;
212 Object *getFileAsObject();
213 Object *getAttrParent(
const std::string &path,
size_t pos);
216 Creator<T> createChildAttribute(
const std::string &path) {
218 return getFileAsObject()->createChildAttribute<T>(path.substr(1));
221 if((pos=path.find_last_of(
'/'))==std::string::npos)
222 return createChild<T>(path);
224 return getAttrParent(path, pos)->createChild<T>(path.substr(pos+1));
228 T* openChildAttribute(
const std::string &path) {
230 return getFileAsObject()->openChildAttribute<T>(path.substr(1));
233 if((pos=path.find_last_of(
'/'))==std::string::npos)
234 return openChild<T>(path);
236 return getAttrParent(path, pos)->openChild<T>(path.substr(pos+1));
238 Attribute *openChildAttribute(
const std::string &name_, ElementType *attributeType=
nullptr, hid_t *type=
nullptr);
239 std::set<std::string> getChildAttributeNames();
240 bool hasChildAttribute(
const std::string &name_);
241 GroupBase *getParent() {
return parent; }
242 File *getFile() {
return file; }
243 std::string getPath();
253 void close()
override;
254 void open()
override;
255 void refresh()
override;
256 void flush()
override;
258 Object *getParent() {
return parent; }
259 File *getFile() {
return file; }
260 std::string getPath();
268 void close()
override;
269 void open()
override;
270 void refresh()
override;
271 void flush()
override;
273 std::vector<hsize_t> getExtentDims();
Definition: interface.h:246
Definition: interface.h:36
Definition: interface.h:146
Definition: interface.h:201
Definition: interface.h:99
Definition: interface.h:47
Definition: interface.h:87
Definition: interface.h:263
hid_t getID()
Note: use the returned hid_t only temporarily since its value may change, at least when File::reopenA...
Definition: interface.h:113