22 #ifndef _HDF5SERIE_INTERFACE_H_
23 #define _HDF5SERIE_INTERFACE_H_
25 #include <fmatvec/atom.h>
33 #define HDF5SERIE_MAXCTORPARAMETERS 5
37 typedef herr_t (*CloseFunc)(hid_t id);
42 ScopedHID(hid_t id_, CloseFunc closeFunc_) : id(id_), closeFunc(closeFunc_) {}
49 void reset(hid_t id_=-1, CloseFunc closeFunc_=NULL) {
61 mutable std::string whatMsg;
63 explicit Exception(
const std::string &path_,
const std::string &msg_);
65 const char* what()
const throw();
79 simpleAttributeScalar,
80 simpleAttributeVector,
85 friend class Container<Attribute, Object>;
86 friend class Container<Object, GroupBase>;
90 Element(
const std::string &name_);
94 virtual void refresh();
99 std::string getName() {
return name; }
103 template<
class Child,
class Self>
109 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
113 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
117 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
121 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
122 it->second->refresh();
125 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
128 std::map<std::string, Child*> childs;
136 std::map<std::string, Child*> &childs;
138 Creator(Self *self_,
const std::string &name_, std::map<std::string, Child*> &childs_) :
139 self(self_), name(name_), childs(childs_) {}
141 template<
typename... Args>
142 T* operator()(Args&&... args) {
143 auto ret=childs.insert(std::pair<std::string, Child*>(name, NULL));
145 throw Exception(self->getPath(),
"A element of name "+name+
" already exists.");
147 T* r=
new T(static_cast<Self*>(
self), name, std::forward<Args>(args)...);
158 Creator<T> createChild(
const std::string &name_) {
159 if(name_.find_first_of(
'/')!=std::string::npos)
160 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
161 return Creator<T>(
static_cast<Self*
>(
this), name_, childs);
165 T* openChild(
const std::string &name_) {
166 if(name_.find_first_of(
'/')!=std::string::npos)
167 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
168 std::pair<typename std::map<std::string, Child*>::iterator,
bool> ret=childs.insert(std::pair<std::string, Child*>(name_, NULL));
170 T *o=
dynamic_cast<T*
>(ret.first->second);
172 std::runtime_error(
"The element "+name_+
" if of other type.");
176 T* r=
new T(0, static_cast<Self*>(
this), name_);
188 friend class Container<Object, GroupBase>;
190 Object(GroupBase *parent_,
const std::string &name_);
198 Object *getFileAsObject();
199 Object *getAttrParent(
const std::string &path,
size_t pos);
202 Creator<T> createChildAttribute(
const std::string &path) {
204 return getFileAsObject()->createChildAttribute<T>(path.substr(1));
207 if((pos=path.find_last_of(
'/'))==std::string::npos)
208 return createChild<T>(path);
210 return getAttrParent(path, pos)->createChild<T>(path.substr(pos+1));
214 T* openChildAttribute(
const std::string &path) {
216 return getFileAsObject()->openChildAttribute<T>(path.substr(1));
219 if((pos=path.find_last_of(
'/'))==std::string::npos)
220 return openChild<T>(path);
222 return getAttrParent(path, pos)->openChild<T>(path.substr(pos+1));
224 Attribute *openChildAttribute(
const std::string &name_, ElementType *objectType=NULL, hid_t *type=NULL);
225 std::set<std::string> getChildAttributeNames();
226 bool hasChildAttribute(
const std::string &name_);
227 GroupBase *getParent() {
return parent; }
228 File *getFile() {
return file; }
229 std::string getPath();
233 friend class Container<Attribute, Object>;
235 Attribute(Object *parent_,
const std::string &name_);
244 Object *getParent() {
return parent; }
245 File *getFile() {
return file; }
246 std::string getPath();
259 std::vector<hsize_t> getExtentDims();
Definition: interface.h:232
Definition: interface.h:57
Definition: interface.h:132
Definition: interface.h:187
Definition: interface.h:84
Definition: interface.h:35
Definition: interface.h:72
Definition: interface.h:249
hid_t getID()
Note: use the returned hid_t only temporarily since its value may change, at least when File::reopenA...
Definition: interface.h:98