HighFive 2.9.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Easy_vector.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#include "H5Easy_misc.hpp"
13#include "H5Easy_scalar.hpp"
14
15namespace H5Easy {
16
17namespace detail {
18
19template <class T>
20struct is_vector: std::false_type {};
21template <class T>
22struct is_vector<std::vector<T>>: std::true_type {};
23
24using HighFive::details::inspector;
25
26template <typename T>
27struct io_impl<T, typename std::enable_if<is_vector<T>::value>::type> {
28 inline static DataSet dump(File& file,
29 const std::string& path,
30 const T& data,
31 const DumpOptions& options) {
32 using value_type = typename inspector<T>::base_type;
33 auto dims = inspector<T>::getDimensions(data);
34 DataSet dataset = initDataset<value_type>(file,
35 path,
36 std::vector<size_t>(dims.begin(), dims.end()),
37 options);
38 dataset.write(data);
39 if (options.flush()) {
40 file.flush();
41 }
42 return dataset;
43 }
44
45 inline static T load(const File& file, const std::string& path) {
46 DataSet dataset = file.getDataSet(path);
47 T data;
48 dataset.read(data);
49 return data;
50 }
51
52 inline static Attribute dumpAttribute(File& file,
53 const std::string& path,
54 const std::string& key,
55 const T& data,
56 const DumpOptions& options) {
57 using value_type = typename inspector<T>::base_type;
58 auto dims = inspector<T>::getDimensions(data);
59 std::vector<size_t> shape(dims.begin(), dims.end());
60 Attribute attribute = initAttribute<value_type>(file, path, key, shape, options);
61 attribute.write(data);
62 if (options.flush()) {
63 file.flush();
64 }
65 return attribute;
66 }
67
68 inline static T loadAttribute(const File& file,
69 const std::string& path,
70 const std::string& key) {
71 DataSet dataset = file.getDataSet(path);
72 Attribute attribute = dataset.getAttribute(key);
73 T data;
74 attribute.read(data);
75 return data;
76 }
77};
78
79} // namespace detail
80} // namespace H5Easy
Read/dump DataSets or Attribute using a minimalistic syntax. To this end, the functions are templated...
Definition H5Easy.hpp:59
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
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