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

#include <h5/group.hpp>

Detailed Description

A handle to an HDF5 group.

This class inherits from the general h5::object class. Each group stores the parent h5::file to which it belongs.

It provides various methods to simplify the creation of new and opening of existing groups, subgroups, datasets and softlinks within the current group.

Definition at line 44 of file group.hpp.

Inheritance diagram for h5::group:
h5::object

Public Member Functions

 group ()=default
 Default constructor (only necessary for the Python interface).
 
 group (file f)
 Constructor to open the root ("/") group in the given file.
 
dataset create_dataset (std::string const &key, datatype ty, dataspace sp) const
 Create a dataset with the given key, datatype and dataspace in this group.
 
dataset create_dataset (std::string const &key, datatype ty, dataspace sp, hid_t pl) const
 Create a dataset with the given key, datatype, dataspace and dataset creation property list in this group.
 
group create_group (std::string const &key, bool delete_if_exists=true) const
 Create a subgroup with the given key in the group.
 
void create_softlink (std::string const &target_key, std::string const &key, bool delete_if_exists=true) const
 Create a softlink with the given key to a target with a given target key in this group.
 
std::vector< std::string > get_all_dataset_names () const
 Get all the names of the datasets in the current group.
 
std::vector< std::string > get_all_subgroup_dataset_names () const
 Get all the names of the subgroups and datasets in the current group.
 
std::vector< std::string > get_all_subgroup_names () const
 Get all the names of the subgroups in the current group.
 
file get_file () const
 Get the parent file to which the group belongs.
 
bool has_dataset (std::string const &key) const
 Check if a dataset with the given key exists in the group and is accessible.
 
bool has_key (std::string const &key) const
 Check if a link with the given key exists in the group.
 
bool has_subgroup (std::string const &key) const
 Check if a subgroup with the given key exists in the group and is accessible.
 
std::string name () const
 Get the name of the group.
 
dataset open_dataset (std::string const &key) const
 Open a dataset with the given key in the group.
 
group open_group (std::string const &key) const
 Open a subgroup with the given key in the group.
 
void unlink (std::string const &key, bool error_if_absent=false) const
 Remove a link with the given key from the group.
 
- 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

◆ group()

h5::group::group ( file f)

Constructor to open the root ("/") group in the given file.

Parameters
fh5::file.

Definition at line 33 of file group.cpp.

Member Function Documentation

◆ create_dataset() [1/2]

dataset h5::group::create_dataset ( std::string const & key,
datatype ty,
dataspace sp ) const

Create a dataset with the given key, datatype and dataspace in this group.

It simply calls group::create_dateset with the default dataset creation property list.

Parameters
keyName of the dataset to be created.
tyh5::datatype.
sph5::dataspace.
Returns
A handle to the created dataset.

Definition at line 160 of file group.cpp.

◆ create_dataset() [2/2]

dataset h5::group::create_dataset ( std::string const & key,
datatype ty,
dataspace sp,
hid_t pl ) const

Create a dataset with the given key, datatype, dataspace and dataset creation property list in this group.

It first unlinks an existing dataset with the same name. Throws an exception if the dataset fails to be created.

Parameters
keyName of the dataset to be created.
tyh5::datatype.
sph5::dataspace.
plDataset creation property list.
Returns
A handle to the created dataset.

Definition at line 150 of file group.cpp.

◆ create_group()

group h5::group::create_group ( std::string const & key,
bool delete_if_exists = true ) const

Create a subgroup with the given key in the group.

If a subgroup with the given key already exists, it is unlinked first if delete_if_exists == true. If the given key is empty, a handle to the current group is returned. Throws an exception if the subgroup fails to be created.

Parameters
keyName of the subgroup to be created.
delete_if_existsIf true, unlink first an existing subgroup with the same name.
Returns
A handle to the created subgroup.

Definition at line 109 of file group.cpp.

◆ create_softlink()

void h5::group::create_softlink ( std::string const & target_key,
std::string const & key,
bool delete_if_exists = true ) const

Create a softlink with the given key to a target with a given target key in this group.

Does nothing if the key or target key is empty. If delete_if_exists == true, it first unlinks an existing link with the same name. Throws an exception if the target does not exist, if a link with the given key already exists and delete_if_exists == false, or if the softlink fails to be created.

Parameters
target_keyName of target.
keyName of the softlink to be created.
delete_if_existsIf true, unlink first an existing key with the same name.

Definition at line 122 of file group.cpp.

◆ get_all_dataset_names()

std::vector< std::string > h5::group::get_all_dataset_names ( ) const
nodiscard

Get all the names of the datasets in the current group.

Returns
A vector with the names of all the datasets.

Definition at line 199 of file group.cpp.

◆ get_all_subgroup_dataset_names()

std::vector< std::string > h5::group::get_all_subgroup_dataset_names ( ) const
nodiscard

Get all the names of the subgroups and datasets in the current group.

Returns
A vector with the names of all the subgroups and datasets.

Definition at line 206 of file group.cpp.

◆ get_all_subgroup_names()

std::vector< std::string > h5::group::get_all_subgroup_names ( ) const
nodiscard

Get all the names of the subgroups in the current group.

Returns
A vector with the names of all the subgroups.

Definition at line 192 of file group.cpp.

◆ has_dataset()

bool h5::group::has_dataset ( std::string const & key) const
nodiscard

Check if a dataset with the given key exists in the group and is accessible.

Parameters
keyName of the dataset.
Returns
True if the dataset exists, false otherwise.

Definition at line 69 of file group.cpp.

◆ has_key()

bool h5::group::has_key ( std::string const & key) const
nodiscard

Check if a link with the given key exists in the group.

Parameters
keyName of the link.
Returns
True if the link exists, false otherwise.

Definition at line 53 of file group.cpp.

◆ has_subgroup()

bool h5::group::has_subgroup ( std::string const & key) const
nodiscard

Check if a subgroup with the given key exists in the group and is accessible.

Parameters
keyName of the subgroup.
Returns
True if the subgroup exists and can be accessed, false otherwise.

Definition at line 55 of file group.cpp.

◆ open_dataset()

dataset h5::group::open_dataset ( std::string const & key) const
nodiscard

Open a dataset with the given key in the group.

Throws an exception if there exists no link with the given key or if the dataset fails to be opened.

Parameters
keyName of the dataset.
Returns
A handle to the opened dataset.

Definition at line 140 of file group.cpp.

◆ open_group()

group h5::group::open_group ( std::string const & key) const
nodiscard

Open a subgroup with the given key in the group.

If the given key is empty, a handle to the current group is returned. Throws an exception if the subgroup fails to be opened.

Parameters
keyName of the subgroup.
Returns
A handle to the opened subgroup.

Definition at line 96 of file group.cpp.

◆ unlink()

void h5::group::unlink ( std::string const & key,
bool error_if_absent = false ) const

Remove a link with the given key from the group.

It simply calls H5Ldelete to delete the link. If the given link does not exist, it throws an exception if error_if_absent == true, otherwise it does nothing.

Parameters
keyName of the link to be removed.
error_if_absentIf true, throws an exception if the key is not the name of a link in the group.

Definition at line 83 of file group.cpp.


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