HighFive 2.3.1
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
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
14namespace HighFive {
15
16namespace {
17inline 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
61 : Object(H5P_DEFAULT) {}
62
63
64template <PropertyType T>
66 if (_hid != H5P_DEFAULT) {
67 return;
68 }
69 if ((_hid = H5Pcreate(convert_plist_type(T))) < 0) {
70 HDF5ErrMapper::ToException<PropertyException>(
71 "Unable to create property list");
72 }
73}
74
75template <PropertyType T>
76template <typename P>
77inline void PropertyList<T>::add(const P& property) {
78 _initializeIfNeeded();
79 property.apply(_hid);
80}
81
82template <PropertyType T>
83template <typename F, typename... Args>
84inline void RawPropertyList<T>::add(const F& funct, const Args&... args) {
85 this->_initializeIfNeeded();
86 if (funct(this->_hid, args...) < 0) {
87 HDF5ErrMapper::ToException<PropertyException>(
88 "Error setting raw hdf5 property.");
89 }
90}
91
92
93// Specific options to be added to Property Lists
94
95inline void Chunking::apply(const hid_t hid) const {
96 if (H5Pset_chunk(hid, static_cast<int>(_dims.size()), _dims.data()) < 0) {
97 HDF5ErrMapper::ToException<PropertyException>(
98 "Error setting chunk property");
99 }
100}
101
102inline void Deflate::apply(const hid_t hid) const {
103 if (!H5Zfilter_avail(H5Z_FILTER_DEFLATE) ||
104 H5Pset_deflate(hid, _level) < 0) {
105 HDF5ErrMapper::ToException<PropertyException>(
106 "Error setting deflate property");
107 }
108}
109
110inline void Szip::apply(const hid_t hid) const {
111 if (!H5Zfilter_avail(H5Z_FILTER_SZIP)) {
112 HDF5ErrMapper::ToException<PropertyException>(
113 "Error setting szip property");
114 }
115
116 if (H5Pset_szip(hid, _options_mask, _pixels_per_block) < 0) {
117 HDF5ErrMapper::ToException<PropertyException>(
118 "Error setting szip property");
119 }
120}
121
122inline void Shuffle::apply(const hid_t hid) const {
123 if (!H5Zfilter_avail(H5Z_FILTER_SHUFFLE)) {
124 HDF5ErrMapper::ToException<PropertyException>(
125 "Error setting shuffle property");
126 }
127
128 if (H5Pset_shuffle(hid) < 0) {
129 HDF5ErrMapper::ToException<PropertyException>(
130 "Error setting shuffle property");
131 }
132}
133
134inline void Caching::apply(const hid_t hid) const {
135 if (H5Pset_chunk_cache(hid, _numSlots, _cacheSize, _w0) < 0) {
136 HDF5ErrMapper::ToException<PropertyException>(
137 "Error setting dataset cache parameters");
138 }
139}
140
141inline void CreateIntermediateGroup::apply(const hid_t hid) const {
142 if (H5Pset_create_intermediate_group(hid, _create ? 1 : 0) < 0) {
143 HDF5ErrMapper::ToException<PropertyException>(
144 "Error setting property for create intermediate groups");
145 }
146}
147
148} // namespace HighFive
149
150#endif // H5PROPERTY_LIST_HPP
Definition: H5Object.hpp:36
PropertyListBase() noexcept
Definition: H5PropertyList_misc.hpp:60
void _initializeIfNeeded()
Definition: H5PropertyList_misc.hpp:65
void add(const P &property)
Definition: H5PropertyList_misc.hpp:77
void add(const F &funct, const Args &... args)
Definition: H5PropertyList_misc.hpp:84
Definition: H5_definitions.hpp:15
PropertyType
Types of property lists.
Definition: H5PropertyList.hpp:24