9#ifndef PBAT_IO_ARCHIVE_H
10#define PBAT_IO_ARCHIVE_H
12#include "PhysicsBasedAnimationToolkitExport.h"
15#include <highfive/H5File.hpp>
16#include <highfive/H5Group.hpp>
17#include <highfive/eigen.hpp>
38 std::filesystem::path
const& filepath,
39 HighFive::File::AccessMode flags = HighFive::File::OpenOrCreate);
73 PBAT_API
bool HasGroup(std::string
const& path)
const;
82 void WriteData(std::string
const& path, T
const& data);
100 T
ReadData(std::string
const& path)
const;
115 PBAT_API
void Unlink(std::string
const& path);
120 PBAT_API std::optional<std::string>
GetPath()
const;
124 std::variant<std::monostate, HighFive::File, HighFive::Group>;
141 using U = std::decay_t<
decltype(arg)>;
142 if constexpr (not std::is_same_v<U, std::monostate>)
144 if (arg.exist(path) and (arg.getObjectType(path) == HighFive::ObjectType::Dataset))
146 arg.getDataSet(path).write(data);
150 arg.createDataSet(path, data);
162 using U = std::decay_t<
decltype(arg)>;
163 if constexpr (not std::is_same_v<U, std::monostate>)
165 if (arg.hasAttribute(key))
167 arg.getAttribute(key).write(value);
171 arg.createAttribute(key, value);
184 using U = std::decay_t<
decltype(arg)>;
185 if constexpr (not std::is_same_v<U, std::monostate>)
187 data = arg.getDataSet(path).template read<T>();
191 return std::move(data);
200 using U = std::decay_t<
decltype(arg)>;
201 if constexpr (not std::is_same_v<U, std::monostate>)
203 data = arg.getAttribute(key).template read<T>();
PBAT_API bool HasGroup(std::string const &path) const
Check if a group exists at the given path.
Definition Archive.cpp:86
PBAT_API Archive GetOrCreateGroup(std::string const &path)
Get or create a group at the given path.
Definition Archive.cpp:29
T ReadData(std::string const &path) const
Read data from the archive.
Definition Archive.h:179
PBAT_API void Unlink(std::string const &path)
Unlink a dataset or group from the archive.
Definition Archive.cpp:102
std::variant< std::monostate, HighFive::File, HighFive::Group > Object
HDF5 object type.
Definition Archive.h:123
PBAT_API bool IsUsable() const
Check if the archive is usable.
Definition Archive.cpp:14
void WriteMetaData(std::string const &key, T const &value)
Write metadata to the archive.
Definition Archive.h:158
PBAT_API Archive operator[](std::string const &path)
Get a group or create it if it does not exist.
Definition Archive.cpp:63
PBAT_API std::optional< std::string > GetPath() const
Get the path of the current HDF5 object.
Definition Archive.cpp:118
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.
Definition Archive.cpp:9
void WriteData(std::string const &path, T const &data)
Write data to the archive.
Definition Archive.h:137
T ReadMetaData(std::string const &key) const
Read metadata from the archive.
Definition Archive.h:195
Namespace for I/O.
Definition Archive.cpp:7