h5cpp 0.7.0
A modern C++ wrapper for the HDF5 C library
dataset_creation.hpp
Go to the documentation of this file.
1//
2// (c) Copyright 2017 DESY,ESS
3//
4// This file is part of h5cpp.
5//
6// This library is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation; either version 2.1 of the License, or
9// (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14// License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the
18// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19// Boston, MA 02110-1301 USA
20// ===========================================================================
21//
22// Authors:
23// Eugen Wintersberger <eugen.wintersberger@desy.de>
24// Martin Shetty <martin.shetty@esss.se>
25// Created on: Aug 21, 2017
26//
27#pragma once
28
29#include <iostream>
31#include <h5cpp/core/types.hpp>
35#include <h5cpp/error/error.hpp>
36
37namespace hdf5 {
38namespace property {
39
43enum class DatasetFillValueStatus : std::underlying_type<H5D_fill_value_t>::type {
44 Undefined = H5D_FILL_VALUE_UNDEFINED,
45 Default = H5D_FILL_VALUE_DEFAULT,
46 UserDefined = H5D_FILL_VALUE_USER_DEFINED
47};
48
49DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetFillValueStatus &status);
50
54enum class DatasetFillTime : std::underlying_type<H5D_fill_time_t>::type {
55 IfSet = H5D_FILL_TIME_IFSET,
56 Alloc = H5D_FILL_TIME_ALLOC,
57 Never = H5D_FILL_TIME_NEVER
58};
59
60DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetFillTime &time);
61
69enum class DatasetAllocTime : std::underlying_type<H5D_alloc_time_t>::type {
73 Default = H5D_ALLOC_TIME_DEFAULT,
74
78 Early = H5D_ALLOC_TIME_EARLY,
79
83 Incr = H5D_ALLOC_TIME_INCR,
84
88 Late = H5D_ALLOC_TIME_LATE
89};
90
91DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetAllocTime &time);
92
96enum class DatasetLayout : std::underlying_type<H5D_layout_t>::type {
97 Compact = H5D_COMPACT,
98 Contiguous = H5D_CONTIGUOUS,
99 Chunked = H5D_CHUNKED,
100#if (defined(_DOXYGEN_) || H5_VERSION_GE(1,10,0))
102 Virtual = H5D_VIRTUAL
103#endif
104};
105
106DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetLayout &layout);
107
112 public:
118
123
135
142 void layout(DatasetLayout layout) const;
143
151
161 void chunk(const hdf5::Dimensions &chunk_dims) const;
162
169
189 template<typename T>
190 void fill_value(const T &value,
192
202 template<typename T>
203 T fill_value(const datatype::Datatype &type = datatype::TypeTrait<T>::create()) const;
204
206
210 void fill_time(DatasetFillTime time) const;
211
216
221
229
233 unsigned int nfilters() const;
234};
235
236template<typename T>
237void DatasetCreationList::fill_value(const T &value, const datatype::Datatype &type) const {
238 if (H5Pset_fill_value(static_cast<hid_t>(*this),
239 static_cast<hid_t>(type), &value) < 0) {
240 error::Singleton::instance().throw_with_stack("Failure to set fill value for dataset!");
241 }
242}
243
244template<typename T>
246 T value;
247 if (H5Pget_fill_value(static_cast<hid_t>(*this), static_cast<hid_t>(type), &value) < 0) {
248 error::Singleton::instance().throw_with_stack("Failure retrieving the fill value for a dataset!");
249 }
250 return value;
251}
252
253} // namespace property
254} // namespace hdf5
Wrapper for hid_t object identifiers.
Definition: object_handle.hpp:67
base class for all data types
Definition: datatype.hpp:42
trait to create HDF5 datatypes
Definition: type_trait.hpp:53
static Singleton & instance()
reference to singleton
Definition: error.hpp:59
void throw_with_stack(const std::string &message)
throws an exception, potentially nested with error stack
dataset creation property list
Definition: dataset_creation.hpp:111
DatasetCreationList()
default constructor
void fill_value(const T &value, const datatype::Datatype &type=datatype::TypeTrait< T >::create()) const
set fill value for a dataset
Definition: dataset_creation.hpp:237
void allocation_time(DatasetAllocTime time) const
set allocation time
void layout(DatasetLayout layout) const
set dataset layout
void chunk(const hdf5::Dimensions &chunk_dims) const
set chunk dimensions
DatasetFillValueStatus fill_value_status() const
void fill_time(DatasetFillTime time) const
set fill time
DatasetCreationList(ObjectHandle &&handle)
constructor
DatasetCreationList(const DatasetCreationList &)=default
DatasetLayout layout() const
get dataset layout
DatasetAllocTime allocation_time() const
get allocation time
hdf5::Dimensions chunk() const
get chunk dimensions
~DatasetCreationList() override
destructor
unsigned int nfilters() const
get a number of filters
DatasetFillTime fill_time() const
get fill time
Definition: object_creation.hpp:36
DatasetFillTime
enumeration for the fill time of a dataset
Definition: dataset_creation.hpp:54
DatasetFillValueStatus
enumeration for the fill value status
Definition: dataset_creation.hpp:43
DatasetAllocTime
enumeration for the dataset allocation time
Definition: dataset_creation.hpp:69
@ Early
all space is allocated when the dataset is created
@ Incr
space is allocated as data is written to the file
@ Late
all space is allocated at the first write to the dataset
std::ostream & operator<<(std::ostream &stream, const VirtualDataView &view)
DatasetLayout
enumeration describing the layout of a dataset
Definition: dataset_creation.hpp:96
@ Virtual
(since hdf5 1.10.0)
top-level namespace of the entire library
Definition: attribute.hpp:45
std::vector< hsize_t > Dimensions
Definition: types.hpp:32
#define DLL_EXPORT
Definition: windows.hpp:29