Skip to content
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
35 changes: 16 additions & 19 deletions doc/design/source/design/property_lists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
Property lists
==============

Property lists are the basic mechanism to pass arguments to the functions
Property lists are the basic mechanism to pass arguments to the functions
of the C-API.
One major obstacle of the C interface is that though there is a whole bunch
of different property lists, all of them are represented as the same instance
of different property lists, all of them are represented as the same instance
of :cpp:type:`hid_t` instance. Hence, the compiler cannot check if the correct
property list is passed to as an argument. The C++ wrapper provides an extensive
set of property list types which make type checking at compile time possible.

.. figure:: ../images/property_lists_inheritance.png
:align: center
:width: 75%

The base class :cpp:class:`property_list_t` owns the :cpp:type:`id_t` instance
associated with a particular property list. The child classes should
provide convenience methods to set the parameters of a particular property
list.
associated with a particular property list. The child classes should
provide convenience methods to set the parameters of a particular property
list.

To demonstrate the motivation for these property list types consider
To demonstrate the motivation for these property list types consider
the following C function to create a dataset

.. code-block:: c
Expand All @@ -31,10 +31,10 @@ the following C function to create a dataset
hid_t lcpl_id,
hid_t dcpl_id,
hid_t dapl_id)
The last three arguments are the id's to the *link creation property list*,
the *dataset creation property list* and the *dataset access property list*.
A possible wrapper for this function in C++ could look like this

The last three arguments are the id's to the *link creation property list*,
the *dataset creation property list* and the *dataset access property list*.
A possible wrapper for this function in C++ could look like this

.. code-block:: c++

Expand All @@ -45,18 +45,15 @@ A possible wrapper for this function in C++ could look like this
const property_list::link_create_t &lcpl,
const property_list::dataset_create_t &dcpl,
const property_list::dataset_access_t &dapl)

With this signature it would be possible for the compiler to check the types
of the property lists passed to the function at compile-time instead of
waiting for a runtime error when testing the program.
of the property lists passed to the function at compile-time instead of
waiting for a runtime error when testing the program.

General requirements
====================

* the base class :cpp:class:`property_list_t` should not be constructible!
* property lists of every type should be *default constructible*
* in case of a default construction the appropriate :cpp:any:`H5P_DEFAULT`
default property list should be constructed.



* in case of a default construction the appropriate :cpp:var:`property::kDefault`
default property list should be constructed.
2 changes: 1 addition & 1 deletion doc/source/api_reference/namespace_error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ Functions
:cpp:func:`print_nested`
------------------------

.. doxygenfunction:: hdf5::error::print_nested(const std::exception&, int)
.. doxygenfunction:: hdf5::error::print_nested(const std::exception&, size_t)
2 changes: 1 addition & 1 deletion examples/rgbpixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class RGBPixel
std::uint8_t green() const;
void green(std::uint8_t value);

};
};
2 changes: 1 addition & 1 deletion examples/useage/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ int main() {
auto file = create_file("test.h5");

return 0;
}
}
2 changes: 1 addition & 1 deletion examples/useage/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

hdf5::file::File create_file(const std::string &name) {
return hdf5::file::create(name);
}
}
2 changes: 1 addition & 1 deletion examples/useage/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
#include <string>


hdf5::file::File create_file(const std::string &filename);
hdf5::file::File create_file(const std::string &filename);
9 changes: 5 additions & 4 deletions src/h5cpp/attribute/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// Created on: Oct 4, 2017
//
#include <h5cpp/attribute/attribute.hpp>
#include <h5cpp/core/utilities.hpp>
#include <h5cpp/node/link.hpp>

namespace hdf5 {
Expand Down Expand Up @@ -69,15 +70,15 @@ dataspace::Dataspace Attribute::dataspace() const

std::string Attribute::name() const
{
ssize_t size = H5Aget_name(static_cast<hid_t>(handle_),0,NULL);
if(size<0)
ssize_t ssize = H5Aget_name(static_cast<hid_t>(handle_),0,nullptr);
if(ssize<0)
{
error::Singleton::instance().throw_with_stack("Could not determine the size of the attributes name!");
}

std::string buffer(size,' ');
std::string buffer(signed2unsigned<size_t>(ssize),' ');
char *ptr = const_cast<char*>(buffer.data());
if(H5Aget_name(static_cast<hid_t>(handle_),size+1,ptr)<0)
if(H5Aget_name(static_cast<hid_t>(handle_),signed2unsigned<size_t>(ssize+1),ptr)<0)
{
error::Singleton::instance().throw_with_stack("Failure retrieving the attributes name!");
}
Expand Down
10 changes: 6 additions & 4 deletions src/h5cpp/attribute/attribute_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Attribute AttributeManager::operator[](size_t index) const
static_cast<H5_index_t>(iter_config_.index()),
static_cast<H5_iter_order_t>(iter_config_.order()),
index,
H5P_DEFAULT,
property::kDefault,
static_cast<hid_t>(iter_config_.link_access_list())
);
if(id<0)
Expand All @@ -62,7 +62,7 @@ Attribute AttributeManager::operator[](const std::string &name) const
{
hid_t id = H5Aopen_by_name(static_cast<hid_t>(node_),".",
name.c_str(),
H5P_DEFAULT,
property::kDefault,
static_cast<hid_t>(iter_config_.link_access_list())
);
if(id<0)
Expand Down Expand Up @@ -134,7 +134,9 @@ bool AttributeManager::exists(const std::string &name) const
<<node_.link().path()<<"]!";
error::Singleton::instance().throw_with_stack(ss.str());
}
#ifndef __clang__
return {};
#endif
}

