h5cpp  0.5.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>
32 #include <h5cpp/core/windows.hpp>
38 
39 //
40 // forward declarations
41 //
42 namespace hdf5 {
43 namespace node {
44 
45 class Node;
46 
47 } // namespace node
48 } // namespace hdf5
49 
50 namespace hdf5 {
51 namespace attribute {
52 
53 //forward declaration
54 class 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,
140  const property::AttributeCreationList &acpl =
142 
155  template<typename T>
156  Attribute create(const std::string &name,
157  const property::AttributeCreationList &acpl =
159 
173  template<typename T>
174  Attribute create(const std::string &name,const Dimensions &shape,
175  const property::AttributeCreationList &acpl =
177 
195  template<typename T>
196  Attribute create_from(const std::string &name,const T &value);
197 
205  IteratorConfig &iterator_config() noexcept;
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 
232 template<typename T>
233 Attribute 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 
242 template<typename T>
243 Attribute 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 
254 template<typename T>
255 Attribute 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
hdf5::dataspace::create
TypeTrait< T >::DataspaceType create(const T &value)
factory function for dataspaces
Definition: type_trait.hpp:89
factory.hpp
hdf5::property::AttributeCreationList
Definition: attribute_creation.hpp:35
hdf5::attribute::AttributeIterator
Definition: attribute_iterator.hpp:39
types.hpp
scalar.hpp
attribute_creation.hpp
hdf5::dataspace::Scalar
scalar dataspace
Definition: scalar.hpp:44
hdf5::datatype::DatatypeHolder::get
const Datatype & get(const T &v=T())
factory holder method for getting reference of data types
Definition: factory.hpp:74
hdf5::datatype::DatatypeHolder
data type object holder
Definition: factory.hpp:53
hdf5::attribute::AttributeManager::create_from
Attribute create_from(const std::string &name, const T &value)
create a new attribute of a given value
Definition: attribute_manager.hpp:255
hdf5::node::Node
Definition: node.hpp:39
windows.hpp
hdf5::attribute::Attribute
Definition: attribute.hpp:48
hdf5::IteratorConfig
iterator configuration
Definition: iterator_config.hpp:71
hdf5::dataspace::Simple
simple multidimensional dataspace
Definition: simple.hpp:43
hdf5::attribute::AttributeManager
provides STL interface for attributes
Definition: attribute_manager.hpp:62
hdf5::node::remove
void remove(const Group &base, const Path &object_path, const property::LinkAccessList &lapl=property::LinkAccessList())
remove node from group
hdf5::Dimensions
std::vector< hsize_t > Dimensions
Definition: types.hpp:32
DLL_EXPORT
#define DLL_EXPORT
Definition: windows.hpp:29
hdf5::dataspace::Dataspace
dataspace base class
Definition: dataspace.hpp:41
attribute.hpp
hdf5::attribute::AttributeManager::create
Attribute create(const std::string &name, const datatype::Datatype &datatype, const dataspace::Dataspace &dataspace, const property::AttributeCreationList &acpl=property::AttributeCreationList()) const
create an attribute
simple.hpp
iterator_config.hpp
hdf5::attribute::Attribute::write
void write(const T &data) const
write data to attribute
Definition: attribute.hpp:351
hdf5::datatype::Datatype
base class for all data types
Definition: datatype.hpp:41
hdf5
top-level namespace of the entire library
Definition: attribute.hpp:45