-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathH5Object.cpp
More file actions
136 lines (98 loc) · 2.34 KB
/
H5Object.cpp
File metadata and controls
136 lines (98 loc) · 2.34 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
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2013, German Neuroinformatics Node (G-Node)
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.
#include "H5Object.hpp"
#include "H5Exception.hpp"
namespace nix {
namespace hdf5 {
H5Object::H5Object(const H5Object &other)
: hid(other.hid)
{
inc();
}
H5Object::H5Object(H5Object &&other) : hid(other.hid) {
other.invalidate();
}
H5Object &H5Object::operator=(const H5Object &other) {
if (hid != other.hid) {
dec();
hid = other.hid;
inc();
}
return *this;
}
H5Object &H5Object::operator=(H5Object &&other) {
hid = other.hid;
other.invalidate();
return *this;
}
bool H5Object::operator==(const H5Object &other) const {
if (H5Iis_valid(hid) && H5Iis_valid(other.hid))
return hid == other.hid;
else
return false;
}
bool H5Object::operator!=(const H5Object &other) const {
return !(*this == other);
}
hid_t H5Object::h5id() const {
return hid;
}
int H5Object::refCount() const {
if (H5Iis_valid(hid)) {
return H5Iget_ref(hid);
} else {
return -1;
}
}
bool H5Object::isValid() const {
HTri res = H5Iis_valid(hid);
res.check("H5Object::isValid() failed");
return res.result();
}
std::string H5Object::name() const {
if (! H5Iis_valid(hid)) {
//maybe throw an exception?
return "";
}
ssize_t len = H5Iget_name(hid, nullptr, 0);
if (len < 0) {
throw H5Exception("Could not get size of name");
}
std::vector<char> buffer(static_cast<size_t>(len + 1), 0);
len = H5Iget_name(hid, buffer.data(), buffer.size());
if (len < 0) {
throw H5Exception("Could not obtain name");
}
std::string name = std::string(buffer.data());
return name;
}
H5I_type_t H5Object::type() const {
return H5Iget_type(hid);
}
void H5Object::close() {
dec();
invalidate();
}
H5Object::~H5Object() {
H5Object::close();
}
void H5Object::inc() const {
if (H5Iis_valid(hid)) {
H5Iinc_ref(hid);
}
}
void H5Object::dec() const {
if (H5Iis_valid(hid)) {
H5Idec_ref(hid);
}
}
void H5Object::invalidate() {
hid = H5I_INVALID_HID;
}
} // namespace hdf5
} // namespace nix