22 #ifndef _HDF5SERIE_INTERFACE_H_
23 #define _HDF5SERIE_INTERFACE_H_
25 #include <fmatvec/atom.h>
30 #include <boost/preprocessor/iteration/iterate.hpp>
34 #define HDF5SERIE_MAXCTORPARAMETERS 5
38 typedef herr_t (*CloseFunc)(hid_t id);
43 ScopedHID(hid_t id_, CloseFunc closeFunc_) : id(id_), closeFunc(closeFunc_) {}
50 void reset(hid_t id_=-1, CloseFunc closeFunc_=NULL) {
62 mutable std::string whatMsg;
64 explicit Exception(
const std::string &path_,
const std::string &msg_);
66 const char* what()
const throw();
80 simpleAttributeScalar,
81 simpleAttributeVector,
86 friend class Container<Attribute, Object>;
87 friend class Container<Object, GroupBase>;
91 Element(
const std::string &name_);
95 virtual void refresh();
100 std::string getName() {
return name; }
104 template<
class Child,
class Self>
110 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
114 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
118 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
122 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
123 it->second->refresh();
126 for(
typename std::map<std::string, Child*>::iterator it=childs.begin(); it!=childs.end(); ++it)
129 std::map<std::string, Child*> childs;
137 std::map<std::string, Child*> &childs;
139 Creator(Self *self_,
const std::string &name_, std::map<std::string, Child*> &childs_) :
140 self(self_), name(name_), childs(childs_) {}
143 #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, HDF5SERIE_MAXCTORPARAMETERS, "hdf5serie/interface_creatoroperator_iter.h"))
144 #include BOOST_PP_ITERATE()
147 Creator<T> createChild(
const std::string &name_) {
148 if(name_.find_first_of(
'/')!=std::string::npos)
149 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
150 return Creator<T>(
static_cast<Self*
>(
this), name_, childs);
154 T* openChild(
const std::string &name_) {
155 if(name_.find_first_of(
'/')!=std::string::npos)
156 throw Exception(static_cast<Self*>(
this)->getPath(),
"Internal error: must be a relative name, not absolute or a path");
157 std::pair<typename std::map<std::string, Child*>::iterator,
bool> ret=childs.insert(std::pair<std::string, Child*>(name_, NULL));
159 T *o=
dynamic_cast<T*
>(ret.first->second);
161 std::runtime_error(
"The element "+name_+
" if of other type.");
165 T* r=
new T(0, static_cast<Self*>(
this), name_);
177 friend class Container<Object, GroupBase>;
179 Object(GroupBase *parent_,
const std::string &name_);
187 Object *getFileAsObject();
188 Object *getAttrParent(
const std::string &path,
size_t pos);
191 Creator<T> createChildAttribute(
const std::string &path) {
193 return getFileAsObject()->createChildAttribute<T>(path.substr(1));
196 if((pos=path.find_last_of(
'/'))==std::string::npos)
197 return createChild<T>(path);
199 return getAttrParent(path, pos)->createChild<T>(path.substr(pos+1));
203 T* openChildAttribute(
const std::string &path) {
205 return getFileAsObject()->openChildAttribute<T>(path.substr(1));
208 if((pos=path.find_last_of(
'/'))==std::string::npos)
209 return openChild<T>(path);
211 return getAttrParent(path, pos)->openChild<T>(path.substr(pos+1));
213 Attribute *openChildAttribute(
const std::string &name_, ElementType *objectType=NULL, hid_t *type=NULL);
214 std::set<std::string> getChildAttributeNames();
215 bool hasChildAttribute(
const std::string &name_);
216 GroupBase *getParent() {
return parent; }
217 File *getFile() {
return file; }
218 std::string getPath();
222 friend class Container<Attribute, Object>;
224 Attribute(Object *parent_,
const std::string &name_);
233 Object *getParent() {
return parent; }
234 File *getFile() {
return file; }
235 std::string getPath();
248 std::vector<hsize_t> getExtentDims();
Definition: interface.h:221
Definition: interface.h:58
Definition: interface.h:133
Definition: interface.h:176
Definition: interface.h:85
Definition: interface.h:36
Definition: interface.h:73
Definition: interface.h:238
hid_t getID()
Note: use the returned hid_t only temporarily since its value may change, at least when File::reopenA...
Definition: interface.h:99