3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-27 06:43:40 +01:00
dft_tools/triqs/h5/group.hpp

100 lines
3.1 KiB
C++
Raw Normal View History

/*******************************************************************************
*
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
*
* Copyright (C) 2011-2013 by O. Parcollet
*
* TRIQS is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* TRIQS. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
2014-05-04 15:30:32 +02:00
#pragma once
#include "./file.hpp"
2014-05-04 15:30:32 +02:00
namespace triqs {
namespace h5 {
/**
* \brief A local derivative of Group.
2014-05-04 15:30:32 +02:00
* Rational : use ADL for h5_read/h5_write, catch and rethrow exception, add some policy for opening/creating
*/
class group : public h5_object {
void _write_triqs_hdf5_data_scheme(const char *a); // impl.
2014-05-04 15:30:32 +02:00
public:
group() = default; // for python converter only
///
2014-05-04 15:30:32 +02:00
group(group const &) = default;
/// Takes the "/" group at the top of the file
group(h5::file f);
/**
* Takes ownership of the id [expert only]
* id can be :
* - a file : in this case, make a group on /
* - a group : in this case, take the id of the group. DOES NOT take ownership of the ref
*/
group(hid_t id_);
// [expert only]. If not present, the obj is casted to hid_t and there is a ref. leak
group(h5_object obj);
/// Name of the group
std::string name() const;
2014-05-04 15:30:32 +02:00
/// Write the triqs tag of the group if it is an object.
template <typename T> void write_triqs_hdf5_data_scheme(T const &obj) {
_write_triqs_hdf5_data_scheme(get_triqs_hdf5_data_scheme(obj).c_str());
}
/// Read the triqs tag of the group if it is an object. Returns"" if attribute is not present
std::string read_triqs_hdf5_data_scheme() const;
///
bool has_key(std::string const &key) const;
///
2014-05-04 15:30:32 +02:00
void unlink_key_if_exists(std::string const &key) const;
/// Open a subgroup. Throw it if does not exists
group open_group(std::string const &key) const;
/// Open an existing DataSet. Throw it if does not exists
dataset open_dataset(std::string const &key) const;
2014-05-04 15:30:32 +02:00
/**
* \brief Create a subgroup.
* \param key The name of the subgroup
* \param delete_if_exists Unlink the group if it exists
*/
group create_group(std::string const &key, bool delete_if_exists = true) const;
2014-05-04 15:30:32 +02:00
/**
* \brief Create a dataset.
* \param key The name of the subgroup
*
* NB : It unlinks the dataset if it exists.
*/
dataset create_dataset(std::string const &key, datatype ty, dataspace sp, hid_t pl = H5P_DEFAULT) const;
2014-05-04 15:30:32 +02:00
/// Returns all names of subgroup of G
std::vector<std::string> get_all_subgroup_names() const;
/// Returns all names of dataset of G
std::vector<std::string> get_all_dataset_names() const;
};
2014-05-04 15:30:32 +02:00
}
}