HighFive 2.3.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#ifndef H5OBJECT_MISC_HPP
10#define H5OBJECT_MISC_HPP
11
12#include <iostream>
13
14namespace HighFive {
15
16inline Object::Object() : _hid(H5I_INVALID_HID) {}
17
18inline Object::Object(hid_t hid) : _hid(hid) {}
19
20inline Object::Object(const Object& other) : _hid(other._hid) {
21 if (other.isValid() && H5Iinc_ref(_hid) < 0) {
22 throw ObjectException("Reference counter increase failure");
23 }
24}
25
26inline Object::Object(Object&& other) noexcept
27 : _hid(other._hid) {
28 other._hid = H5I_INVALID_HID;
29}
30
31inline Object& Object::operator=(const Object& other) {
32 if (this != &other) {
33 if (_hid != H5I_INVALID_HID)
34 H5Idec_ref(_hid);
35
36 _hid = other._hid;
37 if (other.isValid() && H5Iinc_ref(_hid) < 0) {
38 throw ObjectException("Reference counter increase failure");
39 }
40 }
41 return *this;
42}
43
45 if (isValid() && H5Idec_ref(_hid) < 0) {
46 std::cerr << "HighFive::~Object: reference counter decrease failure"
47 << std::endl;
48 }
49}
50
51inline bool Object::isValid() const noexcept {
52 return (_hid != H5I_INVALID_HID) && (H5Iis_valid(_hid) != false);
53}
54
55inline hid_t Object::getId() const noexcept {
56 return _hid;
57}
58
59static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
60 switch (h5type) {
61 case H5I_FILE:
62 return ObjectType::File;
63 case H5I_GROUP:
64 return ObjectType::Group;
65 case H5I_DATATYPE:
67 case H5I_DATASPACE:
69 case H5I_DATASET:
71 case H5I_ATTR:
73 default:
74 return ObjectType::Other;
75 }
77
79 // H5Iget_type is a very lightweight func which extracts the type from the id
80 H5I_type_t h5type;
81 if ((h5type = H5Iget_type(_hid)) == H5I_BADID) {
82 HDF5ErrMapper::ToException<ObjectException>("Invalid hid or object type");
83 }
84 return _convert_object_type(h5type);
85}
86
88 ObjectInfo info;
89#if (H5Oget_info_vers < 3)
90 if (H5Oget_info(_hid, &info.raw_info) < 0) {
91#else
92 if (H5Oget_info1(_hid, &info.raw_info) < 0) {
93#endif
94 HDF5ErrMapper::ToException<ObjectException>("Unable to obtain info for object");
95 }
96 return info;
97}
98
99inline haddr_t ObjectInfo::getAddress() const noexcept {
100 return raw_info.addr;
101}
102inline size_t ObjectInfo::getRefCount() const noexcept {
103 return raw_info.rc;
104}
105inline time_t ObjectInfo::getCreationTime() const noexcept {
106 return raw_info.btime;
107}
108inline time_t ObjectInfo::getModificationTime() const noexcept {
109 return raw_info.mtime;
110}
111
112
113
114} // namespace
115
116#endif // H5OBJECT_MISC_HPP
Exception specific to HighFive Object interface.
Definition: H5Exception.hpp:75
Definition: H5Object.hpp:36
hid_t getId() const noexcept
getId
Definition: H5Object_misc.hpp:55
ObjectInfo getInfo() const
Retrieve several infos about the current object (address, dates, etc)
Definition: H5Object_misc.hpp:87
~Object()
Definition: H5Object_misc.hpp:44
ObjectType getType() const
Gets the fundamental type of the object (dataset, group, etc)
Definition: H5Object_misc.hpp:78
Object()
Definition: H5Object_misc.hpp:16
bool isValid() const noexcept
isValid
Definition: H5Object_misc.hpp:51
hid_t _hid
Definition: H5Object.hpp:87
Object & operator=(const Object &other)
Definition: H5Object_misc.hpp:31
A class for accessing hdf5 objects info.
Definition: H5Object.hpp:100
time_t getCreationTime() const noexcept
Retrieve the object's creation time.
Definition: H5Object_misc.hpp:105
haddr_t getAddress() const noexcept
Retrieve the address of the object (within its file)
Definition: H5Object_misc.hpp:99
size_t getRefCount() const noexcept
Retrieve the number of references to this object.
Definition: H5Object_misc.hpp:102
H5O_info_t raw_info
Definition: H5Object.hpp:118
time_t getModificationTime() const noexcept
Retrieve the object's last modification time.
Definition: H5Object_misc.hpp:108
Definition: H5_definitions.hpp:15
ObjectType
Enum of the types of objects (H5O api)
Definition: H5Object.hpp:25