Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines class h5::Header
6 :
7 : #pragma once
8 :
9 : #include <hdf5.h>
10 : #include <string>
11 :
12 : #include "IO/H5/Object.hpp"
13 : #include "IO/H5/OpenGroup.hpp"
14 :
15 : namespace h5 {
16 : /*!
17 : * \ingroup HDF5Group
18 : * \brief Writes header info about the build, git commit, branch, etc.
19 : *
20 : * A Header object is used to store the ::info_from_build() result in the HDF5
21 : * files. The Header is automatically added to every single file by the
22 : * constructor of H5File.
23 : *
24 : * \example
25 : * You can read the header info out of an H5 file as shown in the example:
26 : * \snippet Test_H5File.cpp h5file_readwrite_get_header
27 : */
28 1 : class Header : public h5::Object {
29 : public:
30 : /// \cond HIDDEN_SYMOLS
31 : static std::string extension() { return ".hdr"; }
32 :
33 : Header(bool exists, detail::OpenGroup&& group, hid_t location,
34 : const std::string& name);
35 :
36 : Header(const Header& /*rhs*/) = delete;
37 : Header& operator=(const Header& /*rhs*/) = delete;
38 :
39 : Header(Header&& /*rhs*/) = delete; // NOLINT
40 : Header& operator=(Header&& /*rhs*/) = delete; // NOLINT
41 :
42 : ~Header() override = default;
43 : /// \endcond
44 :
45 0 : const std::string& get_header() const { return header_info_; }
46 :
47 : /// Returns the environment variables at compile time of the simulation that
48 : /// produced the file
49 1 : std::string get_env_variables() const;
50 :
51 : /// Returns the contents of the `BuildInfo.txt` file generated by CMake
52 : /// of the simulation that produced the file.
53 1 : std::string get_build_info() const;
54 :
55 1 : const std::string& subfile_path() const override { return path_; }
56 :
57 : private:
58 : /// \cond HIDDEN_SYMBOLS
59 : detail::OpenGroup group_;
60 : std::string environment_variables_;
61 : std::string build_info_;
62 : std::string header_info_;
63 : std::string path_;
64 :
65 : static const std::string printenv_delimiter_;
66 : static const std::string build_info_delimiter_;
67 : /// \endcond
68 : };
69 : } // namespace h5
|