TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
file.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_FILE_HPP
23#define LIBH5_FILE_HPP
24
25#include "./object.hpp"
26
27#include <cstddef>
28#include <span>
29#include <string>
30#include <vector>
31
32namespace h5 {
33
43 class file : public object {
44 public:
50 file();
51
67 file(const char *name, char mode);
68
73 file(std::string const &name, char mode) : file(name.c_str(), mode) {}
74
76 [[nodiscard]] std::string name() const;
77
79 void flush();
80
81 private:
82 // Constructor to create a buffered memory file with an initial file image of a given size.
83 file(const std::byte *buf, size_t size);
84
85 public:
90 file(std::span<std::byte> const &buf) : file(buf.data(), buf.size()) {}
91
96 file(std::vector<std::byte> const &buf) : file(buf.data(), buf.size()) {}
97
99 [[nodiscard]] std::vector<std::byte> as_buffer() const;
100 };
101
102} // namespace h5
103
104#endif // LIBH5_FILE_HPP
A handle to an HDF5 file.
Definition file.hpp:43
std::string name() const
Get the name of the file.
Definition file.cpp:71
file(std::span< std::byte > const &buf)
Constructor to create a buffered memory file from a byte buffer.
Definition file.hpp:90
std::vector< std::byte > as_buffer() const
Get a copy of the associated byte buffer.
Definition file.cpp:123
file(std::string const &name, char mode)
Constructor to open an existing file or to create a new file on disk.
Definition file.hpp:73
void flush()
Flush the file by calling H5Fflush.
Definition file.cpp:85
file(std::vector< std::byte > const &buf)
Constructor to create a buffered memory file from a byte buffer.
Definition file.hpp:96
file()
Default constructor creates a buffered memory file.
Definition file.cpp:91
A generic handle for HDF5 objects.
Definition object.hpp:49
Provides a generic handle for HDF5 objects.