TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
group.hpp
Go to the documentation of this file.
1// Copyright (c) 2019-2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Henri Menke, Olivier Parcollet, Nils Wentzell
16
23#ifndef LIBH5_GROUP_HPP
24#define LIBH5_GROUP_HPP
25
26#include "./file.hpp"
27
28#include <string>
29#include <utility>
30#include <vector>
31
32namespace h5 {
33
44 class group : public object {
45 // File to which the group belongs.
46 file parent_file;
47
48 public:
50 group() = default;
51
56 group(file f);
57
58 private:
59 // Copy the given object and parent file (only used internally to open/create a subgroup).
60 group(object obj, file _parent_file) : object{obj}, parent_file{std::move(_parent_file)} {}
61
62 public:
64 [[nodiscard]] std::string name() const;
65
67 [[nodiscard]] file get_file() const { return parent_file; }
68
75 [[nodiscard]] bool has_key(std::string const &key) const;
76
83 [[nodiscard]] bool has_subgroup(std::string const &key) const;
84
91 [[nodiscard]] bool has_dataset(std::string const &key) const;
92
102 void unlink(std::string const &key, bool error_if_absent = false) const;
103
113 [[nodiscard]] group open_group(std::string const &key) const;
114
126 group create_group(std::string const &key, bool delete_if_exists = true) const;
127
139 void create_softlink(std::string const &target_key, std::string const &key, bool delete_if_exists = true) const;
140
149 [[nodiscard]] dataset open_dataset(std::string const &key) const;
150
163 dataset create_dataset(std::string const &key, datatype ty, dataspace sp, hid_t pl) const;
164
175 dataset create_dataset(std::string const &key, datatype ty, dataspace sp) const;
176
181 [[nodiscard]] std::vector<std::string> get_all_subgroup_names() const;
182
187 [[nodiscard]] std::vector<std::string> get_all_dataset_names() const;
188
193 [[nodiscard]] std::vector<std::string> get_all_subgroup_dataset_names() const;
194 };
195
196} // namespace h5
197
198#endif // LIBH5_GROUP_HPP
A handle to an HDF5 file.
Definition file.hpp:43
A handle to an HDF5 group.
Definition group.hpp:44
bool has_dataset(std::string const &key) const
Check if a dataset with the given key exists in the group and is accessible.
Definition group.cpp:69
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 g...
Definition group.cpp:150
dataset open_dataset(std::string const &key) const
Open a dataset with the given key in the group.
Definition group.cpp:140
std::string name() const
Get the name of the group.
Definition group.cpp:39
bool has_subgroup(std::string const &key) const
Check if a subgroup with the given key exists in the group and is accessible.
Definition group.cpp:55
group create_group(std::string const &key, bool delete_if_exists=true) const
Create a subgroup with the given key in the group.
Definition group.cpp:109
group open_group(std::string const &key) const
Open a subgroup with the given key in the group.
Definition group.cpp:96
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.
Definition group.cpp:122
std::vector< std::string > get_all_subgroup_dataset_names() const
Get all the names of the subgroups and datasets in the current group.
Definition group.cpp:206
bool has_key(std::string const &key) const
Check if a link with the given key exists in the group.
Definition group.cpp:53
std::vector< std::string > get_all_dataset_names() const
Get all the names of the datasets in the current group.
Definition group.cpp:199
file get_file() const
Get the parent file to which the group belongs.
Definition group.hpp:67
void unlink(std::string const &key, bool error_if_absent=false) const
Remove a link with the given key from the group.
Definition group.cpp:83
std::vector< std::string > get_all_subgroup_names() const
Get all the names of the subgroups in the current group.
Definition group.cpp:192
group()=default
Default constructor (only necessary for the Python interface).
A generic handle for HDF5 objects.
Definition object.hpp:49
Provides a handle to an HDF5 file.
int64_t hid_t
ID type used in HDF5.
Definition utils.hpp:45