HighFive 2.9.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Annotate_traits_misc.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#include <vector>
13
14#include <H5Apublic.h>
15#include <H5Ppublic.h>
16
17#include "H5Attribute_misc.hpp"
18#include "H5Iterables_misc.hpp"
19#include "h5a_wrapper.hpp"
20
21namespace HighFive {
22
23template <typename Derivate>
24inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
25 const DataSpace& space,
26 const DataType& dtype) {
27 auto attr_id = detail::h5a_create2(static_cast<Derivate*>(this)->getId(),
28 attribute_name.c_str(),
29 dtype.getId(),
30 space.getId(),
31 H5P_DEFAULT,
32 H5P_DEFAULT);
33 return detail::make_attribute(attr_id);
34}
35
36template <typename Derivate>
37template <typename Type>
38inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
39 const DataSpace& space) {
40 return createAttribute(attribute_name, space, create_and_check_datatype<Type>());
41}
42
43template <typename Derivate>
44template <typename T>
45inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
46 const T& data) {
47 Attribute att =
48 createAttribute(attribute_name,
49 DataSpace::From(data),
50 create_and_check_datatype<typename details::inspector<T>::base_type>());
51 att.write(data);
52 return att;
53}
54
55template <typename Derivate>
56inline void AnnotateTraits<Derivate>::deleteAttribute(const std::string& attribute_name) {
57 detail::h5a_delete(static_cast<const Derivate*>(this)->getId(), attribute_name.c_str());
58}
59
60template <typename Derivate>
61inline Attribute AnnotateTraits<Derivate>::getAttribute(const std::string& attribute_name) const {
62 const auto attr_id = detail::h5a_open(static_cast<const Derivate*>(this)->getId(),
63 attribute_name.c_str(),
64 H5P_DEFAULT);
65 return detail::make_attribute(attr_id);
67
68template <typename Derivate>
70 int res = detail::h5a_get_num_attrs(static_cast<const Derivate*>(this)->getId());
71 return static_cast<size_t>(res);
72}
73
74template <typename Derivate>
75inline std::vector<std::string> AnnotateTraits<Derivate>::listAttributeNames() const {
76 std::vector<std::string> names;
77 details::HighFiveIterateData iterateData(names);
78
79 size_t num_objs = getNumberAttributes();
80 names.reserve(num_objs);
81
82 detail::h5a_iterate2(static_cast<const Derivate*>(this)->getId(),
83 H5_INDEX_NAME,
84 H5_ITER_INC,
85 nullptr,
86 &details::internal_high_five_iterate<H5A_info_t>,
87 static_cast<void*>(&iterateData));
88
89 return names;
90}
91
92template <typename Derivate>
93inline bool AnnotateTraits<Derivate>::hasAttribute(const std::string& attr_name) const {
94 return detail::h5a_exists(static_cast<const Derivate*>(this)->getId(), attr_name.c_str()) > 0;
95}
96
97} // namespace HighFive
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:24
std::vector< std::string > listAttributeNames() const
list all attribute name of the node / group
Definition H5Annotate_traits_misc.hpp:75
void deleteAttribute(const std::string &attribute_name)
deleteAttribute let you delete an attribute by its name.
Definition H5Annotate_traits_misc.hpp:56
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition H5Annotate_traits_misc.hpp:61
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition H5Annotate_traits_misc.hpp:93
size_t getNumberAttributes() const
return the number of attributes of the node / group
Definition H5Annotate_traits_misc.hpp:69
Class representing an Attribute of a DataSet or Group.
Definition H5Attribute.hpp:46
void write(const T &value)
Write the value into the Attribute.
Definition H5Attribute_misc.hpp:131
Class representing the space (dimensions) of a DataSet.
Definition H5DataSpace.hpp:31
static DataSpace From(const T &value)
Automatically deduce the DataSpace from a container/value.
Definition H5Dataspace_misc.hpp:122
HDF5 Data Type.
Definition H5DataType.hpp:61
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
Definition H5_definitions.hpp:22
DataType create_and_check_datatype()
Create a DataType instance representing type T and perform a sanity check on its size.
Definition H5DataType_misc.hpp:486