h5cpp  0.3.3
A modern C++ wrapper for the HDF5 C library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  USER_DEFINED = 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 H5_VERSION_GE(1, 10, 0)
101  VIRTUAL = H5D_VIRTUAL
102 #endif
103 };
104 
105 DLL_EXPORT std::ostream &operator<<(std::ostream &stream, const DatasetLayout &layout);
106 
111  public:
116 
121 
132  explicit DatasetCreationList(ObjectHandle &&handle);
133 
140  void layout(DatasetLayout layout) const;
141 
148  DatasetLayout layout() const;
149 
159  void chunk(const hdf5::Dimensions &chunk_dims) const;
160 
166  hdf5::Dimensions chunk() const;
167 
187  template<typename T>
188  void fill_value(const T &value,
189  const datatype::Datatype &type = datatype::TypeTrait<T>::create()) const;
190 
200  template<typename T>
201  T fill_value(const datatype::Datatype &type = datatype::TypeTrait<T>::create()) const;
202 
203  DatasetFillValueStatus fill_value_status() const;
204 
208  void fill_time(DatasetFillTime time) const;
209 
213  DatasetFillTime fill_time() const;
214 
218  void allocation_time(DatasetAllocTime time) const;
219 
226  DatasetAllocTime allocation_time() const;
227 };
228 
229 template<typename T>
230 void DatasetCreationList::fill_value(const T &value, const datatype::Datatype &type) const {
231  if (H5Pset_fill_value(static_cast<hid_t>(*this),
232  static_cast<hid_t>(type), &value) < 0) {
233  error::Singleton::instance().throw_with_stack("Failure to set fill value for dataset!");
234  }
235 }
236 
237 template<typename T>
239  T value;
240  if (H5Pget_fill_value(static_cast<hid_t>(*this), static_cast<hid_t>(type), &value) < 0) {
241  error::Singleton::instance().throw_with_stack("Failure retrieving the fill value for a dataset!");
242  }
243  return value;
244 }
245 
246 } // namespace property
247 } // namespace hdf5
Definition: object_creation.hpp:36
static Singleton & instance()
reference to singleton
Definition: error.hpp:50
void throw_with_stack(const std::string &message)
throws an exception, potentially nested with error stack
DatasetFillValueStatus
enumeration for the fill value status
Definition: dataset_creation.hpp:43
Wrapper for hid_t object identifiers.
Definition: object_handle.hpp:66
all space is allocated at the first write to the dataset
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:230
all space is allocated when the dataset is created
dataset creation property list
Definition: dataset_creation.hpp:110
Definition: attribute.hpp:43
DatasetAllocTime
enumeration for the dataset allocation time
Definition: dataset_creation.hpp:69
trait to create HDF5 datatypes
Definition: type_trait.hpp:53
DLL_EXPORT std::ostream & operator<<(std::ostream &stream, const DatasetFillValueStatus &status)
std::vector< hsize_t > Dimensions
Definition: types.hpp:36
#define DLL_EXPORT
Definition: windows.hpp:35
DatasetLayout
enumeration describing the layout of a dataset
Definition: dataset_creation.hpp:96
DatasetFillTime
enumeration for the fill time of a dataset
Definition: dataset_creation.hpp:54
base class for all data types
Definition: datatype.hpp:41
space is allocated as data is written to the file