PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
pbat::io::Archive Class Reference

Archive class for reading and writing data to HDF5 files. More...

#include <Archive.h>

Public Member Functions

PBAT_API Archive (std::filesystem::path const &filepath, HighFive::File::AccessMode flags=HighFive::File::OpenOrCreate)
 Construct a new Archive object from a filepath to an HDF5 file.
 
PBAT_API bool IsUsable () const
 Check if the archive is usable.
 
PBAT_API Archive GetOrCreateGroup (std::string const &path)
 Get or create a group at the given path.
 
PBAT_API Archive operator[] (std::string const &path)
 Get a group or create it if it does not exist.
 
PBAT_API Archive operator[] (std::string const &path) const
 Get a group if it exists.
 
PBAT_API bool HasGroup (std::string const &path) const
 Check if a group exists at the given path.
 
template<class T>
void WriteData (std::string const &path, T const &data)
 Write data to the archive.
 
template<class T>
void WriteMetaData (std::string const &key, T const &value)
 Write metadata to the archive.
 
template<class T>
ReadData (std::string const &path) const
 Read data from the archive.
 
template<class T>
ReadMetaData (std::string const &key) const
 Read metadata from the archive.
 
PBAT_API void Unlink (std::string const &path)
 Unlink a dataset or group from the archive.
 
PBAT_API std::optional< std::string > GetPath () const
 Get the path of the current HDF5 object.
 

Protected Types

using Object
 HDF5 object type.
 

Protected Member Functions

 Archive (Object obj)
 Construct a new Archive object from an HDF5 object.
 

Detailed Description

Archive class for reading and writing data to HDF5 files.

Member Typedef Documentation

◆ Object

using pbat::io::Archive::Object
protected
Initial value:
std::variant<std::monostate, HighFive::File, HighFive::Group>

HDF5 object type.

Constructor & Destructor Documentation

◆ Archive() [1/2]

pbat::io::Archive::Archive ( std::filesystem::path const & filepath,
HighFive::File::AccessMode flags = HighFive::File::OpenOrCreate )

Construct a new Archive object from a filepath to an HDF5 file.

Parameters
filepathPath to the HDF5 file.
flagsAccess mode for the file (default is OpenOrCreate).

◆ Archive() [2/2]

pbat::io::Archive::Archive ( Object obj)
protected

Construct a new Archive object from an HDF5 object.

Parameters
objHDF5 object (file or group).

Member Function Documentation

◆ GetOrCreateGroup()

Archive pbat::io::Archive::GetOrCreateGroup ( std::string const & path)

Get or create a group at the given path.

Parameters
pathPath to the group.
Returns
Archive object representing the group.
Exceptions
std::runtime_errorif a non-group object of the same name already exists.
HighFive::GroupExceptionif the group cannot be created or fetched.

◆ GetPath()

std::optional< std::string > pbat::io::Archive::GetPath ( ) const

Get the path of the current HDF5 object.

Returns
Path of the current HDF5 object.

◆ HasGroup()

bool pbat::io::Archive::HasGroup ( std::string const & path) const

Check if a group exists at the given path.

Parameters
pathPath to the group.
Returns
true if the group exists, false otherwise.

◆ IsUsable()

bool pbat::io::Archive::IsUsable ( ) const

Check if the archive is usable.

Returns
true if the archive is usable, false otherwise.

◆ operator[]() [1/2]

Archive pbat::io::Archive::operator[] ( std::string const & path)

Get a group or create it if it does not exist.

Parameters
pathPath to the group.
Returns
Archive object representing the group.
Exceptions
std::runtime_errorif a non-group object of the same name already exists.
HighFive::GroupExceptionif the group cannot be created or fetched.

◆ operator[]() [2/2]

Archive pbat::io::Archive::operator[] ( std::string const & path) const

Get a group if it exists.

Parameters
pathPath to the group.
Returns
Archive object representing the group.
Exceptions
HighFive::GroupExceptionif the group does not exist.

◆ ReadData()

template<class T>
T pbat::io::Archive::ReadData ( std::string const & path) const
inline

Read data from the archive.

Template Parameters
TType of the data to read.
Parameters
pathPath to the dataset.
Returns
Data read from the dataset.
Exceptions
HighFive::DataSetExceptionif the dataset cannot be read.

◆ ReadMetaData()

template<class T>
T pbat::io::Archive::ReadMetaData ( std::string const & key) const
inline

Read metadata from the archive.

Template Parameters
TType of the metadata to read.
Parameters
keyName of the attribute.
Returns
Metadata read from the attribute.
Exceptions
HighFive::AttributeExceptionif the attribute cannot be read.

◆ Unlink()

void pbat::io::Archive::Unlink ( std::string const & path)

Unlink a dataset or group from the archive.

Parameters
pathPath to the dataset or group.
Exceptions
HighFive::GroupExceptionif the dataset or group cannot be unlinked.

◆ WriteData()

template<class T>
void pbat::io::Archive::WriteData ( std::string const & path,
T const & data )
inline

Write data to the archive.

Template Parameters
TType of the data to write.
Parameters
pathPath to the dataset.
dataData to write.
Exceptions
HighFive::DataSetExceptionif the dataset cannot be created or written to.

◆ WriteMetaData()

template<class T>
void pbat::io::Archive::WriteMetaData ( std::string const & key,
T const & value )
inline

Write metadata to the archive.

Template Parameters
TType of the metadata to write.
Parameters
keyName the attribute.
valueMetadata to write.
Exceptions
HighFive::AttributeExceptionif the attribute cannot be created or written to.

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