diff options
Diffstat (limited to 'c++')
45 files changed, 872 insertions, 291 deletions
diff --git a/c++/examples/CMakeLists.txt b/c++/examples/CMakeLists.txt index 5ea51a4..ff375f3 100644 --- a/c++/examples/CMakeLists.txt +++ b/c++/examples/CMakeLists.txt @@ -35,7 +35,7 @@ set (tutr_examples foreach (example ${examples}) add_executable (cpp_ex_${example} ${HDF5_CPP_EXAMPLES_SOURCE_DIR}/${example}.cpp) TARGET_NAMING (cpp_ex_${example} ${LIB_TYPE}) - TARGET_C_PROPERTIES (cpp_ex_${example} " " " ") + TARGET_C_PROPERTIES (cpp_ex_${example} ${LIB_TYPE} " " " ") target_link_libraries (cpp_ex_${example} ${HDF5_CPP_LIB_TARGET} ${HDF5_LIB_TARGET}) set_target_properties (cpp_ex_${example} PROPERTIES FOLDER examples/cpp) endforeach (example ${examples}) @@ -43,7 +43,7 @@ endforeach (example ${examples}) foreach (example ${tutr_examples}) add_executable (cpp_ex_${example} ${HDF5_CPP_EXAMPLES_SOURCE_DIR}/${example}.cpp) TARGET_NAMING (cpp_ex_${example} ${LIB_TYPE}) - TARGET_C_PROPERTIES (cpp_ex_${example} " " " ") + TARGET_C_PROPERTIES (cpp_ex_${example} ${LIB_TYPE} " " " ") target_link_libraries (cpp_ex_${example} ${HDF5_CPP_LIB_TARGET} ${HDF5_LIB_TARGET}) set_target_properties (cpp_ex_${example} PROPERTIES FOLDER examples/cpp) endforeach (example ${tutr_examples}) diff --git a/c++/examples/Makefile.am b/c++/examples/Makefile.am index 5bb8d59..2408217 100644 --- a/c++/examples/Makefile.am +++ b/c++/examples/Makefile.am @@ -42,8 +42,8 @@ INSTALL_FILES=create.cpp readdata.cpp writedata.cpp compound.cpp \ # Some of the examples depend on files created by running other examples readdata.chkexe_: create.chkexe_ chunks.chkexe_: extend_ds.chkexe_ -h5tutr_rdwt.chkexe_: h5tutrcrtdat.chkexe -h5tutrcrtatt.chkexe_: h5tutrcrtdat.chkexe +h5tutr_rdwt.chkexe_: h5tutr_crtdat.chkexe +h5tutrcrtatt.chkexe_: h5tutr_crtdat.chkexe h5tutr_crtgrpd.chkexe_: h5tutr_crtgrpar.chkexe # Tell conclude.am that these are C++ tests. @@ -52,6 +52,7 @@ CXX_API=yes # Where to install examples # Note: no '/' after DESTDIR. Explanation in commence.am EXAMPLEDIR=${DESTDIR}$(exec_prefix)/share/hdf5_examples/c++ +EXAMPLETOPDIR=${DESTDIR}$(exec_prefix)/share/hdf5_examples # How to build programs using h5c++ $(EXTRA_PROG): $(H5CPP) diff --git a/c++/examples/run-c++-ex.sh.in b/c++/examples/run-c++-ex.sh.in index 77ac36a..eae2782 100644 --- a/c++/examples/run-c++-ex.sh.in +++ b/c++/examples/run-c++-ex.sh.in @@ -34,7 +34,7 @@ EXIT_FAILURE=1 # Where the tool is installed. # default is relative path to installed location of the tools -prefix="${prefix:-../../../}" +prefix="${prefix:-@prefix@}" AR="@AR@" RANLIB="@RANLIB@" H5TOOL="h5c++" # The tool name diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 513bbb6..2f3a0c4 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -84,7 +84,7 @@ set (CPP_HDRS ) add_library (${HDF5_CPP_LIB_TARGET} ${LIB_TYPE} ${CPP_SRCS} ${CPP_HDRS}) -TARGET_C_PROPERTIES (${HDF5_CPP_LIB_TARGET} " " " ") +TARGET_C_PROPERTIES (${HDF5_CPP_LIB_TARGET} ${LIB_TYPE} " " " ") target_link_libraries (${HDF5_CPP_LIB_TARGET} ${HDF5_LIB_TARGET}) set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_CPP_LIB_TARGET}") H5_SET_LIB_OPTIONS (${HDF5_CPP_LIB_TARGET} ${HDF5_CPP_LIB_NAME} ${LIB_TYPE}) diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index e6cacf9..d59c1eb 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5Object.h" #include "H5AbstractDs.h" +#include "H5DataSpace.h" #include "H5DcreatProp.h" #include "H5CommonFG.h" #include "H5Alltypes.h" @@ -40,6 +41,12 @@ AbstractDs::AbstractDs(){} // Function: AbstractDs default constructor ///\brief Creates an AbstractDs instance using an existing id. // Programmer Binh-Minh Ribler - 2000 +// +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It will be removed in 1.10 release. If its +// removal does not raise any problems in 1.10, it will be removed from 1.8 in +// subsequent releases. //-------------------------------------------------------------------------- AbstractDs::AbstractDs(const hid_t ds_id){} @@ -47,8 +54,13 @@ AbstractDs::AbstractDs(const hid_t ds_id){} // Function: AbstractDs copy constructor ///\brief Copy constructor: makes a copy of the original AbstractDs object. // Programmer Binh-Minh Ribler - 2000 +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It is removed from 1.8.15 because it is +// a noop and it can be generated by the compiler if needed. //-------------------------------------------------------------------------- -AbstractDs::AbstractDs(const AbstractDs& original){} +//-------------------------------------------------------------------------- +// AbstractDs::AbstractDs(const AbstractDs& original){} //-------------------------------------------------------------------------- // Function: AbstractDs::getTypeClass @@ -113,8 +125,9 @@ DataType AbstractDs::getDataType() const // depending on which object invokes getDataType. Then, create and // return the DataType object try { - DataType datatype(p_get_type()); - return(datatype); + DataType datatype; + f_DataType_setId(&datatype, p_get_type()); + return(datatype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getDataType", E.getDetailMsg()); @@ -139,8 +152,9 @@ ArrayType AbstractDs::getArrayType() const // depending on which object invokes getArrayType. Then, create and // return the ArrayType object try { - ArrayType arraytype(p_get_type()); - return(arraytype); + ArrayType arraytype; + f_DataType_setId(&arraytype, p_get_type()); + return(arraytype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getArrayType", E.getDetailMsg()); @@ -165,8 +179,9 @@ CompType AbstractDs::getCompType() const // depending on which object invokes getCompType. Then, create and // return the CompType object try { - CompType comptype(p_get_type()); - return(comptype); + CompType comptype; + f_DataType_setId(&comptype, p_get_type()); + return(comptype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getCompType", E.getDetailMsg()); @@ -191,8 +206,9 @@ EnumType AbstractDs::getEnumType() const // depending on which object invokes getEnumType. Then, create and // return the EnumType object try { - EnumType enumtype(p_get_type()); - return(enumtype); + EnumType enumtype; + f_DataType_setId(&enumtype, p_get_type()); + return(enumtype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getEnumType", E.getDetailMsg()); @@ -217,8 +233,9 @@ IntType AbstractDs::getIntType() const // depending on which object invokes getIntType. Then, create and // return the IntType object try { - IntType inttype(p_get_type()); - return(inttype); + IntType inttype; + f_DataType_setId(&inttype, p_get_type()); + return(inttype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getIntType", E.getDetailMsg()); @@ -243,8 +260,9 @@ FloatType AbstractDs::getFloatType() const // depending on which object invokes getFloatType. Then, create and // return the FloatType object try { - FloatType floatype(p_get_type()); - return(floatype); + FloatType floatype; + f_DataType_setId(&floatype, p_get_type()); + return(floatype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getFloatType", E.getDetailMsg()); @@ -269,8 +287,9 @@ StrType AbstractDs::getStrType() const // depending on which object invokes getStrType. Then, create and // return the StrType object try { - StrType strtype(p_get_type()); - return(strtype); + StrType strtype; + f_DataType_setId(&strtype, p_get_type()); + return(strtype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getStrType", E.getDetailMsg()); @@ -295,8 +314,9 @@ VarLenType AbstractDs::getVarLenType() const // depending on which object invokes getVarLenType. Then, create and // return the VarLenType object try { - VarLenType varlentype(p_get_type()); - return(varlentype); + VarLenType varlentype; + f_DataType_setId(&varlentype, p_get_type()); + return(varlentype); } catch (DataSetIException E) { throw DataTypeIException("DataSet::getVarLenType", E.getDetailMsg()); diff --git a/c++/src/H5AbstractDs.h b/c++/src/H5AbstractDs.h index 01d05b8..810dc8b 100644 --- a/c++/src/H5AbstractDs.h +++ b/c++/src/H5AbstractDs.h @@ -28,6 +28,7 @@ class FloatType; class IntType; class StrType; class VarLenType; +class DataSpace; /*! \class AbstractDs \brief AbstractDs is an abstract base class, inherited by Attribute @@ -70,9 +71,6 @@ class H5_DLLCPP AbstractDs { ///\brief Returns this class name. virtual H5std_string fromClass() const = 0; - // Copy constructor - AbstractDs( const AbstractDs& original ); - // Destructor virtual ~AbstractDs(); @@ -80,8 +78,17 @@ class H5_DLLCPP AbstractDs { // Default constructor AbstractDs(); - // Constructor that takes an attribute id or a dataset id. - AbstractDs( const hid_t ds_id ); + // *** Deprecation warning *** + // The following two constructors are no longer appropriate after the + // data member "id" had been moved to the sub-classes. + // The copy constructor is a noop and is removed in 1.8.15 and the + // other will be removed from 1.10 release, and then from 1.8 if its + // removal does not raise any problems in two 1.10 releases. + + AbstractDs(const hid_t h5_id); + + // Copy constructor + // AbstractDs( const AbstractDs& original ); private: // This member function is implemented by DataSet and Attribute. diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index 511126e..6577a6e 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -49,7 +49,6 @@ class H5_DLLCPP ArrayType : public DataType { // Noop destructor virtual ~ArrayType(); - protected: // Default constructor ArrayType(); diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index a9e928d..0bfdff8 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -74,7 +74,8 @@ Attribute::Attribute(const Attribute& original) : AbstractDs(), IdComponent() //-------------------------------------------------------------------------- Attribute::Attribute(const hid_t existing_id) : AbstractDs(), IdComponent() { - id = existing_id; + id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -270,8 +271,9 @@ DataSpace Attribute::getSpace() const // If the dataspace id is valid, create and return the DataSpace object if( dataspace_id > 0 ) { - DataSpace dataspace( dataspace_id ); - return( dataspace ); + DataSpace dataspace; + f_DataSpace_setId(&dataspace, dataspace_id); + return(dataspace); } else { @@ -392,10 +394,12 @@ H5std_string Attribute::getName() const //-------------------------------------------------------------------------- H5std_string Attribute::getName(size_t len) const { - H5std_string attr_name; - ssize_t name_size = getName(attr_name, len); - return(attr_name); - // let caller catch exception if any + H5std_string attr_name; + ssize_t name_size = getName(attr_name, len); + if (name_size < 0) + return(""); + else + return(attr_name); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index f57b922..eced64e 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -31,6 +31,16 @@ namespace H5 { */ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { public: + + // Copy constructor: makes a copy of an existing Attribute object. + Attribute( const Attribute& original ); + + // Default constructor + Attribute(); + + // Creates a copy of an existing attribute using the attribute id + Attribute( const hid_t attr_id ); + // Closes this attribute. virtual void close(); @@ -70,15 +80,6 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { ///\brief Returns this class name. virtual H5std_string fromClass () const { return("Attribute"); } - // Creates a copy of an existing attribute using the attribute id - Attribute( const hid_t attr_id ); - - // Copy constructor: makes a copy of an existing Attribute object. - Attribute( const Attribute& original ); - - // Default constructor - Attribute(); - // Gets the attribute id. virtual hid_t getId() const; @@ -109,6 +110,10 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { // do not inherit H5Object::renameAttr void renameAttr() {} + + // Friend function to set Attribute id. For library use only. + friend void f_Attribute_setId(Attribute* attr, hid_t new_id); + }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 3aa0386..dbe26b4 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -14,6 +14,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <string> +#include <iostream> #include "H5Include.h" #include "H5Exception.h" @@ -33,9 +34,6 @@ #include "H5Alltypes.h" #include "H5private.h" // for HDstrcpy -#include <iostream> -using namespace std; - // There are a few comments that are common to most of the functions // defined in this file so they are listed here. // - getLocId is called by all functions, that call a C API, to get @@ -51,6 +49,7 @@ using namespace std; #ifndef H5_NO_NAMESPACE namespace H5 { +using namespace std; #endif //-------------------------------------------------------------------------- @@ -100,7 +99,9 @@ Group CommonFG::createGroup( const char* name, size_t size_hint ) const throwException("createGroup", "H5Gcreate2 failed"); // No failure, create and return the Group object - Group group( group_id ); + Group group; + CommonFG *ptr = &group; + ptr->p_setId(group_id); return( group ); } @@ -136,7 +137,9 @@ Group CommonFG::openGroup( const char* name ) const throwException("openGroup", "H5Gopen2 failed"); // No failure, create and return the Group object - Group group( group_id ); + Group group; + CommonFG *ptr = &group; + ptr->p_setId(group_id); return( group ); } @@ -178,7 +181,8 @@ DataSet CommonFG::createDataSet( const char* name, const DataType& data_type, co throwException("createDataSet", "H5Dcreate2 failed"); // No failure, create and return the DataSet object - DataSet dataset( dataset_id ); + DataSet dataset; + f_DataSet_setId(&dataset, dataset_id); return( dataset ); } @@ -213,7 +217,8 @@ DataSet CommonFG::openDataSet( const char* name ) const throwException("openDataSet", "H5Dopen2 failed"); // No failure, create and return the DataSet object - DataSet dataset( dataset_id ); + DataSet dataset; + f_DataSet_setId(&dataset, dataset_id); return( dataset ); } @@ -576,7 +581,8 @@ DataType CommonFG::openDataType( const char* name ) const throwException("openDataType", "H5Topen2 failed"); // No failure, create and return the DataType object - DataType data_type(type_id); + DataType data_type; + f_DataType_setId(&data_type, type_id); return(data_type); } @@ -611,7 +617,8 @@ ArrayType CommonFG::openArrayType( const char* name ) const throwException("openArrayType", "H5Topen2 failed"); // No failure, create and return the ArrayType object - ArrayType array_type (type_id); + ArrayType array_type; + f_DataType_setId(&array_type, type_id); return(array_type); } @@ -646,7 +653,8 @@ CompType CommonFG::openCompType( const char* name ) const throwException("openCompType", "H5Topen2 failed"); // No failure, create and return the CompType object - CompType comp_type(type_id); + CompType comp_type; + f_DataType_setId(&comp_type, type_id); return(comp_type); } @@ -681,7 +689,8 @@ EnumType CommonFG::openEnumType( const char* name ) const throwException("openEnumType", "H5Topen2 failed"); // No failure, create and return the EnumType object - EnumType enum_type(type_id); + EnumType enum_type; + f_DataType_setId(&enum_type, type_id); return(enum_type); } @@ -716,7 +725,8 @@ IntType CommonFG::openIntType( const char* name ) const throwException("openIntType", "H5Topen2 failed"); // No failure, create and return the IntType object - IntType int_type(type_id); + IntType int_type; + f_DataType_setId(&int_type, type_id); return(int_type); } @@ -751,7 +761,8 @@ FloatType CommonFG::openFloatType( const char* name ) const throwException("openFloatType", "H5Topen2 failed"); // No failure, create and return the FloatType object - FloatType float_type(type_id); + FloatType float_type; + f_DataType_setId(&float_type, type_id); return(float_type); } @@ -786,7 +797,8 @@ StrType CommonFG::openStrType( const char* name ) const throwException("openStrType", "H5Topen2 failed"); // No failure, create and return the StrType object - StrType str_type(type_id); + StrType str_type; + f_DataType_setId(&str_type, type_id); return(str_type); } @@ -821,7 +833,8 @@ VarLenType CommonFG::openVarLenType( const char* name ) const throwException("openVarLenType", "H5Topen2 failed"); // No failure, create and return the VarLenType object - VarLenType varlen_type(type_id); + VarLenType varlen_type; + f_DataType_setId(&varlen_type, type_id); return(varlen_type); } @@ -1100,6 +1113,58 @@ H5O_type_t CommonFG::childObjType(hsize_t index, H5_index_t index_type, H5_iter_ return(objtype); } +//-------------------------------------------------------------------------- +// Function: CommonFG::childObjVersion +///\brief Returns the object header version of an object in this file/group, +/// given the object's name. +///\param objname - IN: Name of the object +///\return Object version, which can have the following values: +/// \li \c H5O_VERSION_1 +/// \li \c H5O_VERSION_2 +///\exception H5::FileIException or H5::GroupIException +/// 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 - April, 2014 +//-------------------------------------------------------------------------- +unsigned CommonFG::childObjVersion(const char* objname) const +{ + H5O_info_t objinfo; + unsigned version = 0; + + // Use C API to get information of the object + herr_t ret_value = H5Oget_info_by_name(getLocId(), objname, &objinfo, H5P_DEFAULT); + + // Throw exception if C API returns failure + if (ret_value < 0) + throwException("childObjVersion", "H5Oget_info_by_name 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) + throwException("childObjVersion", "Invalid version for object"); + } + return(version); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::childObjVersion +///\brief This is an overloaded member function, provided for convenience. +/// It takes an \a H5std_string for the object's name. +///\brief Returns the type of an object in this group, given the +/// object's name. +///\param objname - IN: Name of the object (H5std_string&) +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - April, 2014 +//-------------------------------------------------------------------------- +unsigned CommonFG::childObjVersion(const H5std_string& objname) const +{ + // Use overloaded function + unsigned version = childObjVersion(objname.c_str()); + return(version); +} + #ifndef H5_NO_DEPRECATED_SYMBOLS #ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- @@ -1172,6 +1237,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const } return (obj_type); } + #endif // DOXYGEN_SHOULD_SKIP_THIS #endif /* H5_NO_DEPRECATED_SYMBOLS */ @@ -1189,6 +1255,37 @@ CommonFG::CommonFG() {} // 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->id = 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->id = new_id; +} + #endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 5c8a142..d36d78c 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -21,6 +21,7 @@ namespace H5 { #endif +// Class forwarding class Group; class H5File; class ArrayType; @@ -70,6 +71,11 @@ class H5_DLLCPP CommonFG { H5O_type_t childObjType(const char* objname) const; H5O_type_t childObjType(hsize_t index, H5_index_t index_type=H5_INDEX_NAME, H5_iter_order_t order=H5_ITER_INC, const char* objname=".") const; + // Returns the object header version of an object in this file or group, + // given the object's name. + unsigned childObjVersion(const char* objname) const; + unsigned childObjVersion(const H5std_string& objname) const; + #ifndef H5_NO_DEPRECATED_SYMBOLS // Returns the type of an object in this group, given the // object's index. @@ -159,6 +165,10 @@ class H5_DLLCPP CommonFG { // Noop destructor. virtual ~CommonFG(); + + protected: + virtual void p_setId(const hid_t new_id) = 0; + #endif // DOXYGEN_SHOULD_SKIP_THIS }; // end of CommonFG declaration diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 191f004..393aafc 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -227,7 +227,8 @@ hid_t CompType::p_get_member_type(unsigned member_num) const DataType CompType::getMemberDataType( unsigned member_num ) const { try { - DataType datatype(p_get_member_type(member_num)); + DataType datatype; + f_DataType_setId(&datatype, p_get_member_type(member_num)); return(datatype); } catch (DataTypeIException E) { @@ -248,6 +249,7 @@ ArrayType CompType::getMemberArrayType( unsigned member_num ) const { try { ArrayType arraytype(p_get_member_type(member_num)); + f_DataType_setId(&arraytype, p_get_member_type(member_num)); return(arraytype); } catch (DataTypeIException E) { @@ -268,6 +270,7 @@ CompType CompType::getMemberCompType( unsigned member_num ) const { try { CompType comptype(p_get_member_type(member_num)); + f_DataType_setId(&comptype, p_get_member_type(member_num)); return(comptype); } catch (DataTypeIException E) { @@ -288,6 +291,7 @@ EnumType CompType::getMemberEnumType( unsigned member_num ) const { try { EnumType enumtype(p_get_member_type(member_num)); + f_DataType_setId(&enumtype, p_get_member_type(member_num)); return(enumtype); } catch (DataTypeIException E) { @@ -308,6 +312,7 @@ IntType CompType::getMemberIntType( unsigned member_num ) const { try { IntType inttype(p_get_member_type(member_num)); + f_DataType_setId(&inttype, p_get_member_type(member_num)); return(inttype); } catch (DataTypeIException E) { @@ -328,6 +333,7 @@ FloatType CompType::getMemberFloatType( unsigned member_num ) const { try { FloatType floatype(p_get_member_type(member_num)); + f_DataType_setId(&floatype, p_get_member_type(member_num)); return(floatype); } catch (DataTypeIException E) { @@ -348,6 +354,7 @@ StrType CompType::getMemberStrType( unsigned member_num ) const { try { StrType strtype(p_get_member_type(member_num)); + f_DataType_setId(&strtype, p_get_member_type(member_num)); return(strtype); } catch (DataTypeIException E) { @@ -368,6 +375,7 @@ VarLenType CompType::getMemberVarLenType( unsigned member_num ) const { try { VarLenType varlentype(p_get_member_type(member_num)); + f_DataType_setId(&varlentype, p_get_member_type(member_num)); return(varlentype); } catch (DataTypeIException E) { diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 6728264..717ef88 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -52,7 +52,7 @@ namespace H5 { ///\brief Default constructor: creates a stub DataSet. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet() : AbstractDs(), H5Object(), id(H5I_INVALID_HID) {} +DataSet::DataSet() : H5Object(), AbstractDs(), id(H5I_INVALID_HID) {} //-------------------------------------------------------------------------- // Function: DataSet overloaded constructor @@ -60,9 +60,10 @@ DataSet::DataSet() : AbstractDs(), H5Object(), id(H5I_INVALID_HID) {} ///\param existing_id - IN: Id of an existing dataset // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet(const hid_t existing_id) : AbstractDs(), H5Object() +DataSet::DataSet(const hid_t existing_id) : H5Object(), AbstractDs() { id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -71,7 +72,7 @@ DataSet::DataSet(const hid_t existing_id) : AbstractDs(), H5Object() ///\param original - IN: DataSet instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object(original) +DataSet::DataSet(const DataSet& original) : H5Object(), AbstractDs() { id = original.getId(); incRefCount(); // increment number of references to this id @@ -95,7 +96,7 @@ DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object(origi // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : AbstractDs(), H5Object(), id(H5I_INVALID_HID) +DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), AbstractDs(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(loc.getId(), ref, ref_type, plist, "constructor - by dereferenced"); } @@ -114,7 +115,7 @@ DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type, co // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataSet::DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : AbstractDs(), H5Object(), id(H5I_INVALID_HID) +DataSet::DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), AbstractDs(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(attr.getId(), ref, ref_type, plist, "constructor - by dereference"); } @@ -137,7 +138,8 @@ DataSpace DataSet::getSpace() const throw DataSetIException("DataSet::getSpace", "H5Dget_space failed"); } //create dataspace object using the existing id then return the object - DataSpace data_space( dataspace_id ); + DataSpace data_space; + f_DataSpace_setId(&data_space, dataspace_id); return( data_space ); } @@ -170,8 +172,8 @@ DSetCreatPropList DataSet::getCreatePlist() const throw DataSetIException("DataSet::getCreatePlist", "H5Dget_create_plist failed"); } // create and return the DSetCreatPropList object - DSetCreatPropList create_plist( create_plist_id ); - return( create_plist ); + DSetCreatPropList create_plist(create_plist_id); // ok to use existing id const + return(create_plist); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index 529466a..b2544a2 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -30,6 +30,7 @@ namespace H5 { */ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { public: + // Close this dataset. virtual void close(); @@ -125,6 +126,10 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { // Reads variable or fixed len strings from this dataset. void p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const; void p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const; + + // Friend function to set DataSet id. For library use only. + friend void f_DataSet_setId(DataSet* dset, hid_t new_id); + }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp index 20b4e5e..d9c262d 100644 --- a/c++/src/H5DataSpace.cpp +++ b/c++/src/H5DataSpace.cpp @@ -85,6 +85,7 @@ DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : DataSpace::DataSpace(const hid_t existing_id) : IdComponent() { id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -93,7 +94,7 @@ DataSpace::DataSpace(const hid_t existing_id) : IdComponent() ///\param original - IN: DataSpace object to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSpace::DataSpace(const DataSpace& original) : IdComponent(original) +DataSpace::DataSpace(const DataSpace& original) : IdComponent() { id = original.getId(); incRefCount(); // increment number of references to this id diff --git a/c++/src/H5DataSpace.h b/c++/src/H5DataSpace.h index b007fd0..a43cecd 100644 --- a/c++/src/H5DataSpace.h +++ b/c++/src/H5DataSpace.h @@ -129,6 +129,9 @@ class H5_DLLCPP DataSpace : public IdComponent { private: hid_t id; // HDF5 dataspace id + + // Friend function to set DataSpace id. For library use only. + friend void f_DataSpace_setId(DataSpace *dspace, hid_t new_id); }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index a435b4e..cdcd1e6 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -71,6 +71,7 @@ DataType::DataType() : H5Object(), id(H5I_INVALID_HID) {} DataType::DataType(const hid_t existing_id) : H5Object() { id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -105,7 +106,7 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object() // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object(), id(H5I_INVALID_HID) +DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type, const PropList& plist) : H5Object() { id = H5Location::p_dereference(loc.getId(), ref, ref_type, plist, "constructor - by dereference"); } @@ -134,13 +135,34 @@ DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type, ///\brief Copy constructor: makes a copy of the original DataType object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataType::DataType(const DataType& original) : H5Object(original) +DataType::DataType(const DataType& original) : H5Object() { id = original.getId(); incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- +// Function: DataType overloaded constructor +///\brief Creates a integer type using a predefined type +///\param pred_type - IN: Predefined datatype +///\exception H5::DataTypeIException +// Programmer Binh-Minh Ribler - 2000 +// Description +// Copying the type so that when a predefined type is passed in, +// a copy of it is made, not just a duplicate of the HDF5 id. +// Note: calling DataType::copy will invoke DataType::close() +// unnecessarily and will produce undefined behavior. +// -BMR, Apr 2015 +//-------------------------------------------------------------------------- +DataType::DataType(const PredType& pred_type) : H5Object() +{ + // call C routine to copy the datatype + id = H5Tcopy( pred_type.getId() ); + if (id < 0) + throw DataTypeIException("DataType constructor", "H5Tcopy failed"); +} + +//-------------------------------------------------------------------------- // Function: DataType::copy ///\brief Copies an existing datatype to this datatype object ///\param like_type - IN: Datatype to be copied @@ -203,11 +225,22 @@ void DataType::copy(const DataSet& dset) // Makes a copy of the type on the right hand side and stores // the new id in the left hand side object. // Programmer Binh-Minh Ribler - 2000 +// Modification +// Changed operator= to simply copy the id of rhs instead of +// calling H5Tcopy because, when the operator= is invoked, a +// different datatype id is created and it won't have the same +// characteristics as the original one, specifically, if the +// rhs represents a named datatype, "this" would still be a +// transient datatype. +// BMR - Mar, 2015 //-------------------------------------------------------------------------- DataType& DataType::operator=( const DataType& rhs ) { if (this != &rhs) - copy(rhs); + { + id = rhs.id; + incRefCount(); // increment number of references to this id + } return(*this); } @@ -463,8 +496,9 @@ DataType DataType::getSuper() const // the base type, otherwise, raise exception if( base_type_id > 0 ) { - DataType base_type( base_type_id ); - return( base_type ); + DataType base_type; + base_type.p_setId(base_type_id); + return(base_type); } else { diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 064bfe1..6c8a312 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -36,6 +36,9 @@ class H5_DLLCPP DataType : public H5Object { // Copy constructor: makes a copy of the original object DataType( const DataType& original ); + // Creates a copy of a predefined type + DataType(const PredType& pred_type); + // 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); @@ -133,6 +136,9 @@ class H5_DLLCPP DataType : public H5Object { #endif // DOXYGEN_SHOULD_SKIP_THIS private: + // Friend function to set DataType id. For library use only. + friend void f_DataType_setId(DataType* dtype, hid_t new_id); + void p_commit(hid_t loc_id, const char* name); }; #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index f153c92..fb1e42e 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -35,11 +35,11 @@ Exception::Exception() : detail_message(""), func_name("") {} // Function: Exception overloaded constructor ///\brief Creates an exception with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Exception::Exception(const H5std_string& func_name, const H5std_string& message) : detail_message(message), func_name(func_name) {} +Exception::Exception(const H5std_string& func, const H5std_string& message) : detail_message(message), func_name(func) {} //-------------------------------------------------------------------------- // Function: Exception copy constructor @@ -350,10 +350,10 @@ FileIException::FileIException():Exception(){} // Function: FileIException overloaded constructor ///\brief Creates a FileIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -FileIException::FileIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +FileIException::FileIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: FileIException destructor ///\brief Noop destructor. @@ -373,10 +373,10 @@ GroupIException::GroupIException():Exception(){} // Function: GroupIException overloaded constructor ///\brief Creates a GroupIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -GroupIException::GroupIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +GroupIException::GroupIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: GroupIException destructor ///\brief Noop destructor. @@ -396,10 +396,10 @@ DataSpaceIException::DataSpaceIException():Exception(){} // Function: DataSpaceIException overloaded constructor ///\brief Creates a DataSpaceIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -DataSpaceIException::DataSpaceIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +DataSpaceIException::DataSpaceIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: DataSpaceIException destructor ///\brief Noop destructor. @@ -419,10 +419,10 @@ DataTypeIException::DataTypeIException():Exception(){} // Function: DataTypeIException overloaded constructor ///\brief Creates a DataTypeIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -DataTypeIException::DataTypeIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +DataTypeIException::DataTypeIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: DataTypeIException destructor ///\brief Noop destructor. @@ -442,10 +442,10 @@ PropListIException::PropListIException():Exception(){} // Function: PropListIException overloaded constructor ///\brief Creates a PropListIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -PropListIException::PropListIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +PropListIException::PropListIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: PropListIException destructor ///\brief Noop destructor. @@ -465,10 +465,10 @@ DataSetIException::DataSetIException():Exception(){} // Function: DataSetIException overloaded constructor ///\brief Creates a DataSetIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -DataSetIException::DataSetIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +DataSetIException::DataSetIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: DataSetIException destructor ///\brief Noop destructor. @@ -488,10 +488,10 @@ AttributeIException::AttributeIException():Exception(){} // Function: AttributeIException overloaded constructor ///\brief Creates an AttributeIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -AttributeIException::AttributeIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +AttributeIException::AttributeIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: AttributeIException destructor ///\brief Noop destructor. @@ -511,10 +511,10 @@ ReferenceException::ReferenceException():Exception(){} // Function: ReferenceException overloaded constructor ///\brief Creates a ReferenceException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -ReferenceException::ReferenceException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +ReferenceException::ReferenceException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: ReferenceException destructor ///\brief Noop destructor. @@ -534,10 +534,10 @@ LibraryIException::LibraryIException():Exception(){} // Function: LibraryIException overloaded constructor ///\brief Creates a LibraryIException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -LibraryIException::LibraryIException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +LibraryIException::LibraryIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: LibraryIException destructor ///\brief Noop destructor. @@ -557,10 +557,10 @@ LocationException::LocationException():Exception(){} // Function: LocationException overloaded constructor ///\brief Creates a LocationException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -LocationException::LocationException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +LocationException::LocationException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: LocationException destructor ///\brief Noop destructor. @@ -580,10 +580,10 @@ IdComponentException::IdComponentException(): Exception() {} // Function: IdComponentException overloaded constructor ///\brief Creates a IdComponentException with the name of the function, /// in which the failure occurs, and an optional detailed message. -///\param func_name - IN: Name of the function where failure occurs +///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -IdComponentException::IdComponentException(const H5std_string& func_name, const H5std_string& message) : Exception(func_name, message) {} +IdComponentException::IdComponentException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- // Function: IdComponentException destructor ///\brief Noop destructor. diff --git a/c++/src/H5FaccProp.cpp b/c++/src/H5FaccProp.cpp index 5696742..5ce9d8e 100644 --- a/c++/src/H5FaccProp.cpp +++ b/c++/src/H5FaccProp.cpp @@ -40,10 +40,10 @@ FileAccPropList::FileAccPropList() : PropList( H5P_FILE_ACCESS ) {} //-------------------------------------------------------------------------- // Function: FileAccPropList copy constructor ///\brief Copy Constructor: makes a copy of the original -/// FileAccPropList object. +///\param original - IN: FileAccPropList instance to copy // Programmer: Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -FileAccPropList::FileAccPropList(const FileAccPropList& orig) : PropList(orig) {} +FileAccPropList::FileAccPropList(const FileAccPropList& original) : PropList(original) {} //-------------------------------------------------------------------------- // Function: FileAccPropList overloaded constructor @@ -664,6 +664,67 @@ unsigned FileAccPropList::getGcReferences() const } //-------------------------------------------------------------------------- +// Function: FileAccPropList::setLibverBounds +///\brief Sets bounds on versions of library format to be used when creating +/// or writing objects. +///\param libver_low - IN: Earliest version of the library that will be +/// used for creating or writing objects +///\param libver_high - IN: Latest version of the library that will be +///\exception H5::PropListIException +///\par Description +/// Valid values of \a libver_low are as follows: +/// \li \c H5F_LIBVER_EARLIEST (Default) +/// \li \c H5F_LIBVER_18 +/// \li \c H5F_LIBVER_LATEST +/// +/// Valid values of \a libver_high are as follows: +/// \li \c H5F_LIBVER_18 +/// \li \c H5F_LIBVER_LATEST (Default) +/// +/// For more details, please refer to +/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetLibverBounds +// Programmer: Binh-Minh Ribler - March, 2015 +//-------------------------------------------------------------------------- +void FileAccPropList::setLibverBounds(H5F_libver_t libver_low, H5F_libver_t libver_high) const +{ + herr_t ret_value = H5Pset_libver_bounds(id, libver_low, libver_high); + if (ret_value < 0) + { + throw PropListIException("FileAccPropList::setLibverBounds", "H5Pset_libver_bounds failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: FileAccPropList::getLibverBounds +///\brief Gets the current settings for the library version format bounds +/// from a file access property list. +///\param libver_low - OUT: Earliest version of the library that will be +/// used for creating or writing objects +///\param libver_high - OUT: Latest version of the library that will be +/// used for creating or writing objects +///\exception H5::PropListIException +///\par Description +/// On success, the argument \a libver_low can have the following +/// values: +/// \li \c H5F_LIBVER_EARLIEST +/// \li \c H5F_LIBVER_18 +/// \li \c H5F_LIBVER_LATEST +/// +/// and \a libver_high: +/// \li \c H5F_LIBVER_18 +/// \li \c H5F_LIBVER_LATEST +// Programmer: Binh-Minh Ribler - March, 2015 +//-------------------------------------------------------------------------- +void FileAccPropList::getLibverBounds(H5F_libver_t& libver_low, H5F_libver_t& libver_high) const +{ + herr_t ret_value = H5Pget_libver_bounds(id, &libver_low, &libver_high); + if( ret_value < 0 ) + { + throw PropListIException("FileAccPropList::getLibverBounds", "H5Pget_libver_bounds failed"); + } +} + +//-------------------------------------------------------------------------- // Function: FileAccPropList destructor ///\brief Noop destructor // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5FaccProp.h b/c++/src/H5FaccProp.h index 861ac4c..fddc446 100644 --- a/c++/src/H5FaccProp.h +++ b/c++/src/H5FaccProp.h @@ -126,6 +126,13 @@ class H5_DLLCPP FileAccPropList : public PropList { // Returns garbage collecting references setting. unsigned getGcReferences() const; + // Sets bounds on versions of library format to be used when creating + // or writing objects. + void setLibverBounds(H5F_libver_t libver_low, H5F_libver_t libver_high) const; + + // Gets the current settings for the library version format bounds. + void getLibverBounds(H5F_libver_t& libver_low, H5F_libver_t& libver_high) const; + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("FileAccPropList"); } diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 45e08b2..84e7827 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -50,7 +50,7 @@ namespace H5 { ///\brief Default constructor: creates a stub H5File object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File() : H5Location(), id(H5I_INVALID_HID) {} +H5File::H5File() : H5Location(), CommonFG(), id(H5I_INVALID_HID) {} //-------------------------------------------------------------------------- // Function: H5File overloaded constructor @@ -73,9 +73,6 @@ H5File::H5File() : H5Location(), id(H5I_INVALID_HID) {} /// exists, and fail, otherwise /// \li \c H5F_ACC_RDWR - Open file for read/write, if it already /// exists, and fail, otherwise -/// \li \c H5F_ACC_DEBUG - print debug information. This flag is -/// used only by HDF5 library developers; it is neither -/// tested nor supported for use in applications. ///\par /// For info on file creation in the case of an already-open file, /// please refer to the \b Special \b case section in the C layer @@ -86,7 +83,7 @@ H5File::H5File() : H5Location(), id(H5I_INVALID_HID) {} // to catch then re-throw it. -BMR 2013/03/21 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(H5I_INVALID_HID) +H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), CommonFG(), id(H5I_INVALID_HID) { try { p_get_file(name, flags, create_plist, access_plist); @@ -111,7 +108,7 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c // to catch then re-throw it. -BMR 2013/03/21 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(H5I_INVALID_HID) +H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), CommonFG(), id(H5I_INVALID_HID) { try { p_get_file(name.c_str(), flags, create_plist, access_plist); @@ -133,38 +130,57 @@ void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPro { // These bits only set for creation, so if any of them are set, // create the file. - if( flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG)) + if( flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC)) { - hid_t create_plist_id = create_plist.getId(); - hid_t access_plist_id = access_plist.getId(); - id = H5Fcreate( name, flags, create_plist_id, access_plist_id ); - if( id < 0 ) // throw an exception when open/create fail - { - throw FileIException("H5File constructor", "H5Fcreate failed"); - } + hid_t create_plist_id = create_plist.getId(); + hid_t access_plist_id = access_plist.getId(); + id = H5Fcreate( name, flags, create_plist_id, access_plist_id ); + if( id < 0 ) // throw an exception when open/create fail + { + throw FileIException("H5File constructor", "H5Fcreate failed"); + } } // Open the file if none of the bits above are set. else { - hid_t access_plist_id = access_plist.getId(); - id = H5Fopen( name, flags, access_plist_id ); - if( id < 0 ) // throw an exception when open/create fail - { - throw FileIException("H5File constructor", "H5Fopen failed"); - } + hid_t access_plist_id = access_plist.getId(); + id = H5Fopen( name, flags, access_plist_id ); + if( id < 0 ) // throw an exception when open/create fail + { + throw FileIException("H5File constructor", "H5Fopen failed"); + } } } #endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- +// Function: H5File overloaded constructor +///\brief Creates an H5File object using an existing file id. +///\param existing_id - IN: Id of an existing file +// Programmer Binh-Minh Ribler - 2015 +// Description +// Mar 29, 2015 +// Added in responding to a request from user Jason Newton. +// However, it is not recommended to use the private member "id" +// in applications. Unlike other situations, where similar +// constructor is needed by the library in order to return +// an object, H5File doesn't need it. -BMR (HDFFV-8766 partially) +//-------------------------------------------------------------------------- +H5File::H5File(hid_t existing_id) : H5Location(), CommonFG() +{ + id = existing_id; + incRefCount(); // increment number of references to this id +} + +//-------------------------------------------------------------------------- // Function: H5File copy constructor ///\brief Copy constructor: makes a copy of the original /// H5File object. ///\param original - IN: H5File instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File(const H5File& original) : H5Location(original) +H5File::H5File(const H5File& original) : H5Location(), CommonFG() { id = original.getId(); incRefCount(); // increment number of references to this id @@ -225,6 +241,13 @@ bool H5File::isHdf5(const H5std_string& name ) //-------------------------------------------------------------------------- void H5File::openFile(const char* name, unsigned int flags, const FileAccPropList& access_plist) { + try { + close(); + } + catch (Exception close_error) { + throw FileIException("H5File::openFile", close_error.getDetailMsg()); + } + hid_t access_plist_id = access_plist.getId(); id = H5Fopen (name, flags, access_plist_id); if (id < 0) // throw an exception when open fails @@ -379,25 +402,6 @@ ssize_t H5File::getObjCount(unsigned types) const } //-------------------------------------------------------------------------- -// Function: H5File::getObjCount -///\brief This is an overloaded member function, provided for convenience. -/// It takes no parameter and returns the object count of all -/// object types. -///\return Number of opened object IDs -///\exception H5::FileIException -// Programmer Binh-Minh Ribler - May 2004 -//-------------------------------------------------------------------------- -ssize_t H5File::getObjCount() const -{ - ssize_t num_objs = H5Fget_obj_count(id, H5F_OBJ_ALL); - if( num_objs < 0 ) - { - throw FileIException("H5File::getObjCount", "H5Fget_obj_count failed"); - } - return (num_objs); -} - -//-------------------------------------------------------------------------- // Function: H5File::getObjIDs ///\brief Retrieves a list of opened object IDs (files, datasets, /// groups and datatypes) in the same file. diff --git a/c++/src/H5File.h b/c++/src/H5File.h index 0ef85b5..939ac8e 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -59,8 +59,7 @@ class H5_DLLCPP H5File : public H5Location, public CommonFG { // Returns the number of opened object IDs (files, datasets, groups // and datatypes) in the same file. - ssize_t getObjCount(unsigned types) const; - ssize_t getObjCount() const; + ssize_t getObjCount(unsigned types = H5F_OBJ_ALL) const; // Retrieves a list of opened object IDs (files, datasets, groups // and datatypes) in the same file. @@ -84,6 +83,10 @@ class H5_DLLCPP H5File : public H5Location, public CommonFG { // Gets the file id virtual hid_t getLocId() const; + // Creates an H5File using an existing file id. Not recommended + // in applications. + H5File(hid_t existing_id); + #endif // DOXYGEN_SHOULD_SKIP_THIS ///\brief Returns this class name. diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index cad5e29..4d1d61c 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -51,7 +51,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 @@ -59,7 +59,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(original) +Group::Group(const Group& original) : H5Object(), CommonFG() { id = original.getId(); incRefCount(); // increment number of references to this id @@ -82,9 +82,10 @@ 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() +Group::Group(const hid_t existing_id) : H5Object(), CommonFG() { id = existing_id; + incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- @@ -100,7 +101,7 @@ Group::Group(const hid_t existing_id) : H5Object() /// 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"); } @@ -115,7 +116,7 @@ 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(), CommonFG(), id(H5I_INVALID_HID) { id = H5Location::p_dereference(attr.getId(), ref, ref_type, plist, "constructor - by dereference"); } diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 4a9dcac..c01d41e 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -37,16 +37,33 @@ namespace H5 { ///\param h5_id - IN: Id of an existing object ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 +// +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It will be removed in 1.10 release. If its +// removal does not raise any problems in 1.10, it will be removed from 1.8 in +// subsequent releases. //-------------------------------------------------------------------------- IdComponent::IdComponent(const hid_t h5_id) {} +//void IdComponent::p_setId(const hid_t new_id) +//{ + //p_setId(new_id); +//} + //-------------------------------------------------------------------------- // Function: IdComponent copy constructor -///\brief Copy constructor: makes a copy of the original IdComponent object. -///\param original - IN: IdComponent instance to copy +// Purpose: This noop copy constructor is removed as a result of the data +// member "id" being moved down to sub-classes. (Mar 2015) +// Parameters: original - IN: IdComponent instance to copy // Programmer Binh-Minh Ribler - 2000 +// +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It is removed from 1.8.15 because it is +// a noop and it can be generated by the compiler if needed. //-------------------------------------------------------------------------- -IdComponent::IdComponent( const IdComponent& original ) {} +// IdComponent::IdComponent(const IdComponent& original) {} //-------------------------------------------------------------------------- // Function: IdComponent::incRefCount @@ -82,12 +99,14 @@ void IdComponent::decRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Idec_ref(obj_id) < 0) + { if (H5Iget_ref(obj_id) <= 0) throw IdComponentException(inMemFunc("decRefCount"), "object ref count is 0 or negative"); else throw IdComponentException(inMemFunc("decRefCount"), "decrementing object ref count failed"); + } } //-------------------------------------------------------------------------- diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 3208a39..068fb74 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -60,11 +60,18 @@ class H5_DLLCPP IdComponent { // Sets the identifier of this object to a new value. void setId(const hid_t new_id); + // *** Deprecation warning *** + // The following two constructors are no longer appropriate after the + // data member "id" had been moved to the sub-classes. + // The copy constructor is a noop and is removed in 1.8.15 and the + // other will be removed from 1.10 release, and then from 1.8 if its + // removal does not raise any problems in two 1.10 releases. + // Creates an object to hold an HDF5 identifier. IdComponent( const hid_t h5_id ); // Copy constructor: makes copy of the original IdComponent object. - IdComponent( const IdComponent& original ); + // IdComponent( const IdComponent& original ); #ifndef DOXYGEN_SHOULD_SKIP_THIS // Pure virtual function for there are various H5*close for the @@ -97,6 +104,7 @@ class H5_DLLCPP 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/H5Include.h b/c++/src/H5Include.h index 87cb182..1e0e952 100644 --- a/c++/src/H5Include.h +++ b/c++/src/H5Include.h @@ -28,3 +28,15 @@ typedef int bool; const bool false = 0; const bool true = 1; #endif + +// These are defined in H5Opkg.h, which should not be included in the C++ API, +// so re-define them here for now. + +/* Initial version of the object header format */ +#define H5O_VERSION_1 1 + +/* Revised version - leaves out reserved bytes and alignment padding, and adds + * magic number as prefix and checksum as suffix for all chunks. + */ +#define H5O_VERSION_2 2 + diff --git a/c++/src/H5IntType.h b/c++/src/H5IntType.h index 95fa642..e28f5c2 100644 --- a/c++/src/H5IntType.h +++ b/c++/src/H5IntType.h @@ -24,7 +24,7 @@ namespace H5 { //! Class IntType operates on HDF5 integer datatype. class H5_DLLCPP IntType : public AtomType { public: - // Creates a integer type using a predefined type + // Creates an integer type using a predefined type IntType(const PredType& pred_type); // Gets the integer datatype of the specified dataset diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index cd733c4..5100e12 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -70,17 +70,28 @@ H5Location::H5Location() : IdComponent() {} // object. // Parameters object_id - IN: Id of an existing HDF5 object // Programmer Binh-Minh Ribler - 2000 + +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It will be removed in 1.10 release. If its +// removal does not raise any problems in 1.10, it will be removed from 1.8 in +// subsequent releases. //-------------------------------------------------------------------------- -H5Location::H5Location(const hid_t object_id) : IdComponent(object_id) {} +H5Location::H5Location(const hid_t object_id) : IdComponent() {} //-------------------------------------------------------------------------- // Function: H5Location copy constructor -///\brief Copy constructor: makes a copy of the original H5Location -/// instance. +// Purpose: This noop copy constructor is removed as a result of the data +// member "id" being moved down to sub-classes. (Mar 2015) ///\param original - IN: H5Location instance to copy // Programmer Binh-Minh Ribler - 2000 +// +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It is removed from 1.8.15 because it is +// a noop and it can be generated by the compiler if needed. //-------------------------------------------------------------------------- -H5Location::H5Location( const H5Location& original ) : IdComponent( original ) {} +// H5Location::H5Location(const H5Location& original) : IdComponent() {} #endif // DOXYGEN_SHOULD_SKIP_THIS @@ -115,8 +126,9 @@ Attribute H5Location::createAttribute( const char* name, const DataType& data_ty // If the attribute id is valid, create and return the Attribute object if( attr_id > 0 ) { - Attribute attr( attr_id ); - return( attr ); + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return( attr ); } else throw AttributeIException(inMemFunc("createAttribute"), "H5Acreate2 failed"); @@ -147,8 +159,9 @@ Attribute H5Location::openAttribute( const char* name ) const hid_t attr_id = H5Aopen(getId(), name, H5P_DEFAULT); if( attr_id > 0 ) { - Attribute attr( attr_id ); - return( attr ); + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return( attr ); } else { @@ -182,12 +195,13 @@ Attribute H5Location::openAttribute( const unsigned int idx ) const H5_ITER_INC, (hsize_t)idx, H5P_DEFAULT, H5P_DEFAULT); if( attr_id > 0 ) { - Attribute attr( attr_id ); - return( attr ); + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return(attr); } else { - throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen_by_idx failed"); + throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen_by_idx failed"); } } @@ -893,6 +907,12 @@ H5O_type_t H5Location::p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const ///\return DataSpace object ///\exception H5::ReferenceException // Programmer Binh-Minh Ribler - May, 2004 +// Modification +// Mar 29, 2015 +// Used friend function to set id for DataSpace instead of the +// existing id constructor or the setId method to avoid incrementing +// ref count, as a work-around for a problem described in the JIRA +// issue HDFFV-7947. -BMR //-------------------------------------------------------------------------- DataSpace H5Location::getRegion(void *ref, H5R_type_t ref_type) const { @@ -902,8 +922,9 @@ DataSpace H5Location::getRegion(void *ref, H5R_type_t ref_type) const throw ReferenceException(inMemFunc("getRegion"), "H5Rget_region failed"); } try { - DataSpace dataspace(space_id); - return(dataspace); + DataSpace dataspace; + f_DataSpace_setId(&dataspace, space_id); + return(dataspace); } catch (DataSpaceIException E) { throw ReferenceException(inMemFunc("getRegion"), E.getDetailMsg()); @@ -918,6 +939,36 @@ DataSpace H5Location::getRegion(void *ref, H5R_type_t ref_type) const //-------------------------------------------------------------------------- H5Location::~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->id = new_id; +} + +//-------------------------------------------------------------------------- +// Function: f_DataSpace_setId - friend +// Purpose: This function is friend to class H5::DataSpace so that it can +// can set DataSpace::id in order to work around a problem +// described in the JIRA issue HDFFV-7947. +// Applications shouldn't need to use it. +// param dspace - IN/OUT: DataSpace object to be changed +// param new_id - IN: New id to set +// Programmer Binh-Minh Ribler - 2015 +//-------------------------------------------------------------------------- +void f_DataSpace_setId(DataSpace* dspace, hid_t new_id) +{ + dspace->id = new_id; +} + #endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index e015825..79a8d5c 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -138,13 +138,21 @@ class H5_DLLCPP H5Location : public IdComponent { // Default constructor H5Location(); +#ifndef DOXYGEN_SHOULD_SKIP_THIS + + // *** Deprecation warning *** + // The following two constructors are no longer appropriate after the + // data member "id" had been moved to the sub-classes. + // The copy constructor is a noop and is removed in 1.8.15 and the + // other will be removed from 1.10 release, and then from 1.8 if its + // removal does not raise any problems in two 1.10 releases. + // Creates a copy of an existing object giving the location id. H5Location(const hid_t loc_id); // Copy constructor. - H5Location(const H5Location& original); + // H5Location(const H5Location& original); -#ifndef DOXYGEN_SHOULD_SKIP_THIS // Creates a reference to an HDF5 object or a dataset region. void p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const; @@ -159,6 +167,10 @@ class H5_DLLCPP H5Location : public IdComponent { // Retrieves the type of object that an object reference points to. H5O_type_t p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const; + // 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; + #endif // DOXYGEN_SHOULD_SKIP_THIS // Noop destructor. diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 94b03ab..df3f565 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -50,8 +50,26 @@ H5Object::H5Object() : H5Location() {} // object. // Parameters object_id - IN: Id of an existing HDF5 object // Programmer Binh-Minh Ribler - 2000 +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It will be removed in 1.10 release. If its +// removal does not raise any problems in 1.10, it will be removed from 1.8 in +// subsequent releases. //-------------------------------------------------------------------------- -H5Object::H5Object( const hid_t object_id ) : H5Location( object_id ) {} +H5Object::H5Object(const hid_t object_id) : H5Location() {} + +//-------------------------------------------------------------------------- +// Function: H5Object copy constructor +///\brief Copy constructor: makes a copy of the original H5Object +/// instance. +///\param original - IN: H5Object instance to copy +// Programmer Binh-Minh Ribler - 2000 +// *** Deprecation warning *** +// This constructor is no longer appropriate because the data member "id" had +// been moved to the sub-classes. It is removed from 1.8.15 because it is +// a noop and it can be generated by the compiler if needed. +//-------------------------------------------------------------------------- +// H5Object::H5Object(const H5Object& original) : H5Location() {} //-------------------------------------------------------------------------- // Function: getObjName @@ -165,15 +183,6 @@ ssize_t H5Object::getObjName(H5std_string& obj_name, size_t len) const } //-------------------------------------------------------------------------- -// Function: H5Object copy constructor -///\brief Copy constructor: makes a copy of the original H5Object -/// instance. -///\param original - IN: H5Object instance to copy -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -H5Object::H5Object( const H5Object& original ) : H5Location( original ) {} - -//-------------------------------------------------------------------------- // Function: H5Object destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 5576d13..f8ac792 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -47,9 +47,6 @@ namespace H5 { class H5_DLLCPP H5Object : public H5Location { public: #ifndef DOXYGEN_SHOULD_SKIP_THIS - // Copy constructor: makes copy of an H5Object object. - H5Object(const H5Object& original); - // Gets the name of this HDF5 object, i.e., Group, DataSet, or // DataType. ssize_t getObjName(char *obj_name, size_t buf_size = 0) const; @@ -63,9 +60,19 @@ class H5_DLLCPP H5Object : public H5Location { // Default constructor H5Object(); + // *** Deprecation warning *** + // The following two constructors are no longer appropriate after the + // data member "id" had been moved to the sub-classes. + // The copy constructor is a noop and is removed in 1.8.15 and the + // other will be removed from 1.10 release, and then from 1.8 if its + // removal does not raise any problems in two 1.10 releases. + // Creates a copy of an existing object giving the object id H5Object( const hid_t object_id ); + // Copy constructor: makes copy of an H5Object object. + // H5Object(const H5Object& original); + #endif // DOXYGEN_SHOULD_SKIP_THIS }; /* end class H5Object */ diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index 5afe80f..70ec629 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -54,7 +54,7 @@ PropList::PropList() : IdComponent(), id(H5P_DEFAULT) {} ///\param original - IN: The original property list to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList(const PropList& original) : IdComponent(original) +PropList::PropList(const PropList& original) : IdComponent() { id = original.getId(); incRefCount(); // increment number of references to this id @@ -258,6 +258,7 @@ void PropList::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } + #endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- diff --git a/c++/src/H5VarLenType.h b/c++/src/H5VarLenType.h index 40c597f..672b3db 100644 --- a/c++/src/H5VarLenType.h +++ b/c++/src/H5VarLenType.h @@ -40,7 +40,6 @@ class H5_DLLCPP VarLenType : public DataType { // Noop destructor virtual ~VarLenType(); - protected: // Default constructor VarLenType(); }; diff --git a/c++/src/cpp_doc_config b/c++/src/cpp_doc_config index f2caed2..4072c1b 100644 --- a/c++/src/cpp_doc_config +++ b/c++/src/cpp_doc_config @@ -38,7 +38,7 @@ PROJECT_NAME = "HDF5 C++ API" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.8.13 +PROJECT_NUMBER = HDF5 version 1.9.218 currently under development # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt index fe463fa..dcdf3a3 100644 --- a/c++/test/CMakeLists.txt +++ b/c++/test/CMakeLists.txt @@ -36,7 +36,7 @@ configure_file (${HDF5_CPP_TEST_SOURCE_DIR}/H5srcdir_str.h.in H5srcdir_str.h @O add_executable (cpp_testhdf5 ${CPP_TEST_SRCS} ) TARGET_NAMING (cpp_testhdf5 ${LIB_TYPE}) -TARGET_C_PROPERTIES (cpp_testhdf5 " " " ") +TARGET_C_PROPERTIES (cpp_testhdf5 ${LIB_TYPE} " " " ") target_link_libraries (cpp_testhdf5 ${HDF5_CPP_LIB_TARGET} ${HDF5_LIB_TARGET} diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index fc0ea3a..9f1916d 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -56,11 +56,12 @@ const H5std_string DSET_TCONV_NAME ("tconv"); const H5std_string DSET_COMPRESS_NAME("compressed"); const H5std_string DSET_BOGUS_NAME ("bogus"); +/* Temporary filter IDs used for testing */ const int H5Z_FILTER_BOGUS = 305; -// Local prototypes static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); +// UNUSED variables caused warning, but taking them out caused failure. /*------------------------------------------------------------------------- * Function: test_create @@ -458,13 +459,10 @@ const H5Z_class2_t H5Z_BOGUS[1] = {{ *------------------------------------------------------------------------- */ static size_t -/*bogus(unsigned int UNUSED flags, size_t UNUSED cd_nelmts, - const unsigned int UNUSED cd_values[], size_t nbytes, - size_t UNUSED *buf_size, void UNUSED **buf) -BMR: removed UNUSED for now until asking Q. or R. to pass compilation*/ filter_bogus(unsigned int flags, size_t cd_nelmts, const unsigned int cd_values[], size_t nbytes, size_t *buf_size, void **buf) +// UNUSED variables caused warning, but taking them out caused failure. { return nbytes; } diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 29f50f8..c9422ce 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -53,9 +53,9 @@ const size_t ATTR_MAX_DIMS = 7; /* 3-D dataset with fixed dimensions */ const int SPACE1_RANK = 3; -const int SPACE1_DIM1 = 3; -const int SPACE1_DIM2 = 15; -const int SPACE1_DIM3 = 13; +const hsize_t SPACE1_DIM1 = 3; +const hsize_t SPACE1_DIM2 = 15; +const hsize_t SPACE1_DIM3 = 13; /* Object names */ const H5std_string DSET1_NAME("Dataset1"); @@ -65,7 +65,7 @@ const H5std_string TYPE1_NAME("/Type"); /* Attribute Rank & Dimensions */ const H5std_string ATTR1_NAME("Attr1"); const int ATTR1_RANK = 1; -const int ATTR1_DIM1 = 3; +const hsize_t ATTR1_DIM1 = 3; int attr_data1[ATTR1_DIM1]={512,-234,98123}; /* Test data for 1st attribute */ // File attribute, using the same rank and dimensions as ATTR1_NAME's @@ -74,8 +74,8 @@ const H5std_string FATTR2_NAME("File Attr2"); const H5std_string ATTR2_NAME("Attr2"); const int ATTR2_RANK = 2; -const int ATTR2_DIM1 = 2; -const int ATTR2_DIM2 = 2; +const hsize_t ATTR2_DIM1 = 2; +const hsize_t ATTR2_DIM2 = 2; int attr_data2[ATTR2_DIM1][ATTR2_DIM2]={{7614,-416},{197814,-3}}; /* Test data for 2nd attribute */ const H5std_string ATTR3_NAME("Attr3"); @@ -123,7 +123,7 @@ static void test_attr_basic_write() hsize_t dims2[] = {ATTR1_DIM1}; hsize_t dims3[] = {ATTR2_DIM1,ATTR2_DIM2}; int read_data1[ATTR1_DIM1]={0}; // Buffer for reading 1st attribute - int i; + hsize_t i; // Output message about test being performed SUBTEST("Basic Attribute Writing Functions"); @@ -384,7 +384,7 @@ static void test_attr_getname() static void test_attr_rename() { int read_data1[ATTR1_DIM1]={0}; // Buffer for reading the attribute - int i; + hsize_t i; // Output message about test being performed SUBTEST("Checking for Existence and Renaming Attribute"); @@ -493,7 +493,7 @@ static void test_attr_rename() ********************************************************************/ static void test_attr_basic_read() { - int i, j; + hsize_t i, j; // Output message about test being performed SUBTEST("Basic Attribute Reading Functions"); @@ -624,7 +624,6 @@ static void test_attr_compound_read() size_t size; // Attribute datatype size as stored in file size_t offset; // Attribute datatype field offset struct attr4_struct read_data4[ATTR4_DIM1][ATTR4_DIM2]; // Buffer for reading 4th attribute - hsize_t i,j; // Output message about test being performed SUBTEST("Basic Attribute Functions"); @@ -654,7 +653,7 @@ static void test_attr_compound_read() // Get the dims of the dataspace and verify them int ndims = space.getSimpleExtentDims(dims); - if(dims[0]!=ATTR4_DIM1) + verify_val(ndims, ATTR4_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); verify_val((long)dims[0], (long)ATTR4_DIM1, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); verify_val((long)dims[1], (long)ATTR4_DIM2, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); @@ -673,13 +672,14 @@ static void test_attr_compound_read() // Verify that the fields have the same names as when the type // was created - for(i=0; i<fields; i++) + int j; + for(j=0; j<fields; j++) { - H5std_string fieldname = datatype.getMemberName(i); + H5std_string fieldname = datatype.getMemberName(j); if(!((fieldname == ATTR4_FIELDNAME1) || (fieldname == ATTR4_FIELDNAME2) || (fieldname == ATTR4_FIELDNAME3))) - TestErrPrintf("%d:invalid field name for field #%d: %s\n",__LINE__,i,fieldname.c_str()); + TestErrPrintf("%d:invalid field name for field #%d: %s\n",__LINE__,j,fieldname.c_str()); } /* end for */ offset = datatype.getMemberOffset(0); @@ -729,23 +729,38 @@ static void test_attr_compound_read() attr.read(datatype, read_data4); // Verify values read in - for(i=0; i<ATTR4_DIM1; i++) - for(j=0; j<ATTR4_DIM2; j++) - if(HDmemcmp(&attr_data4[i][j],&read_data4[i][j],sizeof(struct attr4_struct))) { - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].i=%d, read_data4[%d][%d].i=%d\n",__LINE__,i,j,attr_data4[i][j].i,i,j,read_data4[i][j].i); - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].d=%f, read_data4[%d][%d].d=%f\n",__LINE__,i,j,attr_data4[i][j].d,i,j,read_data4[i][j].d); - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].c=%c, read_data4[%d][%d].c=%c\n",__LINE__,i,j,attr_data4[i][j].c,i,j,read_data4[i][j].c); + hsize_t ii, jj; + for(ii=0; ii<ATTR4_DIM1; ii++) + for(jj=0; jj<ATTR4_DIM2; jj++) + if(HDmemcmp(&attr_data4[ii][jj],&read_data4[ii][jj],sizeof(struct attr4_struct))) { + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].i=%d, read_data4[%d][%d].i=%d\n",__LINE__,ii,jj,attr_data4[ii][jj].i,ii,jj,read_data4[ii][jj].i); + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].d=%f, read_data4[%d][%d].d=%f\n",__LINE__,ii,jj,attr_data4[ii][jj].d,ii,jj,read_data4[ii][jj].d); + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].c=%c, read_data4[%d][%d].c=%c\n",__LINE__,ii,jj,attr_data4[ii][jj].c,ii,jj,read_data4[ii][jj].c); } /* end if */ // Verify name H5std_string attr_name = attr.getName(); verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__); - PASSED(); } // end try block catch (Exception E) { issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg()); } + + try + { + // Now, try truncating the file to make sure reference counting is good. + // If any references to ids in the previous block are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILE_COMPOUND, H5F_ACC_TRUNC); + + PASSED(); + } // end try block + + catch (FileIException E) { + issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, "Unable to truncate file, possibly because some objects are left opened"); + } } // test_attr_compound_read() /**************************************************************** @@ -928,7 +943,7 @@ static void test_attr_mult_read() int read_data1[ATTR1_DIM1]={0}; // Buffer for reading 1st attribute int read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; // Buffer for reading 2nd attribute double read_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3]={{{0}}}; // Buffer for reading 3rd attribute - int i,j,k; + hsize_t i,j,k; // Output message about test being performed SUBTEST("Multiple Attribute Reading Functions"); @@ -959,7 +974,7 @@ static void test_attr_mult_read() // Get the dims of the dataspace and verify them hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions int ndims = space.getSimpleExtentDims(dims); - if(dims[0]!=ATTR1_DIM1) + if ((long)dims[0] != (long)ATTR1_DIM1) TestErrPrintf("%d:attribute dimensions different: dims[0]=%d, should be %d\n",__LINE__,(int)dims[0],ATTR1_DIM1); /* Verify Datatype */ @@ -1010,10 +1025,9 @@ static void test_attr_mult_read() // Get the dims of the dataspace and verify them ndims = space.getSimpleExtentDims(dims); - if(dims[0]!=ATTR2_DIM1) - TestErrPrintf("%d:attribute dimensions different: dims[0]=%d, should be %d\n",__LINE__,(int)dims[0],ATTR2_DIM1); - if(dims[1]!=ATTR2_DIM2) - TestErrPrintf("%d:attribute dimensions different: dims[1]=%d, should be %d\n",__LINE__,(int)dims[1],ATTR2_DIM2); + + verify_val((long)dims[0], (long)ATTR2_DIM1, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); + verify_val((long)dims[1], (long)ATTR2_DIM2, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); /* Verify Datatype */ diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index 156f438..dbf2f0c 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -780,7 +780,7 @@ static void test_compound_set_size() CompType dtype_tmp = file.openCompType("dtype"); // Make a copy of the data type - dtype = dtype_tmp; + dtype.copy(dtype_tmp); // Verify that the compound is not packed // packed = dtype_tmp.packed(); // not until C library provides API diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index ad5e6fc..f3bbb16 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -330,6 +330,32 @@ static void test_file_open() verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + // Test H5File constructor with existing file id + H5File file2(file1.getId()); + file1.close(); + + // Try truncating the file, and it should fail because the file is + // still opened with file2. + try { + H5File file3 (FILE2, H5F_ACC_TRUNC); // should throw E + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "Attempt truncating an opened file."); + } + catch( FileIException E ) // catching H5F_ACC_TRUNC on opened file + {} // do nothing, FAIL expected + + // Now, really close the file. + file2.close(); + + // Truncating should succeed now. + H5File file3(FILE2, H5F_ACC_TRUNC); + + // Opening another file to file3 object, FILE2 should be closed, so + // the next attempt to truncate FILE2 should succeed. + file3.openFile(FILE1, H5F_ACC_RDONLY); + H5File file4(FILE2, H5F_ACC_TRUNC); + PASSED(); } // end of try block @@ -501,6 +527,7 @@ const H5std_string FATTR1_NAME ("file attribute 1"); const H5std_string FATTR2_NAME ("file attribute 2"); int fattr_data[ATTR1_DIM1]={512,-234,98123}; /* Test data for file attribute */ int dattr_data[ATTR1_DIM1]={256,-123,1000}; /* Test data for dataset attribute */ + static void test_file_attribute() { int rdata[ATTR1_DIM1]; @@ -602,6 +629,119 @@ static void test_file_attribute() } } // test_file_attribute() +const H5std_string FILE6("tfile5.h5"); +const H5std_string ROOTGROUP("/"); +const H5std_string GROUP1("/G1"); +const H5std_string SUBGROUP3("/G1/G3"); + +/*------------------------------------------------------------------------- + * Function: test_libver_bounds_real + * + * Purpose: Verify that a file created and modified with the + * specified libver bounds has the specified object header + * versions for the right objects. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * March, 2015 + * + *------------------------------------------------------------------------- + */ +static void test_libver_bounds_real( + H5F_libver_t libver_create, unsigned oh_vers_create, + H5F_libver_t libver_mod, unsigned oh_vers_mod) +{ + try { + + /* + * Create a new file using the default creation property and access property + * with latest library version. + */ + FileAccPropList fapl; + fapl.setLibverBounds(libver_create, H5F_LIBVER_LATEST); + H5File file(FILE6, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + + /* + * Make sure the root group has the correct object header version + */ + unsigned obj_version = file.childObjVersion(ROOTGROUP); + verify_val(obj_version, oh_vers_create, "H5File::childObjVersion", __LINE__, __FILE__); + + /* + * Reopen the file and make sure the root group still has the correct version + */ + file.close(); + + fapl.setLibverBounds(libver_mod, H5F_LIBVER_LATEST); + + file.openFile(FILE6, H5F_ACC_RDWR, fapl); + + obj_version = file.childObjVersion(ROOTGROUP); + verify_val(obj_version, oh_vers_create, "H5File::childObjVersion", __LINE__, __FILE__); + + /* + * Create a group named "/G1" in the file, and make sure it has the correct + * object header version + */ + Group group = file.createGroup(GROUP1); + + obj_version = file.childObjVersion(GROUP1); + verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__); + + group.close(); // close "/G1" + + /* + * Create a group named "/G1/G3" in the file, and make sure it has the + * correct object header version + */ + group = file.createGroup(SUBGROUP3); + + obj_version = group.childObjVersion(SUBGROUP3); + verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__); + + group.close(); // close "/G1/G3" + + /* + * Make sure the root group still has the correct object header version + */ + obj_version = file.childObjVersion(ROOTGROUP); + verify_val(obj_version, oh_vers_create, "H5File::childObjVersion", __LINE__, __FILE__); + + // Everything should be closed as they go out of scope + } // end of try block + + catch (Exception E) { + issue_fail_msg("test_libver_bounds_real()", __LINE__, __FILE__, E.getCDetailMsg()); + } + +} /* end test_libver_bounds_real() */ + +/*------------------------------------------------------------------------- + * + * Function: test_libver_bounds + * + * Purpose: Verify that a file created and modified with various + * libver bounds is handled correctly. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * March 2015 + * + *------------------------------------------------------------------------- + */ +static void test_libver_bounds() +{ + // Output message about test being performed + SUBTEST("Setting library version bounds"); + + /* Run the tests */ + test_libver_bounds_real(H5F_LIBVER_EARLIEST, H5O_VERSION_1, H5F_LIBVER_LATEST, H5O_VERSION_2); + test_libver_bounds_real(H5F_LIBVER_LATEST, H5O_VERSION_2, H5F_LIBVER_EARLIEST, H5O_VERSION_1); + PASSED(); +} /* end test_libver_bounds() */ + /*------------------------------------------------------------------------- * Function: test_file * @@ -629,6 +769,7 @@ void test_file() test_file_size(); // Test file size test_file_name(); // Test getting file's name test_file_attribute(); // Test file attribute feature + test_libver_bounds(); // Test format version } // test_file() @@ -655,4 +796,5 @@ void cleanup_file() HDremove(FILE3.c_str()); HDremove(FILE4.c_str()); HDremove(FILE5.c_str()); + HDremove(FILE6.c_str()); } // cleanup_file diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp index 854c7bb..3edb83a 100644 --- a/c++/test/tfilter.cpp +++ b/c++/test/tfilter.cpp @@ -57,9 +57,13 @@ static herr_t test_filter_internal(hid_t fid, const char *name, hid_t dcpl, #endif /* Temporary filter IDs used for testing */ -#define H5Z_FILTER_BOGUS 305 +const int H5Z_FILTER_BOGUS = 305; + +#if 0 // UNUSED variables caused warning, so duplicated below with NULL instead static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); +#endif +static size_t filter_bogus(size_t nbytes); /* This message derives from H5Z */ const H5Z_class2_t H5Z_BOGUS[1] = {{ H5Z_CLASS_T_VERS, /* H5Z_class_t version */ @@ -88,9 +92,12 @@ const H5Z_class2_t H5Z_BOGUS[1] = {{ *------------------------------------------------------------------------- */ static size_t +#if 0 // UNUSED variables caused warning, so duplicated below with NULL instead filter_bogus(unsigned int UNUSED flags, size_t UNUSED cd_nelmts, const unsigned int UNUSED *cd_values, size_t nbytes, size_t UNUSED *buf_size, void UNUSED **buf) +#endif +filter_bogus(size_t nbytes) { return nbytes; } @@ -239,7 +246,8 @@ static void test_szip_filter(H5File& file1) #else /* H5_HAVE_FILTER_SZIP */ SUBTEST("szip filter"); SKIPPED(); - puts(" Szip filter not enabled"); + H5std_string fname = file1.getFileName(); + cerr << " Szip filter not enabled for file '" << fname << "'" << endl; #endif /* H5_HAVE_FILTER_SZIP */ } // test_szip_filter diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index b86d7cb..2381ec2 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -181,19 +181,39 @@ static void test_get_objname_ontypes() Group grp = file.createGroup ("typetests"); // Create a datatype and save it + IntType inttype(PredType::STD_B8LE); + inttype.commit(file, "INT type of STD_B8LE"); + + // Close the type then open it again to test getting its name + inttype.close(); + inttype = file.openIntType("INT type of STD_B8LE"); + + // Get and verify its name + H5std_string inttype_name = inttype.getObjName(); + verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Make copy of a predefined type and save it DataType dtype(PredType::STD_B8LE); dtype.commit(file, "STD_B8LE"); + // Close the data type and file + dtype.close(); + file.close(); + + // Re-open the file and the data type to test getting its name + file.openFile(FILE_OBJECTS, H5F_ACC_RDWR); + dtype = file.openDataType("STD_B8LE"); + // Get and verify its name H5std_string type_name = dtype.getObjName(); - verify_val(type_name, "/STD_B8LE", "DataSet::getObjName", __LINE__, __FILE__); + verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); // Test getting type's name from copied type DataType copied_type; copied_type.copy(dtype); copied_type.commit(file, "copy of STD_B8LE"); type_name = copied_type.getObjName(); - verify_val(type_name, "/copy of STD_B8LE", "DataSet::getObjName", __LINE__, __FILE__); + verify_val(type_name, "/copy of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); // Test copying an integer predefined type IntType new_int_type(PredType::NATIVE_INT); @@ -201,14 +221,14 @@ static void test_get_objname_ontypes() // Name this datatype new_int_type.commit(grp, "IntType NATIVE_INT"); ssize_t name_len = new_int_type.getObjName(type_name); // default len - verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataSet::getObjName", __LINE__, __FILE__); + verify_val(name_len, (ssize_t)HDstrlen("/typetests/IntType NATIVE_INT"), "DataType::getObjName", __LINE__, __FILE__); + verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataType::getObjName", __LINE__, __FILE__); // Close everything or they can be closed when objects go out of scope dtype.close(); copied_type.close(); new_int_type.close(); grp.close(); - file.close(); PASSED(); } // end top try block diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index dcfb644..9d072be 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -462,11 +462,11 @@ test_reference_group(void) // Check number of objects in the group dereferenced by constructor hsize_t nobjs = refgroup.getNumObjs(); - verify_val(nobjs, 3, "H5Group::getNumObjs",__LINE__,__FILE__); + verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); // Check number of objects in the group dereferenced by ::reference nobjs = group.getNumObjs(); - verify_val(nobjs, 3, "H5Group::getNumObjs",__LINE__,__FILE__); + verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); // Check getting file name given the group dereferenced via constructor H5std_string fname = refgroup.getFileName(); @@ -479,7 +479,7 @@ test_reference_group(void) // Unlink one of the objects in the dereferenced group, and re-check refgroup.unlink(GROUPNAME2); nobjs = refgroup.getNumObjs(); - verify_val(nobjs, 2, "H5Group::getNumObjs",__LINE__,__FILE__); + verify_val(nobjs, (hsize_t)2, "H5Group::getNumObjs",__LINE__,__FILE__); // Close resources group.close(); @@ -686,43 +686,43 @@ test_reference_region_1D(void) reg_sp.getSelectHyperBlocklist((hsize_t)0, (hsize_t)nelms, coords); // Verify values in the list - verify_val(coords[0], 2, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[1], 3, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[2], 7, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[3], 8, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[4], 12, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[5], 13, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[6], 17, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[7], 18, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[8], 22, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[9], 23, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[10], 27, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[11], 28, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[12], 32, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[13], 33, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[14], 37, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[15], 38, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[16], 42, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[17], 43, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[18], 47, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[19], 48, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[20], 52, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[21], 53, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[22], 57, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[23], 58, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[24], 62, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[25], 63, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[26], 67, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[27], 68, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[28], 72, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[29], 73, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[0], (hsize_t)2, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[1], (hsize_t)3, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[2], (hsize_t)7, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[3], (hsize_t)8, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[4],(hsize_t)12, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[5],(hsize_t)13, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[6],(hsize_t)17, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[7],(hsize_t)18, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[8],(hsize_t)22, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[9],(hsize_t)23, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[10],(hsize_t)27, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[11],(hsize_t)28, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[12],(hsize_t)32, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[13],(hsize_t)33, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[14],(hsize_t)37, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[15],(hsize_t)38, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[16],(hsize_t)42, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[17],(hsize_t)43, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[18],(hsize_t)47, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[19],(hsize_t)48, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[20],(hsize_t)52, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[21],(hsize_t)53, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[22],(hsize_t)57, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[23],(hsize_t)58, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[24],(hsize_t)62, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[25],(hsize_t)63, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[26],(hsize_t)67, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[27],(hsize_t)68, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[28],(hsize_t)72, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[29],(hsize_t)73, "Hyperslab Coordinates",__LINE__,__FILE__); HDfree(coords); // Check boundaries reg_sp.getSelectBounds(low, high); - verify_val(low[0], 2, "DataSpace::getSelectBounds",__LINE__,__FILE__); - verify_val(high[0], 73, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(low[0],(hsize_t)2, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0],(hsize_t)73, "DataSpace::getSelectBounds",__LINE__,__FILE__); /* Close region space */ reg_sp.close(); @@ -760,8 +760,8 @@ test_reference_region_1D(void) // Check boundaries elm_sp.getSelectBounds(low, high); - verify_val(low[0], 3, "DataSpace::getSelectBounds",__LINE__,__FILE__); - verify_val(high[0], 97, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(low[0],(hsize_t)3, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0],(hsize_t)97, "DataSpace::getSelectBounds",__LINE__,__FILE__); // Close element space elm_sp.close(); diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index e9e1427..2e64051 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -109,7 +109,7 @@ static void test_classes() { SUBTEST("PredType::getClass()"); try { - int curr_nerrors = GetTestNumErrs(); + // maybe later, int curr_nerrors = GetTestNumErrs(); // PredType::NATIVE_INT should be in H5T_INTEGER class H5T_class_t tcls = PredType::NATIVE_INT.getClass(); @@ -283,10 +283,16 @@ static void test_query() tid2.close(); file.close(); + // Try truncating the file to make sure reference counting is good. + // If any references to ids of tid1 and tid2 are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILENAME[2], H5F_ACC_TRUNC); + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_query @@ -467,27 +473,20 @@ static void test_named () trans_type.setPrecision(256); trans_type.close(); - /* - * Close the committed type and reopen it. It should return a named type. -* This had something to do with the way IntType was returned and assigned -and caused itype.committed not working correctly. So, use another_type for -now. + // Close the committed type and reopen it. It should be a named type. itype.close(); itype = file.openIntType("native-int"); iscommitted = itype.committed(); -*/ - IntType another_type = file.openIntType("native-int"); - iscommitted = another_type.committed(); if (!iscommitted) throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); // Create a dataset that uses the named type, then get the dataset's // datatype and make sure it's a named type. - DataSet dset = file.createDataSet("dset1", another_type, space); + DataSet dset = file.createDataSet("dset1", itype, space); ds_type = new DataType(dset.getDataType()); iscommitted = ds_type->committed(); if (!iscommitted) - throw InvalidActionException("IntType::committed()", "1 Dataset type should be named type!"); + throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); dset.close(); ds_type->close(); delete ds_type; diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index a2669db..7c81a8e 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -60,6 +60,7 @@ const hsize_t SPACE1_DIM1 = 4; ** Note: exact copy from the C version. ** (Not used now) ****************************************************************/ +#if 0 // not used now static void *test_vlstr_alloc_custom(size_t size, void *info) { void *ret_value=NULL; // Pointer to return @@ -81,6 +82,7 @@ static void *test_vlstr_alloc_custom(size_t size, void *info) return(ret_value); } +#endif /**************************************************************** ** @@ -92,6 +94,7 @@ static void *test_vlstr_alloc_custom(size_t size, void *info) ** Note: exact copy from the C version. ** (Not used now) ****************************************************************/ +#if 0 // not used now static void test_vlstr_free_custom(void *_mem, void *info) { unsigned char *mem; @@ -111,6 +114,7 @@ static void test_vlstr_free_custom(void *_mem, void *info) HDfree(mem); } // end if } +#endif /*------------------------------------------------------------------------- * Function: test_vlstring_dataset @@ -256,7 +260,7 @@ static void test_vlstring_array_dataset() char *string_ds_check[SPACE1_DIM1]; dataset.read(string_ds_check, vlst); - int ii; + hsize_t ii; for (ii = 0; ii < SPACE1_DIM1; ii++) { if(HDstrcmp(string_ds_check[ii], string_ds_array[ii])!=0) @@ -351,25 +355,25 @@ static void test_vlstrings_special() dataset.read(rdata, vlst); // Check data read in. - hsize_t i; // counting variable - for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); + hsize_t ii; // counting variable + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); // Write dataset to disk, then read it back. dataset.write(wdata, vlst); dataset.read(rdata, vlst); // Compare data read in. - for (i = 0; i < SPACE1_DIM1; i++) { - size_t wlen = HDstrlen(wdata[i]); - size_t rlen = HDstrlen(rdata[i]); + for (ii = 0; ii < SPACE1_DIM1; ii++) { + size_t wlen = HDstrlen(wdata[ii]); + size_t rlen = HDstrlen(rdata[ii]); if(wlen != rlen) { - TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)i, (unsigned)wlen, (int)i, (unsigned)rlen); + TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)ii, (unsigned)wlen, (int)ii, (unsigned)rlen); continue; } // end if - if(HDstrcmp(wdata[i],rdata[i]) != 0) { - TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", (int)i, wdata[i], (int)i, rdata[i]); + if(HDstrcmp(wdata[ii],rdata[ii]) != 0) { + TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", (int)ii, wdata[ii], (int)ii, rdata[ii]); continue; } // end if } // end for @@ -398,9 +402,9 @@ static void test_vlstrings_special() dataset.read(rdata, vlst); // Check data read in. - for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); // Try to write nil strings to disk. dataset.write(wdata2, vlst); @@ -409,9 +413,9 @@ static void test_vlstrings_special() dataset.read(rdata, vlst); // Check data read in. - for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); // Close objects and file. dataset.close(); @@ -793,7 +797,7 @@ static void test_vlstring_array_attribute() char *string_att_check[SPACE1_DIM1]; gr_attr.read(vlst, &string_att_check); - int ii; + hsize_t ii; for (ii = 0; ii < SPACE1_DIM1; ii++) { if(HDstrcmp(string_att_check[ii], string_att_array[ii])!=0) |