9#ifndef H5ANNOTATE_TRAITS_MISC_HPP
10#define H5ANNOTATE_TRAITS_MISC_HPP
23template <
typename Derivate>
28 auto attr_id = H5Acreate2(
static_cast<Derivate*
>(
this)->getId(),
29 attribute_name.c_str(),
30 dtype.
_hid, space.
_hid, H5P_DEFAULT, H5P_DEFAULT);
32 HDF5ErrMapper::ToException<AttributeException>(
33 std::string(
"Unable to create the attribute \"") + attribute_name +
"\":");
38template <
typename Derivate>
39template <
typename Type>
43 return createAttribute(attribute_name, space, create_and_check_datatype<Type>());
46template <
typename Derivate>
59template<
typename Derivate>
62 if (H5Adelete(
static_cast<const Derivate*
>(
this)->getId(), attribute_name.c_str()) < 0) {
63 HDF5ErrMapper::ToException<AttributeException>(
64 std::string(
"Unable to delete attribute \"") + attribute_name +
"\":");
68template <
typename Derivate>
70 const std::string& attribute_name)
const {
71 const auto attr_id = H5Aopen(
static_cast<const Derivate*
>(
this)->getId(),
72 attribute_name.c_str(), H5P_DEFAULT);
74 HDF5ErrMapper::ToException<AttributeException>(
75 std::string(
"Unable to open the attribute \"") + attribute_name +
"\":");
80template <
typename Derivate>
82 int res = H5Aget_num_attrs(
static_cast<const Derivate*
>(
this)->getId());
84 HDF5ErrMapper::ToException<AttributeException>(std::string(
85 "Unable to count attributes in existing group or file"));
87 return static_cast<size_t>(res);
90template <
typename Derivate>
91inline std::vector<std::string>
94 std::vector<std::string> names;
95 details::HighFiveIterateData iterateData(names);
97 size_t num_objs = getNumberAttributes();
98 names.reserve(num_objs);
100 if (H5Aiterate2(
static_cast<const Derivate*
>(
this)->getId(), H5_INDEX_NAME,
102 &details::internal_high_five_iterate<H5A_info_t>,
103 static_cast<void*
>(&iterateData)) < 0) {
104 HDF5ErrMapper::ToException<AttributeException>(
105 std::string(
"Unable to list attributes in group"));
111template <
typename Derivate>
114 int res = H5Aexists(
static_cast<const Derivate*
>(
this)->getId(),
117 HDF5ErrMapper::ToException<AttributeException>(
118 std::string(
"Unable to check for attribute in group"));
Attribute createAttribute(const std::string &attribute_name, const DataSpace &space, const DataType &type)
create a new attribute with the name attribute_name
Definition H5Annotate_traits_misc.hpp:25
std::vector< std::string > listAttributeNames() const
list all attribute name of the node / group
Definition H5Annotate_traits_misc.hpp:92
void deleteAttribute(const std::string &attribute_name)
deleteAttribute let you delete an attribute by its name.
Definition H5Annotate_traits_misc.hpp:61
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition H5Annotate_traits_misc.hpp:69
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition H5Annotate_traits_misc.hpp:113
size_t getNumberAttributes() const
return the number of attributes of the node / group
Definition H5Annotate_traits_misc.hpp:81
Class representing an attribute of a dataset or group.
Definition H5Attribute.hpp:25
void write(const T &buffer)
Definition H5Attribute_misc.hpp:94
Class representing the space (dimensions) of a dataset.
Definition H5DataSpace.hpp:37
static DataSpace From(const T &value)
Create a dataspace matching a type accepted by details::inspector.
Definition H5Dataspace_misc.hpp:133
HDF5 Data Type.
Definition H5DataType.hpp:42
hid_t _hid
Definition H5Object.hpp:87
Definition H5_definitions.hpp:15
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition H5DataType_misc.hpp:434