HighFive 2.7.1
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
16namespace HighFive {
17namespace detail {
18inline Object make_object(hid_t hid) {
19 return Object(hid);
20}
21} // namespace detail
22
23
25 : _hid(H5I_INVALID_HID) {}
26
27inline Object::Object(hid_t hid)
28 : _hid(hid) {}
29
30inline Object::Object(const Object& other)
31 : _hid(other._hid) {
32 if (other.isValid() && H5Iinc_ref(_hid) < 0) {
33 throw ObjectException("Reference counter increase failure");
34 }
35}
36
37inline Object::Object(Object&& other) noexcept
38 : _hid(other._hid) {
39 other._hid = H5I_INVALID_HID;
40}
41
42inline Object& Object::operator=(const Object& other) {
43 if (this != &other) {
44 if (isValid())
45 H5Idec_ref(_hid);
46
47 _hid = other._hid;
48 if (other.isValid() && H5Iinc_ref(_hid) < 0) {
49 throw ObjectException("Reference counter increase failure");
50 }
51 }
52 return *this;
53}
54
56 if (isValid() && H5Idec_ref(_hid) < 0) {
57 HIGHFIVE_LOG_ERROR("HighFive::~Object: reference counter decrease failure");
58 }
59}
60
61inline bool Object::isValid() const noexcept {
62 return (_hid != H5I_INVALID_HID) && (H5Iis_valid(_hid) != false);
63}
64
65inline hid_t Object::getId() const noexcept {
66 return _hid;
67}
68
69static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
70 switch (h5type) {
71 case H5I_FILE:
72 return ObjectType::File;
73 case H5I_GROUP:
74 return ObjectType::Group;
75 case H5I_DATATYPE:
77 case H5I_DATASPACE:
79 case H5I_DATASET:
81 case H5I_ATTR:
83 default:
84 return ObjectType::Other;
85 }
86}
87
89 // H5Iget_type is a very lightweight func which extracts the type from the id
90 H5I_type_t h5type;
91 if ((h5type = H5Iget_type(_hid)) == H5I_BADID) {
92 HDF5ErrMapper::ToException<ObjectException>("Invalid hid or object type");
93 }
94 return _convert_object_type(h5type);
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:201
Exception specific to HighFive Object interface.
Definition H5Exception.hpp:85
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:65
ObjectInfo getInfo() const
Retrieve several infos about the current object (address, dates, etc)
Definition H5Object_misc.hpp:97
~Object()
Definition H5Object_misc.hpp:55
ObjectType getType() const
Gets the fundamental type of the object (dataset, group, etc)
Definition H5Object_misc.hpp:88
Object()
Definition H5Object_misc.hpp:24
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:61
hid_t _hid
Definition H5Object.hpp:105
Object & operator=(const Object &other)
Definition H5Object_misc.hpp:42
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:15
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:42