h5cpp 0.7.0
A modern C++ wrapper for the HDF5 C library
attribute_manager.hpp
Go to the documentation of this file.
1//
2// (c) Copyright 2017 DESY,ESS
3//
4// This file is part of h5cpp.
5//
6// This library is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License as published
8// by the Free Software Foundation; either version 2.1 of the License, or
9// (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
13// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14// License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the
18// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
19// Boston, MA 02110-1301 USA
20// ===========================================================================
21//
22// Authors:
23// Eugen Wintersberger <eugen.wintersberger@desy.de>
24// Jan Kotanski <jan.kotanski@desy.de>
25// Created on: Sep 14, 2017
26//
27#pragma once
28
29#include <string>
31#include <h5cpp/core/types.hpp>
38
39//
40// forward declarations
41//
42namespace hdf5 {
43namespace node {
44
45class Node;
46
47} // namespace node
48} // namespace hdf5
49
50namespace hdf5 {
51namespace attribute {
52
53//forward declaration
54class AttributeIterator;
55
63{
64 public:
65 AttributeManager() = delete;
66
77
83 AttributeManager(const AttributeManager &manager) = default;
84
88 Attribute operator[](size_t index) const;
89
93 Attribute operator[](const std::string &name) const;
94
98 size_t size() const;
99
103 void remove(const std::string &name) const;
104
112 void remove(size_t index) const;
113
120 bool exists(const std::string &name) const;
121
129 void rename(const std::string &old_name,const std::string &new_name) const;
130
137 Attribute create(const std::string &name,
138 const datatype::Datatype &datatype,
139 const dataspace::Dataspace &dataspace,
142
155 template<typename T>
156 Attribute create(const std::string &name,
159
173 template<typename T>
174 Attribute create(const std::string &name,const Dimensions &shape,
177
195 template<typename T>
196 Attribute create_from(const std::string &name,const T &value);
197
206 const IteratorConfig &iterator_config() const noexcept;
207
213 const node::Node &node() const noexcept;
214
218 AttributeIterator begin() const;
219
223 AttributeIterator end() const;
224
225 private:
226 node::Node &node_;
227 IteratorConfig iter_config_;
228
229
230};
231
232template<typename T>
233Attribute AttributeManager::create(const std::string &name,
234 const property::AttributeCreationList &acpl) const
235{
236 hdf5::datatype::DatatypeHolder mem_type_holder;
237 dataspace::Scalar space;
238
239 return this->create(name,mem_type_holder.get<T>(),space,acpl);
240}
241
242template<typename T>
243Attribute AttributeManager::create(const std::string &name,
244 const Dimensions &shape,
245 const property::AttributeCreationList &acpl) const
246{
247 hdf5::datatype::DatatypeHolder mem_type_holder;
248 dataspace::Simple space(shape);
249
250 return create(name,mem_type_holder.get<T>(),space,acpl);
251
252}
253
254template<typename T>
255Attribute AttributeManager::create_from(const std::string &name,const T &value)
256{
257 hdf5::datatype::DatatypeHolder mem_type_holder;
258 auto space = dataspace::create(value);
259
260 Attribute a = create(name,mem_type_holder.get<T>(),space);
261 a.write(value);
262 return a;
263}
264
265} // namespace attribute
266} // namespace hdf5
iterator configuration
Definition: iterator_config.hpp:72
Definition: attribute_iterator.hpp:40
provides STL interface for attributes
Definition: attribute_manager.hpp:63
AttributeManager(const AttributeManager &manager)=default
copy constructor
void rename(const std::string &old_name, const std::string &new_name) const
rename an attribute
size_t size() const
get number of attributes
AttributeManager(node::Node &node)
constructor
Attribute create(const std::string &name, const datatype::Datatype &datatype, const dataspace::Dataspace &dataspace, const property::AttributeCreationList &acpl=property::AttributeCreationList()) const
create an attribute
void remove(size_t index) const
remove attribute by index
Attribute operator[](size_t index) const
get attribute by index
bool exists(const std::string &name) const
check existence
void remove(const std::string &name) const
remove attribute by name
IteratorConfig & iterator_config() noexcept
get iterator configuration
Attribute create_from(const std::string &name, const T &value)
create a new attribute of a given value
Definition: attribute_manager.hpp:255
Attribute operator[](const std::string &name) const
get attribute by name
Definition: attribute.hpp:49
void write(const T &data) const
write data to attribute
Definition: attribute.hpp:351
dataspace base class
Definition: dataspace.hpp:41
scalar dataspace
Definition: scalar.hpp:44
simple multidimensional dataspace
Definition: simple.hpp:43
data type object holder
Definition: factory.hpp:54
const Datatype & get(const T &v=T{})
factory holder method for getting reference of data types
Definition: factory.hpp:74
base class for all data types
Definition: datatype.hpp:42
Definition: node.hpp:40
Definition: attribute_creation.hpp:35
TypeTrait< T >::DataspaceType create(const T &value)
factory function for dataspaces
Definition: type_trait.hpp:89
top-level namespace of the entire library
Definition: attribute.hpp:45
std::vector< hsize_t > Dimensions
Definition: types.hpp:32
#define DLL_EXPORT
Definition: windows.hpp:29