Skip to content

Commit

Permalink
start filling in GroupInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 26, 2022
1 parent d81bcdf commit 77a968c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
12 changes: 6 additions & 6 deletions modules/c++/hdf5.lite/include/hdf5/lite/Info.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ namespace hdf5
{
namespace lite
{
struct GroupInfo final
{
};

enum class Class
{
NoClass = -1, /**< error */
Expand Down Expand Up @@ -80,9 +76,8 @@ struct DatasetInfo final
// Attributes
};

struct FileInfo final
struct GroupInfo
{
std::string filename; // could be a URL, so not std::filesystem::path
std::string name;
std::vector<GroupInfo> groups;
std::vector<DatasetInfo> datasets;
Expand All @@ -91,6 +86,11 @@ struct FileInfo final
// Attributes
};

struct FileInfo final : public GroupInfo
{
std::string filename; // could be a URL, so not std::filesystem::path
};


CODA_OSS_API FileInfo fileInfo(coda_oss::filesystem::path);
CODA_OSS_API FileInfo fileInfo(coda_oss::filesystem::path, std::string loc);
Expand Down
37 changes: 36 additions & 1 deletion modules/c++/hdf5.lite/source/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@
#include "H5.h"
#include "hdf5.lite.h"


// https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/h5group_8cpp-example.html
static herr_t group_info(hid_t loc_id, const char *name, const H5L_info_t* /*linfo*/, void *opdata)
{
// only interested in groups
const auto group = H5Gopen2(loc_id, name, H5P_DEFAULT);
if (group > 0)
{
H5Gclose(group);

hdf5::lite::GroupInfo groupInfo;
groupInfo.name = name;

auto pRetval = static_cast<std::vector<hdf5::lite::GroupInfo>*>(opdata);
pRetval->push_back(groupInfo);
}

return 0;
}
static std::vector<hdf5::lite::GroupInfo> getGroups(H5::Group& group)
{
std::vector<hdf5::lite::GroupInfo> retval;

const auto herr = H5Literate(group.getId(), H5_INDEX_NAME, H5_ITER_INC, nullptr /*idx*/, group_info, &retval);
if (herr != 0)
{
// How can this happen?
throw std::logic_error("H5Literate failed.");
}

return retval;
}

// https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/readdata_8cpp-example.html
static hdf5::lite::FileInfo fileInfo_(coda_oss::filesystem::path filename, std::string loc)
{
Expand All @@ -38,7 +71,9 @@ static hdf5::lite::FileInfo fileInfo_(coda_oss::filesystem::path filename, std::
* Open the specified file and the specified dataset in the file.
*/
H5::H5File file(retval.filename, H5F_ACC_RDONLY);
const auto group = file.openGroup(retval.name);
auto group = file.openGroup(retval.name);

retval.groups = getGroups(group);

return retval;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/c++/hdf5.lite/unittests/test_hdf5info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TEST_CASE(test_hdf5Info)
const auto info = hdf5::lite::fileInfo(path);
TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/", info.name);
TEST_ASSERT_EQ(info.groups.size(), 4);
}

TEST_CASE(test_hdf5Info_IOException)
Expand All @@ -69,11 +70,12 @@ TEST_CASE(test_hdf5Info_loc)

TEST_ASSERT_EQ(path.string(), info.filename);
TEST_ASSERT_EQ("/g4", info.name);
TEST_ASSERT_TRUE(info.groups.empty());
}

TEST_MAIN(
TEST_CHECK(test_hdf5Info);
TEST_CHECK(test_hdf5Info_IOException);

//TEST_CHECK(test_hdf5Info_loc);
TEST_CHECK(test_hdf5Info_loc);
)

0 comments on commit 77a968c

Please sign in to comment.