Go to the documentation of this file.
9 #ifndef H5NODE_TRAITS_MISC_HPP
10 #define H5NODE_TRAITS_MISC_HPP
15 #include <H5Apublic.h>
16 #include <H5Dpublic.h>
17 #include <H5Fpublic.h>
18 #include <H5Gpublic.h>
19 #include <H5Ppublic.h>
20 #include <H5Tpublic.h>
22 #include "../H5DataSet.hpp"
23 #include "../H5Group.hpp"
24 #include "../H5Selection.hpp"
25 #include "../H5Utility.hpp"
34 template <
typename Derivate>
41 DataSet ds{H5Dcreate2(
static_cast<Derivate*
>(
this)->getId(),
42 dataset_name.c_str(), dtype.
_hid, space.
_hid,
43 H5P_DEFAULT, createProps.
getId(), accessProps.
getId())};
45 HDF5ErrMapper::ToException<DataSetException>(
46 std::string(
"Unable to create the dataset \"") + dataset_name +
52 template <
typename Derivate>
53 template <
typename Type>
60 return createDataSet(dataset_name, space,
61 create_and_check_datatype<Type>(),
62 createProps, accessProps);
65 template <
typename Derivate>
75 createProps, accessProps);
80 template <
typename Derivate>
81 template <std::
size_t N>
87 DataSet ds = createDataSet<char[N]>(
88 dataset_name,
DataSpace(data.
size()), createProps, accessProps);
93 template <
typename Derivate>
97 DataSet ds{H5Dopen2(
static_cast<const Derivate*
>(
this)->getId(),
98 dataset_name.c_str(), accessProps.
getId())};
100 HDF5ErrMapper::ToException<DataSetException>(
101 std::string(
"Unable to open the dataset \"") + dataset_name +
"\":");
106 template <
typename Derivate>
111 lcpl.
add(H5Pset_create_intermediate_group, 1u);
113 Group group{H5Gcreate2(
static_cast<Derivate*
>(
this)->getId(),
114 group_name.c_str(), lcpl.
getId(), H5P_DEFAULT, H5P_DEFAULT)};
115 if (group._hid < 0) {
116 HDF5ErrMapper::ToException<GroupException>(
117 std::string(
"Unable to create the group \"") + group_name +
"\":");
122 template <
typename Derivate>
125 Group group{H5Gopen2(
static_cast<const Derivate*
>(
this)->getId(),
126 group_name.c_str(), H5P_DEFAULT)};
127 if (group._hid < 0) {
128 HDF5ErrMapper::ToException<GroupException>(
129 std::string(
"Unable to open the group \"") + group_name +
"\":");
134 template <
typename Derivate>
137 if (H5Gget_num_objs(
static_cast<const Derivate*
>(
this)->getId(), &res) < 0) {
138 HDF5ErrMapper::ToException<GroupException>(
139 std::string(
"Unable to count objects in existing group or file"));
141 return static_cast<size_t>(res);
144 template <
typename Derivate>
147 return H5Lget_name_by_idx(
148 static_cast<const Derivate*
>(
this)->getId(),
".", H5_INDEX_NAME, H5_ITER_INC,
149 index, buffer, length, H5P_DEFAULT);
153 template <
typename Derivate>
156 return H5Iget_name(
static_cast<const Derivate*
>(
this)->getId(), buffer, length);
160 template <
typename Derivate>
165 lcpl.
add(H5Pset_create_intermediate_group, 1u);
167 herr_t status = H5Lmove(
static_cast<const Derivate*
>(
this)->getId(), src_path.c_str(),
168 static_cast<const Derivate*
>(
this)->getId(), dst_path.c_str(), lcpl.
getId(), H5P_DEFAULT);
170 HDF5ErrMapper::ToException<GroupException>(
171 std::string(
"Unable to move link to \"") + dst_path +
"\":");
177 template <
typename Derivate>
180 std::vector<std::string> names;
183 size_t num_objs = getNumberObjects();
184 names.reserve(num_objs);
186 if (H5Literate(
static_cast<const Derivate*
>(
this)->getId(), H5_INDEX_NAME,
188 &details::internal_high_five_iterate<H5L_info_t>,
189 static_cast<void*
>(&iterateData)) < 0) {
190 HDF5ErrMapper::ToException<GroupException>(
197 template <
typename Derivate>
199 bool raise_errors)
const {
201 const auto val = H5Lexists(
static_cast<const Derivate*
>(
this)->getId(),
202 node_name.c_str(), H5P_DEFAULT);
205 HDF5ErrMapper::ToException<GroupException>(
"Invalid link for exist()");
214 return (node_name ==
"/") ? true : (val > 0);
217 template <
typename Derivate>
221 if (group_path.find(
'/') != std::string::npos) {
224 return (group_path ==
"/") ? true : _exist(group_path,
false);
226 return _exist(group_path);
230 template <
typename Derivate>
232 const herr_t val = H5Ldelete(
static_cast<const Derivate*
>(
this)->getId(),
233 node_name.c_str(), H5P_DEFAULT);
235 HDF5ErrMapper::ToException<GroupException>(
251 case H5L_TYPE_EXTERNAL:
260 template <
typename Derivate>
263 if (H5Lget_info(
static_cast<const Derivate*
>(
this)->getId(),
264 node_name.c_str(), &linkinfo, H5P_DEFAULT) < 0
265 || linkinfo.type == H5L_TYPE_ERROR) {
266 HDF5ErrMapper::ToException<GroupException>(
267 std::string(
"Unable to obtain info for link ") + node_name);
272 template <
typename Derivate>
274 return _open(node_name).getType();
278 template <
typename Derivate>
281 hid_t
id = H5Oopen(
static_cast<const Derivate*
>(
this)->getId(),
283 accessProps.
getId());
285 HDF5ErrMapper::ToException<GroupException>(
286 std::string(
"Unable to open \"") + node_name +
"\":");
295 #endif // H5NODE_TRAITS_MISC_HPP
std::string get_name(T fct)
Definition: H5Utils.hpp:252
LinkType getLinkType(const std::string &node_name) const
Returns the kind of link of the given name (soft, hard...)
Definition: H5Node_traits_misc.hpp:261
std::string getPath() const
return the path to the current object
Definition: H5Node_traits_misc.hpp:154
HDF5 Data Type.
Definition: H5DataType.hpp:42
void add(const F &funct, const Args &... args)
Definition: H5PropertyList_misc.hpp:106
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
Definition: H5Node_traits_misc.hpp:95
Utility class to disable HDF5 stack printing inside a scope.
Definition: H5Utility.hpp:20
static LinkType _convert_link_type(const H5L_type_t <ype) noexcept
Definition: H5Node_traits_misc.hpp:245
Base HDF5 property List.
Definition: H5_definitions.hpp:48
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:129
Definition: H5Object.hpp:36
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:273
A structure representing a set of fixed-length strings.
Definition: H5_definitions.hpp:42
NodeTraits: Base class for Group and File.
Definition: H5_definitions.hpp:45
size_t getNumberObjects() const
return the number of leaf objects of the node / group
Definition: H5Node_traits_misc.hpp:135
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:200
ObjectType
Enum of the types of objects (H5O api)
Definition: H5Object.hpp:25
std::string getObjectName(size_t index) const
return the name of the object with the given index
Definition: H5Node_traits_misc.hpp:145
std::size_t size() const noexcept
Definition: H5DataType.hpp:281
Represents an hdf5 group.
Definition: H5Group.hpp:21
Definition: H5Iterables_misc.hpp:24
Group getGroup(const std::string &group_name) const
open an existing group with the name group_name
Definition: H5Node_traits_misc.hpp:124
Definition: H5PropertyList.hpp:88
hid_t getId() const
Definition: H5PropertyList.hpp:56
unqualified_t< T > type
Definition: H5Utils.hpp:137
void unlink(const std::string &node_name) const
unlink the given dataset or group
Definition: H5Node_traits_misc.hpp:231
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:161
hid_t _hid
Definition: H5Object.hpp:81
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition: H5DataType_misc.hpp:406
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
Group createGroup(const std::string &group_name, bool parents=true)
create a new group, and eventually intermediate groups
Definition: H5Node_traits_misc.hpp:107
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
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
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps(), const DataSetAccessProps &accessProps=DataSetAccessProps())
createDataSet Create a new dataset in the current file of datatype type and of size space
Definition: H5Node_traits_misc.hpp:36
Class representing a dataset.
Definition: H5DataSet.hpp:27
Definition: H5_definitions.hpp:15
LinkType
The possible types of group entries (link concept)
Definition: H5Node_traits.hpp:173
std::vector< std::string > listObjectNames() const
list all leaf objects name of the node / group
Definition: H5Node_traits_misc.hpp:178