h5gt 0.2.0
C++ wrapper for HDF5 library (based on HighFive project)
Loading...
Searching...
No Matches
H5Easy.hpp
1/*
2 * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3 *
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 */
9#ifndef H5EASY_HPP
10#define H5EASY_HPP
11
12#include <string>
13#include <vector>
14
15// optionally enable xtensor plug-in and load the library
16#ifdef XTENSOR_VERSION_MAJOR
17#ifndef H5GT_USE_XTENSOR
18#define H5GT_USE_XTENSOR
19#endif
20#endif
21
22#ifdef H5GT_USE_XTENSOR
23#include <xtensor/xarray.hpp>
24#include <xtensor/xtensor.hpp>
25#endif
26
27// optionally enable Eigen plug-in and load the library
28#ifdef EIGEN_WORLD_VERSION
29#ifndef H5GT_USE_EIGEN
30#define H5GT_USE_EIGEN
31#endif
32#endif
33
34#ifdef H5GT_USE_EIGEN
35#include <Eigen/Eigen>
36#endif
37
38// optionally enable OpenCV plug-in and load the library
39#ifdef CV_MAJOR_VERSION
40#ifndef H5GT_USE_OPENCV
41#define H5GT_USE_OPENCV
42#endif
43#endif
44
45#ifdef H5GT_USE_OPENCV
46#include <opencv2/opencv.hpp>
47#endif
48
49#include "H5File.hpp"
50
51namespace H5Easy {
52
53using h5gt::Attribute;
55using h5gt::DataSet;
57using h5gt::DataSpace;
58using h5gt::Exception;
59using h5gt::File;
60using h5gt::ObjectType;
63
66enum class DumpMode {
67 Create = 0,
68 Overwrite = 1
69};
70
73enum class Flush
74{
75 False = 0,
76 True = 1
77};
78
82{
83public:
84
85 //
86 // \brief Enable compression with the highest compression level (9).
87 // or disable compression (set compression level to 0).
88 explicit Compression(bool enable = true);
89
90 //
91 // \brief Set compression level.
92 template <class T>
93 Compression(T level);
94
95 //
96 // \brief Return compression level.
97 inline unsigned get() const;
98
99private:
100 unsigned m_compression_level;
101};
102
112{
113public:
116 DumpOptions() = default;
117
121 template <class... Args>
122 DumpOptions(Args... args)
123 {
124 set(args...);
125 }
126
130 inline void set(DumpMode mode);
131
135 inline void set(Flush mode);
136
140 inline void set(const Compression& level);
141
145 template <class T, class... Args>
146 inline void set(T arg, Args... args);
147
151 template <class T>
152 inline void setChunkSize(const std::vector<T>& shape);
153
157 inline void setChunkSize(std::initializer_list<size_t> shape);
158
161 inline bool overwrite() const;
162
165 inline bool flush() const;
166
169 inline bool compress() const;
170
173 inline unsigned getCompressionLevel() const;
174
177 inline bool isChunked() const;
178
181 inline std::vector<hsize_t> getChunkSize() const;
182
183private:
184 bool m_overwrite = false;
185 bool m_flush = true;
186 unsigned m_compression_level = 0;
187 std::vector<hsize_t> m_chunk_size = {};
188};
189
197inline size_t getSize(const File& file, const std::string& path);
198
206inline std::vector<size_t> getShape(const File& file, const std::string& path);
207
218template <class T>
219inline DataSet dump(File& file,
220 const std::string& path,
221 const T& data,
222 DumpMode mode = DumpMode::Create);
223
234template <class T>
235inline DataSet dump(File& file,
236 const std::string& path,
237 const T& data,
238 const DumpOptions& options);
239
250template <class T>
251inline DataSet dump(File& file,
252 const std::string& path,
253 const T& data,
254 const std::vector<size_t>& idx);
255
266template <class T>
267inline DataSet dump(File& file,
268 const std::string& path,
269 const T& data,
270 const std::initializer_list<size_t>& idx);
271
283template <class T>
284inline DataSet dump(File& file,
285 const std::string& path,
286 const T& data,
287 const std::vector<size_t>& idx,
288 const DumpOptions& options);
289
301template <class T>
302inline DataSet dump(File& file,
303 const std::string& path,
304 const T& data,
305 const std::initializer_list<size_t>& idx,
306 const DumpOptions& options);
307
317template <class T>
318inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx);
319
328template <class T>
329inline T load(const File& file, const std::string& path);
330
342template <class T>
343inline Attribute dumpAttribute(File& file,
344 const std::string& path,
345 const std::string& key,
346 const T& data,
347 DumpMode mode = DumpMode::Create);
348
360template <class T>
361inline Attribute dumpAttribute(File& file,
362 const std::string& path,
363 const std::string& key,
364 const T& data,
365 const DumpOptions& options);
366
376template <class T>
377inline T loadAttribute(const File& file, const std::string& path, const std::string& key);
378
379} // namespace H5Easy
380
381#include "h5easy_bits/H5Easy_Eigen.hpp"
382#include "h5easy_bits/H5Easy_misc.hpp"
383#include "h5easy_bits/H5Easy_opencv.hpp"
384#include "h5easy_bits/H5Easy_public.hpp"
385#include "h5easy_bits/H5Easy_scalar.hpp"
386#include "h5easy_bits/H5Easy_vector.hpp"
387#include "h5easy_bits/H5Easy_xtensor.hpp"
388
389#endif // H5EASY_HPP
Set compression level for written DataSets.
Definition H5Easy.hpp:82
Options for dumping data.
Definition H5Easy.hpp:112
bool flush() const
Check to flush.
Definition H5Easy_public.hpp:73
bool isChunked() const
Check if chunk-size is manually set (or should be computed automatically).
Definition H5Easy_public.hpp:88
std::vector< hsize_t > getChunkSize() const
Get chunk size.
Definition H5Easy_public.hpp:93
DumpOptions()=default
Constructor: accept all defaults.
unsigned getCompressionLevel() const
Get compression level.
Definition H5Easy_public.hpp:83
bool overwrite() const
Check to overwrite.
Definition H5Easy_public.hpp:68
void set(DumpMode mode)
Overwrite setting.
Definition H5Easy_public.hpp:35
bool compress() const
Check to compress.
Definition H5Easy_public.hpp:78
DumpOptions(Args... args)
Constructor: overwrite (some of the) defaults.
Definition H5Easy.hpp:122
void setChunkSize(const std::vector< T > &shape)
Set chunk-size. If the input is rank (size) zero, automatic chunking is enabled.
Definition H5Easy_public.hpp:58
create an HDF5 DataType from a C++ type
Definition H5DataType.hpp:124
Class representing an attribute of a dataset or group.
Definition H5Attribute.hpp:22
Definition H5PropertyList.hpp:171
Class representing a dataset.
Definition H5DataSet.hpp:28
Class representing the space (dimensions) of a dataset.
Definition H5DataSpace.hpp:37
Basic h5gt Exception class.
Definition H5Exception.hpp:24
File class.
Definition H5File.hpp:25