00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _HDF5SERIE_GROUP_H_
00023 #define _HDF5SERIE_GROUP_H_
00024
00025 #include <hdf5serie/interface.h>
00026 #include <boost/filesystem.hpp>
00027
00028 namespace H5 {
00029
00030 class GroupBase : public Object, public Container<Object, GroupBase> {
00031 protected:
00032 GroupBase(int dummy, GroupBase *parent_, const std::string &name_);
00033 GroupBase(GroupBase *parent_, const std::string &name_);
00034 ~GroupBase();
00035 void close();
00036 void open();
00037 void refresh();
00038 void flush();
00039 Dataset *openChildDataset(const std::string &name_, ElementType *objectType, hid_t *type);
00040 void handleExternalLink(const std::string &name_);
00041 GroupBase *getFileAsGroup();
00042 public:
00043 template<class T>
00044 Container<Object, GroupBase>::Creator<T> createChildObject(const std::string &path) {
00045 if(path[0]=='/')
00046 return getFileAsGroup()->createChildObject<T>(path.substr(1));
00047
00048 size_t pos;
00049 if((pos=path.find_last_of('/'))==std::string::npos)
00050 return Container<Object, GroupBase>::createChild<T>(path);
00051
00052 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
00053 if(!group)
00054 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
00055 return group->createChildObject<T>(path.substr(pos+1));
00056 }
00057
00058 template<class T>
00059 T* openChildObject(const std::string &path) {
00060 handleExternalLink(path);
00061 if(path[0]=='/')
00062 return getFileAsGroup()->openChildObject<T>(path.substr(1));
00063
00064 size_t pos;
00065 if((pos=path.find_first_of('/'))==std::string::npos)
00066 return Container<Object, GroupBase>::openChild<T>(path);
00067
00068 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
00069 if(!group)
00070 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
00071 return group->openChildObject<T>(path.substr(pos+1));
00072 }
00073 Object *openChildObject(const std::string &name_, ElementType *objectType=NULL, hid_t *type=NULL);
00074 std::set<std::string> getChildObjectNames();
00075 bool hasChildObject(const std::string &name_);
00076
00077 bool isExternalLink(const std::string &name_);
00078 std::pair<boost::filesystem::path, std::string> getExternalLink(const std::string &name_);
00079 void createExternalLink(const std::string &name_, const std::pair<boost::filesystem::path, std::string> &target);
00080 void createSoftLink(const std::string &name_, const std::string &target);
00081 };
00082
00083 class Group : public GroupBase {
00084 friend class Container<Object, GroupBase>;
00085 protected:
00086 Group(int dummy, GroupBase *parent_, const std::string &name_);
00087 Group(GroupBase *parent_, const std::string &name_);
00088 ~Group();
00089 void close();
00090 void open();
00091 void refresh();
00092 void flush();
00093 };
00094
00095 }
00096
00097 #endif