HighFive 2.3.1
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Easy.hpp
Go to the documentation of this file.
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
17
18#ifndef H5EASY_HPP
19#define H5EASY_HPP
20
21#include <string>
22#include <vector>
23
24// optionally enable xtensor plug-in and load the library
25#ifdef XTENSOR_VERSION_MAJOR
26#ifndef H5_USE_XTENSOR
27#define H5_USE_XTENSOR
28#endif
29#endif
30
31#ifdef H5_USE_XTENSOR
32#include <xtensor/xarray.hpp>
33#include <xtensor/xtensor.hpp>
34#endif
35
36// optionally enable Eigen plug-in and load the library
37#ifdef EIGEN_WORLD_VERSION
38#ifndef H5_USE_EIGEN
39#define H5_USE_EIGEN
40#endif
41#endif
42
43#ifdef H5_USE_EIGEN
44#include <Eigen/Eigen>
45#endif
46
47// optionally enable OpenCV plug-in and load the library
48#ifdef CV_MAJOR_VERSION
49#ifndef H5_USE_OPENCV
50#define H5_USE_OPENCV
51#endif
52#endif
53
54#ifdef H5_USE_OPENCV
55#include <opencv2/opencv.hpp>
56#endif
57
58#include "H5File.hpp"
59
60namespace H5Easy {
61
70using HighFive::File;
73
76enum class DumpMode {
77 Create = 0,
78 Overwrite = 1
79};
80
83enum class Flush
84{
85 False = 0,
86 True = 1
87};
88
92{
93public:
94
100 explicit Compression(bool enable = true);
101
106 template <class T>
107 Compression(T level);
108
111 inline unsigned get() const;
112
113private:
114 unsigned m_compression_level;
115};
116
126{
127public:
130 DumpOptions() = default;
131
135 template <class... Args>
136 DumpOptions(Args... args)
137 {
138 set(args...);
139 }
140
144 inline void set(DumpMode mode);
145
149 inline void set(Flush mode);
150
154 inline void set(const Compression& level);
155
160 template <class T, class... Args>
161 inline void set(T arg, Args... args);
162
166 template <class T>
167 inline void setChunkSize(const std::vector<T>& shape);
168
172 inline void setChunkSize(std::initializer_list<size_t> shape);
173
177 inline bool overwrite() const;
178
182 inline bool flush() const;
183
187 inline bool compress() const;
188
192 inline unsigned getCompressionLevel() const;
193
198 inline bool isChunked() const;
199
203 inline std::vector<hsize_t> getChunkSize() const;
204
205private:
206 bool m_overwrite = false;
207 bool m_flush = true;
208 unsigned m_compression_level = 0;
209 std::vector<hsize_t> m_chunk_size = {};
210};
211
219inline size_t getSize(const File& file, const std::string& path);
220
228inline std::vector<size_t> getShape(const File& file, const std::string& path);
229
240template <class T>
241inline DataSet dump(File& file,
242 const std::string& path,
243 const T& data,
245
256template <class T>
257inline DataSet dump(File& file,
258 const std::string& path,
259 const T& data,
260 const DumpOptions& options);
261
272template <class T>
273inline DataSet dump(File& file,
274 const std::string& path,
275 const T& data,
276 const std::vector<size_t>& idx);
277
288template <class T>
289inline DataSet dump(File& file,
290 const std::string& path,
291 const T& data,
292 const std::initializer_list<size_t>& idx);
293
305template <class T>
306inline DataSet dump(File& file,
307 const std::string& path,
308 const T& data,
309 const std::vector<size_t>& idx,
310 const DumpOptions& options);
311
323template <class T>
324inline DataSet dump(File& file,
325 const std::string& path,
326 const T& data,
327 const std::initializer_list<size_t>& idx,
328 const DumpOptions& options);
329
339template <class T>
340inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx);
341
350template <class T>
351inline T load(const File& file, const std::string& path);
352
364template <class T>
365inline Attribute dumpAttribute(File& file,
366 const std::string& path,
367 const std::string& key,
368 const T& data,
370
382template <class T>
383inline Attribute dumpAttribute(File& file,
384 const std::string& path,
385 const std::string& key,
386 const T& data,
387 const DumpOptions& options);
388
398template <class T>
399inline T loadAttribute(const File& file, const std::string& path, const std::string& key);
400
401} // namespace H5Easy
402
410
411#endif // H5EASY_HPP
Signal to set compression level for written DataSets.
Definition: H5Easy.hpp:92
unsigned get() const
Return compression level.
Definition: H5Easy_public.hpp:30
Define options for dumping data.
Definition: H5Easy.hpp:126
bool flush() const
Get flush-mode.
Definition: H5Easy_public.hpp:73
bool isChunked() const
Get chunking mode: true is manually set, false if chunk-size should be computed automatically.
Definition: H5Easy_public.hpp:88
std::vector< hsize_t > getChunkSize() const
Get chunk size. Use DumpOptions::getChunkSize to check if chunk-size should be automatically computed...
Definition: H5Easy_public.hpp:93
DumpOptions()=default
Constructor: accept all default settings.
unsigned getCompressionLevel() const
Get compression level.
Definition: H5Easy_public.hpp:83
bool overwrite() const
Get overwrite-mode.
Definition: H5Easy_public.hpp:68
void set(DumpMode mode)
Overwrite H5Easy::DumpMode setting.
Definition: H5Easy_public.hpp:35
bool compress() const
Get compress-mode.
Definition: H5Easy_public.hpp:78
DumpOptions(Args... args)
Constructor: overwrite (some of the) defaults.
Definition: H5Easy.hpp:136
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:100
Class representing an attribute of a dataset or group.
Definition: H5Attribute.hpp:25
Definition: H5PropertyList.hpp:118
Class representing a dataset.
Definition: H5DataSet.hpp:31
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
Definition: H5PropertyList.hpp:140
Basic HighFive Exception class.
Definition: H5Exception.hpp:24
File class.
Definition: H5File.hpp:26
HDF5 property Lists.
Definition: H5PropertyList.hpp:62
Definition: H5PropertyList.hpp:166
Read/dump DataSets or Attribute using a minimalistic syntax. To this end, the functions are templated...
Definition: H5Easy.hpp:60
size_t getSize(const File &file, const std::string &path)
Get the size of an existing DataSet in an open HDF5 file.
Definition: H5Easy_public.hpp:98
DataSet dump(File &file, const std::string &path, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) DataSet in an open HDF5 file.
Definition: H5Easy_public.hpp:115
DumpMode
Write mode for DataSets.
Definition: H5Easy.hpp:76
T loadAttribute(const File &file, const std::string &path, const std::string &key)
Load a Attribute in an open HDF5 file to an object (templated).
Definition: H5Easy_public.hpp:185
Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) Attribute in an open HDF5 file.
Definition: H5Easy_public.hpp:167
T load(const File &file, const std::string &path, const std::vector< size_t > &idx)
Load entry {i, j, ...} from a DataSet in an open HDF5 file to a scalar.
Definition: H5Easy_public.hpp:157
std::vector< size_t > getShape(const File &file, const std::string &path)
Get the shape of an existing DataSet in an readable file.
Definition: H5Easy_public.hpp:102
Flush
Signal to enable/disable automatic flushing after write operations.
Definition: H5Easy.hpp:84
ObjectType
Enum of the types of objects (H5O api)
Definition: H5Object.hpp:25