Attribute AttributeManager::create(const std::string &name,
Expand All @@ -147,7 +149,7 @@ Attribute AttributeManager::create(const std::string &name,
static_cast<hid_t>(datatype),
static_cast<hid_t>(dataspace),
static_cast<hid_t>(acpl),
H5P_DEFAULT);
property::kDefault);
if(id<0)
{
std::stringstream ss;
Expand Down Expand Up @@ -192,7 +194,7 @@ AttributeIterator AttributeManager::begin() const

AttributeIterator AttributeManager::end() const
{
return AttributeIterator(*this,size());
return AttributeIterator(*this,unsigned2signed<ssize_t>(size()));
}

} // namespace attribute
Expand Down
2 changes: 1 addition & 1 deletion src/h5cpp/core/fixed_length_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct FixedLengthStringTrait<std::vector<std::string>>
for(const auto &str: data)
{
std::copy(str.begin(),str.end(),iter);
std::advance(iter,memory_type.size()); //move iterator to the next position
std::advance(iter,unsigned2signed<ssize_t>(memory_type.size())); //move iterator to the next position
}

return buffer;
Expand Down
8 changes: 2 additions & 6 deletions src/h5cpp/core/iterator_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ std::ostream &operator<<(std::ostream &stream,const IterationOrder &order)
case IterationOrder::Decreasing: return stream<<"DECREASING";
case IterationOrder::Increasing: return stream<<"INCREASING";
case IterationOrder::Native: return stream<<"NATIVE";
default:
return stream;
}

return stream;
}

std::ostream &operator<<(std::ostream &stream,const IterationIndex &index)
Expand All @@ -46,10 +44,8 @@ std::ostream &operator<<(std::ostream &stream,const IterationIndex &index)
{
case IterationIndex::CreationOrder: return stream<<"CREATION_ORDER";
case IterationIndex::Name: return stream<<"NAME";
default:
return stream;
}

return stream;
}

IteratorConfig::IteratorConfig():
Expand Down
48 changes: 42 additions & 6 deletions src/h5cpp/core/object_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,27 @@ void ObjectHandle::close()
case ObjectHandle::Type::ErrorClass:
error_code = H5Eunregister_class(handle_);
break;
case ObjectHandle::Type::Dataset:
error_code = H5Dclose(handle_);
break;
case ObjectHandle::Type::Uninitialized:
error_code = H5Oclose(handle_);
break;
case ObjectHandle::Type::BadObject:
error_code = H5Oclose(handle_);
break;
case ObjectHandle::Type::VirtualFileLayer:
error_code = H5Oclose(handle_);
break;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#endif
default:
error_code = H5Oclose(handle_);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}

if (error_code < 0)
Expand Down Expand Up @@ -277,12 +296,22 @@ ObjectHandle::Type ObjectHandle::get_type() const
return ObjectHandle::Type::ErrorMessage;
case H5I_ERROR_STACK:
return ObjectHandle::Type::ErrorStack;
default:
std::stringstream ss;
ss << "ObjectHandle: unknown object type=" << type;
error::Singleton::instance().throw_with_stack(ss.str());
};
#if H5_VERSION_GE(1,12,0)
case H5I_MAP:
case H5I_VOL:
case H5I_SPACE_SEL_ITER:
#else
case H5I_REFERENCE:
#endif
case H5I_NTYPES:
break;
}
std::stringstream ss;
ss << "ObjectHandle: unknown object type=" << type;
error::Singleton::instance().throw_with_stack(ss.str());
#ifndef __clang__
return {};
#endif
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -387,9 +416,16 @@ std::ostream &operator<<(std::ostream &stream, const ObjectHandle::Type &type)
case ObjectHandle::Type::ErrorStack:
stream << "ERROR_STACK";
break;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#endif
default:
stream << "unknown";
};
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}

