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
29namespace 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 enableSWMR() override;
39 Dataset *openChildDataset(const std::string &name_, ElementType *objectType, ScopedHID *type);
40 GroupBase *getFileAsGroup();
41 public:
43 void flush() override;
44
45 template<class T>
46 Container<Object, GroupBase>::Creator<T> createChildObject(const std::string &path) {
47 if(path[0]=='/') // absolute path -> call createChildObject from file
48 return getFileAsGroup()->createChildObject<T>(path.substr(1));
49 // now its a relative path
50 size_t pos;
51 if((pos=path.find_last_of('/'))==std::string::npos) // no / included -> call createChild from Container<Object, GroupBase>
53 // now its a relative path including at least one /
54 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
55 if(!group)
56 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
57 return group->createChildObject<T>(path.substr(pos+1));
58 }
59
60 template<class T>
61 T* openChildObject(const std::string &path) {
62 if(path[0]=='/') // absolute path -> call openChildObject from file
63 return getFileAsGroup()->openChildObject<T>(path.substr(1));
64 // now its a relative path
65 size_t pos;
66 if((pos=path.find_first_of('/'))==std::string::npos) // no / included -> call openChild from Container<Object, GroupBase>
68 // now its a relative path including at least one /
69 GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
70 if(!group)
71 throw Exception(getPath(), "Got a path (including /) but this object is not a group");
72 return group->openChildObject<T>(path.substr(pos+1));
73 }
74 Object *openChildObject(const std::string &name_, ElementType *objectType=nullptr, ScopedHID *type=nullptr);
75 std::list<std::string> getChildObjectNames();
76 };
77
78 class Group : public GroupBase {
79 friend class Container<Object, GroupBase>;
80 protected:
81 Group(int dummy, GroupBase *parent_, const std::string &name_);
82 Group(GroupBase *parent_, const std::string &name_);
83 ~Group() override;
84 void close() override;
85 void refresh() override;
86 void flush() override;
87 void enableSWMR() override;
88 };
89
90}
91
92#endif
Definition: interface.h:177
Definition: interface.h:331
Definition: interface.h:65
Definition: group.h:31
void flush() override
flush's all dataset below this group
Definition: group.cc:163
Definition: group.h:78
void flush() override
flush's all dataset below this group
Definition: group.cc:200
Definition: interface.h:270
Definition: interface.h:78