HighFive 3.0.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5Object_misc.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3 *
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 */
9#pragma once
10
11#include <iostream>
12
13#include "../H5Exception.hpp"
14#include "../H5Utility.hpp"
15#include "h5i_wrapper.hpp"
16#include "h5o_wrapper.hpp"
17
18namespace HighFive {
19
21 : _hid(H5I_INVALID_HID) {}
22
23inline Object::Object(hid_t hid) noexcept
24 : _hid(hid) {}
25
26inline Object::Object(const Object& other)
27 : _hid(other._hid) {
28 if (other.isValid()) {
29 detail::h5i_inc_ref(_hid);
30 }
31}
32
33inline Object::Object(Object&& other) noexcept
34 : _hid(other._hid) {
35 other._hid = H5I_INVALID_HID;
36}
37
39 if (this != &other) {
40 if ((*this).isValid()) {
41 detail::h5i_dec_ref(_hid);
42 }
43 _hid = other._hid;
44 other._hid = H5I_INVALID_HID;
45 }
46 return *this;
47}
48
49inline Object& Object::operator=(const Object& other) {
50 if (this != &other) {
51 if ((*this).isValid()) {
52 detail::h5i_dec_ref(_hid);
53 }
54
55 _hid = other._hid;
56 if (other.isValid()) {
57 detail::h5i_inc_ref(_hid);
58 }
59 }
60 return *this;
61}
62
64 if (isValid()) {
65 if (detail::nothrow::h5i_dec_ref(_hid) < 0) {
66 HIGHFIVE_LOG_ERROR("Failed to decrease reference count of HID");
67 }
68 }
69}
70
71inline bool Object::isValid() const noexcept {
72 return (_hid > 0) && (detail::nothrow::h5i_is_valid(_hid) > 0);
73}
74
75inline hid_t Object::getId() const noexcept {
76 return _hid;
77}
78
79static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
80 switch (h5type) {
81 case H5I_FILE:
82 return ObjectType::File;
83 case H5I_GROUP:
84 return ObjectType::Group;
85 case H5I_DATATYPE:
87 case H5I_DATASPACE:
89 case H5I_DATASET:
91 case H5I_ATTR:
93 default:
94 return ObjectType::Other;
95 }
96}
97
99 // H5Iget_type is a very lightweight func which extracts the type from the id
100 return _convert_object_type(detail::h5i_get_type(_hid));
101}
102
104 return ObjectInfo(*this);
105}
106
107inline haddr_t Object::getAddress() const {
108 detail::h5o_info1_t raw_info;
109 detail::h5o_get_info1(_hid, &raw_info);
110 return raw_info.addr;
111}
112
113inline ObjectInfo::ObjectInfo(const Object& obj) {
114 detail::h5o_get_info1(obj.getId(), &raw_info);
115}
116
117inline size_t ObjectInfo::getRefCount() const noexcept {
118 return raw_info.rc;
119}
120inline time_t ObjectInfo::getCreationTime() const noexcept {
121 return raw_info.btime;
122}
123inline time_t ObjectInfo::getModificationTime() const noexcept {
124 return raw_info.mtime;
125}
126
127
128} // namespace HighFive
#define HIGHFIVE_LOG_ERROR(message)
Definition H5Utility.hpp:204
Definition H5Object.hpp:36
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:75
ObjectInfo getInfo() const
Retrieve several infos about the current object (address, dates, etc)
Definition H5Object_misc.hpp:103
~Object()
Definition H5Object_misc.hpp:63
ObjectType getType() const
Gets the fundamental type of the object (dataset, group, etc)
Definition H5Object_misc.hpp:98
haddr_t getAddress() const
Address of an HDF5 object in the file.
Definition H5Object_misc.hpp:107
Object()
Definition H5Object_misc.hpp:20
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:71
hid_t _hid
Definition H5Object.hpp:98
Object & operator=(const Object &other)
Definition H5Object_misc.hpp:49
A class for accessing hdf5 objects info.
Definition H5Object.hpp:118
ObjectInfo(const Object &obj)
Definition H5Object_misc.hpp:113
time_t getCreationTime() const noexcept
Retrieve the object's creation time.
Definition H5Object_misc.hpp:120
size_t getRefCount() const noexcept
Retrieve the number of references to this object.
Definition H5Object_misc.hpp:117
time_t getModificationTime() const noexcept
Retrieve the object's last modification time.
Definition H5Object_misc.hpp:123
Definition assert_compatible_spaces.hpp:15
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:25