From 798cdad29a49e0883446f7dad3c7992d53ea6ee3 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Mon, 19 Dec 2016 00:34:18 -0600 Subject: Purpose: Improvement for HDFFV-10004 Description: When adding wrappers for H5Lexists, a new class, LinkAccPropList, was added to the C++ API, triggered complicated circular dependencies. Thus, some improvement was made to resolve the problems. - Replaced existing functions openXxxType with individual type constructors + Added individual XxxType constructors to replace the existing functions openXxxType because it's rather awkward to use these functions. + Moved openXxxType from H5Location back to CommonFG + Put back CommonFG as a baseclass of Group for openXxxType functions. + This replacement should improve usability and prevent the problem of circular dependencies. - Removed overloaded constructor that takes an Attribute when there is already one that takes H5Location because Attribute inherits from H5Location now. Platforms tested: Linux/32 2.6 (jam) Darwin (osx1010test) Linux/64 (platypus) --- c++/src/H5ArrayType.cpp | 36 +++++ c++/src/H5ArrayType.h | 4 + c++/src/H5Attribute.cpp | 2 - c++/src/H5Classes.h | 2 + c++/src/H5CommonFG.cpp | 346 +++++++++++++++++++++++++++++++++++++++-- c++/src/H5CommonFG.h | 55 ++++++- c++/src/H5CompType.cpp | 36 +++++ c++/src/H5CompType.h | 4 + c++/src/H5Cpp.h | 3 + c++/src/H5DataSet.cpp | 4 +- c++/src/H5DataType.cpp | 66 +++++++- c++/src/H5DataType.h | 14 +- c++/src/H5DxferProp.cpp | 2 +- c++/src/H5EnumType.cpp | 38 ++++- c++/src/H5EnumType.h | 4 + c++/src/H5Exception.cpp | 24 +++ c++/src/H5Exception.h | 8 + c++/src/H5File.cpp | 1 + c++/src/H5FloatType.cpp | 36 +++++ c++/src/H5FloatType.h | 4 + c++/src/H5Group.cpp | 14 +- c++/src/H5Group.h | 4 +- c++/src/H5IdComponent.cpp | 2 +- c++/src/H5IntType.cpp | 36 +++++ c++/src/H5IntType.h | 4 + c++/src/H5Library.cpp | 5 + c++/src/H5Location.cpp | 383 +++++++--------------------------------------- c++/src/H5Location.h | 43 ++---- c++/src/H5Object.cpp | 52 ++++++- c++/src/H5Object.h | 4 + c++/src/H5OcreatProp.cpp | 1 - c++/src/H5PropList.cpp | 2 +- c++/src/H5StrType.cpp | 36 +++++ c++/src/H5StrType.h | 4 + c++/src/H5VarLenType.cpp | 36 +++++ c++/src/H5VarLenType.h | 4 + c++/test/tarray.cpp | 16 +- c++/test/tobject.cpp | 21 ++- 38 files changed, 942 insertions(+), 414 deletions(-) diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 0bdd09c..46ac021 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -73,6 +73,42 @@ ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims) } //-------------------------------------------------------------------------- +// Function: ArrayType overloaded constructor +///\brief Creates an ArrayType instance by opening an HDF5 array datatype +/// given its name, provided as a C character string. +///\param dtype_name - IN: Array type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openArrayType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +ArrayType::ArrayType(const H5Location& loc, const char *dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: ArrayType overloaded constructor +///\brief Creates an ArrayType instance by opening an HDF5 array datatype +/// given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Array type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openArrayType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +ArrayType::ArrayType(const H5Location& loc, const H5std_string& dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: ArrayType::operator= ///\brief Assignment operator ///\param rhs - IN: Reference to the existing array datatype diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index 0e9ef46..42e1c2b 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -34,6 +34,10 @@ class H5_DLLCPP ArrayType : public DataType { // Assignment operator ArrayType& operator=(const ArrayType& rhs); + // Constructors that opens a named array datatype, given a location. + ArrayType(const H5Location& loc, const char* name); + ArrayType(const H5Location& loc, const H5std_string& name); + // Returns the number of dimensions of this array datatype. int getArrayNDims() const; //int getArrayNDims(); // removed 1.8.18 and 1.10.1 diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 4daf174..74d246f 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -33,8 +33,6 @@ #include "H5AbstractDs.h" #include "H5DataType.h" #include "H5DataSpace.h" -#include "H5Group.h" -#include "H5File.h" #include "H5Attribute.h" #include "H5private.h" // for HDfree diff --git a/c++/src/H5Classes.h b/c++/src/H5Classes.h index bed0cae..a1525cc 100644 --- a/c++/src/H5Classes.h +++ b/c++/src/H5Classes.h @@ -25,6 +25,8 @@ namespace H5 { class PropList; class FileCreatPropList; class FileAccPropList; + /* class LinkAccPropList; + */ class DSetCreatPropList; class DSetMemXferPropList; class DTypePropList; diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index a1e0c3f..018d3a2 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -16,24 +16,20 @@ #include #include "H5Include.h" +#include "H5private.h" // for HDstrcpy #include "H5Exception.h" #include "H5IdComponent.h" +#include "H5DataSpace.h" #include "H5PropList.h" -#include "H5FaccProp.h" -#include "H5FcreatProp.h" -#include "H5OcreatProp.h" #include "H5DxferProp.h" +#include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5Location.h" #include "H5Object.h" -#include "H5CommonFG.h" -#include "H5Group.h" +#include "H5Alltypes.h" #include "H5AbstractDs.h" -#include "H5DataSpace.h" #include "H5DataSet.h" -#include "H5File.h" -#include "H5Alltypes.h" -#include "H5private.h" // for HDstrcpy +#include "H5CommonFG.h" // There are a few comments that are common to most of the functions // defined in this file so they are listed here. @@ -43,28 +39,346 @@ // to call the right getId() - although, as the structure of the // library at this time, getId() is basically the IdComponent::getId() // - when a failure returned by the C API, the functions will call -// throwwException, which is a pure virtual function and is implemented +// throwException, which is a pure virtual function and is implemented // by H5File to throw a FileIException and by Group to throw a // GroupIException. // December 2000 namespace H5 { +using namespace std; -#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- -// Function: CommonFG default constructor -///\brief Default constructor. +// Function: CommonFG::openDataType +///\brief Opens the named generic datatype at this location. +///\param name - IN: Name of the datatype to open +///\return DataType instance +///\exception H5::FileIException or H5::GroupIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -CommonFG::CommonFG() {} +DataType CommonFG::openDataType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openDataType", "H5Topen2 failed"); + + // No failure, create and return the DataType object + DataType data_type(type_id); + return(data_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openDataType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +DataType CommonFG::openDataType( const H5std_string& name ) const +{ + return( openDataType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openArrayType +///\brief Opens the named array datatype at this location. +///\param name - IN: Name of the array datatype to open +///\return ArrayType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - Jul, 2005 +//-------------------------------------------------------------------------- +ArrayType CommonFG::openArrayType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openArrayType", "H5Topen2 failed"); + + // No failure, create and return the ArrayType object + ArrayType array_type; + f_DataType_setId(&array_type, type_id); + return(array_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openArrayType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - Jul, 2005 +//-------------------------------------------------------------------------- +ArrayType CommonFG::openArrayType( const H5std_string& name ) const +{ + return( openArrayType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openCompType +///\brief Opens the named compound datatype at this location. +///\param name - IN: Name of the compound datatype to open +///\return CompType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +CompType CommonFG::openCompType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openCompType", "H5Topen2 failed"); + + // No failure, create and return the CompType object + CompType comp_type; + f_DataType_setId(&comp_type, type_id); + return(comp_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openCompType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +CompType CommonFG::openCompType( const H5std_string& name ) const +{ + return( openCompType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openEnumType +///\brief Opens the named enumeration datatype at this location. +///\param name - IN: Name of the enumeration datatype to open +///\return EnumType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +EnumType CommonFG::openEnumType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openEnumType", "H5Topen2 failed"); + + // No failure, create and return the EnumType object + EnumType enum_type; + f_DataType_setId(&enum_type, type_id); + return(enum_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openEnumType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +EnumType CommonFG::openEnumType( const H5std_string& name ) const +{ + return( openEnumType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openIntType +///\brief Opens the named integer datatype at this location. +///\param name - IN: Name of the integer datatype to open +///\return IntType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +IntType CommonFG::openIntType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openIntType", "H5Topen2 failed"); + + // No failure, create and return the IntType object + IntType int_type; + f_DataType_setId(&int_type, type_id); + return(int_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openIntType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +IntType CommonFG::openIntType( const H5std_string& name ) const +{ + return( openIntType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openFloatType +///\brief Opens the named floating-point datatype at this location. +///\param name - IN: Name of the floating-point datatype to open +///\return FloatType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +FloatType CommonFG::openFloatType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openFloatType", "H5Topen2 failed"); + + // No failure, create and return the FloatType object + FloatType float_type; + f_DataType_setId(&float_type, type_id); + return(float_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openFloatType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +FloatType CommonFG::openFloatType( const H5std_string& name ) const +{ + return( openFloatType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openStrType +///\brief Opens the named string datatype at this location. +///\param name - IN: Name of the string datatype to open +///\return StrType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +StrType CommonFG::openStrType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openStrType", "H5Topen2 failed"); + + // No failure, create and return the StrType object + StrType str_type; + f_DataType_setId(&str_type, type_id); + return(str_type); +} //-------------------------------------------------------------------------- -// Function: CommonFG destructor -///\brief Noop destructor. +// Function: CommonFG::openStrType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- +StrType CommonFG::openStrType( const H5std_string& name ) const +{ + return( openStrType( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openVarLenType +///\brief Opens the named variable length datatype at this location. +///\param name - IN: Name of the variable length datatype to open +///\return VarLenType instance +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - Jul, 2005 +//-------------------------------------------------------------------------- +VarLenType CommonFG::openVarLenType( const char* name ) const +{ + // Call C function H5Topen2 to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen2(getLocId(), name, H5P_DEFAULT); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + throwException("openVarLenType", "H5Topen2 failed"); + + // No failure, create and return the VarLenType object + VarLenType varlen_type; + f_DataType_setId(&varlen_type, type_id); + return(varlen_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::openVarLenType +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - Jul, 2005 +//-------------------------------------------------------------------------- +VarLenType CommonFG::openVarLenType( const H5std_string& name ) const +{ + return( openVarLenType( name.c_str()) ); +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//-------------------------------------------------------------------------- +// Function: CommonFG default constructor +///\brief Default constructor. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +CommonFG::CommonFG() {} + +//-------------------------------------------------------------------------- +// Function: CommonFG destructor +///\brief Noop destructor. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- CommonFG::~CommonFG() {} +//-------------------------------------------------------------------------- +// Function: f_DataType_setId - friend +// Purpose: This function is friend to class H5::DataType so that it +// can set DataType::id in order to work around a problem +// described in the JIRA issue HDFFV-7947. +// Applications shouldn't need to use it. +// param dtype - IN/OUT: DataType object to be changed +// param new_id - IN: New id to set +// Programmer Binh-Minh Ribler - 2015 +//-------------------------------------------------------------------------- +void f_DataType_setId(DataType* dtype, hid_t new_id) +{ + dtype->p_setId(new_id); +} + +//-------------------------------------------------------------------------- +// Function: f_DataSet_setId - friend +// Purpose: This function is friend to class H5::DataSet so that it +// can set DataSet::id in order to work around a problem +// described in the JIRA issue HDFFV-7947. +// Applications shouldn't need to use it. +// param dset - IN/OUT: DataSet object to be changed +// param new_id - IN: New id to set +// Programmer Binh-Minh Ribler - 2015 +//-------------------------------------------------------------------------- +void f_DataSet_setId(DataSet* dset, hid_t new_id) +{ + dset->p_setId(new_id); +} + #endif // DOXYGEN_SHOULD_SKIP_THIS } diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index a68d586..59f425c 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -19,16 +19,60 @@ namespace H5 { +// Class forwarding +class Group; +class H5File; +class ArrayType; +class VarLenType; + /*! \class CommonFG - \brief \a CommonFG was an abstract base class of H5File and H5Group. + \brief \a CommonFG is an abstract base class of H5File and H5Group. - It provided common operations of H5File and H5Group. - In release 1.10.1, the class structure is modified. - As a result, member functions of CommonFG are moved to Group. + It provides common operations of H5File and H5Group. */ class H5_DLLCPP CommonFG { public: + // Opens a generic named datatype in this location. + DataType openDataType(const char* name) const; + DataType openDataType(const H5std_string& name) const; + + // Opens a named array datatype in this location. + ArrayType openArrayType(const char* name) const; + ArrayType openArrayType(const H5std_string& name) const; + + // Opens a named compound datatype in this location. + CompType openCompType(const char* name) const; + CompType openCompType(const H5std_string& name) const; + + // Opens a named enumeration datatype in this location. + EnumType openEnumType(const char* name) const; + EnumType openEnumType(const H5std_string& name) const; + + // Opens a named integer datatype in this location. + IntType openIntType(const char* name) const; + IntType openIntType(const H5std_string& name) const; + + // Opens a named floating-point datatype in this location. + FloatType openFloatType(const char* name) const; + FloatType openFloatType(const H5std_string& name) const; + + // Opens a named string datatype in this location. + StrType openStrType(const char* name) const; + StrType openStrType(const H5std_string& name) const; + + // Opens a named variable length datatype in this location. + VarLenType openVarLenType(const char* name) const; + VarLenType openVarLenType(const H5std_string& name) const; + #ifndef DOXYGEN_SHOULD_SKIP_THIS + /// For subclasses, H5File and Group, to return the correct + /// object id, i.e. file or group id. + virtual hid_t getLocId() const = 0; + + + /// For subclasses, H5File and Group, to throw appropriate exception. + virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const = 0; + // Default constructor. CommonFG(); @@ -41,6 +85,9 @@ class H5_DLLCPP CommonFG { #endif // DOXYGEN_SHOULD_SKIP_THIS }; // end of CommonFG declaration + +#ifndef H5_NO_NAMESPACE } +#endif #endif // __CommonFG_H diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 784d171..887151e 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -88,6 +88,42 @@ CompType::CompType( const DataSet& dataset ) : DataType() } //-------------------------------------------------------------------------- +// Function: CompType overloaded constructor +///\brief Creates an CompType instance by opening an HDF5 compound +/// given its name, provided as a C character string. +///\param dtype_name - IN: Compound type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openCompType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +CompType::CompType(const H5Location& loc, const char *dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: CompType overloaded constructor +///\brief Creates an CompType instance by opening an HDF5 compound +/// datatype given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Compound type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openCompType(const H5Location&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +CompType::CompType(const H5Location& loc, const H5std_string& dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: CompType::getNmembers ///\brief Returns the number of members in this compound datatype. ///\return Number of members diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h index 6552f9e..879e4f1 100644 --- a/c++/src/H5CompType.h +++ b/c++/src/H5CompType.h @@ -42,6 +42,10 @@ class H5_DLLCPP CompType : public DataType { // Copy constructor - makes a copy of original object CompType( const CompType& original ); + // Constructors that opens a compound datatype, given a location. + CompType(const H5Location& loc, const char* name); + CompType(const H5Location& loc, const H5std_string& name); + // Returns the type class of the specified member of this compound // datatype. It provides to the user a way of knowing what type // to create another datatype of the same class diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index 800eb90..967f689 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -27,6 +27,8 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" + /* #include "H5LaccProp.h" + */ #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" @@ -42,6 +44,7 @@ #include "H5ArrayType.h" #include "H5VarLenType.h" #include "H5DataSet.h" +#include "H5CommonFG.h" #include "H5Group.h" #include "H5File.h" #include "H5Library.h" diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 749a933..d3bf017 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -20,6 +20,7 @@ #endif #include +#include "H5private.h" // for HDfree #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -34,11 +35,8 @@ #include "H5DataType.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" -#include "H5Group.h" -#include "H5File.h" #include "H5Attribute.h" #include "H5DataSet.h" -#include "H5private.h" // for HDfree namespace H5 { using std::cerr; diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 7dcd343..3955ebf 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -23,13 +23,13 @@ #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" +#include "H5DataSpace.h" #include "H5PropList.h" #include "H5FaccProp.h" #include "H5FcreatProp.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" -#include "H5DataSpace.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -38,8 +38,6 @@ #include "H5private.h" #include "H5AbstractDs.h" #include "H5DataSet.h" -#include "H5Group.h" -#include "H5File.h" #include "H5Attribute.h" namespace H5 { @@ -122,10 +120,11 @@ DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type, // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) + /* DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(attr.getId(), ref, ref_type, plist, "constructor - by dereference"); } + */ //-------------------------------------------------------------------------- // Function: DataType copy constructor @@ -152,13 +151,49 @@ DataType::DataType(const DataType& original) : H5Object(), id(original.id) //-------------------------------------------------------------------------- DataType::DataType(const PredType& pred_type) : H5Object() { - // call C routine to copy the datatype + // Call C routine to copy the datatype id = H5Tcopy( pred_type.getId() ); if (id < 0) throw DataTypeIException("DataType constructor", "H5Tcopy failed"); } //-------------------------------------------------------------------------- +// Function: DataType overloaded constructor +///\brief Creates a DataType instance by opening an HDF5 datatype given +/// its name as a char*. +///\param dtype_name - IN: Datatype name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openDataType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +DataType::DataType(const H5Location& loc, const char *dtype_name) : H5Object() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: DataType overloaded constructor +///\brief Creates a DataType instance by opening an HDF5 datatype given +/// its name as an \c H5std_string. +///\param dtype_name - IN: Datatype name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openDataType(const H5std_string&) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +DataType::DataType(const H5Location& loc, const H5std_string& dtype_name) : H5Object() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: DataType::copy ///\brief Copies an existing datatype to this datatype object ///\param like_type - IN: Datatype to be copied @@ -264,6 +299,27 @@ bool DataType::operator==(const DataType& compared_type ) const } //-------------------------------------------------------------------------- +// Function: DataType::p_opentype (private) +///\brief Opens an HDF5 datatype given its name +///\param dtype_name - IN: Datatype name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// This function was introduced in 1.10.1 to be used by the new +// XxxType constructors that were introduced to replace the +// existing functions CommonFG::openXxxType(), which is awkward +// to use. -BMR, Dec 2016 +//-------------------------------------------------------------------------- +hid_t DataType::p_opentype(const H5Location& loc, const char *dtype_name) const +{ + // Call C function to open the named datatype at this location + hid_t ret_value = H5Topen2(loc.getId(), dtype_name, H5P_DEFAULT); + if (ret_value < 0) + throw DataTypeIException("DataType constructor", "H5Topen2 failed"); + return(ret_value); +} + +//-------------------------------------------------------------------------- // Function: DataType::p_commit (private) //\brief Commits a transient datatype to a file, creating a new // named datatype diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 9ac6ecf..7036836 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -44,7 +44,7 @@ class H5_DLLCPP DataType : public H5Object { // Creates a datatype by way of dereference. DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); - DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); +// DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); // Closes this datatype. virtual void close(); @@ -62,6 +62,7 @@ class H5_DLLCPP DataType : public H5Object { // a named datatype which can be accessed from the location. void commit(const H5Location& loc, const char* name); void commit(const H5Location& loc, const H5std_string& name); + // These two overloaded functions are kept for backward compatibility // only; they missed the const - removed from 1.8.18 and 1.10.1 //void commit(H5Location& loc, const char* name); @@ -118,6 +119,13 @@ class H5_DLLCPP DataType : public H5Object { ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataType"); } +// From CommonFG then H5Location + // Constructors to open a generic named datatype at a given location. + DataType(const H5Location& loc, const char* name); + DataType(const H5Location& loc, const H5std_string& name); + +// End of From CommonFG then H5Location + // Creates a copy of an existing DataType using its id DataType( const hid_t type_id ); @@ -136,6 +144,10 @@ class H5_DLLCPP DataType : public H5Object { // Sets the datatype id. virtual void p_setId(const hid_t new_id); + + // Opens a datatype and returns the id. + hid_t p_opentype(const H5Location& loc, const char* dtype_name) const; + #endif // DOXYGEN_SHOULD_SKIP_THIS private: diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp index 7d9b943..8746d35 100644 --- a/c++/src/H5DxferProp.cpp +++ b/c++/src/H5DxferProp.cpp @@ -15,12 +15,12 @@ #include +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" #include "H5DxferProp.h" -#include "H5private.h" // for HDmemset namespace H5 { diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp index 2b614a9..a9f0b41 100644 --- a/c++/src/H5EnumType.cpp +++ b/c++/src/H5EnumType.cpp @@ -15,6 +15,7 @@ #include +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -31,7 +32,6 @@ #include "H5AtomType.h" #include "H5IntType.h" #include "H5EnumType.h" -#include "H5private.h" // for HDmemset namespace H5 { @@ -109,6 +109,42 @@ EnumType::EnumType( const IntType& data_type ) : DataType() } //-------------------------------------------------------------------------- +// Function: EnumType overloaded constructor +///\brief Creates an EnumType instance by opening an HDF5 enum datatype +/// given its name, provided as a C character string. +///\param dtype_name - IN: Enum datatype name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openEnumType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +EnumType::EnumType(const H5Location& loc, const char *dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: EnumType overloaded constructor +///\brief Creates an EnumType instance by opening an HDF5 enum datatype +/// given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Enum datatype name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openEnumType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +EnumType::EnumType(const H5Location& loc, const H5std_string& dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: EnumType::insert ///\brief Inserts a new member to this enumeration datatype. ///\param name - IN: Name of the new member diff --git a/c++/src/H5EnumType.h b/c++/src/H5EnumType.h index 1f96552..b4ffe43 100644 --- a/c++/src/H5EnumType.h +++ b/c++/src/H5EnumType.h @@ -38,6 +38,10 @@ class H5_DLLCPP EnumType : public DataType { // Creates a new enum datatype based on an integer datatype EnumType( const IntType& data_type ); // H5Tenum_create + // Constructors that opens an enum datatype, given a location. + EnumType(const H5Location& loc, const char* name); + EnumType(const H5Location& loc, const H5std_string& name); + // Returns the number of members in this enumeration datatype. int getNmembers () const; diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index 2e23587..9c383a2 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -424,6 +424,30 @@ DataTypeIException::DataTypeIException(const H5std_string& func, const H5std_str //-------------------------------------------------------------------------- DataTypeIException::~DataTypeIException() throw() {} + /* //-------------------------------------------------------------------------- +// Subclass: ObjHeaderIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// Function: ObjHeaderIException default constructor +///\brief Default constructor. +//-------------------------------------------------------------------------- +ObjHeaderIException::ObjHeaderIException():Exception(){} +//-------------------------------------------------------------------------- +// Function: ObjHeaderIException overloaded constructor +///\brief Creates an ObjHeaderIException with the name of the function, +/// in which the failure occurs, and an optional detailed message. +///\param func - IN: Name of the function where failure occurs +///\param message - IN: Message on the failure +//-------------------------------------------------------------------------- +ObjHeaderIException::ObjHeaderIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +//-------------------------------------------------------------------------- +// Function: ObjHeaderIException destructor +///\brief Noop destructor. +//-------------------------------------------------------------------------- +ObjHeaderIException::~ObjHeaderIException() throw() {} + */ + //-------------------------------------------------------------------------- // Subclass: PropListIException // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index da9066a..81068f5 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -120,6 +120,14 @@ class H5_DLLCPP DataTypeIException : public Exception { virtual ~DataTypeIException() throw(); }; + /* class H5_DLLCPP ObjHeaderIException : public Exception { + public: + ObjHeaderIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); + ObjHeaderIException(); + virtual ~ObjHeaderIException() throw(); +}; + */ + class H5_DLLCPP PropListIException : public Exception { public: PropListIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index ff897d7..79f5471 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -31,6 +31,7 @@ #include "H5DcreatProp.h" #include "H5Location.h" #include "H5Object.h" +#include "H5CommonFG.h" #include "H5Group.h" #include "H5AbstractDs.h" #include "H5DataSpace.h" diff --git a/c++/src/H5FloatType.cpp b/c++/src/H5FloatType.cpp index 9ce06f7..abc382d 100644 --- a/c++/src/H5FloatType.cpp +++ b/c++/src/H5FloatType.cpp @@ -91,6 +91,42 @@ FloatType::FloatType( const DataSet& dataset ) : AtomType() } //-------------------------------------------------------------------------- +// Function: FloatType overloaded constructor +///\brief Creates an FloatType instance by opening an HDF5 float datatype +/// given its name, provided as a C character string. +///\param dtype_name - IN: Float type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openFloatType(const char*) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +FloatType::FloatType(const H5Location& loc, const char *dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: FloatType overloaded constructor +///\brief Creates an FloatType instance by opening an HDF5 float datatype +/// given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Float type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openFloatType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +FloatType::FloatType(const H5Location& loc, const H5std_string& dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: FloatType::getFields ///\brief Retrieves floating point datatype bit field information. ///\param spos - OUT: Retrieved floating-point sign bit diff --git a/c++/src/H5FloatType.h b/c++/src/H5FloatType.h index c0119eb..1f3b409 100644 --- a/c++/src/H5FloatType.h +++ b/c++/src/H5FloatType.h @@ -33,6 +33,10 @@ class H5_DLLCPP FloatType : public AtomType { // Gets the floating-point datatype of the specified dataset. FloatType( const DataSet& dataset ); + // Constructors that opens an HDF5 float datatype, given a location. + FloatType(const H5Location& loc, const char* name); + FloatType(const H5Location& loc, const H5std_string& name); + // Retrieves the exponent bias of a floating-point type. size_t getEbias() const; diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 20f14a3..fa0a206 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -20,6 +20,7 @@ #endif #include +#include "H5private.h" // for HDstrcpy #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -34,11 +35,11 @@ #include "H5AbstractDs.h" #include "H5DataSpace.h" #include "H5DataSet.h" +#include "H5CommonFG.h" #include "H5Attribute.h" #include "H5Group.h" #include "H5File.h" #include "H5Alltypes.h" -#include "H5private.h" // for HDstrcpy namespace H5 { using std::cerr; @@ -49,7 +50,7 @@ namespace H5 { ///\brief Default constructor: creates a stub Group. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Group::Group() : H5Object(), id(H5I_INVALID_HID) {} +Group::Group() : H5Object(), CommonFG(), id(H5I_INVALID_HID) {} //-------------------------------------------------------------------------- // Function: Group copy constructor @@ -57,7 +58,7 @@ Group::Group() : H5Object(), id(H5I_INVALID_HID) {} ///\param original - IN: Original group to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Group::Group(const Group& original) : H5Object(), id(original.id) +Group::Group(const Group& original) : H5Object(), CommonFG(), id(original.id) { incRefCount(); // increment number of references to this id } @@ -84,7 +85,7 @@ hid_t Group::getLocId() const ///\param existing_id - IN: Id of an existing group // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Group::Group(const hid_t existing_id) : H5Object(), id(existing_id) +Group::Group(const hid_t existing_id) : H5Object(), CommonFG(), id(existing_id) { incRefCount(); // increment number of references to this id } @@ -102,7 +103,7 @@ Group::Group(const hid_t existing_id) : H5Object(), id(existing_id) /// is a datatype that has been named by DataType::commit. // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) +Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), CommonFG(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(loc.getId(), ref, ref_type, plist, "constructor - by dereference"); } @@ -117,10 +118,11 @@ Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type, const ///\exception H5::ReferenceException // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) + /* Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(attr.getId(), ref, ref_type, plist, "constructor - by dereference"); } + */ //-------------------------------------------------------------------------- // Function: Group::getId diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 5f4b0f3..0a9e975 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -28,7 +28,7 @@ namespace H5 { class ArrayType; class VarLenType; -class H5_DLLCPP Group : public H5Object { +class H5_DLLCPP Group : public H5Object, public CommonFG { public: // Group constructor to create a group or file (aka root group). Group(const char* name, size_t size_hint = 0); @@ -52,7 +52,7 @@ class H5_DLLCPP Group : public H5Object { // Creates a group by way of dereference. Group(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); - Group(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); +// Group(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); // default constructor Group(); diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index d869b07..f3d916a 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -15,12 +15,12 @@ #include +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5Library.h" #include "H5IdComponent.h" #include "H5DataSpace.h" -#include "H5private.h" // for HDmemset namespace H5 { diff --git a/c++/src/H5IntType.cpp b/c++/src/H5IntType.cpp index 69fbedb..a60bcf3 100644 --- a/c++/src/H5IntType.cpp +++ b/c++/src/H5IntType.cpp @@ -90,6 +90,42 @@ IntType::IntType( const DataSet& dataset ) : AtomType() } //-------------------------------------------------------------------------- +// Function: IntType overloaded constructor +///\brief Creates a IntType instance by opening an HDF5 integer datatype +/// given its name as a char*. +///\param dtype_name - IN: Integer type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openIntType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +IntType::IntType(const H5Location& loc, const char *dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: IntType overloaded constructor +///\brief Creates a IntType instance by opening an HDF5 integer datatype +/// given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Integer type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openArrayType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +IntType::IntType(const H5Location& loc, const H5std_string& dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: IntType::getSign ///\brief Retrieves the sign type for an integer type. ///\return Valid sign type diff --git a/c++/src/H5IntType.h b/c++/src/H5IntType.h index 54c0d57..09a311f 100644 --- a/c++/src/H5IntType.h +++ b/c++/src/H5IntType.h @@ -33,6 +33,10 @@ class H5_DLLCPP IntType : public AtomType { // Gets the integer datatype of the specified dataset IntType(const DataSet& dataset); + // Constructors that opens an HDF5 integer datatype, given a location. + IntType(const H5Location& loc, const char* name); + IntType(const H5Location& loc, const H5std_string& name); + // Retrieves the sign type for an integer type H5T_sign_t getSign() const; diff --git a/c++/src/H5Library.cpp b/c++/src/H5Library.cpp index 1726121..30be367 100644 --- a/c++/src/H5Library.cpp +++ b/c++/src/H5Library.cpp @@ -185,6 +185,11 @@ void H5Library::initH5cpp() if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating PropList::deleteConstants failed"); + /* ret_value = std::atexit(LinkAccPropList::deleteConstants); + if (ret_value != 0) + throw LibraryIException("H5Library::initH5cpp", "Registrating LinkAccPropList::deleteConstants failed"); + */ + ret_value = std::atexit(FileAccPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating FileAccPropList::deleteConstants failed"); diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index cb4fd12..91de0f5 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -15,9 +15,11 @@ #include +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" +#include "H5DataSpace.h" #include "H5PropList.h" #include "H5FaccProp.h" #include "H5FcreatProp.h" @@ -26,14 +28,12 @@ #include "H5DxferProp.h" #include "H5Location.h" #include "H5Object.h" +#include "H5DataType.h" #include "H5AbstractDs.h" -#include "H5DataSpace.h" #include "H5DataSet.h" -#include "H5Attribute.h" +#include "H5CommonFG.h" #include "H5Group.h" #include "H5File.h" -#include "H5Alltypes.h" -#include "H5private.h" // for HDmemset namespace H5 { @@ -76,6 +76,45 @@ H5Location::H5Location() : IdComponent() {} #endif // DOXYGEN_SHOULD_SKIP_THIS + /* //-------------------------------------------------------------------------- +// Function: H5Location::exists +///\brief Checks if a link of a given name exists in a location +///\param name - IN: Searched name +///\param lapl - IN: Link access property list +///\exception H5::LocationException +// Programmer Binh-Minh Ribler - Nov, 2016 +// Modification +//-------------------------------------------------------------------------- +bool H5Location::exists(const char* name, const LinkAccPropList& lapl) const +{ + htri_t ret_value = H5Lexists(getId(), name, lapl.getId()); + if (ret_value > 0) + return true; + else if (ret_value == 0) + return false; + else // Raise exception when H5Lexists returns a negative value + { + throwException("exists", "H5Lexists failed"); + } + return false; // warning: control reaches end of non-void function +} + */ + + /* //-------------------------------------------------------------------------- +// Function: H5Location::exists +///\brief Checks if a link of a given name exists in a location +///\param name - IN: Searched name +///\param lapl - IN: Link access property list +///\exception H5::LocationException +// Programmer Binh-Minh Ribler - Dec, 2016 +// Modification +//-------------------------------------------------------------------------- +bool H5Location::exists(const H5std_string& name, const LinkAccPropList& lapl) const +{ + return(exists(name.c_str(), lapl)); +} + */ + //-------------------------------------------------------------------------- // Function: H5Location::flush ///\brief Flushes all buffers associated with a location to disk. @@ -498,10 +537,11 @@ void H5Location::dereference(const H5Location& loc, const void* ref, H5R_type_t // May, 2008 // Corrected missing parameters. - BMR //-------------------------------------------------------------------------- -void H5Location::dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) + /* void H5Location::dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) { p_setId(p_dereference(attr.getId(), ref, ref_type, plist, "dereference")); } + */ #ifndef H5_NO_DEPRECATED_SYMBOLS //-------------------------------------------------------------------------- @@ -1206,294 +1246,6 @@ void H5Location::unmount( const H5std_string& name ) const unmount( name.c_str() ); } -//-------------------------------------------------------------------------- -// Function: H5Location::openDataType -///\brief Opens the named generic datatype at this location. -///\param name - IN: Name of the datatype to open -///\return DataType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -DataType H5Location::openDataType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openDataType", "H5Topen2 failed"); - - // No failure, create and return the DataType object - DataType data_type; - f_DataType_setId(&data_type, type_id); - return(data_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openDataType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -DataType H5Location::openDataType( const H5std_string& name ) const -{ - return( openDataType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openArrayType -///\brief Opens the named array datatype at this location. -///\param name - IN: Name of the array datatype to open -///\return ArrayType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - Jul, 2005 -//-------------------------------------------------------------------------- -ArrayType H5Location::openArrayType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openArrayType", "H5Topen2 failed"); - - // No failure, create and return the ArrayType object - ArrayType array_type; - f_DataType_setId(&array_type, type_id); - return(array_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openArrayType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - Jul, 2005 -//-------------------------------------------------------------------------- -ArrayType H5Location::openArrayType( const H5std_string& name ) const -{ - return( openArrayType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openCompType -///\brief Opens the named compound datatype at this location. -///\param name - IN: Name of the compound datatype to open -///\return CompType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -CompType H5Location::openCompType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openCompType", "H5Topen2 failed"); - - // No failure, create and return the CompType object - CompType comp_type; - f_DataType_setId(&comp_type, type_id); - return(comp_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openCompType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -CompType H5Location::openCompType( const H5std_string& name ) const -{ - return( openCompType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openEnumType -///\brief Opens the named enumeration datatype at this location. -///\param name - IN: Name of the enumeration datatype to open -///\return EnumType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -EnumType H5Location::openEnumType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openEnumType", "H5Topen2 failed"); - - // No failure, create and return the EnumType object - EnumType enum_type; - f_DataType_setId(&enum_type, type_id); - return(enum_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openEnumType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -EnumType H5Location::openEnumType( const H5std_string& name ) const -{ - return( openEnumType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openIntType -///\brief Opens the named integer datatype at this location. -///\param name - IN: Name of the integer datatype to open -///\return IntType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -IntType H5Location::openIntType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openIntType", "H5Topen2 failed"); - - // No failure, create and return the IntType object - IntType int_type; - f_DataType_setId(&int_type, type_id); - return(int_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openIntType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -IntType H5Location::openIntType( const H5std_string& name ) const -{ - return( openIntType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openFloatType -///\brief Opens the named floating-point datatype at this location. -///\param name - IN: Name of the floating-point datatype to open -///\return FloatType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -FloatType H5Location::openFloatType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openFloatType", "H5Topen2 failed"); - - // No failure, create and return the FloatType object - FloatType float_type; - f_DataType_setId(&float_type, type_id); - return(float_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openFloatType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -FloatType H5Location::openFloatType( const H5std_string& name ) const -{ - return( openFloatType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openStrType -///\brief Opens the named string datatype at this location. -///\param name - IN: Name of the string datatype to open -///\return StrType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -StrType H5Location::openStrType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openStrType", "H5Topen2 failed"); - - // No failure, create and return the StrType object - StrType str_type; - f_DataType_setId(&str_type, type_id); - return(str_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openStrType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -StrType H5Location::openStrType( const H5std_string& name ) const -{ - return( openStrType( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openVarLenType -///\brief Opens the named variable length datatype at this location. -///\param name - IN: Name of the variable length datatype to open -///\return VarLenType instance -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - Jul, 2005 -//-------------------------------------------------------------------------- -VarLenType H5Location::openVarLenType( const char* name ) const -{ - // Call C function H5Topen2 to open the named datatype in this group, - // given either the file or group id - hid_t type_id = H5Topen2(getId(), name, H5P_DEFAULT); - - // If the datatype's opening failed, throw an exception - if( type_id < 0 ) - throwException("openVarLenType", "H5Topen2 failed"); - - // No failure, create and return the VarLenType object - VarLenType varlen_type; - f_DataType_setId(&varlen_type, type_id); - return(varlen_type); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::openVarLenType -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - Jul, 2005 -//-------------------------------------------------------------------------- -VarLenType H5Location::openVarLenType( const H5std_string& name ) const -{ - return( openVarLenType( name.c_str()) ); -} - #ifndef H5_NO_DEPRECATED_SYMBOLS //-------------------------------------------------------------------------- // Function: H5Location::iterateElems @@ -1899,51 +1651,20 @@ void H5Location::throwException(const H5std_string& func_name, const H5std_strin } //-------------------------------------------------------------------------- -// Function: f_DataType_setId - friend -// Purpose: This function is friend to class H5::DataType so that it -// can set DataType::id in order to work around a problem -// described in the JIRA issue HDFFV-7947. -// Applications shouldn't need to use it. -// param dtype - IN/OUT: DataType object to be changed -// param new_id - IN: New id to set -// Programmer Binh-Minh Ribler - 2015 +// Function: f_DataSet_setId - friend +// Modification: +// Moved to H5CommonFG.cpp after the rearrangement of classes +// -BMR, Dec 2016 //-------------------------------------------------------------------------- -void f_DataType_setId(DataType* dtype, hid_t new_id) -{ - dtype->p_setId(new_id); -} - -//-------------------------------------------------------------------------- -// Function: f_DataSet_setId - friend -// Purpose: This function is friend to class H5::DataSet so that it -// can set DataSet::id in order to work around a problem -// described in the JIRA issue HDFFV-7947. -// Applications shouldn't need to use it. -// param dset - IN/OUT: DataSet object to be changed -// param new_id - IN: New id to set -// Programmer Binh-Minh Ribler - 2015 -//-------------------------------------------------------------------------- -void f_DataSet_setId(DataSet* dset, hid_t new_id) -{ - dset->p_setId(new_id); -} // end of From H5CommonFG.cpp //-------------------------------------------------------------------------- // Function: f_Attribute_setId - friend -// Purpose: This function is friend to class H5::Attribute so that it -// can set Attribute::id in order to work around a problem -// described in the JIRA issue HDFFV-7947. -// Applications shouldn't need to use it. -// param attr - IN/OUT: Attribute object to be changed -// param new_id - IN: New id to set -// Programmer Binh-Minh Ribler - 2015 +// Modification: +// Moved to H5Object.cpp after the rearrangement of classes +// -BMR, Dec 2016 //-------------------------------------------------------------------------- -void f_Attribute_setId(Attribute* attr, hid_t new_id) -{ - attr->p_setId(new_id); -} //-------------------------------------------------------------------------- // Function: f_DataSpace_setId - friend diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index 647904b..795e7a7 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -33,9 +33,16 @@ namespace H5 { */ // Class forwarding class H5_DLLCPP ArrayType; + /* class H5_DLLCPP LinkAccPropList; // remove when done + */ class H5_DLLCPP VarLenType; class H5_DLLCPP H5Location : public IdComponent { public: + /* // Checks if a link of a given name exists in a location + bool exists(const char* name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + bool exists(const H5std_string& name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + */ + // Flushes all buffers associated with this location to disk. void flush( H5F_scope_t scope ) const; @@ -81,7 +88,7 @@ class H5_DLLCPP H5Location : public IdComponent { // Open a referenced object whose location is specified by either // a file, an HDF5 object, or an attribute. void dereference(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); - void dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); + //void dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const PropList& plist = PropList::DEFAULT); // Retrieves a dataspace with the region pointed to selected. DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; @@ -172,38 +179,6 @@ class H5_DLLCPP H5Location : public IdComponent { void move(const char* src, const char* dst) const; void move(const H5std_string& src, const H5std_string& dst) const; - // Opens a generic named datatype in this location. - DataType openDataType(const char* name) const; - DataType openDataType(const H5std_string& name) const; - - // Opens a named array datatype in this location. - ArrayType openArrayType(const char* name) const; - ArrayType openArrayType(const H5std_string& name) const; - - // Opens a named compound datatype in this location. - CompType openCompType(const char* name) const; - CompType openCompType(const H5std_string& name) const; - - // Opens a named enumeration datatype in this location. - EnumType openEnumType(const char* name) const; - EnumType openEnumType(const H5std_string& name) const; - - // Opens a named integer datatype in this location. - IntType openIntType(const char* name) const; - IntType openIntType(const H5std_string& name) const; - - // Opens a named floating-point datatype in this location. - FloatType openFloatType(const char* name) const; - FloatType openFloatType(const H5std_string& name) const; - - // Opens a named string datatype in this location. - StrType openStrType(const char* name) const; - StrType openStrType(const H5std_string& name) const; - - // Opens a named variable length datatype in this location. - VarLenType openVarLenType(const char* name) const; - VarLenType openVarLenType(const H5std_string& name) const; - // end From CommonFG /// For subclasses, H5File and Group, to throw appropriate exception. @@ -240,7 +215,7 @@ class H5_DLLCPP H5Location : public IdComponent { // Sets the identifier of this object to a new value. - this one // doesn't increment reference count - virtual void p_setId(const hid_t new_id) = 0; + //virtual void p_setId(const hid_t new_id); #endif // DOXYGEN_SHOULD_SKIP_THIS diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index ab79d9d..66699d4 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -15,6 +15,7 @@ #include +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -29,11 +30,11 @@ #include "H5DataType.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" +#include "H5CommonFG.h" #include "H5Group.h" #include "H5File.h" #include "H5DataSet.h" #include "H5Attribute.h" -#include "H5private.h" // for HDmemset namespace H5 { @@ -86,6 +87,21 @@ H5Object::H5Object() : H5Location() {} // H5Object::H5Object(const H5Object& original) : H5Location() {} //-------------------------------------------------------------------------- +// Function: f_Attribute_setId - friend +// Purpose: This function is friend to class H5::Attribute so that it +// can set Attribute::id in order to work around a problem +// described in the JIRA issue HDFFV-7947. +// Applications shouldn't need to use it. +// param attr - IN/OUT: Attribute object to be changed +// param new_id - IN: New id to set +// Programmer Binh-Minh Ribler - 2015 +//-------------------------------------------------------------------------- +void f_Attribute_setId(Attribute* attr, hid_t new_id) +{ + attr->p_setId(new_id); +} + +//-------------------------------------------------------------------------- // Function: H5Object::createAttribute ///\brief Creates an attribute for a group, dataset, or named datatype. ///\param name - IN: Name of the attribute @@ -241,6 +257,40 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_da } //-------------------------------------------------------------------------- +// Function: H5Object::objVersion +///\brief Returns the header version of this HDF5 object. +///\return Object version, which can have the following values: +/// \li \c H5O_VERSION_1 +/// \li \c H5O_VERSION_2 +///\exception H5::ObjHeaderIException +/// Exception will be thrown when: +/// - an error returned by the C API +/// - version number is not one of the valid values above +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- + /* unsigned H5Object::objVersion() const +{ + H5O_info_t objinfo; + unsigned version = 0; + + // Use C API to get information of the object + herr_t ret_value = H5Oget_info(getId(), &objinfo); + + // Throw exception if C API returns failure + if (ret_value < 0) + throw Exception(inMemFunc("objVersion"), "H5Oget_info failed"); + // Return a valid version or throw an exception for invalid value + else + { + version = objinfo.hdr.version; + if (version != H5O_VERSION_1 && version != H5O_VERSION_2) + throw ObjHeaderIException("objVersion", "Invalid version for object"); + } + return(version); +} + */ + +//-------------------------------------------------------------------------- // Function: H5Object::getNumAttrs ///\brief Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 72a9f50..70acda9 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -77,6 +77,10 @@ class H5_DLLCPP H5Object : public H5Location { // Iterate user's function over the attributes of this object. int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); + // Returns the object header version of an object + /* unsigned objVersion() const; + */ + // Determines the number of attributes belong to this object. int getNumAttrs() const; diff --git a/c++/src/H5OcreatProp.cpp b/c++/src/H5OcreatProp.cpp index 3cda945..397a96f 100644 --- a/c++/src/H5OcreatProp.cpp +++ b/c++/src/H5OcreatProp.cpp @@ -20,7 +20,6 @@ #include "H5IdComponent.h" #include "H5PropList.h" #include "H5OcreatProp.h" -#include "H5FaccProp.h" namespace H5 { diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index b6f7c15..42c9b83 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -21,11 +21,11 @@ #include +#include "H5private.h" // for HDfree #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" -#include "H5private.h" // for HDfree namespace H5 { diff --git a/c++/src/H5StrType.cpp b/c++/src/H5StrType.cpp index 962a5dc..ca0ad56 100644 --- a/c++/src/H5StrType.cpp +++ b/c++/src/H5StrType.cpp @@ -144,6 +144,42 @@ StrType::StrType( const DataSet& dataset ) : AtomType () } //-------------------------------------------------------------------------- +// Function: StrType overloaded constructor +///\brief Creates an StrType instance by opening an HDF5 string datatype +/// given its name, provided as a C character string. +///\param dtype_name - IN: String type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openStrType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +StrType::StrType(const H5Location& loc, const char *dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: StrType overloaded constructor +///\brief Creates an StrType instance by opening an HDF5 string datatype +/// given its name, provided as an \c H5std_string. +///\param dtype_name - IN: String type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openStrType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +StrType::StrType(const H5Location& loc, const H5std_string& dtype_name) : AtomType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: StrType::getCset ///\brief Retrieves the character set type of this string datatype. ///\return Character set type, which can be: diff --git a/c++/src/H5StrType.h b/c++/src/H5StrType.h index 5d223b3..5ff88b6 100644 --- a/c++/src/H5StrType.h +++ b/c++/src/H5StrType.h @@ -39,6 +39,10 @@ class H5_DLLCPP StrType : public AtomType { // Gets the string datatype of the specified dataset StrType(const DataSet& dataset); + // Constructors that opens an HDF5 string datatype, given a location. + StrType(const H5Location& loc, const char* name); + StrType(const H5Location& loc, const H5std_string& name); + // Retrieves the character set type of this string datatype. H5T_cset_t getCset() const; diff --git a/c++/src/H5VarLenType.cpp b/c++/src/H5VarLenType.cpp index fa3a18f..e14e1ce 100644 --- a/c++/src/H5VarLenType.cpp +++ b/c++/src/H5VarLenType.cpp @@ -72,6 +72,42 @@ VarLenType::VarLenType(const DataType* base_type) : DataType() } //-------------------------------------------------------------------------- +// Function: VarLenType overloaded constructor +///\brief Creates an VarLenType instance by opening an HDF5 variable +/// length datatype given its name, provided as a C char*. +///\param dtype_name - IN: Variable length type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openVarLenType(const char*) to +// improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +VarLenType::VarLenType(const H5Location& loc, const char *dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name); +} + +//-------------------------------------------------------------------------- +// Function: VarLenType overloaded constructor +///\brief Creates an VarLenType instance by opening an HDF5 variable +/// length datatype given its name, provided as an \c H5std_string. +///\param dtype_name - IN: Variable length type name +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - Dec 2016 +// Description +// In 1.10.1, this constructor was introduced and will replace the +// existing function CommonFG::openVarLenType(const H5std_string&) +// to improve usability. +// -BMR, Dec 2016 +//-------------------------------------------------------------------------- +VarLenType::VarLenType(const H5Location& loc, const H5std_string& dtype_name) : DataType() +{ + id = p_opentype(loc, dtype_name.c_str()); +} + +//-------------------------------------------------------------------------- // Function: VarLenType destructor ///\brief Properly terminates access to this datatype. // Programmer Binh-Minh Ribler - May, 2004 diff --git a/c++/src/H5VarLenType.h b/c++/src/H5VarLenType.h index d7141b0..accb13e 100644 --- a/c++/src/H5VarLenType.h +++ b/c++/src/H5VarLenType.h @@ -40,6 +40,10 @@ class H5_DLLCPP VarLenType : public DataType { // Constructor that takes an existing id VarLenType( const hid_t existing_id ); + // Constructors that opens a variable-length datatype, given a location. + VarLenType(const H5Location& loc, const char* name); + VarLenType(const H5Location& loc, const H5std_string& name); + // Noop destructor virtual ~VarLenType(); diff --git a/c++/test/tarray.cpp b/c++/test/tarray.cpp index 7fe2e6b..f10016f 100644 --- a/c++/test/tarray.cpp +++ b/c++/test/tarray.cpp @@ -34,6 +34,7 @@ using namespace H5; #include "h5cpputil.h" // C++ utilility header file const H5std_string FILENAME("tarray.h5"); +const H5std_string ARRAYTYPE_NAME("/Array type 1"); const int SPACE1_RANK = 1; const hsize_t SPACE1_DIM1 = 4; const int ARRAY1_RANK = 1; @@ -130,9 +131,22 @@ static void test_array_compound_array() // Write dataset to disk dataset.write(wdata, arrtype); + // Test opening ArrayType with opening constructor (Dec 2016) + + // Commit the arrtype to give it a name + arrtype.commit(file1, ARRAYTYPE_NAME); + + // Close it, then re-open with the opening constructor + arrtype.close(); + ArrayType named_type(file1, ARRAYTYPE_NAME); + + // Get and verify the type's name + H5std_string type_name = named_type.getObjName(); + verify_val(type_name, ARRAYTYPE_NAME, "DataType::getObjName tests constructor", __LINE__, __FILE__); + named_type.close(); + // Close all dataset.close(); - arrtype.close(); space.close(); file1.close(); diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index b8654c3..e142f02 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -23,8 +23,6 @@ #else #include #endif -using std::cerr; -using std::endl; #include #include "H5Cpp.h" // C++ API header file @@ -184,6 +182,16 @@ static void test_get_objname_ontypes() H5std_string inttype_name = inttype.getObjName(); verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + // Close the type then open it again to test getting its name with + // the constructor + inttype.close(); + IntType newtype(file, "INT type of STD_B8LE"); + + // Get and verify its name + H5std_string type_name = newtype.getObjName(); + verify_val(type_name, "/INT type of STD_B8LE", "DataType::getObjName tests constructor", __LINE__, __FILE__); + newtype.close(); + // Make copy of a predefined type and save it DataType dtype(PredType::STD_B8LE); dtype.commit(file, "STD_B8LE"); @@ -197,7 +205,14 @@ static void test_get_objname_ontypes() dtype = file.openDataType("STD_B8LE"); // Get and verify its name - H5std_string type_name = dtype.getObjName(); + type_name = dtype.getObjName(); + verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Repeat the test with openDataType's replacement + DataType dtype2(file, "STD_B8LE"); + + // Get and verify its name + type_name = dtype2.getObjName(); verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); // Test getting type's name from copied type -- cgit v0.12 From e05da1b533d5eb9527a5b67ba2683379f8e1e7ac Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Fri, 23 Dec 2016 13:24:45 -0600 Subject: Description: Removed commented out code and fixed miscellaneous typos. Platforms tested: Linux/32 2.6 (jam) (very minor) --- c++/src/H5ArrayType.h | 2 +- c++/src/H5Attribute.cpp | 2 +- c++/src/H5Classes.h | 2 -- c++/src/H5CompType.cpp | 1 - c++/src/H5CompType.h | 2 +- c++/src/H5Cpp.h | 2 -- c++/src/H5DataType.h | 3 --- c++/src/H5DcreatProp.h | 3 --- c++/src/H5DxferProp.h | 3 --- c++/src/H5EnumType.h | 2 +- c++/src/H5FaccProp.h | 3 --- c++/src/H5FloatType.h | 2 +- c++/src/H5Group.cpp | 1 - c++/src/H5IntType.h | 2 +- c++/src/H5Object.cpp | 34 ---------------------------------- c++/src/H5Object.h | 4 ---- c++/src/H5PropList.cpp | 2 +- c++/src/H5StrType.h | 2 +- c++/src/H5VarLenType.h | 2 +- 19 files changed, 9 insertions(+), 65 deletions(-) diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index 42e1c2b..65917ae 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -34,7 +34,7 @@ class H5_DLLCPP ArrayType : public DataType { // Assignment operator ArrayType& operator=(const ArrayType& rhs); - // Constructors that opens a named array datatype, given a location. + // Constructors that open an array datatype, given a location. ArrayType(const H5Location& loc, const char* name); ArrayType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 74d246f..c71c035 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -20,6 +20,7 @@ #endif #include +#include "H5private.h" // for HDfree #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" @@ -34,7 +35,6 @@ #include "H5DataType.h" #include "H5DataSpace.h" #include "H5Attribute.h" -#include "H5private.h" // for HDfree namespace H5 { using std::cerr; diff --git a/c++/src/H5Classes.h b/c++/src/H5Classes.h index a1525cc..bed0cae 100644 --- a/c++/src/H5Classes.h +++ b/c++/src/H5Classes.h @@ -25,8 +25,6 @@ namespace H5 { class PropList; class FileCreatPropList; class FileAccPropList; - /* class LinkAccPropList; - */ class DSetCreatPropList; class DSetMemXferPropList; class DTypePropList; diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 887151e..0562e75 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -28,7 +28,6 @@ #include "H5AbstractDs.h" #include "H5DataSpace.h" #include "H5DataSet.h" -#include "H5private.h" namespace H5 { diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h index 879e4f1..3337df7 100644 --- a/c++/src/H5CompType.h +++ b/c++/src/H5CompType.h @@ -42,7 +42,7 @@ class H5_DLLCPP CompType : public DataType { // Copy constructor - makes a copy of original object CompType( const CompType& original ); - // Constructors that opens a compound datatype, given a location. + // Constructors that open a compound datatype, given a location. CompType(const H5Location& loc, const char* name); CompType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index 967f689..90f0a2a 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -27,8 +27,6 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" - /* #include "H5LaccProp.h" - */ #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 7036836..4e904a6 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -14,9 +14,6 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Class DataType inherits from H5Object and has several subclasses for -// specific HDF5 data types. - #ifndef __H5DataType_H #define __H5DataType_H diff --git a/c++/src/H5DcreatProp.h b/c++/src/H5DcreatProp.h index 787d3ec..60ce1d5 100644 --- a/c++/src/H5DcreatProp.h +++ b/c++/src/H5DcreatProp.h @@ -14,9 +14,6 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Class DSetCreatPropList represents the HDF5 dataset creation property list -// and inherits from PropList. - #ifndef __H5DSCreatPropList_H #define __H5DSCreatPropList_H diff --git a/c++/src/H5DxferProp.h b/c++/src/H5DxferProp.h index 81361cf..42194fb 100644 --- a/c++/src/H5DxferProp.h +++ b/c++/src/H5DxferProp.h @@ -14,9 +14,6 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Class DSetMemXferPropList represents the HDF5 dataset transfer property list -// and inherits from PropList. - #ifndef __H5DSetMemXferPropList_H #define __H5DSetMemXferPropList_H diff --git a/c++/src/H5EnumType.h b/c++/src/H5EnumType.h index b4ffe43..054811b 100644 --- a/c++/src/H5EnumType.h +++ b/c++/src/H5EnumType.h @@ -38,7 +38,7 @@ class H5_DLLCPP EnumType : public DataType { // Creates a new enum datatype based on an integer datatype EnumType( const IntType& data_type ); // H5Tenum_create - // Constructors that opens an enum datatype, given a location. + // Constructors that open an enum datatype, given a location. EnumType(const H5Location& loc, const char* name); EnumType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5FaccProp.h b/c++/src/H5FaccProp.h index a0605e0..aec5fcc 100644 --- a/c++/src/H5FaccProp.h +++ b/c++/src/H5FaccProp.h @@ -14,9 +14,6 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Class FileAccPropList represents the HDF5 file access property list and -// inherits from DataType. - #ifndef __H5FileAccPropList_H #define __H5FileAccPropList_H diff --git a/c++/src/H5FloatType.h b/c++/src/H5FloatType.h index 1f3b409..1f4b227 100644 --- a/c++/src/H5FloatType.h +++ b/c++/src/H5FloatType.h @@ -33,7 +33,7 @@ class H5_DLLCPP FloatType : public AtomType { // Gets the floating-point datatype of the specified dataset. FloatType( const DataSet& dataset ); - // Constructors that opens an HDF5 float datatype, given a location. + // Constructors that open an HDF5 float datatype, given a location. FloatType(const H5Location& loc, const char* name); FloatType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index fa0a206..4325a68 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -20,7 +20,6 @@ #endif #include -#include "H5private.h" // for HDstrcpy #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" diff --git a/c++/src/H5IntType.h b/c++/src/H5IntType.h index 09a311f..74786b9 100644 --- a/c++/src/H5IntType.h +++ b/c++/src/H5IntType.h @@ -33,7 +33,7 @@ class H5_DLLCPP IntType : public AtomType { // Gets the integer datatype of the specified dataset IntType(const DataSet& dataset); - // Constructors that opens an HDF5 integer datatype, given a location. + // Constructors that open an HDF5 integer datatype, given a location. IntType(const H5Location& loc, const char* name); IntType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 66699d4..d656ccf 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -257,40 +257,6 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_da } //-------------------------------------------------------------------------- -// Function: H5Object::objVersion -///\brief Returns the header version of this HDF5 object. -///\return Object version, which can have the following values: -/// \li \c H5O_VERSION_1 -/// \li \c H5O_VERSION_2 -///\exception H5::ObjHeaderIException -/// Exception will be thrown when: -/// - an error returned by the C API -/// - version number is not one of the valid values above -// Programmer Binh-Minh Ribler - December, 2016 -//-------------------------------------------------------------------------- - /* unsigned H5Object::objVersion() const -{ - H5O_info_t objinfo; - unsigned version = 0; - - // Use C API to get information of the object - herr_t ret_value = H5Oget_info(getId(), &objinfo); - - // Throw exception if C API returns failure - if (ret_value < 0) - throw Exception(inMemFunc("objVersion"), "H5Oget_info failed"); - // Return a valid version or throw an exception for invalid value - else - { - version = objinfo.hdr.version; - if (version != H5O_VERSION_1 && version != H5O_VERSION_2) - throw ObjHeaderIException("objVersion", "Invalid version for object"); - } - return(version); -} - */ - -//-------------------------------------------------------------------------- // Function: H5Object::getNumAttrs ///\brief Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 70acda9..72a9f50 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -77,10 +77,6 @@ class H5_DLLCPP H5Object : public H5Location { // Iterate user's function over the attributes of this object. int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); - // Returns the object header version of an object - /* unsigned objVersion() const; - */ - // Determines the number of attributes belong to this object. int getNumAttrs() const; diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index 42c9b83..f0eb847 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -21,7 +21,7 @@ #include -#include "H5private.h" // for HDfree +#include "H5private.h" // for HDmemset #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" diff --git a/c++/src/H5StrType.h b/c++/src/H5StrType.h index 5ff88b6..b920a3b 100644 --- a/c++/src/H5StrType.h +++ b/c++/src/H5StrType.h @@ -39,7 +39,7 @@ class H5_DLLCPP StrType : public AtomType { // Gets the string datatype of the specified dataset StrType(const DataSet& dataset); - // Constructors that opens an HDF5 string datatype, given a location. + // Constructors that open an HDF5 string datatype, given a location. StrType(const H5Location& loc, const char* name); StrType(const H5Location& loc, const H5std_string& name); diff --git a/c++/src/H5VarLenType.h b/c++/src/H5VarLenType.h index accb13e..af4f7b7 100644 --- a/c++/src/H5VarLenType.h +++ b/c++/src/H5VarLenType.h @@ -40,7 +40,7 @@ class H5_DLLCPP VarLenType : public DataType { // Constructor that takes an existing id VarLenType( const hid_t existing_id ); - // Constructors that opens a variable-length datatype, given a location. + // Constructors that open a variable-length datatype, given a location. VarLenType(const H5Location& loc, const char* name); VarLenType(const H5Location& loc, const H5std_string& name); -- cgit v0.12