HighFive  2.3.1
HighFive - Header-only C++ HDF5 interface
H5DataSet_misc.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 H5DATASET_MISC_HPP
10 #define H5DATASET_MISC_HPP
11 
12 #include <algorithm>
13 #include <functional>
14 #include <numeric>
15 #include <sstream>
16 #include <string>
17 
18 #ifdef H5_USE_BOOST
19 #include <boost/multi_array.hpp>
20 #endif
21 
22 #include <H5Dpublic.h>
23 #include <H5Ppublic.h>
24 
25 #include "H5Utils.hpp"
26 
27 namespace HighFive {
28 
29 inline uint64_t DataSet::getStorageSize() const {
30  return H5Dget_storage_size(_hid);
31 }
32 
34  return DataType(H5Dget_type(_hid));
35 }
36 
37 inline DataSpace DataSet::getSpace() const {
38  DataSpace space;
39  if ((space._hid = H5Dget_space(_hid)) < 0) {
40  HDF5ErrMapper::ToException<DataSetException>(
41  "Unable to get DataSpace out of DataSet");
42  }
43  return space;
44 }
45 
47  return getSpace();
48 }
49 
50 inline uint64_t DataSet::getOffset() const {
51  uint64_t addr = H5Dget_offset(_hid);
52  if (addr == HADDR_UNDEF) {
53  HDF5ErrMapper::ToException<DataSetException>(
54  "Cannot get offset of DataSet.");
55  }
56  return addr;
57 }
58 
59 inline void DataSet::resize(const std::vector<size_t>& dims) {
60 
61  const size_t numDimensions = getSpace().getDimensions().size();
62  if (dims.size() != numDimensions) {
63  HDF5ErrMapper::ToException<DataSetException>(
64  "Invalid dataspace dimensions, got " + std::to_string(dims.size()) +
65  " expected " + std::to_string(numDimensions));
66  }
67 
68  std::vector<hsize_t> real_dims(dims.begin(), dims.end());
69 
70  if (H5Dset_extent(getId(), real_dims.data()) < 0) {
71  HDF5ErrMapper::ToException<DataSetException>(
72  "Could not resize dataset.");
73  }
74 }
75 
76 } // namespace HighFive
77 
78 #endif // H5DATASET_MISC_HPP
DataSpace getMemSpace() const
getMemSpace
Definition: H5DataSet_misc.hpp:46
void resize(const std::vector< size_t > &dims)
Change the size of the dataset.
Definition: H5DataSet_misc.hpp:59
DataType getDataType() const
getDataType
Definition: H5DataSet_misc.hpp:33
uint64_t getOffset() const
getOffset
Definition: H5DataSet_misc.hpp:50
uint64_t getStorageSize() const
getStorageSize
Definition: H5DataSet_misc.hpp:29
DataSpace getSpace() const
getSpace
Definition: H5DataSet_misc.hpp:37
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
std::vector< size_t > getDimensions() const
getDimensions
Definition: H5Dataspace_misc.hpp:103
HDF5 Data Type.
Definition: H5DataType.hpp:42
hid_t getId() const noexcept
getId
Definition: H5Object_misc.hpp:55
hid_t _hid
Definition: H5Object.hpp:87
Definition: H5_definitions.hpp:15