HighFive 2.10.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
17namespace HighFive {
18namespace detail {
19inline Object make_object(hid_t hid) {
20 return Object(hid);
21}
22} // namespace detail
23
24
26 : _hid(H5I_INVALID_HID) {}
27
28inline Object::Object(hid_t hid)
29 : _hid(hid) {}
30
31inline Object::Object(const Object& other)
32 : _hid(other._hid) {
33 if (other.isValid()) {
34 detail::h5i_inc_ref(_hid);
35 }
36}
37
38inline Object::Object(Object&& other) noexcept
39 : _hid(other._hid) {
40 other._hid = H5I_INVALID_HID;
41}
42
43inline Object& Object::operator=(const Object& other) {
44 if (this != &other) {
45 if ((*this).isValid()) {
46 detail::h5i_dec_ref(_hid);
47 }
48
49 _hid = other._hid;
50 if (other.isValid()) {
51 detail::h5i_inc_ref(_hid);
52 }
53 }
54 return *this;
55}
56
58 if (isValid()) {
59 if (detail::nothrow::h5i_dec_ref(_hid) < 0) {
60 HIGHFIVE_LOG_ERROR("Failed to decrease reference count of HID");
61 }
62 }
63}
64
65inline bool Object::isValid() const noexcept {
66 return (_hid > 0) && (detail::nothrow::h5i_is_valid(_hid) > 0);
67}
68
69inline hid_t Object::getId() const noexcept {
70 return _hid;
71}
72
73static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
74 switch (h5type) {
75 case H5I_FILE:
76 return ObjectType::File;
77 case H5I_GROUP:
78 return ObjectType::Group;
79 case H5I_DATATYPE:
81 case H5I_DATASPACE:
83 case H5I_DATASET:
85 case H5I_ATTR:
87 default:
88 return ObjectType::Other;
89 }
90}
91
93 // H5Iget_type is a very lightweight func which extracts the type from the id
94 return _convert_object_type(detail::h5i_get_type(_hid));
95}
96
98 ObjectInfo info;
99#if (H5Oget_info_vers < 3)
100 if (H5Oget_info(_hid, &info.raw_info) < 0) {
101#else
102 if (H5Oget_info1(_hid, &info.raw_info) < 0) {
103#endif
104 HDF5ErrMapper::ToException<ObjectException>("Unable to obtain info for object");
105 }
106 return info;
107}
108
109inline haddr_t ObjectInfo::getAddress() const noexcept {
110 return raw_info.addr;
111}
112inline size_t ObjectInfo::getRefCount() const noexcept {
113 return raw_info.rc;
114}
115inline time_t ObjectInfo::getCreationTime() const noexcept {
116 return raw_info.btime;
117}
118inline time_t ObjectInfo::getModificationTime() const noexcept {
119 return raw_info.mtime;
120}
121
122
123} // namespace HighFive
#define HIGHFIVE_LOG_ERROR(message)
Definition H5Utility.hpp:204
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
ObjectInfo getInfo() const
Retrieve several infos about the current object (address, dates, etc)
Definition H5Object_misc.hpp:97
~Object()
Definition H5Object_misc.hpp:57
ObjectType getType() const
Gets the fundamental type of the object (dataset, group, etc)
Definition H5Object_misc.hpp:92
Object()
Definition H5Object_misc.hpp:25
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:65
hid_t _hid
Definition H5Object.hpp:105
Object & operator=(const Object &other)
Definition H5Object_misc.hpp:43
A class for accessing hdf5 objects info.
Definition H5Object.hpp:126
time_t getCreationTime() const noexcept
Retrieve the object's creation time.
Definition H5Object_misc.hpp:115
haddr_t getAddress() const noexcept
Retrieve the address of the object (within its file)
Definition H5Object_misc.hpp:109
size_t getRefCount() const noexcept
Retrieve the number of references to this object.
Definition H5Object_misc.hpp:112
H5O_info_t raw_info
Definition H5Object.hpp:144
time_t getModificationTime() const noexcept
Retrieve the object's last modification time.
Definition H5Object_misc.hpp:118
Definition H5_definitions.hpp:22
ObjectType
Enum of the types of objects (H5O api)
Definition H5Object.hpp:24
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43