TRIQS/h5
2.0.0
C++ interface to HDF5
Toggle main menu visibility
Loading...
Searching...
No Matches
object.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019-2024 Simons Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0.txt
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
21
22
#ifndef LIBH5_OBJECT_HPP
23
#define LIBH5_OBJECT_HPP
24
25
#include "
./utils.hpp
"
26
27
#include <string>
28
29
namespace
h5 {
30
35
49
class
object
{
50
protected
:
51
// Wrapped HDF5 ID.
52
hid_t
id
= 0;
// NOLINT (protected member is wanted here)
53
54
public
:
61
[[nodiscard]]
static
object
from_borrowed
(
hid_t
id
);
62
71
object
(
hid_t
id
= 0) : id(id) {}
72
77
object
(
object
const
&other);
78
83
object
(
object
&&other) noexcept : id(other.id) { other.id = 0; }
84
89
object
&
operator=
(
object
const
&rhs) {
90
operator=
(
object
(rhs));
91
return
*
this
;
92
}
93
98
object
&
operator=
(
object
&&rhs)
noexcept
;
99
101
~object
() {
close
(); }
102
104
void
close
();
105
107
operator
hid_t
()
const
{
return
id; }
108
110
[[nodiscard]]
int
get_ref_count
()
const
;
111
113
[[nodiscard]]
bool
is_valid
()
const
;
114
};
115
116
// simple but useful aliases. It does NOT check the h5 type of the object.
117
// FIXME : derive and make a check ??
118
120
using
dataset
=
object
;
121
123
using
datatype
=
object
;
124
126
using
dataspace
=
object
;
127
129
using
proplist
=
object
;
130
132
using
attribute
=
object
;
133
135
140
141
namespace
detail {
142
143
// Map a C++ type to an HDF5 type (specializations are in object.cpp).
144
template
<
typename
T>
145
hid_t
hid_t_of();
146
147
}
// namespace detail
148
155
template
<
typename
T>
156
[[nodiscard]]
datatype
hdf5_type
() {
157
return
object::from_borrowed
(detail::hid_t_of<T>());
158
}
159
168
[[nodiscard]] std::string
get_name_of_h5_type
(
datatype
dt);
169
176
[[nodiscard]]
datatype
get_hdf5_type
(
dataset
ds);
177
190
[[nodiscard]]
bool
hdf5_type_equal
(
datatype
dt1,
datatype
dt2);
191
193
194
}
// namespace h5
195
196
#endif
// LIBH5_OBJECT_HPP
h5::object
A generic handle for HDF5 objects.
Definition
object.hpp:49
h5::object::is_valid
bool is_valid() const
Ensure that the wrapped HDF5 ID is valid (by calling H5Iis_valid).
Definition
object.cpp:116
h5::object::get_ref_count
int get_ref_count() const
Get the current reference count.
Definition
object.cpp:114
h5::object::object
object(object &&other) noexcept
Move constructor steals the underlying HDF5 ID without increasing its reference count.
Definition
object.hpp:83
h5::object::~object
~object()
Destructor decreases the reference count and sets the object's ID to zero.
Definition
object.hpp:101
h5::object::operator=
object & operator=(object const &rhs)
Copy assignment operator copies the underlying HDF5 ID and increases its reference count.
Definition
object.hpp:89
h5::object::object
object(hid_t id=0)
Construct a new h5::object for a given HDF5 ID by taking ownership, i.e. without increasing the refer...
Definition
object.hpp:71
h5::object::from_borrowed
static object from_borrowed(hid_t id)
Create an h5::object for a given HDF5 ID and increase its reference count.
Definition
object.cpp:95
h5::object::close
void close()
Release the HDF5 handle by decreasing the reference count and by setting the object's ID to zero.
Definition
object.cpp:109
h5::datatype
object datatype
Type alias for an HDF5 datatype.
Definition
object.hpp:123
h5::attribute
object attribute
Type alias for an HDF5 attribute.
Definition
object.hpp:132
h5::dataset
object dataset
Type alias for an HDF5 dataset.
Definition
object.hpp:120
h5::dataspace
object dataspace
Type alias for an HDF5 dataspace.
Definition
object.hpp:126
h5::proplist
object proplist
Type alias for an HDF5 property list.
Definition
object.hpp:129
h5::hdf5_type_equal
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
Definition
object.cpp:198
h5::hdf5_type
datatype hdf5_type()
Map a given C++ type to an HDF5 datatype.
Definition
object.hpp:156
h5::get_hdf5_type
datatype get_hdf5_type(dataset ds)
Get the HDF5 type stored in a given h5::dataset.
Definition
object.cpp:196
h5::get_name_of_h5_type
std::string get_name_of_h5_type(datatype dt)
Get the name of an h5::datatype (for error messages).
Definition
object.cpp:183
h5::hid_t
int64_t hid_t
ID type used in HDF5.
Definition
utils.hpp:45
utils.hpp
Provides some utility functions for h5.
h5
object.hpp
Generated by
1.17.0