Skip to content

Commit

Permalink
Added GroupInfo class
Browse files Browse the repository at this point in the history
Update #318
  • Loading branch information
eugenwintersberger committed Jan 12, 2019
1 parent c38d499 commit 7ade2dd
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/h5cpp/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(SOURCES
${dir}/chunked_dataset.cpp
${dir}/recursive_node_iterator.cpp
${dir}/recursive_link_iterator.cpp
${dir}/group_info.cpp
)

set(HEADERS
Expand All @@ -34,6 +35,7 @@ set(HEADERS
${dir}/chunked_dataset.hpp
${dir}/recursive_node_iterator.hpp
${dir}/recursive_link_iterator.hpp
${dir}/group_info.hpp
)

install(FILES ${HEADERS}
Expand Down
13 changes: 13 additions & 0 deletions src/h5cpp/node/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,18 @@ Dataset Group::get_dataset(const Path &path, const property::LinkAccessList &lap
return hdf5::node::get_dataset(*this, path, lapl);
}

GroupInfo Group::info() const
{
GroupInfo group_info;
herr_t status = H5Gget_info(static_cast<hid_t>(*this),
static_cast<H5G_info_t*>(group_info));
if(status<0)
{
error::Singleton::instance().throw_with_stack("Failure to retrieve group information");
}

return group_info;
}

} // namespace node
} // namespace hdf5
7 changes: 7 additions & 0 deletions src/h5cpp/node/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <h5cpp/property/object_copy.hpp>
#include <h5cpp/dataspace/dataspace.hpp>
#include <h5cpp/datatype/datatype.hpp>
#include <h5cpp/node/group_info.hpp>


namespace hdf5 {
Expand Down Expand Up @@ -388,6 +389,12 @@ class DLL_EXPORT Group : public Node
const property::LinkAccessList &lapl = property::LinkAccessList()) const;


//!
//! \brief get GroupInfo instance for this group instance
//!
GroupInfo info() const;


private:
IteratorConfig iter_config_;

Expand Down
57 changes: 57 additions & 0 deletions src/h5cpp/node/group_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// (c) Copyright 2019 DESY,ESS,Eugen Wintersberger <[email protected]>
//
// This file is part of h5cpp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Author: Eugen Wintersberger <[email protected]>
// Created on: Jan 12, 2019
//


#include <h5cpp/node/group_info.hpp>

namespace hdf5 {
namespace node {

StorageType GroupInfo::storage_type() const noexcept
{
return static_cast<StorageType>(_info.storage_type);
}

size_t GroupInfo::number_of_links() const noexcept
{
return _info.nlinks;
}

bool GroupInfo::has_file_mounted() const noexcept
{
return _info.mounted;
}

int64_t GroupInfo::maximum_corder() const noexcept
{
return _info.max_corder;
}


} // end of namespace node
} // end of namespace hdf5



72 changes: 72 additions & 0 deletions src/h5cpp/node/group_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// (c) Copyright 2019 DESY,ESS,Eugen Wintersberger <[email protected]>
//
// This file is part of h5cpp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Author: Eugen Wintersberger <[email protected]>
// Created on: Jan 12, 2019
//
#pragma once

extern "C" {
#include <hdf5.h>
}

#include <h5cpp/node/types.hpp>

namespace hdf5 {
namespace node {

class GroupInfo
{
private:
H5G_info_t _info;
public:

StorageType storage_type() const noexcept;

size_t number_of_links() const noexcept;

bool has_file_mounted() const noexcept;

int64_t maximum_corder() const noexcept;

explicit operator H5G_info_t() const noexcept
{
return _info;
}

explicit operator H5G_info_t*() noexcept
{
return &_info;
}

explicit operator const H5G_info_t*() const noexcept
{
return &_info;
}

};


} // end of namespace node
} // end of namespace hdf5



