HighFive 3.0.0
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#pragma once
19
20#include <string>
21#include <vector>
22
23// optionally enable xtensor plug-in and load the library
24#ifdef XTENSOR_VERSION_MAJOR
25#ifndef H5_USE_XTENSOR
26#define H5_USE_XTENSOR
27#endif
28#endif
29
30#ifdef H5_USE_XTENSOR
31#include "xtensor.hpp"
32#endif
33
34// optionally enable Eigen plug-in and load the library
35#ifdef EIGEN_WORLD_VERSION
36#ifndef H5_USE_EIGEN
37#define H5_USE_EIGEN
38#endif
39#endif
40
41#ifdef H5_USE_EIGEN
42#include <Eigen/Eigen>
43#include "eigen.hpp"
44#endif
45
46// optionally enable OpenCV plug-in and load the library
47#ifdef CV_MAJOR_VERSION
48#ifndef H5_USE_OPENCV
49#define H5_USE_OPENCV
50#endif
51#endif
52
53#ifdef H5_USE_OPENCV
54#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 False = 0,
85 True = 1
86};
87
91 public:
97 explicit Compression(bool enable = true);
98
103 template <class T>
104 Compression(T level);
105
108 inline unsigned get() const;
109
110 private:
111 unsigned m_compression_level;
112};
113
123 public:
126 DumpOptions() = default;
127
131 template <class... Args>
132 DumpOptions(Args... args) {
133 set(args...);
134 }
135
139 inline void set(DumpMode mode);
140
144 inline void set(Flush mode);
145
149 inline void set(const Compression& level);
150
155 template <class T, class... Args>
156 inline void set(T arg, Args... args);
157
161 template <class T>
162 inline void setChunkSize(const std::vector<T>& shape);
163
167 inline void setChunkSize(std::initializer_list<size_t> shape);
168
172 inline bool overwrite() const;
173
177 inline bool flush() const;
178
182 inline bool compress() const;
183
187 inline unsigned getCompressionLevel() const;
188
193 inline bool isChunked() const;
194
198 inline std::vector<hsize_t> getChunkSize() const;
199
200 private:
201 bool m_overwrite = false;
202 bool m_flush = true;
203 unsigned m_compression_level = 0;
204 std::vector<hsize_t> m_chunk_size = {};
205};
206
214inline size_t getSize(const File& file, const std::string& path);
215
223inline std::vector<size_t> getShape(const File& file, const std::string& path);
224
235template <class T>
236inline DataSet dump(File& file,
237 const std::string& path,
238 const T& data,
240
251template <class T>
252inline DataSet dump(File& file, const std::string& path, const T& data, const DumpOptions& options);
253
264template <class T>
265inline DataSet dump(File& file,
266 const std::string& path,
267 const T& data,
268 const std::vector<size_t>& idx);
269
280template <class T>
281inline DataSet dump(File& file,
282 const std::string& path,
283 const T& data,
284 const std::initializer_list<size_t>& idx);
285
297template <class T>
298inline DataSet dump(File& file,
299 const std::string& path,
300 const T& data,
301 const std::vector<size_t>& idx,
302 const DumpOptions& options);
303
315template <class T>
316inline DataSet dump(File& file,
317 const std::string& path,
318 const T& data,
319 const std::initializer_list<size_t>& idx,
320 const DumpOptions& options);
321
331template <class T>
332inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx);
333
342template <class T>
343inline T load(const File& file, const std::string& path);
344
356template <class T>
357inline Attribute dumpAttribute(File& file,
358 const std::string& path,
359 const std::string& key,
360 const T& data,
362
374template <class T>
375inline Attribute dumpAttribute(File& file,
376 const std::string& path,
377 const std::string& key,
378 const T& data,
379 const DumpOptions& options);
380
390template <class T>
391inline T loadAttribute(const File& file, const std::string& path, const std::string& key);
392
393} // namespace H5Easy
394
Signal to set compression level for written DataSets.
Definition H5Easy.hpp:90
unsigned get() const
Return compression level.
Definition H5Easy_public.hpp:27
Define options for dumping data.
Definition H5Easy.hpp:122
bool flush() const
Get flush-mode.
Definition H5Easy_public.hpp:62
bool isChunked() const
Get chunking mode: true is manually set, false if chunk-size should be computed automatically.
Definition H5Easy_public.hpp:74
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:78
DumpOptions()=default
Constructor: accept all default settings.
unsigned getCompressionLevel() const
Get compression level.
Definition H5Easy_public.hpp:70
bool overwrite() const
Get overwrite-mode.
Definition H5Easy_public.hpp:58
void set(DumpMode mode)
Overwrite H5Easy::DumpMode setting.
Definition H5Easy_public.hpp:31
bool compress() const
Get compress-mode.
Definition H5Easy_public.hpp:66
DumpOptions(Args... args)
Constructor: overwrite (some of the) defaults.
Definition H5Easy.hpp:132
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:50
create an HDF5 DataType from a C++ type
Definition H5DataType.hpp:189
Class representing an Attribute of a DataSet or Group.
Definition H5Attribute.hpp:47
Definition H5PropertyList.hpp:476
Class representing a dataset.
Definition H5DataSet.hpp:30
Class representing the space (dimensions) of a DataSet.
Definition H5DataSpace.hpp:39
Definition H5PropertyList.hpp:494
Basic HighFive Exception class.
Definition H5Exception.hpp:23
File class.
Definition H5File.hpp:25
HDF5 property Lists.
Definition H5PropertyList.hpp:138
Definition H5PropertyList.hpp:520
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:82
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:99
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:166
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:148
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:138
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:86
Flush
Signal to enable/disable automatic flushing after write operations.
Definition H5Easy.hpp:83
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:25