Header.hpp
Go to the documentation of this file.
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_H5.cpp h5file_readwrite_get_header
27  */
28 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*/) noexcept = delete; // NOLINT
40  Header& operator=(Header&& /*rhs*/) noexcept = delete; // NOLINT
41 
42  ~Header() override = default;
43  /// \endcond
44 
45  const std::string& get_header() const noexcept { return header_info_; }
46 
47  /// Returns the environment variables at compile time of the simulation that
48  /// produced the file
49  std::string get_env_variables() const noexcept;
50 
51  /// Returns the contents of the `LibraryVersions.txt` file generated by CMake
52  /// of the simulation that produced the file.
53  std::string get_library_versions() const noexcept;
54 
55  private:
56  /// \cond HIDDEN_SYMBOLS
57  detail::OpenGroup group_;
58  std::string environment_variables_;
59  std::string library_versions_;
60  std::string header_info_;
61 
62  static const std::string printenv_delimiter_;
63  static const std::string library_versions_delimiter_;
64  /// \endcond
65 };
66 } // namespace h5
Defines class OpenGroup for opening groups in HDF5.
Contains functions and classes for manipulating HDF5 files.
Definition: AccessType.cpp:10
Defines class h5::Object abstract base class.
Writes header info about the build, git commit, branch, etc.
Definition: Header.hpp:28
Abstract base class representing an object in an HDF5 file.
Definition: Object.hpp:14
std::string get_library_versions() const noexcept
Returns the contents of the LibraryVersions.txt file generated by CMake of the simulation that produc...
std::string get_env_variables() const noexcept
Returns the environment variables at compile time of the simulation that produced the file...