Theoretica
Mathematical Library
Loading...
Searching...
No Matches
theoretica::io::hdf5_file Class Reference

High-level interface for managing an HDF5 file, its structure, and operations. More...

#include <hdf5.h>

Public Member Functions

 hdf5_file (const std::string &filename, bool write=false)
 Open the file persistently.
 
void refresh ()
 Refresh the cached tree structure from disk.
 
void close ()
 Close the HDF5 file immediately.
 
const std::string & filename () const
 Get the name of the file.
 
const hdf5_noderoot () const
 Get the base node containing the entire loaded file structure.
 
hid_t id () const
 Get the raw ID of the HDF5 file handle for direct API access.
 
hdf5_nodeoperator[] (const std::string &child_name)
 Access children of the root node by reference using dictionary-like syntax.
 
const hdf5_nodeoperator[] (const std::string &child_name) const
 Access children of the root node by const reference using dictionary-like syntax.
 
void create_group (const std::string &path)
 Create a new group inside the file.
 
void create_group (const hdf5_node &parent, const std::string &child_name)
 Create a new group using a parent node and a child name.
 
void delete_group (const std::string &path)
 Delete a group inside the file.
 
void delete_group (const hdf5_node &node)
 Delete a group referenced by a node.
 
template<typename Vector = vec<real>>
Vector read_vec (const std::string &path) const
 Loads a 1D dataset array into a vector from the given path inside the HDF5 file.
 
template<typename Vector = vec<real>>
Vector read_vec (const hdf5_node &node) const
 Loads a 1D dataset array into a vector from the given node inside the HDF5 file.
 
template<typename Vector >
void write_vec (const std::string &path, const Vector &v)
 Writes a 1D vector to an HDF5 dataset at the given path, overwriting if it exists.
 
template<typename Vector >
void write_vec (const hdf5_node &node, const Vector &v)
 Writes a 1D vector to the HDF5 dataset represented by the given node, overwriting if it exists.
 
template<typename Matrix = mat<real>>
Matrix read_mat (const std::string &path) const
 Read a 2D dataset array into a matrix from the given path.
 
template<typename Matrix = mat<real>>
Matrix read_mat (const hdf5_node &node) const
 Read a 2D dataset array into a matrix from the given node.
 
template<typename Matrix >
void write_mat (const std::string &path, const Matrix &m)
 Write a 2D matrix to an HDF5 dataset at the given path, overwriting if it exists.
 
template<typename Matrix >
void write_mat (const hdf5_node &node, const Matrix &m)
 Write a 2D matrix to an HDF5 dataset at the given node, overwriting if it exists.
 
void delete_dataset (const std::string &path)
 Delete a dataset at the given path if it exists.
 
void delete_dataset (const hdf5_node &node)
 Delete a dataset at the given node if it exists.
 
template<typename Type >
Type read_attribute (const std::string &path, const std::string &attr_name) const
 Read metadata (attribute) attached to a specific node by path.
 
template<typename Type >
Type read_attribute (const hdf5_node &node, const std::string &attr_name) const
 Read metadata (attribute) attached to a specific node by reference.
 
template<typename Type >
void write_attribute (const std::string &path, const std::string &attr_name, const Type &value)
 Write or overwrite metadata (attribute) attached to a specific node by path.
 
template<typename Type >
void write_attribute (const hdf5_node &node, const std::string &attr_name, const Type &value)
 Write or overwrite metadata (attribute) attached to a specific node by reference.
 
void delete_attribute (const std::string &path, const std::string &attr_name)
 Delete an attribute attached to a specific node by path, if it exists.
 
void delete_attribute (const hdf5_node &node, const std::string &attr_name)
 Delete an attribute attached to a specific node by path, if it exists.
 
std::string to_string () const
 Converts an entire HDF5 file structure into a formatted tree string.
 

Friends

std::ostream & operator<< (std::ostream &os, const hdf5_file &file)
 Print the HDF5 file structure to a stream in a formatted tree representation.
 

Detailed Description

High-level interface for managing an HDF5 file, its structure, and operations.

Constructor & Destructor Documentation

◆ hdf5_file()

