HighFive 2.9.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Node_traits.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3 *
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#pragma once
10
11#include <string>
12
13#include "../H5PropertyList.hpp"
14#include "H5_definitions.hpp"
15#include "H5Converter_misc.hpp"
16
17namespace HighFive {
18
19enum class IndexType : std::underlying_type<H5_index_t>::type {
20 NAME = H5_INDEX_NAME,
21 CRT_ORDER = H5_INDEX_CRT_ORDER,
22};
23
27template <typename Derivate>
29 public:
40 DataSet createDataSet(const std::string& dataset_name,
41 const DataSpace& space,
42 const DataType& type,
45 bool parents = true);
46
56 template <typename T>
57 DataSet createDataSet(const std::string& dataset_name,
58 const DataSpace& space,
61 bool parents = true);
62
73 template <typename T>
74 DataSet createDataSet(const std::string& dataset_name,
75 const T& data,
78 bool parents = true);
79
80
81 template <std::size_t N>
82 H5_DEPRECATED("Use 'std::vector<std::string>'.")
83 DataSet createDataSet(const std::string& dataset_name,
87 bool parents = true);
88
94 DataSet getDataSet(const std::string& dataset_name,
95 const DataSetAccessProps& accessProps = DataSetAccessProps::Default()) const;
96
102 Group createGroup(const std::string& group_name, bool parents = true);
103
110 Group createGroup(const std::string& group_name,
111 const GroupCreateProps& createProps,
112 bool parents = true);
113
118 Group getGroup(const std::string& group_name) const;
119
125 const std::string& type_name,
126 const DataTypeAccessProps& accessProps = DataTypeAccessProps::Default()) const;
127
131 size_t getNumberObjects() const;
132
136 std::string getObjectName(size_t index) const;
137
144 bool rename(const std::string& src_path,
145 const std::string& dest_path,
146 bool parents = true) const;
147
154 std::vector<std::string> listObjectNames(IndexType idx_type = IndexType::NAME) const;
155
160 bool exist(const std::string& node_name) const;
161
165 void unlink(const std::string& node_name) const;
166
170 LinkType getLinkType(const std::string& node_name) const;
171
175 ObjectType getObjectType(const std::string& node_name) const;
176
180 template <typename T, typename = decltype(&T::getPath)>
181 void createSoftLink(const std::string& linkName, const T& obj) {
182 static_assert(!std::is_same<T, Attribute>::value,
183 "hdf5 doesn't support soft links to Attributes");
184 createSoftLink(linkName, obj.getPath());
185 }
186
194 void createSoftLink(const std::string& link_name,
195 const std::string& obj_path,
196 LinkCreateProps linkCreateProps = LinkCreateProps(),
197 const LinkAccessProps& linkAccessProps = LinkAccessProps(),
198 const bool parents = true);
199
200 void createExternalLink(const std::string& link_name,
201 const std::string& h5_file,
202 const std::string& obj_path,
203 LinkCreateProps linkCreateProps = LinkCreateProps(),
204 const LinkAccessProps& linkAccessProps = LinkAccessProps(),
205 const bool parents = true);
206
214 template <typename T, typename = decltype(&T::getPath)>
215 void createHardLink(const std::string& link_name,
216 const T& target_obj,
217 LinkCreateProps linkCreateProps = LinkCreateProps(),
218 const LinkAccessProps& linkAccessProps = LinkAccessProps(),
219 const bool parents = true);
220
221 private:
222 using derivate_type = Derivate;
223
224 // A wrapper over the low-level H5Lexist
225 // It makes behavior consistent among versions and by default transforms
226 // errors to exceptions
227 bool _exist(const std::string& node_name, bool raise_errors = true) const;
228
229 // Opens an arbitrary object to obtain info
230 Object _open(const std::string& node_name) const;
231};
232
233
237enum class LinkType {
238 Hard,
239 Soft,
240 External,
241 Other // Reserved or User-defined
242};
243
244
245} // namespace HighFive
#define H5_DEPRECATED(msg)
Definition H5_definitions.hpp:9
Class representing a dataset.
Definition H5DataSet.hpp:30
Class representing the space (dimensions) of a DataSet.
Definition H5DataSpace.hpp:31
HDF5 Data Type.
Definition H5DataType.hpp:61
Represents an hdf5 group.
Definition H5Group.hpp:46
NodeTraits: Base class for Group and File.
Definition H5Node_traits.hpp:28
Group getGroup(const std::string &group_name) const
open an existing group with the name group_name
Definition H5Node_traits_misc.hpp:129
std::vector< std::string > listObjectNames(IndexType idx_type=IndexType::NAME) const
list all leaf objects name of the node / group
Definition H5Node_traits_misc.hpp:181
void unlink(const std::string &node_name) const
unlink the given dataset or group
Definition H5Node_traits_misc.hpp:231
void createExternalLink(const std::string &link_name, const std::string &h5_file, const std::string &obj_path, LinkCreateProps linkCreateProps=LinkCreateProps(), const LinkAccessProps &linkAccessProps=LinkAccessProps(), const bool parents=true)
Definition H5Node_traits_misc.hpp:292
DataType getDataType(const std::string &type_name, const DataTypeAccessProps &accessProps=DataTypeAccessProps::Default()) const
open a commited datatype with the name type_name
Definition H5Node_traits_misc.hpp:136
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps::Default()) const
get an existing dataset in the current file
Definition H5Node_traits_misc.hpp:97
void createSoftLink(const std::string &linkName, const T &obj)
A shorthand to create softlink to any object which provides getPath The link will be created with def...
Definition H5Node_traits.hpp:181
void createHardLink(const std::string &link_name, const T &target_obj, LinkCreateProps linkCreateProps=LinkCreateProps(), const LinkAccessProps &linkAccessProps=LinkAccessProps(), const bool parents=true)
Creates hardlinks.
Definition H5Node_traits_misc.hpp:311
Group createGroup(const std::string &group_name, bool parents=true)
create a new group, and eventually intermediate groups
Definition H5Node_traits_misc.hpp:105
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps::Default(), const DataSetAccessProps &accessProps=DataSetAccessProps::Default(), bool parents=true)
createDataSet Create a new dataset in the current file of datatype type and of size space
Definition H5Node_traits_misc.hpp:37
bool rename(const std::string &src_path, const std::string &dest_path, bool parents=true) const
moves an object and its content within an HDF5 file.
Definition H5Node_traits_misc.hpp:165
bool exist(const std::string &node_name) const
check a dataset or group exists in the current node / group
Definition H5Node_traits_misc.hpp:218
ObjectType getObjectType(const std::string &node_name) const
A shorthand to get the kind of object pointed to (group, dataset, type...)
Definition H5Node_traits_misc.hpp:269
size_t getNumberObjects() const
return the number of leaf objects of the node / group
Definition H5Node_traits_misc.hpp:144
std::string getObjectName(size_t index) const
return the name of the object with the given index
Definition H5Node_traits_misc.hpp:151
LinkType getLinkType(const std::string &node_name) const
Returns the kind of link of the given name (soft, hard...)
Definition H5Node_traits_misc.hpp:254
Definition H5Object.hpp:54
HDF5 property Lists.
Definition H5PropertyList.hpp:160
static const PropertyList< T > & Default() noexcept
Return the Default property type object.
Definition H5PropertyList.hpp:178
A structure representing a set of fixed-length strings.
Definition H5DataType.hpp:356
PropertyList< PropertyType::LINK_CREATE > LinkCreateProps
Definition H5PropertyList.hpp:211
PropertyList< PropertyType::LINK_ACCESS > LinkAccessProps
Definition H5PropertyList.hpp:212
Definition H5_definitions.hpp:22
LinkType
The possible types of group entries (link concept)
Definition H5Node_traits.hpp:237
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:24
IndexType
Definition H5Node_traits.hpp:19