File indexing completed on 2025-12-16 10:18:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "../H5Easy.hpp"
0012 #include "H5Easy_misc.hpp"
0013 #include "H5Easy_scalar.hpp"
0014
0015 namespace H5Easy {
0016
0017 namespace detail {
0018
0019 template <class T>
0020 struct is_vector: std::false_type {};
0021 template <class T>
0022 struct is_vector<std::vector<T>>: std::true_type {};
0023
0024 using HighFive::details::inspector;
0025
0026 template <typename T>
0027 struct io_impl<T, typename std::enable_if<is_vector<T>::value>::type> {
0028 inline static DataSet dump(File& file,
0029 const std::string& path,
0030 const T& data,
0031 const DumpOptions& options) {
0032 using value_type = typename inspector<T>::base_type;
0033 auto dims = inspector<T>::getDimensions(data);
0034 DataSet dataset = initDataset<value_type>(file,
0035 path,
0036 std::vector<size_t>(dims.begin(), dims.end()),
0037 options);
0038 dataset.write(data);
0039 if (options.flush()) {
0040 file.flush();
0041 }
0042 return dataset;
0043 }
0044
0045 inline static T load(const File& file, const std::string& path) {
0046 DataSet dataset = file.getDataSet(path);
0047 T data;
0048 dataset.read(data);
0049 return data;
0050 }
0051
0052 inline static Attribute dumpAttribute(File& file,
0053 const std::string& path,
0054 const std::string& key,
0055 const T& data,
0056 const DumpOptions& options) {
0057 using value_type = typename inspector<T>::base_type;
0058 auto dims = inspector<T>::getDimensions(data);
0059 std::vector<size_t> shape(dims.begin(), dims.end());
0060 Attribute attribute = initAttribute<value_type>(file, path, key, shape, options);
0061 attribute.write(data);
0062 if (options.flush()) {
0063 file.flush();
0064 }
0065 return attribute;
0066 }
0067
0068 inline static T loadAttribute(const File& file,
0069 const std::string& path,
0070 const std::string& key) {
0071 DataSet dataset = file.getDataSet(path);
0072 Attribute attribute = dataset.getAttribute(key);
0073 T data;
0074 attribute.read(data);
0075 return data;
0076 }
0077 };
0078
0079 }
0080 }