theoretica::io::hdf5_file::hdf5_file ( const std::string &  filename,
bool  write = false 
)
inlineexplicit

Open the file persistently.

Parameters
filenamePath to the target HDF5 file
writeIf true, opens the file with write permissions (creating it if it doesn't exist)

Member Function Documentation

◆ create_group() [1/2]

void theoretica::io::hdf5_file::create_group ( const hdf5_node parent,
const std::string &  child_name 
)
inline

Create a new group using a parent node and a child name.

Parameters
parentParent node under which the new group will be created.
child_nameName of the child group.

◆ create_group() [2/2]

void theoretica::io::hdf5_file::create_group ( const std::string &  path)
inline

Create a new group inside the file.

Parameters
pathAbsolute or relative group path.

◆ delete_attribute() [1/2]

void theoretica::io::hdf5_file::delete_attribute ( const hdf5_node node,
const std::string &  attr_name 
)
inline

Delete an attribute attached to a specific node by path, if it exists.

Parameters
nodeNode representing the object with the attribute
attr_nameName of the attribute to delete

◆ delete_attribute() [2/2]

void theoretica::io::hdf5_file::delete_attribute ( const std::string &  path,
const std::string &  attr_name 
)
inline

Delete an attribute attached to a specific node by path, if it exists.

Parameters
pathInternal path to the node
attr_nameName of the attribute to delete

◆ delete_dataset() [1/2]

void theoretica::io::hdf5_file::delete_dataset ( const hdf5_node node)
inline

Delete a dataset at the given node if it exists.

Parameters
nodeNode representing the dataset to delete

◆ delete_dataset() [2/2]

void theoretica::io::hdf5_file::delete_dataset ( const std::string &  path)
inline

Delete a dataset at the given path if it exists.

Parameters
pathInternal path to the dataset

◆ delete_group() [1/2]

void theoretica::io::hdf5_file::delete_group ( const hdf5_node node)
inline

Delete a group referenced by a node.

Parameters
nodeNode to delete.

◆ delete_group() [2/2]

void theoretica::io::hdf5_file::delete_group ( const std::string &  path)
inline

Delete a group inside the file.

Parameters
pathAbsolute or relative group path.

◆ id()

hid_t theoretica::io::hdf5_file::id ( ) const
inline

Get the raw ID of the HDF5 file handle for direct API access.

Returns
Internal HDF5 file identifier

◆ operator[]() [1/2]

hdf5_node & theoretica::io::hdf5_file::operator[] ( const std::string &  child_name)
inline

Access children of the root node by reference using dictionary-like syntax.

Parameters
child_nameNode name

◆ operator[]() [2/2]

const hdf5_node & theoretica::io::hdf5_file::operator[] ( const std::string &  child_name) const
inline

Access children of the root node by const reference using dictionary-like syntax.

Parameters
child_nameNode name

◆ read_attribute() [1/2]

template<typename Type >
Type theoretica::io::hdf5_file::read_attribute ( const hdf5_node node,
const std::string &  attr_name 
) const
inline

Read metadata (attribute) attached to a specific node by reference.

Template Parameters
TypeThe expected scalar type or std::string of the attribute
Parameters
nodeNode representing the object with the attribute
attr_nameName of the attribute to read
Returns
The value of the attribute

◆ read_attribute() [2/2]

template<typename Type >
Type theoretica::io::hdf5_file::read_attribute ( const std::string &  path,
const std::string &  attr_name 
) const
inline

Read metadata (attribute) attached to a specific node by path.

Template Parameters
TypeThe expected scalar type or std::string of the attribute
Parameters
pathInternal path to the node
attr_nameName of the attribute to read
Returns
The value of the attribute

◆ read_mat() [1/2]

template<typename Matrix = mat<real>>
Matrix theoretica::io::hdf5_file::read_mat ( const hdf5_node node) const
inline

Read a 2D dataset array into a matrix from the given node.

Template Parameters
MatrixThe return container type (defaults to mat<real>).
Parameters
nodeNode representing the dataset to read
Returns
The matrix populated with the dataset values

◆ read_mat() [2/2]

template<typename Matrix = mat<real>>
Matrix theoretica::io::hdf5_file::read_mat ( const std::string &  path) const
inline

Read a 2D dataset array into a matrix from the given path.

Template Parameters
MatrixThe return container type (defaults to mat<real>).
Parameters
pathInternal path to the dataset
Returns
The matrix populated with the dataset values

◆ read_vec() [1/2]

template<typename Vector = vec<real>>
Vector theoretica::io::hdf5_file::read_vec ( const hdf5_node node) const
inline

Loads a 1D dataset array into a vector from the given node inside the HDF5 file.

Template Parameters
VectorThe return container type (defaults to vec<real>).
Parameters
nodeNode representing the dataset to read
Returns
The vector populated with the dataset values

◆ read_vec() [2/2]

template<typename Vector = vec<real>>
Vector theoretica::io::hdf5_file::read_vec ( const std::string &  path) const
inline

Loads a 1D dataset array into a vector from the given path inside the HDF5 file.

Template Parameters
VectorThe return container type (defaults to vec<real>).
Parameters
pathInternal path to the dataset
Returns
The vector populated with the dataset values

◆ root()

const hdf5_node & theoretica::io::hdf5_file::root ( ) const
inline

Get the base node containing the entire loaded file structure.

Returns
A const hdf5_node reference representing the root "/"

◆ to_string()

std::string theoretica::io::hdf5_file::to_string ( ) const
inline

Converts an entire HDF5 file structure into a formatted tree string.

Parameters
fileThe opened HDF5 file to format
Returns
Formatted string hierarchy

◆ write_attribute() [1/2]

template<typename Type >
void theoretica::io::hdf5_file::write_attribute ( const hdf5_node node,
const std::string &  attr_name,
const Type value 
)
inline

Write or overwrite metadata (attribute) attached to a specific node by reference.

Template Parameters
TypeThe scalar type or std::string of the attribute
Parameters
nodeNode representing the object with the attribute
attr_nameName of the attribute
valueThe value to write

◆ write_attribute() [2/2]

template<typename Type >
void theoretica::io::hdf5_file::write_attribute ( const std::string &  path,
const std::string &  attr_name,
const Type value 
)
inline

Write or overwrite metadata (attribute) attached to a specific node by path.

Template Parameters
TypeThe scalar type or std::string of the attribute
Parameters
pathInternal path to the node
attr_nameName of the attribute
valueThe value to write

◆ write_mat() [1/2]

template<typename Matrix >
void theoretica::io::hdf5_file::write_mat ( const hdf5_node node,
const Matrix m 
)
inline

Write a 2D matrix to an HDF5 dataset at the given node, overwriting if it exists.

Template Parameters
MatrixThe generic container type (deduced). Must support .rows(), .cols(), and .data().
Parameters
nodeNode representing the dataset to write
mThe matrix data to write

◆ write_mat() [2/2]

template<typename Matrix >
void theoretica::io::hdf5_file::write_mat ( const std::string &  path,
const Matrix m 
)
inline

Write a 2D matrix to an HDF5 dataset at the given path, overwriting if it exists.

Template Parameters
MatrixThe generic container type (deduced). Must support .rows(), .cols(), and .data().
Parameters
pathInternal path to place the dataset
mThe matrix data to write

◆ write_vec() [1/2]

template<typename Vector >
void theoretica::io::hdf5_file::write_vec ( const hdf5_node node,
const Vector v 
)
inline

Writes a 1D vector to the HDF5 dataset represented by the given node, overwriting if it exists.

Template Parameters
VectorThe generic container type.
Parameters
nodeHDF5 node identifying the dataset to write
vThe vector data to write

◆ write_vec() [2/2]

template<typename Vector >
void theoretica::io::hdf5_file::write_vec ( const std::string &  path,
const Vector v 
)
inline

Writes a 1D vector to an HDF5 dataset at the given path, overwriting if it exists.

Template Parameters
VectorThe generic container type.
Parameters
pathInternal path to place the dataset
vThe vector data to write

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const hdf5_file file 
)
friend

Print the HDF5 file structure to a stream in a formatted tree representation.

Parameters
osStandard output stream
fileThe HDF5 wrapper instance
Returns
Reference to the stream

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