9#ifndef H5ANNOTATE_TRAITS_MISC_HPP
10#define H5ANNOTATE_TRAITS_MISC_HPP
18#include "H5Attribute_misc.hpp"
19#include "H5Iterables_misc.hpp"
23template <
typename Derivate>
29 if ((attribute._hid = H5Acreate2(
30 static_cast<Derivate*
>(
this)->getId(
false), attr_name.c_str(),
31 dtype._hid, space._hid, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
32 HDF5ErrMapper::ToException<AttributeException>(
33 std::string(
"Unable to create the attribute \"") + attr_name +
"\":");
38template <
typename Derivate>
39template <
typename Type>
43 return createAttribute(attr_name, space, create_and_check_datatype<Type>());
46template <
typename Derivate>
54 create_and_check_datatype<
typename details::inspector<T>::base_type>());
59template<
typename Derivate>
62 if (H5Adelete(
static_cast<const Derivate*
>(
this)->getId(
false), attr_name.c_str()) < 0) {
63 HDF5ErrMapper::ToException<AttributeException>(
64 std::string(
"Unable to delete attribute \"") + attr_name +
"\":");
68template <
typename Derivate>
70 const std::string& attr_name)
const {
72 if ((attribute._hid = H5Aopen(
static_cast<const Derivate*
>(
this)->getId(
false),
73 attr_name.c_str(), H5P_DEFAULT)) < 0) {
74 HDF5ErrMapper::ToException<AttributeException>(
75 std::string(
"Unable to open the attribute \"") + attr_name +
81template <
typename Derivate>
83 int res = H5Aget_num_attrs(
static_cast<const Derivate*
>(
this)->getId(
false));
85 HDF5ErrMapper::ToException<AttributeException>(
87 "Unable to count attributes in existing group or file"));
89 return static_cast<size_t>(res);
92template <
typename Derivate>
93inline std::vector<std::string>
96 std::vector<std::string> names;
99 size_t num_objs = getNumberAttributes();
100 names.reserve(num_objs);
102 if (H5Aiterate2(
static_cast<const Derivate*
>(
this)->getId(
false), H5_INDEX_NAME,
104 &details::internal_h5gt_iterate<H5A_info_t>,
105 static_cast<void*
>(&iterateData)) < 0) {
106 HDF5ErrMapper::ToException<AttributeException>(
107 std::string(
"Unable to list attributes in group"));
113template <
typename Derivate>
116 if (attr_name.empty())
119 int res = H5Aexists(
static_cast<const Derivate*
>(
this)->getId(
false),
122 HDF5ErrMapper::ToException<AttributeException>(
123 std::string(
"Unable to check for attribute in group"));
std::vector< std::string > listAttributeNames() const
list all attribute name of the object
Definition H5Annotate_traits_misc.hpp:94
void deleteAttribute(const std::string &attr_name)
deleteAttribute let you delete an attribute by its name.
Definition H5Annotate_traits_misc.hpp:61
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition H5Annotate_traits_misc.hpp:115
Attribute getAttribute(const std::string &attr_name) const
open an existing attribute with the name attr_name
Definition H5Annotate_traits_misc.hpp:69
size_t getNumberAttributes() const
return the number of attributes of the object
Definition H5Annotate_traits_misc.hpp:82
Attribute createAttribute(const std::string &attr_name, const DataSpace &space, const DataType &type)
create a new attribute with the name attr_name
Definition H5Annotate_traits_misc.hpp:25
Class representing an attribute of a dataset or group.
Definition H5Attribute.hpp:22
void write(const T &buffer)
Definition H5Attribute_misc.hpp:113
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:137
HDF5 Data Type.
Definition H5DataType.hpp:48
Definition H5Iterables_misc.hpp:24