This repository was archived by the owner on Feb 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathH5Object_misc.hpp
More file actions
123 lines (104 loc) · 2.86 KB
/
H5Object_misc.hpp
File metadata and controls
123 lines (104 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
*/
#pragma once
#include <iostream>
#include "../H5Exception.hpp"
#include "../H5Utility.hpp"
#include "h5i_wrapper.hpp"
namespace HighFive {
namespace detail {
inline Object make_object(hid_t hid) {
return Object(hid);
}
} // namespace detail
inline Object::Object()
: _hid(H5I_INVALID_HID) {}
inline Object::Object(hid_t hid)
: _hid(hid) {}
inline Object::Object(const Object& other)
: _hid(other._hid) {
if (other.isValid()) {
detail::h5i_inc_ref(_hid);
}
}
inline Object::Object(Object&& other) noexcept
: _hid(other._hid) {
other._hid = H5I_INVALID_HID;
}
inline Object& Object::operator=(const Object& other) {
if (this != &other) {
if ((*this).isValid()) {
detail::h5i_dec_ref(_hid);
}
_hid = other._hid;
if (other.isValid()) {
detail::h5i_inc_ref(_hid);
}
}
return *this;
}
inline Object::~Object() {
if (isValid()) {
if (detail::nothrow::h5i_dec_ref(_hid) < 0) {
HIGHFIVE_LOG_ERROR("Failed to decrease reference count of HID");
}
}
}
inline bool Object::isValid() const noexcept {
return (_hid > 0) && (detail::nothrow::h5i_is_valid(_hid) > 0);
}
inline hid_t Object::getId() const noexcept {
return _hid;
}
static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
switch (h5type) {
case H5I_FILE:
return ObjectType::File;
case H5I_GROUP:
return ObjectType::Group;
case H5I_DATATYPE:
return ObjectType::UserDataType;
case H5I_DATASPACE:
return ObjectType::DataSpace;
case H5I_DATASET:
return ObjectType::Dataset;
case H5I_ATTR:
return ObjectType::Attribute;
default:
return ObjectType::Other;
}
}
inline ObjectType Object::getType() const {
// H5Iget_type is a very lightweight func which extracts the type from the id
return _convert_object_type(detail::h5i_get_type(_hid));
}
inline ObjectInfo Object::getInfo() const {
ObjectInfo info;
#if (H5Oget_info_vers < 3)
if (H5Oget_info(_hid, &info.raw_info) < 0) {
#else
if (H5Oget_info1(_hid, &info.raw_info) < 0) {
#endif
HDF5ErrMapper::ToException<ObjectException>("Unable to obtain info for object");
}
return info;
}
inline haddr_t ObjectInfo::getAddress() const noexcept {
return raw_info.addr;
}
inline size_t ObjectInfo::getRefCount() const noexcept {
return raw_info.rc;
}
inline time_t ObjectInfo::getCreationTime() const noexcept {
return raw_info.btime;
}
inline time_t ObjectInfo::getModificationTime() const noexcept {
return raw_info.mtime;
}
} // namespace HighFive