13 changes: 13 additions & 0 deletions src/h5cpp/node/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ namespace hdf5 {
namespace node {


std::ostream &operator<<(std::ostream &stream,const StorageType &storage_type)
{
switch(storage_type)
{
case StorageType::UNKNOWN: return stream<<"UNKNOWN";
case StorageType::COMPACT: return stream<<"COMPACT";
case StorageType::DENSE: return stream<<"DENSE";
case StorageType::SYMBOL_TABLE: return stream<<"SYMBOL_TABLE";
default:
return stream;
}
}

std::ostream &operator<<(std::ostream &stream,const Type &type)
{
switch(type)
Expand Down
13 changes: 13 additions & 0 deletions src/h5cpp/node/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
namespace hdf5 {
namespace node {

//!
//! \brief enumeration for group storage type
//!
enum class StorageType : std::underlying_type<H5G_storage_type_t>::type
{
UNKNOWN = H5G_STORAGE_TYPE_UNKNOWN,
COMPACT = H5G_STORAGE_TYPE_COMPACT,
DENSE = H5G_STORAGE_TYPE_DENSE,
SYMBOL_TABLE = H5G_STORAGE_TYPE_SYMBOL_TABLE
};

DLL_EXPORT std::ostream &operator<<(std::ostream &stream,const StorageType &storage_type);

//!
//! \brief enumeration for node type
//!
Expand Down
1 change: 1 addition & 0 deletions test/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(test_sources
${dir}/dataset_h5py_bool_test.cpp
${dir}/dataset_pniio_bool_test.cpp
${dir}/dataset_read_speed_test.cpp
${dir}/storage_type_test.cpp
PARENT_SCOPE)

set(test_headers
Expand Down
11 changes: 11 additions & 0 deletions test/node/group_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,16 @@ TEST_F(GroupTest, test_group_convenience)
EXPECT_EQ(g.get_group(Path("soft")), g1);
}

TEST_F(GroupTest,test_group_info)
{
node::Group root_group = file_.root();
node::Group(root_group,"group_1");
node::Group(root_group,"group_2");

node::GroupInfo info = root_group.info();
EXPECT_EQ(2,info.number_of_links());
EXPECT_EQ(node::StorageType::COMPACT,info.storage_type());
}



66 changes: 66 additions & 0 deletions test/node/storage_type_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// (c) Copyright 2019 DESY,ESS, Eugen Wintersberger <[email protected]>
//
// This file is part of h5pp.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
// Boston, MA 02110-1301 USA
// ===========================================================================
//
// Author: Eugen Wintersberger <[email protected]>
// Created on: Jan 12, 2019
//

#include <gtest/gtest.h>
#include <h5cpp/hdf5.hpp>

using namespace hdf5;

TEST(StorageTypeTest,test_string_representation)
{
std::stringstream stream;

stream<<node::StorageType::UNKNOWN;
EXPECT_EQ("UNKNOWN",stream.str());

stream.str(std::string());
stream<<node::StorageType::COMPACT;
EXPECT_EQ("COMPACT",stream.str());

stream.str(std::string());
stream<<node::StorageType::DENSE;
EXPECT_EQ("DENSE",stream.str());

stream.str(std::string());
stream<<node::StorageType::SYMBOL_TABLE;
EXPECT_EQ("SYMBOL_TABLE",stream.str());

}


TEST(StorageTypeTest,test_values)
{
EXPECT_EQ(H5G_STORAGE_TYPE_UNKNOWN,
static_cast<H5G_storage_type_t>(node::StorageType::UNKNOWN));
EXPECT_EQ(H5G_STORAGE_TYPE_COMPACT,
static_cast<H5G_storage_type_t>(node::StorageType::COMPACT));
EXPECT_EQ(H5G_STORAGE_TYPE_DENSE,
static_cast<H5G_storage_type_t>(node::StorageType::DENSE));
EXPECT_EQ(H5G_STORAGE_TYPE_SYMBOL_TABLE,
static_cast<H5G_storage_type_t>(node::StorageType::SYMBOL_TABLE));

}


3 changes: 3 additions & 0 deletions test/property/dataset_transfer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ TEST(DatasetTransferList,test_data_transform)
std::string transform_expression="x+1";
EXPECT_NO_THROW(dxpl.data_transform(transform_expression));
EXPECT_EQ("x+1",dxpl.data_transform());
EXPECT_TRUE(dxpl.has_data_transform());
}



#ifdef WITH_MPI

TEST(DatasetTransferList, flags)
Expand Down

0 comments on commit 7ade2dd

Please sign in to comment.