TRIQS/h5
2.0.0
C++ interface to HDF5
Toggle main menu visibility
Loading...
Searching...
No Matches
format.cpp
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
#include "
./format.hpp
"
23
#include "
./group.hpp
"
24
#include "
./object.hpp
"
25
#include "
./stl/string.hpp
"
26
27
#include <stdexcept>
28
#include <string>
29
30
namespace
h5 {
31
32
void
read_hdf5_format
(
object
obj, std::string &s) {
33
h5_read_attribute
(obj,
"Format"
, s);
34
35
// backward compatibility
36
if
(s ==
""
) {
h5_read_attribute
(obj,
"TRIQS_HDF5_data_scheme"
, s); }
37
}
38
39
std::string
read_hdf5_format
(
object
obj) {
40
std::string s;
41
read_hdf5_format
(obj, s);
42
return
s;
43
}
44
45
void
read_hdf5_format_from_key
(
group
g, std::string
const
&key, std::string &s) {
46
h5_read_attribute_from_key
(g, key,
"Format"
, s);
47
48
// backward compatibility
49
if
(s ==
""
) {
h5_read_attribute_from_key
(g, key,
"TRIQS_HDF5_data_scheme"
, s); }
50
}
51
52
void
assert_hdf5_format_as_string
(
object
obj,
const
char
*tag_expected,
bool
ignore_if_absent) {
53
auto
tag =
read_hdf5_format
(obj);
54
if
(ignore_if_absent and tag.empty())
return
;
55
if
(tag != tag_expected)
56
throw
std::runtime_error(
"Error in assert_hdf5_format_as_string: hdf5_format tag mistmatch: "
+ tag +
" != "
+ tag_expected);
57
}
58
59
}
// namespace h5
h5::group
A handle to an HDF5 group.
Definition
group.hpp:44
format.hpp
Provides utilities for reading and writing hdf5_format tags.
group.hpp
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
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::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::h5_read_attribute_from_key
T h5_read_attribute_from_key(group g, std::string const &key, std::string const &name)
Generic implementation for reading an HDF5 attribute.
Definition
generic.hpp:191
h5::h5_read_attribute
T h5_read_attribute(object obj, std::string const &name)
Generic implementation for reading an HDF5 attribute.
Definition
generic.hpp:125
object.hpp
Provides a generic handle for HDF5 objects.
string.hpp
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.
h5
format.cpp
Generated by
1.17.0