DOLFIN
DOLFIN C++ interface
HDF5Attribute.h
1 // Copyright (C) 2013 Chris N. Richardson
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // First added: 2013-10-16
19 // Last changed: 2014-11-24
20 
21 #ifndef __DOLFIN_HDF5ATTRIBUTE_H
22 #define __DOLFIN_HDF5ATTRIBUTE_H
23 
24 #ifdef HAS_HDF5
25 
26 #include <string>
27 #include <vector>
28 
29 #include<dolfin/common/Array.h>
30 #include "HDF5Interface.h"
31 
32 namespace dolfin
33 {
34 
37 
39  {
40  public:
41 
42  // FIXME: Check validity of file and dataset
43 
45  HDF5Attribute(const hid_t hdf5_file_id, std::string dataset_name)
46  : hdf5_file_id(hdf5_file_id), dataset_name(dataset_name) {}
47 
50 
52  bool exists(const std::string attribute_name) const;
53 
55  void set(const std::string attribute_name, const double value);
56 
58  void set(const std::string attribute_name, const std::size_t value);
59 
61  void set(const std::string attribute_name,
62  const std::vector<double>& value);
63 
65  void set(const std::string attribute_name,
66  const std::vector<std::size_t>& value);
67 
69  void set(const std::string attribute_name, const std::string value);
70 
72  void get(const std::string attribute_name, double& value) const;
73 
75  void get(const std::string attribute_name,
76  std::vector<double>& value) const;
77 
79  void get(const std::string attribute_name, std::size_t& value) const;
80 
82  void get(const std::string attribute_name,
83  std::vector<std::size_t>& value) const;
84 
86  void get(const std::string attribute_name, std::string& value) const;
87 
90  const std::string str(const std::string attribute_name) const;
91 
94  const std::string type_str(const std::string attribute_name) const;
95 
97  const std::string str() const;
98 
101  const std::vector<std::string> list_attributes() const;
102 
103  private:
104 
105  const hid_t hdf5_file_id;
106  const std::string dataset_name;
107 
108  // Set the value of an attribute in the HDF5 file
109  template <typename T>
110  void set_value(const std::string attribute_name, const T& value);
111 
112  // Get the value of an attribute in the HDF5 file
113  template <typename T>
114  void get_value(const std::string attribute_name, T& value) const;
115 
116  template <typename T>
117  const std::string
118  vector_to_string(const std::vector<T>& vector_value) const;
119 
120  };
121 }
122 
123 #endif
124 #endif
bool exists(const std::string attribute_name) const
Check for the existence of an attribute on a dataset.
Definition: HDF5Attribute.cpp:180
Definition: adapt.h:29
const std::string type_str(const std::string attribute_name) const
Definition: HDF5Attribute.cpp:212
const std::vector< std::string > list_attributes() const
Definition: HDF5Attribute.cpp:206
Definition: HDF5Attribute.h:38
HDF5Attribute(const hid_t hdf5_file_id, std::string dataset_name)
Constructor.
Definition: HDF5Attribute.h:45
const std::string str() const
Get the names of all the attributes on this dataset.
Definition: HDF5Attribute.cpp:193
~HDF5Attribute()
Destructor.
Definition: HDF5Attribute.h:49