h5cpp  0.4.1
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 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 // Created on: Sep 14, 2017
24 //
25 #pragma once
26 
27 #include <string>
29 #include <h5cpp/core/types.hpp>
30 #include <h5cpp/core/windows.hpp>
36 
37 //
38 // forward declarations
39 //
40 namespace hdf5 {
41 namespace node {
42 
43 class Node;
44 
45 } // namespace node
46 } // namespace hdf5
47 
48 namespace hdf5 {
49 namespace attribute {
50 
51 //forward declaration
52 class AttributeIterator;
53 
61 {
62  public:
63  AttributeManager() = delete;
64 
75 
81  AttributeManager(const AttributeManager &manager) = default;
82 
86  Attribute operator[](size_t index) const;
87 
91  Attribute operator[](const std::string &name) const;
92 
96  size_t size() const;
97 
101  void remove(const std::string &name) const;
102 
110  void remove(size_t index) const;
111 
118  bool exists(const std::string &name) const;
119 
127  void rename(const std::string &old_name,const std::string &new_name) const;
128 
135  Attribute create(const std::string &name,
136  const datatype::Datatype &datatype,
137  const dataspace::Dataspace &dataspace,
138  const property::AttributeCreationList &acpl =
140 
153  template<typename T>
154  Attribute create(const std::string &name,
155  const property::AttributeCreationList &acpl =
157 
171  template<typename T>
172  Attribute create(const std::string &name,const Dimensions &shape,
173  const property::AttributeCreationList &acpl =
175 
193  template<typename T>
194  Attribute create_from(const std::string &name,const T &value);
195 
203  IteratorConfig &iterator_config() noexcept;
204  const IteratorConfig &iterator_config() const noexcept;
205 
211  const node::Node &node() const noexcept;
212 
216  AttributeIterator begin() const;
217 
221  AttributeIterator end() const;
222 
223  private:
224  node::Node &node_;
225  IteratorConfig iter_config_;
226 
227 
228 };
229 
230 template<typename T>
231 Attribute AttributeManager::create(const std::string &name,
232  const property::AttributeCreationList &acpl) const
233 {
234  auto type = datatype::create<T>();
235  dataspace::Scalar space;
236 
237  return this->create(name,type,space,acpl);
238 }
239 
240 template<typename T>
241 Attribute AttributeManager::create(const std::string &name,
242  const Dimensions &shape,
243  const property::AttributeCreationList &acpl) const
244 {
245  auto type = datatype::create<T>();
246  dataspace::Simple space(shape);
247 
248  return create(name,type,space,acpl);
249 
250 }
251 
252 template<typename T>
253 Attribute AttributeManager::create_from(const std::string &name,const T &value)
254 {
255  auto type = datatype::create<T>();
256  auto space = dataspace::create(value);
257 
258  Attribute a = create(name,type,space);
259  a.write(value);
260  return a;
261 }
262 
263 } // namespace attribute
264 } // namespace hdf5
TypeTrait< T >::DataspaceType create(const T &value)
factory function for dataspaces
Definition: type_trait.hpp:115
dataspace base class
Definition: dataspace.hpp:41
scalar dataspace
Definition: scalar.hpp:40
iterator configuration
Definition: iterator_config.hpp:71
provides STL interface for attributes
Definition: attribute_manager.hpp:60
Definition: attribute_iterator.hpp:35
Definition: attribute.hpp:43
void write(const T &data) const
write data to attribute
Definition: attribute.hpp:356
simple multidimensional dataspace
Definition: simple.hpp:39
Definition: node.hpp:39
std::vector< hsize_t > Dimensions
Definition: types.hpp:36
#define DLL_EXPORT
Definition: windows.hpp:35
Definition: attribute.hpp:46
base class for all data types
Definition: datatype.hpp:41
Definition: attribute_creation.hpp:35