echelon  0.8.0
hdf5/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_HDF5_FILE_HPP
7 #define ECHELON_HDF5_FILE_HPP
8 
9 #include <echelon/hdf5/group.hpp>
10 #include <echelon/hdf5/link.hpp>
11 #include <echelon/hdf5/precursor/file.hpp>
12 
13 #include <string>
14 #include <memory>
15 
16 namespace echelon
17 {
18 namespace hdf5
19 {
26 class file
27 {
28 public:
31  using native_handle_type = hdf5::precursor::file;
32 
35  enum class create_mode
36  {
37  truncate,
38  exclusive
39  };
40 
43  enum class open_mode
44  {
45  read_only,
46  read_write
47  };
48 
49  // file interface
50 
53  file() = default;
54 
60  file(const std::string& path, create_mode mode);
61 
68  file(const std::string& path, open_mode mode);
69 
70  explicit file(native_handle_type file_wrapper_);
71 
72  // group interface
73 
79  group create_group(const std::string& name);
80 
94  dataset create_dataset(const std::string& name, const type& datatype,
95  const std::vector<hsize_t>& dims, const dataset_options& options = {});
96 
112  template <typename T>
113  dataset create_dataset(const std::string& name, const std::vector<hsize_t>& dims,
114  const dataset_options& options = {})
115  {
116  return root_group_.create_dataset<T>(name, dims, options);
117  }
118 
126  scalar_dataset create_scalar_dataset(const std::string& name, const type& datatype);
127 
137  template <typename T>
138  scalar_dataset create_scalar_dataset(const std::string& name)
139  {
140  return root_group_.create_scalar_dataset<T>(name);
141  }
142 
154  template <typename T>
155  scalar_dataset create_scalar_dataset(const std::string& name, const T& value)
156  {
157  return root_group_.create_scalar_dataset(name, value);
158  }
159 
166  object operator[](const std::string& name) const;
167 
173  void remove(const std::string& name) const;
174 
183  group require_group(const std::string& name);
184 
213  dataset require_dataset(const std::string& name, const type& datatype,
214  const std::vector<hsize_t>& dims, const dataset_options& options = {});
215 
246  template <typename T>
247  dataset require_dataset(const std::string& name, const std::vector<hsize_t>& dims,
248  const dataset_options& options = {})
249  {
250  return root_group_.require_dataset<T>(name, dims, options);
251  }
252 
275  scalar_dataset require_scalar_dataset(const std::string& name, const type& datatype);
276 
301  template <typename T>
302  scalar_dataset require_scalar_dataset(const std::string& name)
303  {
304  return root_group_.require_scalar_dataset<T>(name);
305  }
306 
333  template <typename T>
334  scalar_dataset require_scalar_dataset(const std::string& name, const T& value)
335  {
336  return root_group_.require_scalar_dataset(name, value);
337  }
338 
344  void iterate_links(const std::function<void(const link&)>& op) const;
345 
351  void visit_links(const std::function<void(const link&)>& visitor) const;
352 
359  void visit_objects(const std::function<void(const object&)>& visitor) const;
360 
363  object_reference ref() const;
364 
365  // general interface
366 
369  const native_handle_type& native_handle() const;
370 
373  explicit operator bool() const;
374 private:
375  hdf5::precursor::file file_wrapper_;
376  group root_group_;
377 
378 public:
382 };
383 
393 group mount(const file& mounted_file, const group& mount_point);
394 
404 group mount(const file& mounted_file, const file& mount_point);
405 
412 void unmount(const group& mount_point);
413 }
414 }
415 
416 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
A handle to an HDF5 dataset.
Definition: hdf5/dataset.hpp:62
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: hdf5/file.hpp:334
Raise an error, if the file already exists.
scalar_dataset create_scalar_dataset(const std::string &name, const type &datatype)
Creates a new HDF5 scalar dataset within the root group.
Definition: hdf5/file.cpp:41
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: hdf5/file.cpp:82
A handle to an HDF5 group object.
Definition: hdf5/group.hpp:161
object operator[](const std::string &name) const
Accessor function for the root group.
Definition: hdf5/file.cpp:46
A handle to an HDF5 file object.
Definition: hdf5/file.hpp:26
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: hdf5/file.cpp:67
create_mode
Definition: hdf5/file.hpp:35
object_reference ref() const
A HDF5 object reference to the root group.
Definition: hdf5/file.cpp:87
void iterate_links(const std::function< void(const link &)> &op) const
Iterates over every link within the root group.
Definition: hdf5/file.cpp:72
dataset create_dataset(const std::string &name, const type &datatype, const std::vector< hsize_t > &dims, const dataset_options &options={})
Creates a new HDF5 dataset within the root group.
Definition: hdf5/file.cpp:35
scalar_dataset create_scalar_dataset(const std::string &name, const T &value)
Creates a new HDF5 scalar dataset within the root group and initializes it with a given value...
Definition: hdf5/file.hpp:155
group create_group(const std::string &name)
Creates a new HDF5 group within the root group.
Definition: hdf5/file.cpp:30
A handle to an HDF5 type.
Definition: hdf5/type.hpp:23
Attribute manager, which should be embedded into a parent object, which supports attributes.
Definition: hdf5/attribute_repository.hpp:52
group require_group(const std::string &name)
Returns the requested group, if it already exists, otherwise a new group is created.
Definition: hdf5/file.cpp:56
dataset require_dataset(const std::string &name, const type &datatype, const std::vector< hsize_t > &dims, const dataset_options &options={})
Returns the requested dataset, if it already exists, otherwise a new dataset is created.
Definition: hdf5/file.cpp:61
open_mode
Definition: hdf5/file.hpp:43
A reference to an HDF5 object.
Definition: hdf5/object_reference.hpp:25
const native_handle_type & native_handle() const
The underlying HDF5 low-level handle.
Definition: hdf5/file.cpp:92
dataset require_dataset(const std::string &name, const std::vector< hsize_t > &dims, const dataset_options &options={})
Returns the requested dataset, if it already exists, otherwise a new dataset is created.
Definition: hdf5/file.hpp:247
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: hdf5/file.hpp:302
A handle to an HDF5 scalar dataset.
Definition: hdf5/scalar_dataset.hpp:27
scalar_dataset create_scalar_dataset(const std::string &name)
Creates a new HDF5 scalar dataset within the root group.
Definition: hdf5/file.hpp:138
Additional options for the dataset creation.
Definition: hdf5/group.hpp:72
Truncate any pre-existing file.
dataset create_dataset(const std::string &name, const std::vector< hsize_t > &dims, const dataset_options &options={})
Creates a new HDF5 dataset within the root group.
Definition: hdf5/file.hpp:113
attribute_repository< group > attributes() const
The attributes, which are attached to the root group.
Definition: hdf5/file.cpp:102
hdf5::precursor::file native_handle_type
Type of the underlying HDF5 low-level handle.
Definition: hdf5/file.hpp:31
void visit_links(const std::function< void(const link &)> &visitor) const
Visits every link, which is reachable from the root group.
Definition: hdf5/file.cpp:77
file()=default
Initializes the handle with its null state.