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 #ifndef H5ANNOTATE_TRAITS_MISC_HPP
10 #define H5ANNOTATE_TRAITS_MISC_HPP
11 
12 #include "H5Annotate_traits.hpp"
13 #include "H5Iterables_misc.hpp"
14 
15 #include <string>
16 #include <vector>
17 
18 #include "../H5Attribute.hpp"
19 #include "../H5DataSpace.hpp"
20 #include "../H5DataType.hpp"
21 #include "../H5Exception.hpp"
22 
23 #include <H5Apublic.h>
24 
25 namespace HighFive {
26 
27 template <typename Derivate>
28 inline Attribute
29 AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
30  const DataSpace& space,
31  const DataType& dtype) {
32  Attribute attribute;
33  if ((attribute._hid = H5Acreate2(
34  static_cast<Derivate*>(this)->getId(), attribute_name.c_str(),
35  dtype._hid, space._hid, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
36  HDF5ErrMapper::ToException<AttributeException>(
37  std::string("Unable to create the attribute \"") + attribute_name +
38  "\":");
39  }
40  return attribute;
41 }
42 
43 template <typename Derivate>
44 template <typename Type>
45 inline Attribute
46 AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
47  const DataSpace& space) {
48  return createAttribute(attribute_name, space, AtomicType<Type>());
49 }
50 
51 template <typename Derivate>
52 template <typename T>
53 inline Attribute
54 AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
55  const T& data) {
57  attribute_name, DataSpace::From(data),
59  att.write(data);
60  return att;
61 }
62 
63 template <typename Derivate>
65  const std::string& attribute_name) const {
66  Attribute attribute;
67  if ((attribute._hid = H5Aopen(static_cast<const Derivate*>(this)->getId(),
68  attribute_name.c_str(), H5P_DEFAULT)) < 0) {
69  HDF5ErrMapper::ToException<AttributeException>(
70  std::string("Unable to open the attribute \"") + attribute_name +
71  "\":");
72  }
73  return attribute;
74 }
75 
76 template <typename Derivate>
78  int res = H5Aget_num_attrs(static_cast<const Derivate*>(this)->getId());
79  if (res < 0) {
80  HDF5ErrMapper::ToException<AttributeException>(std::string(
81  "Unable to count attributes in existing group or file"));
82  }
83  return res;
84 }
85 
86 template <typename Derivate>
87 inline std::vector<std::string>
89 
90  std::vector<std::string> names;
91  details::HighFiveIterateData iterateData(names);
92 
93  size_t num_objs = getNumberAttributes();
94  names.reserve(num_objs);
95 
96  if (H5Aiterate2(static_cast<const Derivate*>(this)->getId(), H5_INDEX_NAME,
97  H5_ITER_INC, NULL,
98  &details::internal_high_five_iterate<H5A_info_t>,
99  static_cast<void*>(&iterateData)) < 0) {
100  HDF5ErrMapper::ToException<AttributeException>(
101  std::string("Unable to list attributes in group"));
102  }
103 
104  return names;
105 }
106 
107 template <typename Derivate>
108 inline bool
109 AnnotateTraits<Derivate>::hasAttribute(const std::string& attr_name) const {
110  int res = H5Aexists(static_cast<const Derivate*>(this)->getId(),
111  attr_name.c_str());
112  if (res < 0) {
113  HDF5ErrMapper::ToException<AttributeException>(
114  std::string("Unable to check for attribute in group"));
115  }
116  return res;
117 }
118 }
119 
120 #endif // H5ANNOTATE_TRAITS_MISC_HPP
HighFive::DataType
HDF5 Data Type.
Definition: H5DataType.hpp:21
HighFive::AnnotateTraits::getNumberAttributes
size_t getNumberAttributes() const
return the number of attributes of the node / group
Definition: H5Annotate_traits_misc.hpp:77
HighFive::AnnotateTraits::createAttribute
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:29
NULL
#define NULL
Definition: mydefs.hpp:141
HighFive::AnnotateTraits::hasAttribute
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition: H5Annotate_traits_misc.hpp:109
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
HighFive::details::type_of_array::type
T type
Definition: H5Utils.hpp:102
HighFive::details::HighFiveIterateData
Definition: H5Iterables_misc.hpp:26
H5Iterables_misc.hpp
H5Annotate_traits.hpp
HighFive::AtomicType
create an HDF5 DataType from a C++ type
Definition: H5DataType.hpp:41
HighFive::Attribute
Definition: H5Attribute.hpp:23
HighFive::AnnotateTraits::listAttributeNames
std::vector< std::string > listAttributeNames() const
list all attribute name of the node / group
Definition: H5Annotate_traits_misc.hpp:88
HighFive::AnnotateTraits::getAttribute
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:64
HighFive::Object::_hid
hid_t _hid
Definition: H5Object.hpp:48
HighFive::DataSpace
Definition: H5DataSpace.hpp:30
HighFive::AnnotateTraits::createAttribute
Attribute createAttribute(const std::string &attribute_name, const T &data)
createAttribute create a new attribute on the current dataset and write to it, inferring the DataSpac...
Definition: H5Annotate_traits_misc.hpp:54
HighFive
Definition: H5Annotate_traits.hpp:14
HighFive::Attribute::write
void write(const T &buffer)
Definition: H5Attribute_misc.hpp:93


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23