h5gt 0.2.0
C++ wrapper for HDF5 library (based on HighFive project)
Loading...
Searching...
No Matches
H5Easy_vector.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_VECTOR_HPP
10#define H5EASY_BITS_VECTOR_HPP
11
12#include "../H5Easy.hpp"
13#include "H5Easy_misc.hpp"
14#include "H5Easy_scalar.hpp"
15
16namespace H5Easy {
17
18namespace detail {
19
20template <class T>
21struct is_vector : std::false_type {};
22template <class T>
23struct is_vector<std::vector<T>> : std::true_type {};
24
26
27template <typename T>
28struct io_impl<T, typename std::enable_if<is_vector<T>::value>::type> {
29
30 inline static DataSet dump(File& file,
31 const std::string& path,
32 const T& data,
33 const DumpOptions& options) {
34 using value_type = typename inspector<T>::base_type;
35 auto dims = inspector<T>::getDimensions(data);
36 DataSet dataset = initDataset<value_type>(file, path, std::vector<size_t>(dims.begin(), dims.end()), options);
37 dataset.write(data);
38 if (options.flush()) {
39 file.flush();
40 }
41 return dataset;
42 }
43
44 inline static T load(const File& file, const std::string& path) {
45 DataSet dataset = file.getDataSet(path);
46 T data;
47 dataset.read(data);
48 return data;
49 }
50
51 inline static Attribute dumpAttribute(File& file,
52 const std::string& path,
53 const std::string& key,
54 const T& data,
55 const DumpOptions& options) {
56 using value_type = typename inspector<T>::base_type;
57 auto dims = inspector<T>::getDimensions(data);
58 std::vector<size_t> shape(dims.begin(), dims.end());
59 Attribute attribute = initAttribute<value_type>(file, path, key, shape, options);
60 attribute.write(data);
61 if (options.flush()) {
62 file.flush();
63 }
64 return attribute;
65 }
66
67 inline static T loadAttribute(const File& file,
68 const std::string& path,
69 const std::string& key) {
70 DataSet dataset = file.getDataSet(path);
71 Attribute attribute = dataset.getAttribute(key);
72 T data;
73 attribute.read(data);
74 return data;
75 }
76};
77
78} // namespace detail
79} // namespace H5Easy
80
81#endif // H5EASY_BITS_VECTOR_HPP
Options for dumping data.
Definition H5Easy.hpp:112
bool flush() const
Check to flush.
Definition H5Easy_public.hpp:73
Attribute getAttribute(const std::string &attr_name) const
open an existing attribute with the name attr_name
Definition H5Annotate_traits_misc.hpp:69
Class representing an attribute of a dataset or group.
Definition H5Attribute.hpp:22
void write(const T &buffer)
Definition H5Attribute_misc.hpp:113
void read(T &array) const
Definition H5Attribute_misc.hpp:68
Class representing a dataset.
Definition H5DataSet.hpp:28
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
void flush(bool globalScope=true)
flush
Definition H5Object_misc.hpp:150
void write(const T &buffer)
Definition H5Slice_traits_misc.hpp:275
void read(T &array) const
Definition H5Slice_traits_misc.hpp:224
Definition H5Easy_scalar.hpp:24
Definition H5Easy_vector.hpp:21
Definition H5Utils.hpp:49