TRIQS/h5
2.0.0
C++ interface to HDF5
Toggle main menu visibility
Loading...
Searching...
No Matches
format.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
27
28
#ifndef LIBH5_FORMAT_HPP
29
#define LIBH5_FORMAT_HPP
30
31
#include "
./macros.hpp
"
32
#include "
./group.hpp
"
33
#include "
./stl/string.hpp
"
34
35
#include <complex>
36
#include <string>
37
38
namespace
h5 {
39
44
51
template
<
typename
T>
52
struct
hdf5_format_impl
{
53
static
std::string invoke() {
return
T::hdf5_format(); }
54
};
55
56
#define H5_SPECIALIZE_FORMAT2(X, Y) \
57
\
58
template <> \
59
struct hdf5_format_impl<X> { \
60
static std::string invoke() { return H5_AS_STRING(Y); } \
61
}
62
63
#define H5_SPECIALIZE_FORMAT(X) H5_SPECIALIZE_FORMAT2(X, X)
64
65
H5_SPECIALIZE_FORMAT(
bool
);
66
H5_SPECIALIZE_FORMAT(
int
);
67
H5_SPECIALIZE_FORMAT(
long
);
68
H5_SPECIALIZE_FORMAT(
long
long
);
69
H5_SPECIALIZE_FORMAT(
unsigned
int
);
70
H5_SPECIALIZE_FORMAT(
unsigned
long
);
71
H5_SPECIALIZE_FORMAT(
unsigned
long
long
);
72
H5_SPECIALIZE_FORMAT(
float
);
73
H5_SPECIALIZE_FORMAT(
double
);
74
H5_SPECIALIZE_FORMAT(
long
double
);
75
H5_SPECIALIZE_FORMAT2(std::complex<double>, complex);
76
83
template
<
typename
T>
84
std::string
get_hdf5_format
() {
85
return
hdf5_format_impl<T>::invoke();
86
}
87
95
template
<
typename
T>
96
std::string
get_hdf5_format
([[maybe_unused]] T
const
&t) {
97
return
hdf5_format_impl<T>::invoke();
98
}
99
106
inline
void
write_hdf5_format_as_string
(
object
obj, std::string
const
&s) {
h5_write_attribute
(obj,
"Format"
, s); }
107
114
template
<
typename
T>
115
inline
void
write_hdf5_format
(
object
obj) {
116
h5_write_attribute
(obj,
"Format"
,
get_hdf5_format<T>
());
117
}
118
127
template
<
typename
T>
128
inline
void
write_hdf5_format
(
object
obj, [[maybe_unused]] T
const
&t) {
129
h5_write_attribute
(obj,
"Format"
,
get_hdf5_format<T>
());
130
}
131
138
void
read_hdf5_format
(
object
obj, std::string &s);
139
146
std::string
read_hdf5_format
(
object
obj);
147
155
void
read_hdf5_format_from_key
(group g, std::string
const
&key, std::string &s);
156
166
void
assert_hdf5_format_as_string
(
object
obj,
const
char
*tag_expected,
bool
ignore_if_absent =
false
);
167
178
template
<
typename
T>
179
void
assert_hdf5_format
(
object
obj,
bool
ignore_if_absent =
false
) {
180
assert_hdf5_format_as_string
(obj,
get_hdf5_format<T>
().c_str(), ignore_if_absent);
181
}
182
194
template
<
typename
T>
195
void
assert_hdf5_format
(
object
obj, [[maybe_unused]] T
const
&t,
bool
ignore_if_absent =
false
) {
196
assert_hdf5_format_as_string
(obj,
get_hdf5_format<T>
().c_str(), ignore_if_absent);
197
}
198
200
201
}
// namespace h5
202
203
#endif
// LIBH5_FORMAT_HPP
group.hpp
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
h5::assert_hdf5_format
void assert_hdf5_format(object obj, bool ignore_if_absent=false)
Assert that the hdf5_format tag attached to the given object is the same as the hdf5_format tag of th...
Definition
format.hpp:179
h5::assert_hdf5_format_as_string
void assert_hdf5_format_as_string(object obj, const char *tag_expected, bool ignore_if_absent)
Assert that the hdf5_format tag attached to the given object is the same as the given tag.
Definition
format.cpp:52
h5::write_hdf5_format
void write_hdf5_format(object obj)
Write an hdf5_format tag for type T to an HDF5 attribute with the name 'Format'.
Definition
format.hpp:115
h5::get_hdf5_format
std::string get_hdf5_format()
Get the hdf5_format tag of type T.
Definition
format.hpp:84
h5::read_hdf5_format
void read_hdf5_format(object obj, std::string &s)
Read an hdf5_format tag from an HDF5 attribute with the name 'Format'.
Definition
format.cpp:32
h5::read_hdf5_format_from_key
void read_hdf5_format_from_key(group g, std::string const &key, std::string &s)
Read an hdf5_format tag from an HDF5 attribute with the name 'Format'.
Definition
format.cpp:45
h5::write_hdf5_format_as_string
void write_hdf5_format_as_string(object obj, std::string const &s)
Write a std::string to an HDF5 attribute with the name 'Format'.
Definition
format.hpp:106
h5::h5_write_attribute
void h5_write_attribute(object, std::string const &, std::string const &)
Write a std::string to an HDF5 attribute.
Definition
string.cpp:99
macros.hpp
Macros used in the h5 library.
string.hpp
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.
h5::hdf5_format_impl
Default type trait to get the hdf5_format tag of type T by calling its static member function T::hdf5...
Definition
format.hpp:52
h5
format.hpp
Generated by
1.17.0