hops
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
H5PropertyList_misc.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017-2018, Adrien Devresse <adrien.devresse@epfl.ch>
3  * Juan Hernando <juan.hernando@epfl.ch>
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 H5PROPERTY_LIST_MISC_HPP
10 #define H5PROPERTY_LIST_MISC_HPP
11 
12 #include <H5Ppublic.h>
13 
14 namespace HighFive {
15 
16 namespace {
17 inline hid_t convert_plist_type(PropertyType propertyType) {
18  // The HP5_XXX are macros with function calls so we can't assign
19  // them as the enum values
20  switch (propertyType) {
22  return H5P_OBJECT_CREATE;
24  return H5P_FILE_CREATE;
26  return H5P_FILE_ACCESS;
28  return H5P_DATASET_CREATE;
30  return H5P_DATASET_ACCESS;
32  return H5P_DATASET_XFER;
34  return H5P_GROUP_CREATE;
36  return H5P_GROUP_ACCESS;
38  return H5P_DATATYPE_CREATE;
40  return H5P_DATATYPE_ACCESS;
42  return H5P_STRING_CREATE;
44  return H5P_ATTRIBUTE_CREATE;
46  return H5P_OBJECT_COPY;
48  return H5P_LINK_CREATE;
50  return H5P_LINK_ACCESS;
51  default:
52  HDF5ErrMapper::ToException<PropertyException>(
53  "Unsupported property list type");
54  }
55 }
56 
57 } // namespace
58 
59 template <PropertyType T>
61  : _hid(H5P_DEFAULT) {}
62 
63 template <PropertyType T>
65  : _hid(other._hid) {
66  other._hid = H5P_DEFAULT;
67 }
68 
69 template <PropertyType T>
71  // This code handles self-assignment without ifs
72  const auto hid = other._hid;
73  other._hid = H5P_DEFAULT;
74  _hid = hid;
75  return *this;
76 }
77 
78 template <PropertyType T>
80  // H5P_DEFAULT and H5I_INVALID_HID are not the same Ensuring that ~Object
81  if (_hid != H5P_DEFAULT) {
82  H5Pclose(_hid);
83  }
84 }
85 
86 template <PropertyType T>
88  if (_hid != H5P_DEFAULT) {
89  return;
90  }
91  if ((_hid = H5Pcreate(convert_plist_type(T))) < 0) {
92  HDF5ErrMapper::ToException<PropertyException>(
93  "Unable to create property list");
94  }
95 }
96 
97 template <PropertyType T>
98 template <typename P>
99 inline void PropertyList<T>::add(const P& property) {
100  _initializeIfNeeded();
101  property.apply(_hid);
102 }
103 
104 template <PropertyType T>
105 template <typename F, typename... Args>
106 inline void RawPropertyList<T>::add(const F& funct, const Args&... args) {
107  this->_initializeIfNeeded();
108  if (funct(this->_hid, args...) < 0) {
109  HDF5ErrMapper::ToException<PropertyException>(
110  "Error setting raw hdf5 property.");
111  }
112 }
113 
114 inline void Chunking::apply(const hid_t hid) const {
115  if (H5Pset_chunk(hid, static_cast<int>(_dims.size()), _dims.data()) < 0) {
116  HDF5ErrMapper::ToException<PropertyException>(
117  "Error setting chunk property");
118  }
119 }
120 
121 inline void Deflate::apply(const hid_t hid) const {
122  if (!H5Zfilter_avail(H5Z_FILTER_DEFLATE)) {
123  HDF5ErrMapper::ToException<PropertyException>(
124  "Error setting deflate property");
125  }
126 
127  if (H5Pset_deflate(hid, _level) < 0) {
128  HDF5ErrMapper::ToException<PropertyException>(
129  "Error setting deflate property");
130  }
131 }
132 
133 inline void Shuffle::apply(const hid_t hid) const {
134  if (!H5Zfilter_avail(H5Z_FILTER_SHUFFLE)) {
135  HDF5ErrMapper::ToException<PropertyException>(
136  "Error setting shuffle property");
137  }
138 
139  if (H5Pset_shuffle(hid) < 0) {
140  HDF5ErrMapper::ToException<PropertyException>(
141  "Error setting shuffle property");
142  }
143 }
144 
145 inline void Caching::apply(const hid_t hid) const {
146  if (H5Pset_chunk_cache(hid, _numSlots, _cacheSize, _w0) < 0) {
147  HDF5ErrMapper::ToException<PropertyException>(
148  "Error setting dataset cache parameters");
149  }
150 }
151 
152 } // namespace HighFive
153 
154 #endif // H5PROPERTY_LIST_HPP
HighFive::PropertyList::operator=
PropertyList & operator=(const PropertyList< T > &)=delete
HighFive::PropertyList::_initializeIfNeeded
void _initializeIfNeeded()
Definition: H5PropertyList_misc.hpp:87
HighFive::PropertyType
PropertyType
Types of property lists.
Definition: H5PropertyList.hpp:24
HighFive::PropertyType::OBJECT_COPY
@ OBJECT_COPY
HighFive::PropertyType::STRING_CREATE
@ STRING_CREATE
HighFive::PropertyType::FILE_CREATE
@ FILE_CREATE
HighFive::PropertyType::LINK_CREATE
@ LINK_CREATE
HighFive::PropertyType::DATATYPE_CREATE
@ DATATYPE_CREATE
HighFive::RawPropertyList::add
void add(const F &funct, const Args &... args)
Definition: H5PropertyList_misc.hpp:106
HighFive::PropertyList
Base HDF5 property List.
Definition: H5_definitions.hpp:48
HighFive::PropertyType::DATASET_CREATE
@ DATASET_CREATE
HighFive::PropertyType::ATTRIBUTE_CREATE
@ ATTRIBUTE_CREATE
HighFive::PropertyList::add
void add(const P &property)
Definition: H5PropertyList_misc.hpp:99
HighFive::PropertyList::~PropertyList
~PropertyList()
Definition: H5PropertyList_misc.hpp:79
HighFive::PropertyType::DATASET_XFER
@ DATASET_XFER
HighFive::PropertyType::GROUP_CREATE
@ GROUP_CREATE
HighFive::PropertyType::OBJECT_CREATE
@ OBJECT_CREATE
HighFive::PropertyType::DATATYPE_ACCESS
@ DATATYPE_ACCESS
HighFive::PropertyType::DATASET_ACCESS
@ DATASET_ACCESS
HighFive::PropertyList::_hid
hid_t _hid
Definition: H5PropertyList.hpp:74
HighFive::PropertyList::PropertyList
PropertyList() noexcept
Definition: H5PropertyList_misc.hpp:60
HighFive::PropertyType::GROUP_ACCESS
@ GROUP_ACCESS
HighFive::PropertyType::FILE_ACCESS
@ FILE_ACCESS
HighFive
Definition: H5_definitions.hpp:15
HighFive::PropertyType::LINK_ACCESS
@ LINK_ACCESS