hdf5serie 2.0.0 HDF5 Serie

group.h
1 /* Copyright (C) 2009 Markus Friedrich
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 * Contact:
18 * friedrich.at.gc@googlemail.com
19 *
20 */
21
22 #ifndef _HDF5SERIE_GROUP_H_
23 #define _HDF5SERIE_GROUP_H_
24
25 #include <hdf5serie/interface.h>
26 #include <boost/filesystem.hpp>
27 #include <list>
28
29 namespace H5 {
30
31 class GroupBase : public Object, public Container<Object, GroupBase> {
32 protected:
33 GroupBase(int dummy, GroupBase *parent_, const std::string &name_);
34 GroupBase(GroupBase *parent_, const std::string &name_);
35 ~GroupBase() override;
36 void close() override;
37 void refresh() override;
38 void flush() override;
39 void enableSWMR() override;
40 Dataset *openChildDataset(const std::string &name_, ElementType *objectType, hid_t *type);
41 GroupBase *getFileAsGroup();
42 public:
43 template<class T>
44 Container<Object, GroupBase>::Creator<T> createChildObject(const std::string &path) {
45 if(path[0]=='/') // absolute path -> call createChildObject from file
46 return getFileAsGroup()->createChildObject<T>(path.substr(1));
47 // now its a relative path
48 size_t pos;
49 if((pos=path.find_last_of('/'))==std::string::npos) // no / included -> call createChild from Container<Object, GroupBase>
50 return Container<Object, GroupBase>::createChild<T>(path);
51 // now its a relative path including at least one /
52 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
53 if(!group)
54 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
55 return group->createChildObject<T>(path.substr(pos+1));
56 }
57
58 template<class T>
59 T* openChildObject(const std::string &path) {
60 if(path[0]=='/') // absolute path -> call openChildObject from file
61 return getFileAsGroup()->openChildObject<T>(path.substr(1));
62 // now its a relative path
63 size_t pos;
64 if((pos=path.find_first_of('/'))==std::string::npos) // no / included -> call openChild from Container<Object, GroupBase>
65 return Container<Object, GroupBase>::openChild<T>(path);
66 // now its a relative path including at least one /
67 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
68 if(!group)
69 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
70 return group->openChildObject<T>(path.substr(pos+1));
71 }
72 Object *openChildObject(const std::string &name_, ElementType *objectType=nullptr, hid_t *type=nullptr);
73 std::list<std::string> getChildObjectNames();
74 };
75
76 class Group : public GroupBase {
77 friend class Container<Object, GroupBase>;
78 protected:
79 Group(int dummy, GroupBase *parent_, const std::string &name_);
80 Group(GroupBase *parent_, const std::string &name_);
81 ~Group() override;
82 void close() override;
83 void refresh() override;
84 void flush() override;
85 void enableSWMR() override;
86 };
87
88 }
89
90 #endif
H5::Exception
Definition: interface.h:36
H5::Object
Definition: interface.h:212
H5::GroupBase
Definition: group.h:31
H5::Group
Definition: group.h:76
H5::Container
Definition: interface.h:87
H5::Dataset
Definition: interface.h:273