File indexing completed on 2025-04-19 08:55:35
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "../H5Easy.hpp"
0012
0013 namespace H5Easy {
0014
0015 inline Compression::Compression(bool enable) {
0016 if (enable) {
0017 m_compression_level = 9;
0018 } else {
0019 m_compression_level = 0;
0020 }
0021 }
0022
0023 template <class T>
0024 inline Compression::Compression(T level)
0025 : m_compression_level(static_cast<unsigned>(level)) {}
0026
0027 inline unsigned Compression::get() const {
0028 return m_compression_level;
0029 }
0030
0031 inline void DumpOptions::set(DumpMode mode) {
0032 m_overwrite = static_cast<bool>(mode);
0033 }
0034
0035 inline void DumpOptions::set(Flush mode) {
0036 m_flush = static_cast<bool>(mode);
0037 }
0038
0039 inline void DumpOptions::set(const Compression& level) {
0040 m_compression_level = level.get();
0041 }
0042
0043 template <class T, class... Args>
0044 inline void DumpOptions::set(T arg, Args... args) {
0045 set(arg);
0046 set(args...);
0047 }
0048
0049 template <class T>
0050 inline void DumpOptions::setChunkSize(const std::vector<T>& shape) {
0051 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
0052 }
0053
0054 inline void DumpOptions::setChunkSize(std::initializer_list<size_t> shape) {
0055 m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
0056 }
0057
0058 inline bool DumpOptions::overwrite() const {
0059 return m_overwrite;
0060 }
0061
0062 inline bool DumpOptions::flush() const {
0063 return m_flush;
0064 }
0065
0066 inline bool DumpOptions::compress() const {
0067 return m_compression_level > 0;
0068 }
0069
0070 inline unsigned DumpOptions::getCompressionLevel() const {
0071 return m_compression_level;
0072 }
0073
0074 inline bool DumpOptions::isChunked() const {
0075 return m_chunk_size.size() > 0;
0076 }
0077
0078 inline std::vector<hsize_t> DumpOptions::getChunkSize() const {
0079 return m_chunk_size;
0080 }
0081
0082 inline size_t getSize(const File& file, const std::string& path) {
0083 return file.getDataSet(path).getElementCount();
0084 }
0085
0086 inline std::vector<size_t> getShape(const File& file, const std::string& path) {
0087 return file.getDataSet(path).getDimensions();
0088 }
0089
0090 template <class T>
0091 inline DataSet dump(File& file,
0092 const std::string& path,
0093 const T& data,
0094 const DumpOptions& options) {
0095 return detail::io_impl<T>::dump(file, path, data, options);
0096 }
0097
0098 template <class T>
0099 inline DataSet dump(File& file, const std::string& path, const T& data, DumpMode mode) {
0100 return detail::io_impl<T>::dump(file, path, data, DumpOptions(mode));
0101 }
0102
0103 template <class T>
0104 inline DataSet dump(File& file,
0105 const std::string& path,
0106 const T& data,
0107 const std::vector<size_t>& idx,
0108 const DumpOptions& options) {
0109 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
0110 }
0111
0112 template <class T>
0113 inline DataSet dump(File& file,
0114 const std::string& path,
0115 const T& data,
0116 const std::initializer_list<size_t>& idx,
0117 const DumpOptions& options) {
0118 return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
0119 }
0120
0121 template <class T>
0122 inline DataSet dump(File& file,
0123 const std::string& path,
0124 const T& data,
0125 const std::vector<size_t>& idx) {
0126 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
0127 }
0128
0129 template <class T>
0130 inline DataSet dump(File& file,
0131 const std::string& path,
0132 const T& data,
0133 const std::initializer_list<size_t>& idx) {
0134 return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
0135 }
0136
0137 template <class T>
0138 inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx) {
0139 return detail::io_impl<T>::load_part(file, path, idx);
0140 }
0141
0142 template <class T>
0143 inline T load(const File& file, const std::string& path) {
0144 return detail::io_impl<T>::load(file, path);
0145 }
0146
0147 template <class T>
0148 inline Attribute dumpAttribute(File& file,
0149 const std::string& path,
0150 const std::string& key,
0151 const T& data,
0152 DumpMode mode) {
0153 return detail::io_impl<T>::dumpAttribute(file, path, key, data, DumpOptions(mode));
0154 }
0155
0156 template <class T>
0157 inline Attribute dumpAttribute(File& file,
0158 const std::string& path,
0159 const std::string& key,
0160 const T& data,
0161 const DumpOptions& options) {
0162 return detail::io_impl<T>::dumpAttribute(file, path, key, data, options);
0163 }
0164
0165 template <class T>
0166 inline T loadAttribute(const File& file, const std::string& path, const std::string& key) {
0167 return detail::io_impl<T>::loadAttribute(file, path, key);
0168 }
0169
0170 }