All Classes Namespaces Functions Typedefs Enumerations Pages
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 
28 namespace H5 {
29 
30  class GroupBase : public Object, public Container<Object, GroupBase> {
31  protected:
32  GroupBase(int dummy, GroupBase *parent_, const std::string &name_);
33  GroupBase(GroupBase *parent_, const std::string &name_);
34  ~GroupBase();
35  void close();
36  void open();
37  void refresh();
38  void flush();
39  Dataset *openChildDataset(const std::string &name_, ElementType *objectType, hid_t *type);
40  void handleExternalLink(const std::string &name_);
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>
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  handleExternalLink(path);
61  if(path[0]=='/') // absolute path -> call openChildObject from file
62  return getFileAsGroup()->openChildObject<T>(path.substr(1));
63  // now its a relative path
64  size_t pos;
65  if((pos=path.find_first_of('/'))==std::string::npos) // no / included -> call openChild from Container<Object, GroupBase>
67  // now its a relative path including at least one /
68  GroupBase *group=dynamic_cast<GroupBase*>(openChildObject(path.substr(0, pos)));
69  if(!group)
70  throw Exception(getPath(), "Got a path (including /) but this object is not a group");
71  return group->openChildObject<T>(path.substr(pos+1));
72  }
73  Object *openChildObject(const std::string &name_, ElementType *objectType=NULL, hid_t *type=NULL);
74  std::set<std::string> getChildObjectNames();
75  bool hasChildObject(const std::string &name_);
76 
77  bool isExternalLink(const std::string &name_);
78  std::pair<boost::filesystem::path, std::string> getExternalLink(const std::string &name_);
79  void createExternalLink(const std::string &name_, const std::pair<boost::filesystem::path, std::string> &target);
80  void createSoftLink(const std::string &name_, const std::string &target);
81  };
82 
83  class Group : public GroupBase {
84  friend class Container<Object, GroupBase>;
85  protected:
86  Group(int dummy, GroupBase *parent_, const std::string &name_);
87  Group(GroupBase *parent_, const std::string &name_);
88  ~Group();
89  void close();
90  void open();
91  void refresh();
92  void flush();
93  };
94 
95 }
96 
97 #endif
Definition: interface.h:58
Definition: interface.h:176
Definition: group.h:30
Definition: group.h:83
Definition: interface.h:73
Definition: interface.h:238

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML