h5cpp  0.5.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>
34 #include <h5cpp/core/windows.hpp>
35 #include <h5cpp/error/error.hpp>
36 
37 namespace hdf5 {
38 namespace property {
39 
43 enum 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 
49 DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetFillValueStatus &status);
50 
54 enum 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 
60 DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetFillTime &time);
61 
69 enum 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 
91 DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetAllocTime &time);
92 
96 enum 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))
101  Virtual = H5D_VIRTUAL
103 #endif
104 };
105 
106 DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetLayout &layout);
107 
112  public:
117  DatasetCreationList(const DatasetCreationList &) = default;
118 
122  ~DatasetCreationList() override;
123 
134  explicit DatasetCreationList(ObjectHandle &&handle);
135 
142  void layout(DatasetLayout layout) const;
143 
150  DatasetLayout layout() const;
151 
161  void chunk(const hdf5::Dimensions &chunk_dims) const;
162 
168  hdf5::Dimensions chunk() const;
169 
189  template<typename T>
190  void fill_value(const T &value,
191  const datatype::Datatype &type = datatype::TypeTrait<T>::create()) const;
192 
202  template<typename T>
203  T fill_value(const datatype::Datatype &type = datatype::TypeTrait<T>::create()) const;
204 
205  DatasetFillValueStatus fill_value_status() const;
206 
210  void fill_time(DatasetFillTime time) const;
211 
215  DatasetFillTime fill_time() const;
216 
220  void allocation_time(DatasetAllocTime time) const;
221 
228  DatasetAllocTime allocation_time() const;
229 
233  unsigned int nfilters() const;
234 };
235 
236 template<typename T>
237 void 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 
244 template<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
hdf5::property::DatasetAllocTime::Default
@ Default
choose the default allocation strategy for the particular layout
hdf5::property::DatasetFillValueStatus::Default
@ Default
types.hpp
hdf5::datatype::TypeTrait
trait to create HDF5 datatypes
Definition: type_trait.hpp:53
hdf5::property::DatasetFillValueStatus::Undefined
@ Undefined
hdf5::property::DatasetFillTime::IfSet
@ IfSet
hdf5::property::DatasetAllocTime
DatasetAllocTime
enumeration for the dataset allocation time
Definition: dataset_creation.hpp:69
hdf5::property::DatasetAllocTime::Early
@ Early
all space is allocated when the dataset is created
datatype.hpp
hdf5::property::DatasetFillTime::Alloc
@ Alloc
hdf5::property::DatasetFillTime::Never
@ Never
windows.hpp
hdf5::property::DatasetFillValueStatus::UserDefined
@ UserDefined
hdf5::property::DatasetLayout::Chunked
@ Chunked
object_creation.hpp
hdf5::property::ObjectCreationList
Definition: object_creation.hpp:36
hdf5::error::Singleton::instance
static Singleton & instance()
reference to singleton
Definition: error.hpp:59
hdf5::property::DatasetLayout::Contiguous
@ Contiguous
hdf5::error::Singleton::throw_with_stack
void throw_with_stack(const std::string &message)
throws an exception, potentially nested with error stack
hdf5::property::DatasetLayout::Compact
@ Compact
hdf5::property::DatasetCreationList
dataset creation property list
Definition: dataset_creation.hpp:111
hdf5::Dimensions
std::vector< hsize_t > Dimensions
Definition: types.hpp:32
hdf5::property::operator<<
std::ostream & operator<<(std::ostream &stream, const VirtualDataView &view)
hdf5::ObjectHandle
Wrapper for hid_t object identifiers.
Definition: object_handle.hpp:66
DLL_EXPORT
#define DLL_EXPORT
Definition: windows.hpp:29
type_trait.hpp
hdf5::property::DatasetLayout
DatasetLayout
enumeration describing the layout of a dataset
Definition: dataset_creation.hpp:96
hdf5::property::DatasetLayout::Virtual
@ Virtual
(since hdf5 1.10.0)
hdf5::property::DatasetCreationList::fill_value
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
hdf5::property::DatasetAllocTime::Late
@ Late
all space is allocated at the first write to the dataset
hdf5::property::DatasetFillTime
DatasetFillTime
enumeration for the fill time of a dataset
Definition: dataset_creation.hpp:54
hdf5::datatype::Datatype
base class for all data types
Definition: datatype.hpp:41
hdf5
top-level namespace of the entire library
Definition: attribute.hpp:45
error.hpp
hdf5::property::DatasetFillValueStatus
DatasetFillValueStatus
enumeration for the fill value status
Definition: dataset_creation.hpp:43
hdf5::property::DatasetAllocTime::Incr
@ Incr
space is allocated as data is written to the file