hops
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #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 
16 namespace H5Easy {
17 
18 namespace detail {
19 
20 template <class T>
21 struct is_vector : std::false_type {};
22 template <class T>
23 struct is_vector<std::vector<T>> : std::true_type {};
24 
27 
28 template <typename T>
29 struct io_impl<T, typename std::enable_if<is_vector<T>::value>::type> {
30 
31  inline static DataSet dump(File& file,
32  const std::string& path,
33  const T& data,
34  const DumpOptions& options) {
35  using value_type = typename type_of_array<T>::type;
36  DataSet dataset = initDataset<value_type>(file, path, get_dim_vector(data), 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 type_of_array<T>::type;
57  std::vector<size_t> shape = get_dim_vector(data);
58  Attribute attribute = initAttribute<value_type>(file, path, key, shape, options);
59  attribute.write(data);
60  if (options.flush()) {
61  file.flush();
62  }
63  return attribute;
64  }
65 
66  inline static T loadAttribute(const File& file,
67  const std::string& path,
68  const std::string& key) {
69  DataSet dataset = file.getDataSet(path);
70  Attribute attribute = dataset.getAttribute(key);
71  T data;
72  attribute.read(data);
73  return data;
74  }
75 };
76 
77 } // namespace detail
78 } // namespace H5Easy
79 
80 #endif // H5EASY_BITS_VECTOR_HPP
H5Easy::detail::io_impl< T, typename std::enable_if< is_vector< T >::value >::type >::load
static T load(const File &file, const std::string &path)
Definition: H5Easy_vector.hpp:44
HighFive::details::type_of_array
Definition: H5Utils.hpp:136
HighFive::Attribute::read
void read(T &array) const
Definition: H5Attribute_misc.hpp:58
H5Easy::detail::io_impl
Definition: H5Easy_scalar.hpp:24
HighFive::NodeTraits::getDataSet
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:95
H5Easy_misc.hpp
H5Easy_scalar.hpp
HighFive::details::get_dim_vector
std::vector< size_t > get_dim_vector(const std::vector< T > &vec)
Definition: H5Utils.hpp:109
HighFive::SliceTraits::read
void read(T &array) const
Definition: H5Slice_traits_misc.hpp:158
H5Easy::detail::io_impl< T, typename std::enable_if< is_vector< T >::value >::type >::loadAttribute
static T loadAttribute(const File &file, const std::string &path, const std::string &key)
Definition: H5Easy_vector.hpp:66
H5Easy::detail::io_impl< T, typename std::enable_if< is_vector< T >::value >::type >::dump
static DataSet dump(File &file, const std::string &path, const T &data, const DumpOptions &options)
Definition: H5Easy_vector.hpp:31
H5Easy::DumpOptions
Options for dumping data.
Definition: H5Easy.hpp:112
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:200
H5Easy
Definition: H5Easy.hpp:51
HighFive::File
File class.
Definition: H5File.hpp:24
HighFive::details::type_of_array::type
unqualified_t< T > type
Definition: H5Utils.hpp:137
HighFive::Attribute
Class representing an attribute of a dataset or group.
Definition: H5Attribute.hpp:23
HighFive::AnnotateTraits::getAttribute
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:69
H5Easy::detail::io_impl< T, typename std::enable_if< is_vector< T >::value >::type >::dumpAttribute
static Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, const DumpOptions &options)
Definition: H5Easy_vector.hpp:51
string
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
HighFive::File::flush
void flush()
flush
Definition: H5File_misc.hpp:83
H5Easy::DumpOptions::flush
bool flush() const
Check to flush.
Definition: H5Easy_public.hpp:73
HighFive::DataSet
Class representing a dataset.
Definition: H5DataSet.hpp:27
H5Easy::detail::is_vector
Definition: H5Easy_vector.hpp:21
HighFive::Attribute::write
void write(const T &buffer)
Definition: H5Attribute_misc.hpp:106