FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
H++/H5Object.hpp
1#ifndef __H5_OBJECT_HPP
2#define __H5_OBJECT_HPP
3
4#include <memcore/RefPtr.hpp>
5#include <hdf5.h>
6#include <hdf5init.hpp>
7
8#include <vector>
9#include <filesystem>
10
11class H5LinkAccess;
12
13class H5Identifier : public MemCore::ReferenceBase<H5Identifier>, HDF5User
14{
15protected:
16 hid_t hid = 0;
17
18 H5Identifier(hid_t id);
19 H5Identifier(const H5Identifier&) = delete;
20 H5Identifier&operator=(const H5Identifier&) = delete;
21
22 virtual ~H5Identifier();
23
24public:
25 template <class T>
27
28static consteval hid_t invalid_id()
29 {
30 return H5I_INVALID_HID;
31 }
32
33
34 void inc_ref() const
35 {
36 H5Iinc_ref(hid);
37 }
38
39 void dec_ref() const
40 {
41 H5Idec_ref(hid);
42 }
43
44
45 struct Silence
46 {
47 H5E_auto2_t func;
48 void *client_data;
49
50 Silence(const Silence&) = delete;
51 void operator=(const Silence&) = delete;
52
53 Silence()
54 {
55 H5Eget_auto2( H5E_DEFAULT, &func, &client_data );
56 H5Eset_auto2( H5E_DEFAULT, 0,0);
57 }
58
59 ~Silence()
60 {
61 H5Eset_auto2( H5E_DEFAULT, func, client_data);
62 }
63 };
64
65 template <class Lambda>
66static auto Silentio(const Lambda&L) -> decltype( L() )
67 {
68 Silence BeSilent;
69 return L();
70 }
71
72
73 struct CaptureErrors : std::string, Silence
74 {
76
78 };
79
81 hid_t getHid() const
82 {
83 return hid;
84 }
85
87 hid_t getHidClone() const
88 {
89 H5Iinc_ref( hid );
90 return hid;
91 }
92
94 hid_t clone() const
95 {
96 inc_ref();
97 return hid;
98 }
99
102 bool isValid() const
103 {
104 return hid>0;
105 }
106
112static bool isActive()
113 {
114 return HDF5Init::isActive();
115 }
116};
117
121class H5Object : public H5Identifier
122{
123protected:
124 H5Object();
125 H5Object(const H5Object&) = delete;
126
127 H5Object&operator=(const H5Object&) = delete;
128
129 virtual ~H5Object();
130
131 H5Object(hid_t ID);
132
133public:
134
136 H5Object(hid_t parent_id, const char*name, hid_t link_access_properties = H5P_DEFAULT);
137
139 H5Object(const refptr<H5Object>&parent, const char*name, hid_t link_access_properties = H5P_DEFAULT)
140 : H5Object( parent?parent->hid : 0, name, link_access_properties)
141 {}
142
144 H5Object(hid_t parent_id, const char*name, const H5LinkAccess&link_access_properties);
145
147 H5Object(const refptr<H5Object>&parent, const char*name, const H5LinkAccess&link_access_properties);
148
149
150 bool Awrite(const char*AttributeName, hid_t file_type_id,
151 hid_t mem_type_id,
152 const void*data,
153 size_t Elements) const;
154
155 bool Awrite(const std::string&AttributeName, hid_t file_type_id,
156 hid_t mem_type_id,
157 const void*data,
158 size_t Elements) const
159 {
160 return Awrite(AttributeName.c_str(), file_type_id,
161 mem_type_id, data, Elements);
162 }
163
164 template <class name_t>
165 bool Awrite(const name_t&AttributeName, hid_t type_id, const void*data, size_t Elements) const
166 {
167 return Awrite(AttributeName, type_id, type_id, data, Elements);
168 }
169
170
171 template <class name_t>
172 bool Awrite(const name_t&AttributeName, const int16_t*data, size_t Elements) const
173 {
174 return Awrite( AttributeName, H5T_NATIVE_INT16, data, Elements);
175 }
176
177 template <class name_t>
178 bool Awrite(const name_t&AttributeName, const int32_t*data, size_t Elements) const
179 {
180 return Awrite( AttributeName, H5T_NATIVE_INT32, data, Elements);
181 }
182
183 template <class name_t>
184 bool Awrite(const name_t&AttributeName, const int64_t*data, size_t Elements) const
185 {
186 return Awrite( AttributeName, H5T_NATIVE_INT64, data, Elements);
187 }
188
189
190 template <class name_t>
191 bool Awrite(const name_t&AttributeName, const uint16_t*data, size_t Elements) const
192 {
193 return Awrite( AttributeName, H5T_NATIVE_UINT16, data, Elements);
194 }
195
196 template <class name_t>
197 bool Awrite(const name_t&AttributeName, const uint32_t*data, size_t Elements) const
198 {
199 return Awrite( AttributeName, H5T_NATIVE_UINT32, data, Elements);
200 }
201
202 template <class name_t>
203 bool Awrite(const name_t&AttributeName, const uint64_t*data, size_t Elements) const
204 {
205 return Awrite( AttributeName, H5T_NATIVE_UINT64, data, Elements);
206 }
207
208 template <class name_t>
209 bool Awrite(const name_t&AttributeName, const double*data, size_t Elements = 1) const
210 {
211 return Awrite( AttributeName, H5T_NATIVE_DOUBLE, data, Elements);
212 }
213
214 template <class name_t, class value_type>
215 bool Awrite(const name_t&AttributeName, const value_type&value) const
216 {
217 return Awrite( AttributeName, &value, 1);
218 }
219
220
221 template <class T>
222 bool Awrite(const std::string&AttributeName, const std::vector<T>&data) const
223 {
224 return Awrite( AttributeName, data.data(), data.size());
225 }
226
227 bool Awrite(const char*AttributeName, const std::string&data) const;
228 bool Awrite(const std::string&AttributeName, const std::string&data) const
229 {
230 return Awrite(AttributeName.c_str(), data);
231 }
232
233
238static std::string getFilename(hid_t hid);
239
241 std::string getFilename() const
242 {
243 if (!isValid() )
244 return {};
245
246 return getFilename( hid );
247 }
248
250 std::string get_filename() const
251 {
252 return getFilename();
253 }
254
255static std::filesystem::path getFilePath(hid_t hid)
256 {
257 return getFilename(hid);
258 }
259
262 {
263 return getFilePath(hid);
264 }
265
270static std::string get_name(hid_t hid);
271
272 std::string get_name() const
273 {
274 if (!isValid() )
275 return {};
276
277 return get_name( hid );
278 }
279
280 std::string get_object_path() const
281 {
282 return get_name();
283 }
284
285 std::string get_object_path_within_file() const
286 {
287 return get_name();
288 }
289
290 std::string get_path() const
291 {
292 return get_name();
293 }
294
295 herr_t get_info(H5O_info2_t&object_info, unsigned info_fields) const;
296 time_t get_modification_time() const;
297 hsize_t num_attribs() const;
298
299 H5O_type_t get_type() const;
300 refptr<H5Object> get_typed_object() const;
301
302
303 time_t get_age() const
304 {
305 return get_modification_time();
306 }
307};
308
309#endif // __H5_OBJECT_HPP
basic_string< char > string
Definition H++/H5Object.hpp:14
bool isValid() const
Check whether this HDF5 object is valid, i.e., has a valid ID.
Definition H++/H5Object.hpp:102
hid_t clone() const
Get a copy of the associated HDF5 ID.
Definition H++/H5Object.hpp:94
hid_t getHid() const
Get the associated HDF5 ID.
Definition H++/H5Object.hpp:81
static bool isActive()
Check whether the HDF5 library is active, i.e., has been correctly initialized and not been closed al...
Definition H++/H5Object.hpp:112
hid_t getHidClone() const
Get a copy of the associated HDF5 ID.
Definition H++/H5Object.hpp:87
Definition H++/H5Property.hpp:57
Base class for groups, datasets and named datatypes.
Definition H++/H5Object.hpp:122
std::string getFilename() const
Get the filename associated with this HDF5 object.
Definition H++/H5Object.hpp:241
std::string get_filename() const
Get the filename associated with this HDF5 object.
Definition H++/H5Object.hpp:250
H5Object(const refptr< H5Object > &parent, const char *name, hid_t link_access_properties=H5P_DEFAULT)
H5Oopen()
Definition H++/H5Object.hpp:139
static std::string get_name(hid_t hid)
Gets the name associated with the given HDF5 ID, a wrapper to H5Iget_name() .
Definition H++/H5Object.cpp:157
std::filesystem::path getFilePath() const
Get the filename associated with this HDF5 object.
Definition H++/H5Object.hpp:261
Definition H++/H5Object.hpp:74
Definition H++/H5Object.hpp:46