return stream;
}
Expand Down
2 changes: 1 addition & 1 deletion src/h5cpp/core/object_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class DLL_EXPORT ObjectHandle
/*!
\code
.....
hdf5::ObjectHandle handle(H5Gopen(fid,"data",H5P_DEFAULT));
hdf5::ObjectHandle handle(H5Gopen(fid,"data",hdf5::property::kDefault));
...
\endcode
*/
Expand Down
7 changes: 4 additions & 3 deletions src/h5cpp/core/object_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// Author: Martin Shetty <martin.shetty@esss.se>
//
#include <h5cpp/core/object_id.hpp>
#include <h5cpp/core/utilities.hpp>
#include <h5cpp/error/error.hpp>
#include <vector>

Expand All @@ -30,18 +31,18 @@ namespace hdf5

std::string ObjectId::get_file_name(const ObjectHandle &handle)
{
ssize_t size = H5Fget_name(static_cast<hid_t>(handle), NULL, 0);
ssize_t size = H5Fget_name(static_cast<hid_t>(handle), nullptr, 0);
if(size<0)
{
error::Singleton::instance().throw_with_stack("Failure retrieving the size of the filename string!");
}

//we have to add the space for the space for the \0 which will terminate the
//string
std::vector<char> buffer(size+1,'\0');
std::vector<char> buffer(signed2unsigned<size_t>(size+1),'\0');

//read the characters to the buffer
if(H5Fget_name(static_cast<hid_t>(handle), buffer.data(), size+1)<0)
if(H5Fget_name(static_cast<hid_t>(handle), buffer.data(), signed2unsigned<size_t>(size+1))<0)
{
error::Singleton::instance().throw_with_stack("Failure to retrieve the name of the HDF5 file.");
}
Expand Down
3 changes: 2 additions & 1 deletion src/h5cpp/core/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//

#include <h5cpp/core/path.hpp>
#include <h5cpp/core/utilities.hpp>
#include <sstream>
#include <stdexcept>

Expand Down Expand Up @@ -233,7 +234,7 @@ Path Path::relative_to(const Path &base) const
throw std::runtime_error("invalid base for relative path!");
}
auto it = link_names_.begin();
std::advance(it, base.size());
std::advance(it, unsigned2signed<ssize_t>(base.size()));
Path ret;
for (; it != link_names_.end(); ++it)
ret.link_names_.push_back(*it);
Expand Down
5 changes: 3 additions & 2 deletions src/h5cpp/core/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <limits>
#include <type_traits>
#include <utility>
#include <stdexcept>

/**
* @brief convert unsigned to signed integers
Expand All @@ -52,10 +53,10 @@ TType unsigned2signed(SType &&source_value) {
// provide compile time errors if types are not appropriate
static_assert(std::is_integral<stripped_target_t>::value &&
std::is_signed<stripped_target_t>::value,
"source type must be an unsigned integral type");
"target type must be a signed integral type");
static_assert(std::is_integral<stripped_source_t>::value &&
std::is_unsigned<stripped_source_t>::value,
"target type must be a signed integral type");
"source type must be an unsigned integral type");

using target_limits = std::numeric_limits<stripped_target_t>;
// if the source value is smaller than the maximum positive value of the
Expand Down
6 changes: 5 additions & 1 deletion src/h5cpp/dataspace/hyperslab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class DLL_EXPORT Hyperslab : public Selection {
//! \brief get current dimensions
//!
//! Get a number of elements along each dimension a selection spans
//! this is particularly useful in the case of a Hyperslab
//! this is particularly useful in the case of a Hyperslab
//!
//! \throws std::runtime_error in case of a failure
//!
Expand Down Expand Up @@ -317,5 +317,9 @@ class DLL_EXPORT Hyperslab : public Selection {

DLL_EXPORT Dataspace operator||(const Dataspace &space, const Hyperslab &selection);

DLL_EXPORT SelectionList operator|(const Hyperslab &a, const Hyperslab &b);

DLL_EXPORT SelectionList &operator|(SelectionList &selections, const Hyperslab &b);

} // namespace dataspace
} // namespace hdf5
2 changes: 0 additions & 2 deletions src/h5cpp/dataspace/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ namespace dataspace {
Scalar::Scalar() :
Dataspace(Type::Scalar) {}

Scalar::~Scalar() {}

Scalar::Scalar(const Dataspace &space)
: Dataspace(space) {
if (space.type() != Type::Scalar) {
Expand Down
Loading