h5cpp  0.3.3
A modern C++ wrapper for the HDF5 C library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
152  template<typename T>
153  Attribute create(const std::string &name,
154  const property::AttributeCreationList &acpl =
156 
169  template<typename T>
170  Attribute create(const std::string &name,const Dimensions &shape,
171  const property::AttributeCreationList &acpl =
173 
191  template<typename T>
192  Attribute create_from(const std::string &name,const T &value);
193 
201  IteratorConfig &iterator_config() noexcept;
202  const IteratorConfig &iterator_config() const noexcept;
203 
209  const node::Node &node() const noexcept;
210 
214  AttributeIterator begin() const;
215 
219  AttributeIterator end() const;
220 
221  private:
222  node::Node &node_;
223  IteratorConfig iter_config_;
224 
225 
226 };
227 
228 template<typename T>
229 Attribute AttributeManager::create(const std::string &name,
230  const property::AttributeCreationList &acpl) const
231 {
232  auto type = datatype::create<T>();
233  dataspace::Scalar space;
234 
235  return this->create(name,type,space,acpl);
236 }
237 
238 template<typename T>
239 Attribute AttributeManager::create(const std::string &name,
240  const Dimensions &shape,
241  const property::AttributeCreationList &acpl) const
242 {
243  auto type = datatype::create<T>();
244  dataspace::Simple space(shape);
245 
246  return create(name,type,space,acpl);
247 
248 }
249 
250 template<typename T>
251 Attribute AttributeManager::create_from(const std::string &name,const T &value)
252 {
253  auto type = datatype::create<T>();
254  auto space = dataspace::create(value);
255 
256  Attribute a = create(name,type,space);
257  a.write(value);
258  return a;
259 }
260 
261 } // namespace attribute
262 } // 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:72
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:355
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