echelon  0.8.0
file.hpp
1 // Copyright (c) 2012-2014 Christopher Hinz
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef ECHELON_FILE_HPP
7 #define ECHELON_FILE_HPP
8 
9 #include <echelon/group.hpp>
10 #include <echelon/link.hpp>
11 #include <echelon/attribute_repository.hpp>
12 
13 #include <echelon/hdf5/file.hpp>
14 
15 #include <string>
16 #include <memory>
17 
18 namespace echelon
19 {
20 
27 class file
28 {
29 public:
33 
36  file() = default;
37 
40  enum class create_mode
41  {
42  truncate,
43  exclusive
44  };
45 
48  enum class open_mode
49  {
50  read_only,
51  read_write
52  };
53 
54  // file interface
55 
61  file(const std::string& path, create_mode mode);
62 
69  file(const std::string& path, open_mode mode);
70 
71  explicit file(native_handle_type native_handle_);
72 
73  // group interface
74 
80  group create_group(const std::string& name);
81 
97  dataset create_dataset(const std::string& name, const type& datatype,
98  const std::vector<hsize_t>& dims, const dataset_options& options = dataset_options());
99 
119  dataset create_dataset(const std::string& name, const type& datatype,
120  const std::vector<hsize_t>& dims, const std::vector<hsize_t>& max_dims,
121  const dataset_options& options = dataset_options());
122 
140  template <typename T>
141  dataset create_dataset(const std::string& name, const std::vector<hsize_t>& dims,
142  const dataset_options& options = dataset_options())
143  {
144  return root_group_.create_dataset<T>(name, dims, options);
145  }
146 
168  template <typename T>
169  dataset create_dataset(const std::string& name, const std::vector<hsize_t>& dims,
170  const std::vector<hsize_t>& max_dims,
171  const dataset_options& options = dataset_options())
172  {
173  return create_dataset(name, type(hdf5::get_hdf5_type<T>()), dims, max_dims, options);
174  }
175 
183  scalar_dataset create_scalar_dataset(const std::string& name, const type& datatype);
184 
194  template <typename T>
195  scalar_dataset create_scalar_dataset(const std::string& name)
196  {
197  return root_group_.create_scalar_dataset<T>(name);
198  }
199 
211  template <typename T>
212  scalar_dataset create_scalar_dataset(const std::string& name, const T& value)
213  {
214  return root_group_.create_scalar_dataset(name, value);
215  }
216 
223  object operator[](const std::string& name) const;
224 
230  void remove(const std::string& name) const;
231 
240  group require_group(const std::string& name);
241 
272  dataset require_dataset(const std::string& name, const type& datatype,
273  const std::vector<hsize_t>& dims, const dataset_options& options = dataset_options());
274 
307  template <typename T>
308  dataset require_dataset(const std::string& name, const std::vector<hsize_t>& dims,
309  const dataset_options& options = dataset_options())
310  {
311  return root_group_.require_dataset<T>(name, dims, options);
312  }
313 
336  scalar_dataset require_scalar_dataset(const std::string& name, const type& datatype);
337 
362  template <typename T>
363  scalar_dataset require_scalar_dataset(const std::string& name)
364  {
365  return root_group_.require_scalar_dataset<T>(name);
366  }
367 
394  template <typename T>
395  scalar_dataset require_scalar_dataset(const std::string& name, const T& value)
396  {
397  return root_group_.require_scalar_dataset(name, value);
398  }
399 
405  void iterate_links(const std::function<void(const link&)>& op) const;
406 
412  void visit_links(const std::function<void(const link&)>& visitor) const;
413 
420  void visit_objects(const std::function<void(const object&)>& visitor) const;
421 
424  object_reference ref() const;
425 
426  // general interface
427 
431 
434  explicit operator bool() const;
435 private:
436  hdf5::file file_handle_;
437  group root_group_;
438 
439 public:
443 };
444 
454 group mount(const file& mounted_file, const group& mount_point);
455 
465 group mount(const file& mounted_file, const file& mount_point);
466 
473 void unmount(const group& mount_point);
474 }
475 
476 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
A handle to a group object.
Definition: group.hpp:125
A handle to an HDF5 scalar dataset.
Definition: scalar_dataset.hpp:23
Attribute manager, which should be embedded into a parent object, which supports attributes.
Definition: attribute_repository.hpp:27
object operator[](const std::string &name) const
Accessor function for the root group.
Definition: file.cpp:56
scalar_dataset create_scalar_dataset(const std::string &name, const T &value)
Creates a new scalar dataset within the root group and initializes it with a given value...
Definition: file.hpp:212
group require_group(const std::string &name)
Returns the requested group, if it already exists, otherwise a new group is created.
Definition: file.cpp:66
A handle to an HDF5 type.
Definition: type.hpp:21
scalar_dataset create_scalar_dataset(const std::string &name)
Creates a new scalar dataset within the root group.
Definition: file.hpp:195
dataset create_dataset(const std::string &name, const std::vector< hsize_t > &dims, const dataset_options &options=dataset_options())
Creates a new dataset within the root group.
Definition: file.hpp:141
group mount(const file &mounted_file, const group &mount_point)
Mounts a file at a specified location.
Definition: file.cpp:117
object_reference ref() const
A object reference to the root group.
Definition: file.cpp:97
open_mode
Definition: file.hpp:48
dataset require_dataset(const std::string &name, const std::vector< hsize_t > &dims, const dataset_options &options=dataset_options())
Returns the requested dataset, if it already exists, otherwise a new dataset is created.
Definition: file.hpp:308
native_handle_type native_handle() const
The underlying HDF5 low-level handle.
Definition: file.cpp:102
A handle to an HDF5 file object.
Definition: hdf5/file.hpp:26
Truncate any pre-existing file.
void visit_links(const std::function< void(const link &)> &visitor) const
Visits every link, which is reachable from the root group.
Definition: file.cpp:87
scalar_dataset require_scalar_dataset(const std::string &name, const type &datatype)
Returns the requested scalar dataset, if it already exists, otherwise a new scalar dataset is created...
Definition: file.cpp:77
dataset create_dataset(const std::string &name, const type &datatype, const std::vector< hsize_t > &dims, const dataset_options &options=dataset_options())
Creates a new dataset within the root group.
Definition: file.cpp:38
create_mode
Definition: file.hpp:40
group create_group(const std::string &name)
Creates a new group within the root group.
Definition: file.cpp:33
A handle to a file object.
Definition: file.hpp:27
scalar_dataset require_scalar_dataset(const std::string &name, const T &value)
Returns the requested scalar dataset, if it already exists, otherwise a new scalar dataset is created...
Definition: file.hpp:395
void unmount(const group &mount_point)
Unmounts a previously mounted file.
Definition: file.cpp:127
void iterate_links(const std::function< void(const link &)> &op) const
Iterates over every link within the root group.
Definition: file.cpp:82
Raise an error, if the file already exists.
scalar_dataset require_scalar_dataset(const std::string &name)
Returns the requested scalar dataset, if it already exists, otherwise the scalar dataset is created...
Definition: file.hpp:363
attribute_repository< group > attributes() const
The attributes, which are attached to the root group.
Definition: file.cpp:112
Additional options for the dataset creation.
Definition: group.hpp:36
dataset create_dataset(const std::string &name, const std::vector< hsize_t > &dims, const std::vector< hsize_t > &max_dims, const dataset_options &options=dataset_options())
Creates a new dataset within the root group.
Definition: file.hpp:169
void visit_objects(const std::function< void(const object &)> &visitor) const
Visits every object, which is reachable from the root group (including the root group) ...
Definition: file.cpp:92
A reference to an HDF5 object.
Definition: object_reference.hpp:24
A handle to an echelon dataset.
Definition: dataset.hpp:33
scalar_dataset create_scalar_dataset(const std::string &name, const type &datatype)
Creates a new scalar dataset within the root group.
Definition: file.cpp:51
dataset require_dataset(const std::string &name, const type &datatype, const std::vector< hsize_t > &dims, const dataset_options &options=dataset_options())
Returns the requested dataset, if it already exists, otherwise a new dataset is created.
Definition: file.cpp:71
file()=default
Initializes the handle with its null state.