TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
string.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
22#ifndef LIBH5_STL_STRING_HPP
23#define LIBH5_STL_STRING_HPP
24
25#include "../group.hpp"
26
27#include <string>
28#include <vector>
29
30namespace h5 {
31
32 // Forward declaration.
33 template <typename T>
35
42 template <>
43 struct hdf5_format_impl<std::string> {
44 static std::string invoke() { return "string"; }
45 };
46
54 void h5_write(group g, std::string const &name, std::string const &s);
55
63 inline void h5_write(group g, std::string const &name, const char *s) { h5_write(g, name, std::string{s}); }
64
72 void h5_read(group g, std::string const &name, std::string &s);
73
78 inline void h5_read(group g, std::string const &name, char *s) = delete;
79
87 void h5_write_attribute(object obj, std::string const &name, std::string const &s);
88
96 inline void h5_write_attribute(object obj, std::string const &name, const char *s) { h5_write_attribute(obj, name, std::string{s}); }
97
107 void h5_read_attribute(object obj, std::string const &name, std::string &s);
108
113 inline void h5_read_attribute(object obj, std::string const &name, char *s) = delete;
114
123 void h5_write_attribute_to_key(group g, std::string const &key, std::string const &name, std::string const &s);
124
133 inline void h5_write_attribute_to_key(group g, std::string const &key, std::string const &name, const char *s) {
134 h5_write_attribute_to_key(g, key, name, std::string{s});
135 }
136
147 void h5_read_attribute_from_key(group g, std::string const &key, std::string const &name, std::string &s);
148
160 struct char_buf {
162 std::vector<char> buffer;
163
166
168 [[nodiscard]] datatype dtype() const;
169
171 [[nodiscard]] dataspace dspace() const;
172 };
173
181 void h5_write(group g, std::string const &name, char_buf const &cb);
182
190 void h5_read(group g, std::string const &name, char_buf &cb);
191
199 void h5_write_attribute(object obj, std::string const &name, char_buf const &cb);
200
208 void h5_read_attribute(object obj, std::string const &name, char_buf &cb);
209
212} // namespace h5
213
214#endif // LIBH5_STL_STRING_HPP
A handle to an HDF5 group.
Definition group.hpp:44
A generic handle for HDF5 objects.
Definition object.hpp:49
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition generic.hpp:51
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:184
T h5_read_attribute(object obj, std::string const &name)
Generic implementation for reading an HDF5 attribute.
Definition generic.hpp:120
void h5_write(group g, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 dataset.
Definition scalar.hpp:70
void h5_write_attribute(object obj, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 attribute.
Definition scalar.hpp:125
void h5_write_attribute_to_key(group g, std::string const &key, std::string const &name, std::string const &s)
Write a std::string to an HDF5 attribute.
Definition string.cpp:147
std::vector< hsize_t > v_t
Vector of h5::hsize_t used throughout the h5 library.
Definition utils.hpp:59
Stores an arbitrary number of strings in a 1-dimensional std::vector<char>.
Definition string.hpp:160
dataspace dspace() const
Get the HDF5 dataspace.
Definition string.cpp:198
datatype dtype() const
Get the HDF5 datatype.
Definition string.cpp:195
v_t lengths
Stores the number of strings in each dimension and the max. allowed length of the strings + 1.
Definition string.hpp:165
std::vector< char > buffer
Stores strings in a 1-dimensional vector.
Definition string.hpp:162
Default type trait to get the hdf5_format tag of type T by calling its static member function T::hdf5...
Definition string.hpp:34