Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enum class for DataSpace::DataspaceType. #900

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/highfive/H5DataSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ class DataSpace: public Object {
/// This enum is needed otherwise we will not be able to distringuish between both with normal
/// constructors. Both have a dimension of 0.
/// \since 1.3
enum DataspaceType {
enum class DataspaceType {
dataspace_scalar, ///< Value to create scalar DataSpace
dataspace_null, ///< Value to create null DataSpace
// simple dataspace are handle directly from their dimensions
};

// For backward compatibility: `DataSpace::dataspace_scalar`.
constexpr static DataspaceType dataspace_scalar = DataspaceType::dataspace_scalar;
constexpr static DataspaceType dataspace_null = DataspaceType::dataspace_null;

/// \brief Create a DataSpace of N-dimensions from a std::vector<size_t>.
/// \param dims Dimensions of the new DataSpace
///
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/tests_high_five_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,12 @@ TEST_CASE("DataSpace::getElementCount") {
CHECK(detail::h5s_get_simple_extent_type(space.getId()) == H5S_NULL);
}

SECTION("null initializer_list") {
auto space = DataSpace{DataSpace::dataspace_null};
CHECK(space.getElementCount() == 0);
CHECK(detail::h5s_get_simple_extent_type(space.getId()) == H5S_NULL);
}

SECTION("null named ctor") {
auto space = DataSpace::Null();
CHECK(space.getElementCount() == 0);
Expand All @@ -798,6 +804,12 @@ TEST_CASE("DataSpace::getElementCount") {
CHECK(detail::h5s_get_simple_extent_type(space.getId()) == H5S_SCALAR);
}

SECTION("scalar initializer_list") {
auto space = DataSpace{DataSpace::dataspace_scalar};
CHECK(space.getElementCount() == 1);
CHECK(detail::h5s_get_simple_extent_type(space.getId()) == H5S_SCALAR);
}

SECTION("scalar named ctor") {
auto space = DataSpace::Scalar();
CHECK(space.getElementCount() == 1);
Expand Down
Loading