echelon  0.8.0
group.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_GROUP_HPP
7 #define ECHELON_GROUP_HPP
8 
9 #include <echelon/object.hpp>
10 #include <echelon/type.hpp>
11 #include <echelon/attribute_repository.hpp>
12 #include <echelon/dataset.hpp>
13 #include <echelon/scalar_dataset.hpp>
14 #include <echelon/object_reference.hpp>
15 #include <echelon/link.hpp>
16 
17 #include <echelon/hdf5/group.hpp>
18 #include <echelon/hdf5/type_factory.hpp>
19 
20 #include <string>
21 #include <vector>
22 #include <map>
23 #include <memory>
24 #include <functional>
25 
26 namespace echelon
27 {
28 
29 class file;
30 
31 using hdf5::unlimited;
32 
37 {
38 public:
46  {
47  auto_chunking_ = value;
48 
49  return *this;
50  }
51 
59  {
60  compression_level_ = value;
61 
62  return *this;
63  }
64 
68  {
69  shuffle_filter_ = value;
70 
71  return *this;
72  }
73 
80  dataset_options& chunk_shape(std::vector<hsize_t> value)
81  {
82  chunk_shape_ = std::move(value);
83 
84  return *this;
85  }
86 
89  bool auto_chunking() const
90  {
91  return auto_chunking_;
92  }
93 
96  int compression_level() const
97  {
98  return compression_level_;
99  }
100 
103  bool shuffle_filter() const
104  {
105  return shuffle_filter_;
106  }
107 
110  const std::vector<hsize_t>& chunk_shape() const
111  {
112  return chunk_shape_;
113  }
114 
115 private:
116  bool auto_chunking_ = false;
117  int compression_level_ = -1;
118  bool shuffle_filter_ = false;
119  std::vector<hsize_t> chunk_shape_ = {};
120 };
121 
125 class group
126 {
127 public:
131 
132  friend class file;
133 
136  group() = default;
137 
138  explicit group(native_handle_type native_handle_);
139 
145  group create_group(const std::string& name);
146 
162  dataset create_dataset(const std::string& name, const type& datatype,
163  const std::vector<hsize_t>& dims, const dataset_options& options = dataset_options());
164 
184  dataset create_dataset(const std::string& name, const type& datatype,
185  const std::vector<hsize_t>& dims, const std::vector<hsize_t>& max_dims,
186  const dataset_options& options = dataset_options());
187 
205  template <typename T>
206  dataset create_dataset(const std::string& name, const std::vector<hsize_t>& dims,
207  const dataset_options& options = dataset_options())
208  {
209  return create_dataset(name, type(hdf5::get_hdf5_type<T>()), dims, options);
210  }
211 
233  template <typename T>
234  dataset create_dataset(const std::string& name, const std::vector<hsize_t>& dims,
235  const std::vector<hsize_t>& max_dims,
236  const dataset_options& options = dataset_options())
237  {
238  return create_dataset(name, type(hdf5::get_hdf5_type<T>()), dims, max_dims, options);
239  }
240 
248  scalar_dataset create_scalar_dataset(const std::string& name, const type& datatype);
249 
259  template <typename T>
260  scalar_dataset create_scalar_dataset(const std::string& name)
261  {
262  return create_scalar_dataset(name, type(hdf5::get_hdf5_type<T>()));
263  }
264 
276  template <typename T>
277  scalar_dataset create_scalar_dataset(const std::string& name, const T& value)
278  {
279  scalar_dataset ds = create_scalar_dataset<T>(name);
280 
281  ds <<= value;
282 
283  return ds;
284  }
285 
292  object operator[](const std::string& name) const;
293 
299  void remove(const std::string& name) const;
300 
309  group require_group(const std::string& name);
310 
341  dataset require_dataset(const std::string& name, const type& datatype,
342  const std::vector<hsize_t>& dims, const dataset_options& options = dataset_options());
343 
376  template <typename T>
377  dataset require_dataset(const std::string& name, const std::vector<hsize_t>& dims,
378  const dataset_options& options = dataset_options())
379  {
380  return require_dataset(name, type(hdf5::get_hdf5_type<T>()), dims, options);
381  }
382 
405  scalar_dataset require_scalar_dataset(const std::string& name, const type& datatype);
406 
431  template <typename T>
432  scalar_dataset require_scalar_dataset(const std::string& name)
433  {
434  return require_scalar_dataset(name, type(hdf5::get_hdf5_type<T>()));
435  }
436 
463  template <typename T>
464  scalar_dataset require_scalar_dataset(const std::string& name, const T& value)
465  {
466  return require_scalar_dataset(name, value);
467  }
468 
474  void iterate_links(const std::function<void(const link&)>& op) const;
475 
481  void visit_links(const std::function<void(const link&)>& visitor) const;
482 
489  void visit_objects(const std::function<void(const object&)>& visitor) const;
490 
493  object_reference ref() const;
494 
497  native_handle_type native_handle() const;
498 
501  explicit operator bool() const;
502 private:
503  friend class constructor_access;
504  friend class object;
505 
506  enum class creation_mode
507  {
508  open,
509  create
510  };
511 
512  explicit group(const file& loc, const std::string& name = "/");
513 
514  dataset create_dataset(const std::string& name, const type& datatype,
515  const std::vector<hsize_t>& dims, const std::vector<hsize_t>& max_dims,
516  int comp_level, bool auto_chunking, bool shuffle_filter,
517  const std::vector<hsize_t> chunk_shape);
518 
519  hdf5::group group_handle_;
520 
521 public:
524  attribute_repository<group> attributes() const;
525 };
526 }
527 
528 #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
dataset_options & shuffle_filter(bool value)
Enables/disables the shuffle filter.
Definition: group.hpp:67
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 this group.
Definition: group.hpp:234
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: group.hpp:377
dataset_options & auto_chunking(bool value)
Enables/Disables auto-chunking.
Definition: group.hpp:45
scalar_dataset create_scalar_dataset(const std::string &name)
Creates a new scalar dataset within this group.
Definition: group.hpp:260
A handle to an HDF5 type.
Definition: type.hpp:21
A handle to an HDF5 group object.
Definition: hdf5/group.hpp:161
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: group.hpp:464
bool auto_chunking() const
auto-chunking option
Definition: group.hpp:89
scalar_dataset create_scalar_dataset(const std::string &name, const T &value)
Creates a new scalar dataset within this group and initializes it with a given value.
Definition: group.hpp:277
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: group.hpp:432
Polymorphic handle to an HDF5 object.
Definition: object.hpp:25
dataset_options & chunk_shape(std::vector< hsize_t > value)
Sets the chunk shape of the dataset.
Definition: group.hpp:80
const std::vector< hsize_t > & chunk_shape() const
chunk shape
Definition: group.hpp:110
bool shuffle_filter() const
shuffle filter option
Definition: group.hpp:103
int compression_level() const
gzip compression level
Definition: group.hpp:96
A handle to a file object.
Definition: file.hpp:27
dataset create_dataset(const std::string &name, const std::vector< hsize_t > &dims, const dataset_options &options=dataset_options())
Creates a new dataset within this group.
Definition: group.hpp:206
Additional options for the dataset creation.
Definition: group.hpp:36
A reference to an HDF5 object.
Definition: object_reference.hpp:24
A handle to an echelon dataset.
Definition: dataset.hpp:33
dataset_options & compression_level(int value)
Sets the gzip compression level (0 - 9) of the dataset.
Definition: group.hpp:58