h5gt 0.2.0
C++ wrapper for HDF5 library (based on HighFive project)
Loading...
Searching...
No Matches
H5Easy_public.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_BITS_PUBLIC_HPP
10#define H5EASY_BITS_PUBLIC_HPP
11
12#include "../H5Easy.hpp"
13
14namespace H5Easy {
15
16inline Compression::Compression(bool enable)
17{
18 if (enable) {
19 m_compression_level = 9;
20 } else {
21 m_compression_level = 0;
22 }
23}
24
25template <class T>
26inline Compression::Compression(T level) : m_compression_level(static_cast<unsigned>(level))
27{
28}
29
30inline unsigned Compression::get() const
31{
32 return m_compression_level;
33}
34
35inline void DumpOptions::set(DumpMode mode)
36{
37 m_overwrite = static_cast<bool>(mode);
38}
39
40inline void DumpOptions::set(Flush mode)
41{
42 m_flush = static_cast<bool>(mode);
43}
44
45inline void DumpOptions::set(const Compression& level)
46{
47 m_compression_level = level.get();
48}
49
50template <class T, class... Args>
51inline void DumpOptions::set(T arg, Args... args)
52{
53 set(arg);
54 set(args...);
55}
56
57template <class T>
58inline void DumpOptions::setChunkSize(const std::vector<T>& shape)
59{
60 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
61}
62
63inline void DumpOptions::setChunkSize(std::initializer_list<size_t> shape)
64{
65 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
66}
67
68inline bool DumpOptions::overwrite() const
69{
70 return m_overwrite;
71}
72
73inline bool DumpOptions::flush() const
74{
75 return m_flush;
76}
77
78inline bool DumpOptions::compress() const
79{
80 return m_compression_level > 0;
81}
82
83inline unsigned DumpOptions::getCompressionLevel() const
84{
85 return m_compression_level;
86}
87
88inline bool DumpOptions::isChunked() const
89{
90 return m_chunk_size.size() > 0;
91}
92
93inline std::vector<hsize_t> DumpOptions::getChunkSize() const
94{
95 return m_chunk_size;
96}
97
98inline size_t getSize(const File& file, const std::string& path) {
99 return file.getDataSet(path).getElementCount();
100}
101
102inline std::vector<size_t> getShape(const File& file, const std::string& path) {
103 return file.getDataSet(path).getDimensions();
104}
105
106template <class T>
107inline DataSet dump(File& file,
108 const std::string& path,
109 const T& data,
110 const DumpOptions& options) {
111 return detail::io_impl<T>::dump(file, path, data, options);
112}
113
114template <class T>
115inline DataSet dump(File& file,
116 const std::string& path,
117 const T& data,
118 DumpMode mode) {
119 return detail::io_impl<T>::dump(file, path, data, DumpOptions(mode));
120}
121
122template <class T>
123inline DataSet dump(File& file,
124 const std::string& path,
125 const T& data,
126 const std::vector<size_t>& idx,
127 const DumpOptions& options) {
128 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
129}
130
131template <class T>
132inline DataSet dump(File& file,
133 const std::string& path,
134 const T& data,
135 const std::initializer_list<size_t>& idx,
136 const DumpOptions& options) {
137 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
138}
139
140template <class T>
141inline DataSet dump(File& file,
142 const std::string& path,
143 const T& data,
144 const std::vector<size_t>& idx) {
145 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
146}
147
148template <class T>
149inline DataSet dump(File& file,
150 const std::string& path,
151 const T& data,
152 const std::initializer_list<size_t>& idx) {
153 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
154}
155
156template <class T>
157inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx) {
158 return detail::io_impl<T>::load_part(file, path, idx);
159}
160
161template <class T>
162inline T load(const File& file, const std::string& path) {
163 return detail::io_impl<T>::load(file, path);
164}
165
166template <class T>
167inline Attribute dumpAttribute(File& file,
168 const std::string& path,
169 const std::string& key,
170 const T& data,
171 DumpMode mode) {
172 return detail::io_impl<T>::dumpAttribute(file, path, key, data, DumpOptions(mode));
173}
174
175template <class T>
176inline Attribute dumpAttribute(File& file,
177 const std::string& path,
178 const std::string& key,
179 const T& data,
180 const DumpOptions& options) {
181 return detail::io_impl<T>::dumpAttribute(file, path, key, data, options);
182}
183
184template <class T>
185inline T loadAttribute(const File& file, const std::string& path, const std::string& key) {
186 return detail::io_impl<T>::loadAttribute(file, path, key);
187}
188
189} // namespace H5Easy
190
191#endif // H5EASY_BITS_MISC_HPP
Set compression level for written DataSets.
Definition H5Easy.hpp:82
size_t getElementCount() const
Get the total number of elements in the current dataset. E.g. 2x2x2 matrix has size 8....
Definition H5DataSet.hpp:113
File class.
Definition H5File.hpp:25
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
Definition H5Node_traits_misc.hpp:102