HighFive 2.10.1
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Easy_public.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#pragma once
10
11#include "../H5Easy.hpp"
12
13namespace H5Easy {
14
15inline Compression::Compression(bool enable) {
16 if (enable) {
17 m_compression_level = 9;
18 } else {
19 m_compression_level = 0;
20 }
21}
22
23template <class T>
24inline Compression::Compression(T level)
25 : m_compression_level(static_cast<unsigned>(level)) {}
26
27inline unsigned Compression::get() const {
28 return m_compression_level;
29}
30
31inline void DumpOptions::set(DumpMode mode) {
32 m_overwrite = static_cast<bool>(mode);
33}
34
35inline void DumpOptions::set(Flush mode) {
36 m_flush = static_cast<bool>(mode);
37}
38
39inline void DumpOptions::set(const Compression& level) {
40 m_compression_level = level.get();
41}
42
43template <class T, class... Args>
44inline void DumpOptions::set(T arg, Args... args) {
45 set(arg);
46 set(args...);
47}
48
49template <class T>
50inline void DumpOptions::setChunkSize(const std::vector<T>& shape) {
51 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
52}
53
54inline void DumpOptions::setChunkSize(std::initializer_list<size_t> shape) {
55 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
56}
57
58inline bool DumpOptions::overwrite() const {
59 return m_overwrite;
60}
61
62inline bool DumpOptions::flush() const {
63 return m_flush;
64}
65
66inline bool DumpOptions::compress() const {
67 return m_compression_level > 0;
68}
69
70inline unsigned DumpOptions::getCompressionLevel() const {
71 return m_compression_level;
72}
73
74inline bool DumpOptions::isChunked() const {
75 return m_chunk_size.size() > 0;
76}
77
78inline std::vector<hsize_t> DumpOptions::getChunkSize() const {
79 return m_chunk_size;
80}
81
82inline size_t getSize(const File& file, const std::string& path) {
83 return file.getDataSet(path).getElementCount();
84}
85
86inline std::vector<size_t> getShape(const File& file, const std::string& path) {
87 return file.getDataSet(path).getDimensions();
88}
89
90template <class T>
91inline DataSet dump(File& file,
92 const std::string& path,
93 const T& data,
94 const DumpOptions& options) {
95 return detail::io_impl<T>::dump(file, path, data, options);
96}
97
98template <class T>
99inline DataSet dump(File& file, const std::string& path, const T& data, DumpMode mode) {
100 return detail::io_impl<T>::dump(file, path, data, DumpOptions(mode));
101}
102
103template <class T>
104inline DataSet dump(File& file,
105 const std::string& path,
106 const T& data,
107 const std::vector<size_t>& idx,
108 const DumpOptions& options) {
109 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
110}
111
112template <class T>
113inline DataSet dump(File& file,
114 const std::string& path,
115 const T& data,
116 const std::initializer_list<size_t>& idx,
117 const DumpOptions& options) {
118 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
119}
120
121template <class T>
122inline DataSet dump(File& file,
123 const std::string& path,
124 const T& data,
125 const std::vector<size_t>& idx) {
126 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
127}
128
129template <class T>
130inline DataSet dump(File& file,
131 const std::string& path,
132 const T& data,
133 const std::initializer_list<size_t>& idx) {
134 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
135}
136
137template <class T>
138inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx) {
139 return detail::io_impl<T>::load_part(file, path, idx);
140}
141
142template <class T>
143inline T load(const File& file, const std::string& path) {
144 return detail::io_impl<T>::load(file, path);
145}
146
147template <class T>
148inline Attribute dumpAttribute(File& file,
149 const std::string& path,
150 const std::string& key,
151 const T& data,
152 DumpMode mode) {
153 return detail::io_impl<T>::dumpAttribute(file, path, key, data, DumpOptions(mode));
154}
155
156template <class T>
157inline Attribute dumpAttribute(File& file,
158 const std::string& path,
159 const std::string& key,
160 const T& data,
161 const DumpOptions& options) {
162 return detail::io_impl<T>::dumpAttribute(file, path, key, data, options);
163}
164
165template <class T>
166inline T loadAttribute(const File& file, const std::string& path, const std::string& key) {
167 return detail::io_impl<T>::loadAttribute(file, path, key);
168}
169
170} // namespace H5Easy
Definition H5Easy_Eigen.hpp:17
size_t getSize(const File &file, const std::string &path)
Definition H5Easy_public.hpp:82
T loadAttribute(const File &file, const std::string &path, const std::string &key)
Definition H5Easy_public.hpp:166
DataSet dump(File &file, const std::string &path, const T &data, const DumpOptions &options)
Definition H5Easy_public.hpp:91
T load(const File &file, const std::string &path, const std::vector< size_t > &idx)
Definition H5Easy_public.hpp:138
std::vector< size_t > getShape(const File &file, const std::string &path)
Definition H5Easy_public.hpp:86
Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, DumpMode mode)
Definition H5Easy_public.hpp:148