TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches

#include <h5/file.hpp>

Detailed Description

A handle to an HDF5 file.

This class inherits from the general h5::object class. It simply wraps the HDF5 functions to open an existing file or to create a new file.

An h5::file is automatically closed when it goes out of scope, i.e. its reference count is decreased.

Definition at line 43 of file file.hpp.

Inheritance diagram for h5::file:
h5::object

Public Member Functions

 file ()
 Default constructor creates a buffered memory file.
 
 file (const char *name, char mode)
 Constructor to open an existing file or to create a new file on disk.
 
 file (std::span< std::byte > const &buf)
 Constructor to create a buffered memory file from a byte buffer.
 
 file (std::string const &name, char mode)
 Constructor to open an existing file or to create a new file on disk.
 
 file (std::vector< std::byte > const &buf)
 Constructor to create a buffered memory file from a byte buffer.
 
std::vector< std::byte > as_buffer () const
 Get a copy of the associated byte buffer.
 
void flush ()
 Flush the file by calling H5Fflush.
 
std::string name () const
 Get the name of the file.
 
- Public Member Functions inherited from h5::object
 object (hid_t id=0)
 Construct a new h5::object for a given HDF5 ID by taking ownership, i.e. without increasing the reference count.
 
 object (object &&x) noexcept
 Move constructor steals the underlying HDF5 ID without increasing its reference count.
 
 object (object const &x)
 Copy constructor copies the underlying HDF5 ID and increases its reference count.
 
 ~object ()
 Destructor decreases the reference count and sets the object's ID to zero.
 
void close ()
 Release the HDF5 handle by decreasing the reference count and by setting the object's ID to zero.
 
int get_ref_count () const
 Get the current reference count.
 
bool is_valid () const
 Ensure that the wrapped HDF5 ID is valid (by calling H5Iis_valid).
 
 operator hid_t () const
 User-defined conversion to h5::hid_t.
 
objectoperator= (object &&x) noexcept
 Move assignment operator steals the underlying HDF5 ID without increasing its reference count.
 
objectoperator= (object const &x)
 Copy assignment operator copies the underlying HDF5 ID and increases its reference count.
 

Additional Inherited Members

- Static Public Member Functions inherited from h5::object
static object from_borrowed (hid_t id)
 Create an h5::object for a given HDF5 ID and increase its reference count.
 
- Protected Attributes inherited from h5::object

Constructor & Destructor Documentation

◆ file() [1/5]

h5::file::file ( )

Default constructor creates a buffered memory file.

It modifies the file access property list to use the H5FD_CORE driver. It can be used for serializing and deserializing data (see h5::serialize and h5::deserialize).

Definition at line 91 of file file.cpp.

◆ file() [2/5]

h5::file::file ( const char * name,
char mode )

Constructor to open an existing file or to create a new file on disk.

The file is opened in the specified mode. The following modes are available:

  • 'r': Open an existing file in read only mode (calls H5Fopen with H5F_ACC_RDONLY).
  • 'w': Create a new file or overwrite an existing file in read-write mode (calls H5Fcreate with H5F_ACC_TRUNC).
  • 'a': Create a new file or append to an existing file in read-write mode (calls H5Fcreate with H5F_ACC_EXCL or H5Fopen with H5F_ACC_RDWR in case the file already exists).
  • 'e': Create a new file if the file does not already exists, otherwise throw an exception (calls H5Fcreate with H5F_ACC_EXCL)
Parameters
nameName of the file.
modeMode in which to open the file.

Definition at line 37 of file file.cpp.

◆ file() [3/5]

h5::file::file ( std::string const & name,
char mode )
inline

Constructor to open an existing file or to create a new file on disk.

See file::file(const char*, char) for a more detailed description.

Definition at line 73 of file file.hpp.

◆ file() [4/5]

h5::file::file ( std::span< std::byte > const & buf)
inline

Constructor to create a buffered memory file from a byte buffer.

Parameters
bufByte buffer.

Definition at line 90 of file file.hpp.

◆ file() [5/5]

h5::file::file ( std::vector< std::byte > const & buf)
inline

Constructor to create a buffered memory file from a byte buffer.

Parameters
bufByte buffer.

Definition at line 96 of file file.hpp.


The documentation for this class was generated from the following files: