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 open() override;
38  void refresh() override;
39  void flush() override;
40  Dataset *openChildDataset(const std::string &name_, ElementType *objectType, hid_t *type);
41  void handleExternalLink(const std::string &name_);
42  GroupBase *getFileAsGroup();
43  public:
44  template<class T>
45  Container<Object, GroupBase>::Creator<T> createChildObject(const std::string &path) {
46  if(path[0]=='/') // absolute path -> call createChildObject from file
47  return getFileAsGroup()->createChildObject<T>(path.substr(1));
48  // now its a relative path
49  size_t pos;
50  if((pos=path.find_last_of('/'))==std::string::npos) // no / included -> call createChild from Container<Object, GroupBase>
52  // now its a relative path including at least one /
53  GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
54  if(!group)
55  throw Exception(getPath(), "Got a path (including /) but this object is not a group");
56  return group->createChildObject<T>(path.substr(pos+1));
57  }
58 
59  template<class T>
60  T* openChildObject(const std::string &path) {
61  handleExternalLink(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, hid_t *type=nullptr);
75  std::list<std::string> getChildObjectNames();
76  bool hasChildObject(const std::string &name_);
77 
78  bool isExternalLink(const std::string &name_);
79  std::pair<boost::filesystem::path, std::string> getExternalLink(const std::string &name_);
80  void createExternalLink(const std::string &name_, const std::pair<boost::filesystem::path, std::string> &target);
81  void createSoftLink(const std::string &name_, const std::string &target);
82  };
83 
84  class Group : public GroupBase {
85  friend class Container<Object, GroupBase>;
86  protected:
87  Group(int dummy, GroupBase *parent_, const std::string &name_);
88  Group(GroupBase *parent_, const std::string &name_);
89  ~Group() override;
90  void close() override;
91  void open() override;
92  void refresh() override;
93  void flush() override;
94  };
95 
96 }
97 
98 #endif
Definition: interface.h:36
Definition: interface.h:201
Definition: group.h:31
Definition: group.h:84
Definition: interface.h:87
Definition: interface.h:263