diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-08-08 03:53:58 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2005-08-08 03:53:58 (GMT) |
commit | 07592ad7c32fe5ed0b947a7a6a4ee3aef58173ab (patch) | |
tree | a9439aefae26c6a9897e1190095079e32e891fb5 /c++ | |
parent | e49bb1feeaa3e2c18a2bd38ff5a5ef3142b5f9b1 (diff) | |
download | hdf5-07592ad7c32fe5ed0b947a7a6a4ee3aef58173ab.zip hdf5-07592ad7c32fe5ed0b947a7a6a4ee3aef58173ab.tar.gz hdf5-07592ad7c32fe5ed0b947a7a6a4ee3aef58173ab.tar.bz2 |
[svn-r11206] Purpose: Additional wrapper/Code improvement
Description:
Added wrapper for H5Iget_type.
Added try/catch to many APIs that call private functions so that more
specific information can be provided at failure.
Added IdComponent::inMemFunc to help providing specific info.
Added const to parameters of several functions that missed that.
Platforms tested:
Linux 2.4 (heping)
SunOS 5.8 64-bit (sol)
AIX 5.1 (copper)
IRIX64 with -n32 (modi4)
HPUX 11.00 (kelgia)
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5AbstractDs.cpp | 151 | ||||
-rw-r--r-- | c++/src/H5ArrayType.h | 3 | ||||
-rw-r--r-- | c++/src/H5AtomType.h | 3 | ||||
-rw-r--r-- | c++/src/H5Attribute.h | 3 | ||||
-rw-r--r-- | c++/src/H5CommonFG.cpp | 147 | ||||
-rw-r--r-- | c++/src/H5CommonFG.h | 7 | ||||
-rw-r--r-- | c++/src/H5CompType.cpp | 78 | ||||
-rw-r--r-- | c++/src/H5CompType.h | 3 | ||||
-rw-r--r-- | c++/src/H5DataSet.cpp | 58 | ||||
-rw-r--r-- | c++/src/H5DataSet.h | 4 | ||||
-rw-r--r-- | c++/src/H5DataType.cpp | 96 | ||||
-rw-r--r-- | c++/src/H5DataType.h | 3 | ||||
-rw-r--r-- | c++/src/H5EnumType.cpp | 2 | ||||
-rw-r--r-- | c++/src/H5EnumType.h | 3 | ||||
-rw-r--r-- | c++/src/H5File.cpp | 50 | ||||
-rw-r--r-- | c++/src/H5File.h | 4 | ||||
-rw-r--r-- | c++/src/H5FloatType.h | 3 | ||||
-rw-r--r-- | c++/src/H5Group.cpp | 53 | ||||
-rw-r--r-- | c++/src/H5Group.h | 4 | ||||
-rw-r--r-- | c++/src/H5IdComponent.cpp | 70 | ||||
-rw-r--r-- | c++/src/H5IdComponent.h | 23 | ||||
-rw-r--r-- | c++/src/H5IntType.h | 3 | ||||
-rw-r--r-- | c++/src/H5Object.cpp | 7 | ||||
-rw-r--r-- | c++/src/H5PropList.cpp | 4 | ||||
-rw-r--r-- | c++/src/H5StrType.h | 3 | ||||
-rw-r--r-- | c++/src/H5VarLenType.h | 3 |
26 files changed, 606 insertions, 182 deletions
diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index 9e54d94..9e02181 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -62,15 +62,24 @@ H5T_class_t AbstractDs::getTypeClass() const // Gets the datatype used by this dataset or attribute. // p_get_type calls either H5Dget_type or H5Aget_type depending on // which object invokes getTypeClass - DataType datatype(p_get_type()); + hid_t datatype_id; + try { + datatype_id = p_get_type(); // returned value is already validated + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getTypeClass", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getTypeClass", E.getDetailMsg()); + } // Gets the class of the datatype and validate it before returning - H5T_class_t type_class = H5Tget_class( datatype.getId()); + H5T_class_t type_class = H5Tget_class(datatype_id); if( type_class != H5T_NO_CLASS ) return( type_class ); else { - throw DataTypeIException("AbstractDs::getTypeClass", + throw DataTypeIException(inMemFunc("getTypeClass"), "H5Tget_class returns H5T_NO_CLASS"); } } @@ -85,19 +94,25 @@ H5T_class_t AbstractDs::getTypeClass() const //-------------------------------------------------------------------------- DataType AbstractDs::getDataType() const { - // Gets the id of the datatype used by this dataset or attribute. - // p_get_type calls either H5Dget_type or H5Aget_type depending on - // which object invokes getTypeClass - hid_t datatype_id = p_get_type(); // returned value is already validated - - // Create and return the DataType object - DataType datatype( datatype_id ); - return( datatype ); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getDataType. Then, create and + // return the DataType object + try { + DataType datatype(p_get_type()); + return(datatype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getDataType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getDataType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- // Function: AbstractDs::getArrayType -///\brief Returns the compound datatype of this abstract dataset which +///\brief Returns the array datatype of this abstract dataset which /// can be a dataset or an attribute. ///\return ArrayType instance ///\exception H5::DataTypeIException @@ -105,8 +120,20 @@ DataType AbstractDs::getDataType() const //-------------------------------------------------------------------------- ArrayType AbstractDs::getArrayType() const { - ArrayType arraytype(p_get_type()); - return(arraytype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getArrayType. Then, create and + // return the ArrayType object + try { + ArrayType arraytype(p_get_type()); + return(arraytype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getArrayType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getArrayType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -119,8 +146,20 @@ ArrayType AbstractDs::getArrayType() const //-------------------------------------------------------------------------- CompType AbstractDs::getCompType() const { - CompType comptype(p_get_type()); - return(comptype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getCompType. Then, create and + // return the CompType object + try { + CompType comptype(p_get_type()); + return(comptype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getCompType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getCompType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -133,8 +172,20 @@ CompType AbstractDs::getCompType() const //-------------------------------------------------------------------------- EnumType AbstractDs::getEnumType() const { - EnumType enumtype(p_get_type()); - return(enumtype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getEnumType. Then, create and + // return the EnumType object + try { + EnumType enumtype(p_get_type()); + return(enumtype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getEnumType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getEnumType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -147,8 +198,20 @@ EnumType AbstractDs::getEnumType() const //-------------------------------------------------------------------------- IntType AbstractDs::getIntType() const { - IntType inttype(p_get_type()); - return(inttype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getIntType. Then, create and + // return the IntType object + try { + IntType inttype(p_get_type()); + return(inttype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getIntType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getIntType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -161,8 +224,20 @@ IntType AbstractDs::getIntType() const //-------------------------------------------------------------------------- FloatType AbstractDs::getFloatType() const { - FloatType floatype(p_get_type()); - return(floatype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getFloatType. Then, create and + // return the FloatType object + try { + FloatType floatype(p_get_type()); + return(floatype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getFloatType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getFloatType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -175,8 +250,20 @@ FloatType AbstractDs::getFloatType() const //-------------------------------------------------------------------------- StrType AbstractDs::getStrType() const { - StrType strtype(p_get_type()); - return(strtype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getStrType. Then, create and + // return the StrType object + try { + StrType strtype(p_get_type()); + return(strtype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getStrType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getStrType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -189,8 +276,20 @@ StrType AbstractDs::getStrType() const //-------------------------------------------------------------------------- VarLenType AbstractDs::getVarLenType() const { - VarLenType varlentype(p_get_type()); - return(varlentype); + // Gets the id of the datatype used by this dataset or attribute using + // p_get_type. p_get_type calls either H5Dget_type or H5Aget_type + // depending on which object invokes getVarLenType. Then, create and + // return the VarLenType object + try { + VarLenType varlentype(p_get_type()); + return(varlentype); + } + catch (DataSetIException E) { + throw DataTypeIException("DataSet::getVarLenType", E.getDetailMsg()); + } + catch (AttributeIException E) { + throw DataTypeIException("Attribute::getVarLenType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index 3f1ddc5..023998d 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -34,6 +34,9 @@ class H5_DLLCPP ArrayType : public DataType { // Returns the sizes of dimensions of this array datatype. int getArrayDims(hsize_t* dims); + // Returns this class name + virtual string fromClass () const { return ("ArrayType"); } + // Copy constructor: makes copy of the original object. ArrayType( const ArrayType& original ); diff --git a/c++/src/H5AtomType.h b/c++/src/H5AtomType.h index f9b43c4..9cca02c 100644 --- a/c++/src/H5AtomType.h +++ b/c++/src/H5AtomType.h @@ -55,6 +55,9 @@ class H5_DLLCPP AtomType : public DataType { // Sets the total size for an atomic datatype. void setSize( size_t size ) const; + // Returns this class name + virtual string fromClass () const { return("AtomType"); } + // Copy constructor - makes copy of the original object AtomType( const AtomType& original ); diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index cf6f5c4..73a5612 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -44,6 +44,9 @@ class H5_DLLCPP Attribute : public AbstractDs { void write(const DataType& mem_type, const void *buf ) const; void write(const DataType& mem_type, const string& strg ) const; + // Returns this class name + virtual string fromClass () const { return ("Attribute"); } + // Creates a copy of an existing attribute using the attribute id Attribute( const hid_t attr_id ); diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 9660096..767286e 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -56,7 +56,7 @@ namespace H5 { ///\param size_hint - IN: Indicates the number of bytes to reserve for /// the names that will appear in the group ///\return Group instance -///\exception H5::FileIException or H5::GroupIException +///\exception H5::GroupIException ///\par Description /// The optional \a size_hint specifies how much file space to /// reserve for storing the names that will appear in this new @@ -99,7 +99,7 @@ Group CommonFG::createGroup( const string& name, size_t size_hint ) const /// or another group. ///\param name - IN: Name of the group to open ///\return Group instance -///\exception H5::FileIException or H5::GroupIException +///\exception H5::GroupIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- Group CommonFG::openGroup( const char* name ) const @@ -139,7 +139,7 @@ Group CommonFG::openGroup( const string& name ) const ///\param data_space - IN: Dataspace for the dataset ///\param create_plist - IN: Creation properly list for the dataset ///\return DataSet instance -///\exception H5::FileIException or H5::GroupIException +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- DataSet CommonFG::createDataSet( const char* name, const DataType& data_type, const DataSpace& data_space, const DSetCreatPropList& create_plist ) const @@ -180,7 +180,7 @@ DataSet CommonFG::createDataSet( const string& name, const DataType& data_type, ///\brief Opens an existing dataset at this location. ///\param name - IN: Name of the dataset to open ///\return DataSet instance -///\exception H5::FileIException or H5::GroupIException +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- DataSet CommonFG::openDataSet( const char* name ) const @@ -283,6 +283,11 @@ void CommonFG::unlink( const string& name ) const ///\param src - IN: Object's original name ///\param dst - IN: Object's new name ///\exception H5::FileIException or H5::GroupIException +///\note +/// Exercise care in moving groups as it is possible to render +/// data in a file inaccessible with Group::move. Please refer +/// to the Group Interface in the HDF5 User's Guide at: +/// http://hdf.ncsa.uiuc.edu/HDF5/doc/Groups.html // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CommonFG::move( const char* src, const char* dst ) const @@ -314,6 +319,10 @@ void CommonFG::move( const string& src, const string& dst ) const ///\param statbuf - OUT: Buffer to return information about the object ///\exception H5::FileIException or H5::GroupIException // Programmer Binh-Minh Ribler - 2000 +///\par Description +/// For more information, please refer to the C layer Reference +/// Manual at: +/// http://hdf.ncsa.uiuc.edu/HDF5/doc/RM_H5G.html#Group-GetObjinfo //-------------------------------------------------------------------------- void CommonFG::getObjinfo( const char* name, hbool_t follow_link, H5G_stat_t& statbuf ) const { @@ -581,38 +590,6 @@ void CommonFG::unmount( const string& name ) const } //-------------------------------------------------------------------------- -// Function: CommonFG::p_open_data_type (private) -// Purpose Opens the named datatype and returns the datatype's identifier. -// Return Id of the datatype -// Exception H5::FileIException or H5::GroupIException -// Description -// This private function is used by the member functions -// CommonFG::openXxxType, where Xxx indicates the specific -// datatypes. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -hid_t CommonFG::p_open_data_type( const char* name ) const -{ - // Call C function H5Topen to open the named datatype in this group, - // giving either the file or group id - hid_t datatype_id = H5Topen( getLocId(), name ); - - // If the datatype's opening failed, throw an exception - if( datatype_id < 0 ) - { - throwException("openDataType", "H5Topen failed"); - } - - // No failure, return the datatype id - return( datatype_id ); -} - -// -// The following member functions use the private function -// p_open_data_type to open a named datatype in this location -// - -//-------------------------------------------------------------------------- // Function: CommonFG::openDataType ///\brief Opens the named generic datatype at this location. ///\param name - IN: Name of the datatype to open @@ -622,8 +599,18 @@ hid_t CommonFG::p_open_data_type( const char* name ) const //-------------------------------------------------------------------------- DataType CommonFG::openDataType( const char* name ) const { - DataType data_type(p_open_data_type(name)); - return( data_type ); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openDataType", "H5Topen failed"); + } + // No failure, create and return the DataType object + DataType data_type(type_id); + return(data_type); } //-------------------------------------------------------------------------- @@ -648,7 +635,17 @@ DataType CommonFG::openDataType( const string& name ) const //-------------------------------------------------------------------------- ArrayType CommonFG::openArrayType( const char* name ) const { - ArrayType array_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openArrayType", "H5Topen failed"); + } + // No failure, create and return the ArrayType object + ArrayType array_type (type_id); return(array_type); } @@ -674,7 +671,17 @@ ArrayType CommonFG::openArrayType( const string& name ) const //-------------------------------------------------------------------------- CompType CommonFG::openCompType( const char* name ) const { - CompType comp_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openCompType", "H5Topen failed"); + } + // No failure, create and return the CompType object + CompType comp_type(type_id); return(comp_type); } @@ -700,7 +707,17 @@ CompType CommonFG::openCompType( const string& name ) const //-------------------------------------------------------------------------- EnumType CommonFG::openEnumType( const char* name ) const { - EnumType enum_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openEnumType", "H5Topen failed"); + } + // No failure, create and return the EnumType object + EnumType enum_type(type_id); return(enum_type); } @@ -726,7 +743,17 @@ EnumType CommonFG::openEnumType( const string& name ) const //-------------------------------------------------------------------------- IntType CommonFG::openIntType( const char* name ) const { - IntType int_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openIntType", "H5Topen failed"); + } + // No failure, create and return the IntType object + IntType int_type(type_id); return(int_type); } @@ -752,7 +779,17 @@ IntType CommonFG::openIntType( const string& name ) const //-------------------------------------------------------------------------- FloatType CommonFG::openFloatType( const char* name ) const { - FloatType float_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openFloatType", "H5Topen failed"); + } + // No failure, create and return the FloatType object + FloatType float_type(type_id); return(float_type); } @@ -778,7 +815,17 @@ FloatType CommonFG::openFloatType( const string& name ) const //-------------------------------------------------------------------------- StrType CommonFG::openStrType( const char* name ) const { - StrType str_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openStrType", "H5Topen failed"); + } + // No failure, create and return the StrType object + StrType str_type(type_id); return(str_type); } @@ -804,7 +851,17 @@ StrType CommonFG::openStrType( const string& name ) const //-------------------------------------------------------------------------- VarLenType CommonFG::openVarLenType( const char* name ) const { - VarLenType varlen_type(p_open_data_type(name)); + // Call C function H5Topen to open the named datatype in this group, + // given either the file or group id + hid_t type_id = H5Topen(getLocId(), name); + + // If the datatype's opening failed, throw an exception + if( type_id < 0 ) + { + throwException("openVarLenType", "H5Topen failed"); + } + // No failure, create and return the VarLenType object + VarLenType varlen_type(type_id); return(varlen_type); } diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 1ad18f2..0bb8e67 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -141,10 +141,13 @@ class H5_DLLCPP CommonFG { VarLenType openVarLenType(const char* name) const; VarLenType openVarLenType(const string& name) const; +#ifndef DOXYGEN_SHOULD_SKIP_THIS /// For subclasses, H5File and Group, to return the correct /// object id, i.e. file or group id. virtual hid_t getLocId() const = 0; +#endif // DOXYGEN_SHOULD_SKIP_THIS + /// For subclasses, H5File and Group, to throw appropriate exception. virtual void throwException(const string func_name, const string msg) const = 0; @@ -154,10 +157,6 @@ class H5_DLLCPP CommonFG { // Noop destructor. virtual ~CommonFG(); - private: - // Common code for member functions openXxxType - hid_t p_open_data_type(const char* name) const; - }; // end of CommonFG declaration #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 2007891..aed4b58 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -216,9 +216,9 @@ hid_t CompType::p_get_member_type(unsigned member_num) const return( member_type_id ); else { - // p_get_member_type is private, use caller's function name for api - throw DataTypeIException("CompType::getMemberDataType", - "H5Tget_member_type failed"); + // p_get_member_type is private, caller will catch this exception + // then throw another with appropriate API name + throw DataTypeIException("", "H5Tget_member_type failed"); } } @@ -233,8 +233,13 @@ hid_t CompType::p_get_member_type(unsigned member_num) const //-------------------------------------------------------------------------- DataType CompType::getMemberDataType( unsigned member_num ) const { - DataType datatype(p_get_member_type(member_num)); - return(datatype); + try { + DataType datatype(p_get_member_type(member_num)); + return(datatype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberDataType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -248,8 +253,13 @@ DataType CompType::getMemberDataType( unsigned member_num ) const //-------------------------------------------------------------------------- ArrayType CompType::getMemberArrayType( unsigned member_num ) const { - ArrayType arraytype(p_get_member_type(member_num)); - return(arraytype); + try { + ArrayType arraytype(p_get_member_type(member_num)); + return(arraytype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberArrayType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -263,8 +273,13 @@ ArrayType CompType::getMemberArrayType( unsigned member_num ) const //-------------------------------------------------------------------------- EnumType CompType::getMemberEnumType( unsigned member_num ) const { - EnumType enumtype(p_get_member_type(member_num)); - return(enumtype); + try { + EnumType enumtype(p_get_member_type(member_num)); + return(enumtype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberEnumType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -278,8 +293,13 @@ EnumType CompType::getMemberEnumType( unsigned member_num ) const //-------------------------------------------------------------------------- CompType CompType::getMemberCompType( unsigned member_num ) const { - CompType comptype(p_get_member_type(member_num)); - return(comptype); + try { + CompType comptype(p_get_member_type(member_num)); + return(comptype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberCompType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -293,8 +313,13 @@ CompType CompType::getMemberCompType( unsigned member_num ) const //-------------------------------------------------------------------------- IntType CompType::getMemberIntType( unsigned member_num ) const { - IntType inttype(p_get_member_type(member_num)); - return(inttype); + try { + IntType inttype(p_get_member_type(member_num)); + return(inttype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberIntType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -308,8 +333,13 @@ IntType CompType::getMemberIntType( unsigned member_num ) const //-------------------------------------------------------------------------- FloatType CompType::getMemberFloatType( unsigned member_num ) const { - FloatType floatype(p_get_member_type(member_num)); - return(floatype); + try { + FloatType floatype(p_get_member_type(member_num)); + return(floatype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberFloatType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -323,8 +353,13 @@ FloatType CompType::getMemberFloatType( unsigned member_num ) const //-------------------------------------------------------------------------- StrType CompType::getMemberStrType( unsigned member_num ) const { - StrType strtype(p_get_member_type(member_num)); - return(strtype); + try { + StrType strtype(p_get_member_type(member_num)); + return(strtype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberStrType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -338,8 +373,13 @@ StrType CompType::getMemberStrType( unsigned member_num ) const //-------------------------------------------------------------------------- VarLenType CompType::getMemberVarLenType( unsigned member_num ) const { - VarLenType varlentype(p_get_member_type(member_num)); - return(varlentype); + try { + VarLenType varlentype(p_get_member_type(member_num)); + return(varlentype); + } + catch (DataTypeIException E) { + throw DataTypeIException("CompType::getMemberVarLenType", E.getDetailMsg()); + } } /* old style of getMemberType - using overloads; new style above diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h index d018c13..d548043 100644 --- a/c++/src/H5CompType.h +++ b/c++/src/H5CompType.h @@ -90,6 +90,9 @@ class H5_DLLCPP CompType : public DataType { // Recursively removes padding from within this compound datatype. void pack() const; + // Returns this class name + virtual string fromClass () const { return ("CompType"); } + // Default constructor CompType(); diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 765b1e5..7ab5179 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -349,7 +349,8 @@ int DataSet::iterateElems( void* buf, const DataType& type, const DataSpace& spa ///\par Description /// For more information, please see the Description section in /// C layer Reference Manual at: -/// http: +///\par +/// http://hdf.ncsa.uiuc.edu/HDF5/doc/RM_H5D.html#Dataset-Extend // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void DataSet::extend( const hsize_t* size ) const @@ -413,12 +414,17 @@ void DataSet::fillMemBuf(void *buf, DataType& buf_type, DataSpace& space) ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION ///\return A reference -///\exception H5::IdComponentException +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void* DataSet::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const { - return(p_reference(name, dataspace.getId(), ref_type)); + try { + return(p_reference(name, dataspace.getId(), ref_type)); + } + catch (IdComponentException E) { + throw DataSetIException("DataSet::Reference", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -428,7 +434,7 @@ void* DataSet::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_ /// a reference to an HDF5 object, not to a dataset region. ///\param name - IN: Name of the object to be referenced ///\return A reference -///\exception H5::IdComponentException +///\exception H5::DataSetIException ///\par Description // This function passes H5R_OBJECT and -1 to the protected // function for it to pass to the C API H5Rcreate @@ -437,7 +443,25 @@ void* DataSet::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_ //-------------------------------------------------------------------------- void* DataSet::Reference(const char* name) const { - return(p_reference(name, -1, H5R_OBJECT)); + try { + return(p_reference(name, -1, H5R_OBJECT)); + } + catch (IdComponentException E) { + throw DataSetIException("DataSet::Reference", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: DataSet::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it takes an +/// \c std::string for the object's name. +///\param name - IN: Name of the object to be referenced - \c std::string +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataSet::Reference(const string& name) const +{ + return(Reference(name.c_str())); } //-------------------------------------------------------------------------- @@ -445,17 +469,22 @@ void* DataSet::Reference(const char* name) const ///\brief Retrieves the type of object that an object reference points to. ///\param ref_type - IN: Type of reference to query ///\param ref - IN: Reference to query -// Return An object type, which can be one of the following: +///\return An object type, which can be one of the following: // H5G_LINK Object is a symbolic link. // H5G_GROUP Object is a group. // H5G_DATASET Object is a dataset. // H5G_TYPE Object is a named datatype -// Exception H5::IdComponentException +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- H5G_obj_t DataSet::getObjType(void *ref, H5R_type_t ref_type) const { - return(p_get_obj_type(ref, ref_type)); + try { + return(p_get_obj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw DataSetIException("DataSet::getObjType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -465,13 +494,18 @@ H5G_obj_t DataSet::getObjType(void *ref, H5R_type_t ref_type) const /// to H5R_DATASET_REGION ///\param ref - IN: Reference to get region of ///\return DataSpace instance -///\exception H5::IdComponentException +///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- DataSpace DataSet::getRegion(void *ref, H5R_type_t ref_type) const { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); + try { + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); + } + catch (IdComponentException E) { + throw DataSetIException("DataSet::getRegion", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -488,7 +522,7 @@ void DataSet::close() { throw DataSetIException("DataSet::close", "H5Dclose failed"); } - // reset the id because the group that it represents is now closed + // reset the id because the dataset that it represents is now closed id = 0; } diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index a15103a..24e88a7 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -81,6 +81,10 @@ class H5_DLLCPP DataSet : public AbstractDs { // Creates a reference to a named Hdf5 object in this object. void* Reference(const char* name) const; + void* Reference(const string& name) const; + + // Returns this class name + virtual string fromClass () const { return ("DataSet"); } // Creates a copy of an existing DataSet using its id. DataSet(const hid_t existing_id); diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 96aee12..28668a46 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -107,7 +107,7 @@ void DataType::copy( const DataType& like_type ) decRefCount(); } catch (Exception close_error) { - throw DataTypeIException("DataType::copy", close_error.getDetailMsg()); + throw DataTypeIException(inMemFunc("copy"), close_error.getDetailMsg()); } } @@ -115,7 +115,7 @@ void DataType::copy( const DataType& like_type ) id = H5Tcopy( like_type.getId() ); if( id < 0 ) - throw DataTypeIException("DataType::copy", "H5Tcopy failed"); + throw DataTypeIException(inMemFunc("copy"), "H5Tcopy failed"); } //-------------------------------------------------------------------------- @@ -155,8 +155,7 @@ bool DataType::operator==(const DataType& compared_type ) const return false; else { - throw DataTypeIException("DataType::operator==", - "H5Tequal returns negative value"); + throw DataTypeIException(inMemFunc("operator=="), "H5Tequal returns negative value"); } } @@ -177,7 +176,7 @@ void DataType::commit(CommonFG& loc, const char* name) const herr_t ret_value = H5Tcommit( loc_id, name, id ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::commit", "H5Tcommit failed"); + throw DataTypeIException(inMemFunc("commit"), "H5Tcommit failed"); } } @@ -211,7 +210,7 @@ bool DataType::committed() const return false; else { - throw DataTypeIException("DataType::committed", "H5Tcommitted return negative value"); + throw DataTypeIException(inMemFunc("committed"), "H5Tcommitted return negative value"); } } @@ -231,7 +230,7 @@ H5T_conv_t DataType::find( const DataType& dest, H5T_cdata_t **pcdata ) const H5T_conv_t func = H5Tfind( id, dest.getId(), pcdata ); if( func == NULL ) { - throw DataTypeIException("DataType::find", "H5Tfind returns a NULL function"); + throw DataTypeIException(inMemFunc("find"), "H5Tfind returns a NULL function"); } return( func ); } @@ -260,7 +259,7 @@ void DataType::convert( const DataType& dest, size_t nelmts, void *buf, void *ba ret_value = H5Tconvert( id, dest_id, nelmts, buf, background, plist_id ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::convert", "H5Tconvert failed"); + throw DataTypeIException(inMemFunc("convert"), "H5Tconvert failed"); } } @@ -284,7 +283,7 @@ void DataType::lock() const herr_t ret_value = H5Tlock( id ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::lock", "H5Tlock failed"); + throw DataTypeIException(inMemFunc("lock"), "H5Tlock failed"); } } @@ -302,8 +301,7 @@ H5T_class_t DataType::getClass() const // Return datatype class identifier if successful if( type_class == H5T_NO_CLASS ) { - throw DataTypeIException("DataType::getClass", - "H5Tget_class returns H5T_NO_CLASS"); + throw DataTypeIException(inMemFunc("getClass"), "H5Tget_class returns H5T_NO_CLASS"); } return( type_class ); } @@ -321,8 +319,7 @@ size_t DataType::getSize() const size_t type_size = H5Tget_size( id ); if( type_size <= 0 ) // valid data types are never zero size { - throw DataTypeIException("DataType::getSize", - "H5Tget_size returns invalid datatype size"); + throw DataTypeIException(inMemFunc("getSize"), "H5Tget_size returns invalid datatype size"); } return( type_size ); } @@ -349,7 +346,7 @@ DataType DataType::getSuper() const } else { - throw DataTypeIException("DataType::getSuper", "H5Tget_super failed"); + throw DataTypeIException(inMemFunc("getSuper"), "H5Tget_super failed"); } } @@ -377,7 +374,7 @@ void DataType::registerFunc( H5T_pers_t pers, const char* name, const DataType& herr_t ret_value = H5Tregister( pers, name, id, dest_id, func ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::registerFunc", "H5Tregister failed"); + throw DataTypeIException(inMemFunc("registerFunc"), "H5Tregister failed"); } } @@ -414,7 +411,7 @@ void DataType::unregister( H5T_pers_t pers, const char* name, const DataType& de herr_t ret_value = H5Tunregister( pers, name, id, dest_id, func ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::unregister", "H5Tunregister failed"); + throw DataTypeIException(inMemFunc("unregister"), "H5Tunregister failed"); } } @@ -444,7 +441,7 @@ void DataType::setTag( const char* tag ) const herr_t ret_value = H5Tset_tag( id, tag ); if( ret_value < 0 ) { - throw DataTypeIException("DataType::setTag", "H5Tset_tag failed"); + throw DataTypeIException(inMemFunc("setTag"), "H5Tset_tag failed"); } } @@ -481,8 +478,7 @@ string DataType::getTag() const } else { - throw DataTypeIException("DataType::getTag", - "H5Tget_tag returns NULL for tag"); + throw DataTypeIException(inMemFunc("getTag"), "H5Tget_tag returns NULL for tag"); } } @@ -504,8 +500,7 @@ bool DataType::detectClass(H5T_class_t cls) const return false; else { - throw DataTypeIException("DataType::detectClass", - "H5Tdetect_class returns negative value"); + throw DataTypeIException(inMemFunc("detectClass"), "H5Tdetect_class returns negative value"); } } @@ -526,8 +521,7 @@ bool DataType::isVariableStr() const return false; else { - throw DataTypeIException("DataType::isVariableStr", - "H5Tis_variable_str returns negative value"); + throw DataTypeIException(inMemFunc("isVariableStr"), "H5Tis_variable_str returns negative value"); } } @@ -538,12 +532,17 @@ bool DataType::isVariableStr() const ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION ///\return A reference -///\exception H5::IdComponentException +///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const { - return(p_reference(name, dataspace.getId(), ref_type)); + try { + return(p_reference(name, dataspace.getId(), ref_type)); + } + catch (IdComponentException E) { + throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -553,7 +552,7 @@ void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref /// a reference to an HDF5 object, not to a dataset region. ///\param name - IN: Name of the object to be referenced ///\return A reference -///\exception H5::IdComponentException +///\exception H5::DataTypeIException ///\par Description // This function passes H5R_OBJECT and -1 to the protected // function for it to pass to the C API H5Rcreate @@ -562,7 +561,26 @@ void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref //-------------------------------------------------------------------------- void* DataType::Reference(const char* name) const { - return(p_reference(name, -1, H5R_OBJECT)); + try { + return(p_reference(name, -1, H5R_OBJECT)); + } + catch (IdComponentException E) { + throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg()); + } + +} + +//-------------------------------------------------------------------------- +// Function: DataType::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it takes an +/// \c std::string for the object's name. +///\param name - IN: Name of the object to be referenced - \c std::string +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* DataType::Reference(const string& name) const +{ + return(Reference(name.c_str())); } //-------------------------------------------------------------------------- @@ -575,12 +593,17 @@ void* DataType::Reference(const char* name) const /// \li \c H5G_GROUP Object is a group. /// \li \c H5G_DATASET Object is a dataset. /// \li \c H5G_TYPE Object is a named datatype -///\exception H5::IdComponentException +///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- H5G_obj_t DataType::getObjType(void *ref, H5R_type_t ref_type) const { - return(p_get_obj_type(ref, ref_type)); + try { + return(p_get_obj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw DataTypeIException(inMemFunc("getObjType"), E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -589,13 +612,18 @@ H5G_obj_t DataType::getObjType(void *ref, H5R_type_t ref_type) const ///\param ref - IN: Reference to get region of ///\param ref_type - IN: Type of reference to get region of - default ///\return DataSpace instance -///\exception H5::IdComponentException +///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); + try { + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); + } + catch (IdComponentException E) { + throw DataTypeIException(inMemFunc("getRegion"), E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -613,7 +641,7 @@ void DataType::close() herr_t ret_value = H5Tclose(id); if( ret_value < 0 ) { - throw DataTypeIException("DataType::close", "H5Tclose failed"); + throw DataTypeIException(inMemFunc("close"), "H5Tclose failed"); } // reset the id because the datatype that it represents is now closed id = 0; @@ -638,7 +666,7 @@ DataType::~DataType() decRefCount(); } catch (Exception close_error) { - cerr << "DataType::~DataType - " << close_error.getDetailMsg() << endl; + cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl; } } } diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index f6a30ff..c135845 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -92,6 +92,7 @@ class H5_DLLCPP DataType : public H5Object { // Creates a reference to a named Hdf5 object in this object. void* Reference(const char* name) const; + void* Reference(const string& name) const; // Creates a reference to a named Hdf5 object or to a dataset region // in this object. @@ -103,6 +104,8 @@ class H5_DLLCPP DataType : public H5Object { // Retrieves a dataspace with the region pointed to selected. DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + virtual string fromClass () const { return ("DataType"); } + // Creates a copy of an existing DataType using its id DataType( const hid_t type_id, bool predtype = false ); diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp index 9ba71bf..abd9c51 100644 --- a/c++/src/H5EnumType.cpp +++ b/c++/src/H5EnumType.cpp @@ -240,7 +240,7 @@ int EnumType::getNmembers() const int num_members = H5Tget_nmembers( id ); if( num_members < 0 ) { - throw DataTypeIException("CompType::getNmembers", + throw DataTypeIException("EnumType::getNmembers", "H5Tget_nmembers returns negative number of members"); } return( num_members ); diff --git a/c++/src/H5EnumType.h b/c++/src/H5EnumType.h index f88b337..0313acb 100644 --- a/c++/src/H5EnumType.h +++ b/c++/src/H5EnumType.h @@ -56,6 +56,9 @@ class H5_DLLCPP EnumType : public DataType { void valueOf( const char* name, void *value ) const; void valueOf( const string& name, void *value ) const; + // Returns this class name + virtual string fromClass () const { return ("EnumType"); } + // Default constructor EnumType(); diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 985fc72..361d448 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -427,7 +427,12 @@ void H5File::getVFDHandle(void **file_handle) const //-------------------------------------------------------------------------- string H5File::getFileName() const { - return(p_get_file_name()); + try { + return(p_get_file_name()); + } + catch (IdComponentException E) { + throw FileIException("H5File::getFileName", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -444,7 +449,12 @@ string H5File::getFileName() const //-------------------------------------------------------------------------- void* H5File::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const { - return(p_reference(name, dataspace.getId(), ref_type)); + try { + return(p_reference(name, dataspace.getId(), ref_type)); + } + catch (IdComponentException E) { + throw FileIException("H5File::Reference", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -466,7 +476,25 @@ void* H5File::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_t //-------------------------------------------------------------------------- void* H5File::Reference(const char* name) const { - return(p_reference(name, -1, H5R_OBJECT)); + try { + return(p_reference(name, -1, H5R_OBJECT)); + } + catch (IdComponentException E) { + throw FileIException("H5File::Reference", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5File::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it takes an +/// \c std::string for the object's name. +///\param name - IN: Name of the object to be referenced - \c std::string +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* H5File::Reference(const string& name) const +{ + return(Reference(name.c_str())); } //-------------------------------------------------------------------------- @@ -484,7 +512,12 @@ void* H5File::Reference(const char* name) const //-------------------------------------------------------------------------- H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const { - return(p_get_obj_type(ref, ref_type)); + try { + return(p_get_obj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw FileIException("H5File::getObjType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -498,8 +531,13 @@ H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const //-------------------------------------------------------------------------- DataSpace H5File::getRegion(void *ref, H5R_type_t ref_type) const { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); + try { + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); + } + catch (IdComponentException E) { + throw FileIException("H5File::getRegion", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- diff --git a/c++/src/H5File.h b/c++/src/H5File.h index f9c1667..3b7ffaf 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -81,6 +81,10 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // Creates a reference to a named Hdf5 object in this object. void* Reference(const char* name) const; + void* Reference(const string& name) const; + + // Returns this class name + virtual string fromClass () const { return ("H5File"); } // Throw file exception. virtual void throwException(const string func_name, const string msg) const; diff --git a/c++/src/H5FloatType.h b/c++/src/H5FloatType.h index bdc2f6f..bc30963 100644 --- a/c++/src/H5FloatType.h +++ b/c++/src/H5FloatType.h @@ -52,6 +52,9 @@ class H5_DLLCPP FloatType : public AtomType { // Sets the mantissa normalization of a floating-point datatype. void setNorm( H5T_norm_t norm ) const; + // Returns this class name + virtual string fromClass () const { return ("FloatType"); } + // Default constructor FloatType(); diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 384ea1e..1d587c8 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -81,12 +81,17 @@ Group::Group( const hid_t group_id ) : H5Object( group_id ) {} ///\param dataspace - IN: Dataspace with selection ///\param ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION ///\return A reference -///\exception H5::IdComponentException +///\exception H5::GroupIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void* Group::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const { - return(p_reference(name, dataspace.getId(), ref_type)); + try { + return(p_reference(name, dataspace.getId(), ref_type)); + } + catch (IdComponentException E) { + throw GroupIException("Group::Reference", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -96,7 +101,7 @@ void* Group::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_ty /// a reference to an HDF5 object, not to a dataset region. ///\param name - IN: Name of the object to be referenced ///\return A reference -///\exception H5::IdComponentException +///\exception H5::GroupIException ///\par Description // This function passes H5R_OBJECT and -1 to the protected // function for it to pass to the C API H5Rcreate @@ -105,7 +110,25 @@ void* Group::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_ty //-------------------------------------------------------------------------- void* Group::Reference(const char* name) const { - return(p_reference(name, -1, H5R_OBJECT)); + try { + return(p_reference(name, -1, H5R_OBJECT)); + } + catch (IdComponentException E) { + throw GroupIException("Group::Reference", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: Group::Reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it takes an +/// \c std::string for the object's name. +///\param name - IN: Name of the object to be referenced +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void* Group::Reference(const string& name) const +{ + return(Reference(name.c_str())); } //-------------------------------------------------------------------------- @@ -113,17 +136,22 @@ void* Group::Reference(const char* name) const ///\brief Retrieves the type of object that an object reference points to. ///\param ref - IN: Reference to query ///\param ref_type - IN: Type of reference to query -// Return An object type, which can be one of the following: +///\return An object type, which can be one of the following: // H5G_LINK Object is a symbolic link. // H5G_GROUP Object is a group. // H5G_DATASET Object is a dataset. // H5G_TYPE Object is a named datatype -// Exception H5::IdComponentException +///\exception H5::GroupIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const { - return(p_get_obj_type(ref, ref_type)); + try { + return(p_get_obj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw GroupIException("Group::getObjType", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- @@ -132,13 +160,18 @@ H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const ///\param ref - IN: Reference to get region of ///\param ref_type - IN: Type of reference to get region of - default ///\return DataSpace instance -///\exception H5::IdComponentException +///\exception H5::GroupIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); + try { + DataSpace dataspace(p_get_region(ref, ref_type)); + return(dataspace); + } + catch (IdComponentException E) { + throw GroupIException("Group::getRegion", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 9a7b33b..a0ed933 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -37,6 +37,10 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Creates a reference to a named Hdf5 object in this object. void* Reference(const char* name) const; + void* Reference(const string& name) const; + + // Returns this class name + virtual string fromClass () const { return ("Group"); } // Throw group exception. virtual void throwException(const string func_name, const string msg) const; diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index aed355d..15a4898 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -49,7 +49,7 @@ IdComponent::IdComponent( const IdComponent& original ) ///\brief Increment reference counter for a given id. // Programmer Binh-Minh Ribler - May 2005 //-------------------------------------------------------------------------- -void IdComponent::incRefCount(hid_t obj_id) const +void IdComponent::incRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Iinc_ref(obj_id) < 0) @@ -74,7 +74,7 @@ void IdComponent::incRefCount() const // Added the check for ref counter to give a little more info // on why H5Idec_ref fails in some cases - BMR 5/19/2005 //-------------------------------------------------------------------------- -void IdComponent::decRefCount(hid_t obj_id) const +void IdComponent::decRefCount(const hid_t obj_id) const { if (p_valid_id(obj_id)) if (H5Idec_ref(obj_id) < 0) @@ -102,7 +102,7 @@ void IdComponent::decRefCount() const ///\return Reference count // Programmer Binh-Minh Ribler - May 2005 //-------------------------------------------------------------------------- -int IdComponent::getCounter(hid_t obj_id) const +int IdComponent::getCounter(const hid_t obj_id) const { int counter = 0; if (p_valid_id(obj_id)) @@ -126,6 +126,29 @@ int IdComponent::getCounter() const } //-------------------------------------------------------------------------- +// Function: hdfObjectType +///\brief Given an id, returns the type of the object. +///return a valid HDF object type, which may be one of the following: +/// \li \c H5I_FILE +/// \li \c H5I_GROUP +/// \li \c H5I_DATATYPE +/// \li \c H5I_DATASPACE +/// \li \c H5I_DATASET +/// \li \c H5I_ATTR +/// \li or \c H5I_BADID, if no valid type can be determined or the +/// input object id is invalid. +// Programmer Binh-Minh Ribler - Jul, 2005 +//-------------------------------------------------------------------------- +H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id) +{ + H5I_type_t id_type = H5Iget_type(obj_id); + if (id_type <= H5I_BADID || id_type >= H5I_NTYPES) + return H5I_BADID; // invalid + else + return id_type; // valid type +} + +//-------------------------------------------------------------------------- // Function: IdComponent::operator= ///\brief Assignment operator. ///\param rhs - IN: Reference to the existing object @@ -166,7 +189,7 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) // Then the object's id is reset to the new id. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -void IdComponent::setId( hid_t new_id ) +void IdComponent::setId(const hid_t new_id) { // handling references to this id decRefCount(); @@ -223,6 +246,26 @@ IdComponent::~IdComponent() { #ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- +// Function: IdComponent::inMemFunc +///\brief Makes and returns string "<class-name>::<func_name>" +///\param func_name - Name of the function where failure occurs +// Description +/// Concatenates the class name of this object with the +/// passed-in function name to create a string that indicates +/// where the failure occurs. The class-name is provided by +/// fromClass(). This string will be used by a base class when +/// an exception is thrown. +// Programmer Binh-Minh Ribler - Aug 6, 2005 +//-------------------------------------------------------------------------- +string IdComponent::inMemFunc(const char* func_name) const +{ + string full_name = func_name; + full_name.insert(0, "::"); + full_name.insert(0, fromClass()); + return (full_name); +} + +//-------------------------------------------------------------------------- // Function: IdComponent default constructor - private ///\brief Default constructor. // Programmer Binh-Minh Ribler - 2000 @@ -230,7 +273,7 @@ IdComponent::~IdComponent() { IdComponent::IdComponent() : id(-1) {} //-------------------------------------------------------------------------- -// Function: IdComponent::p_get_file_name +// Function: IdComponent::p_get_file_name (protected) // Purpose: Gets the name of the file, in which this object belongs. // Exception: H5::IdComponentException // Description: @@ -247,8 +290,7 @@ string IdComponent::p_get_file_name() const // If H5Aget_name returns a negative value, raise an exception, if( name_size < 0 ) { - throw IdComponentException("IdComponent::p_get_file_name", - "H5Fget_name failed"); + throw IdComponentException("", "H5Fget_name failed"); } // Call H5Fget_name again to get the actual file name @@ -258,8 +300,7 @@ string IdComponent::p_get_file_name() const // Check for failure again if( name_size < 0 ) { - throw IdComponentException("IdComponent::p_get_file_name", - "H5Fget_name failed"); + throw IdComponentException("", "H5Fget_name failed"); } // Convert the C file name and return @@ -285,8 +326,7 @@ void* IdComponent::p_reference(const char* name, hid_t space_id, H5R_type_t ref_ herr_t ret_value = H5Rcreate(ref, id, name, ref_type, space_id); if (ret_value < 0) { - throw IdComponentException("IdComponent::p_reference", - "H5Rcreate failed"); + throw IdComponentException("", "H5Rcreate failed"); } return(ref); } @@ -310,8 +350,7 @@ H5G_obj_t IdComponent::p_get_obj_type(void *ref, H5R_type_t ref_type) const H5G_obj_t obj_type = H5Rget_obj_type(id, ref_type, ref); if (obj_type == H5G_UNKNOWN) { - throw IdComponentException("IdComponent::p_get_obj_type", - "H5R_get_obj_type failed"); + throw IdComponentException("", "H5R_get_obj_type failed"); } return(obj_type); } @@ -332,8 +371,7 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const hid_t space_id = H5Rget_region(id, ref_type, ref); if (space_id < 0) { - throw IdComponentException("IdComponent::p_get_region", - "H5Rget_region failed"); + throw IdComponentException("", "H5Rget_region failed"); } return(space_id); } @@ -349,7 +387,7 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const // Return true if id is valid, false, otherwise // Programmer Binh-Minh Ribler - May, 2005 //-------------------------------------------------------------------------- -bool IdComponent::p_valid_id(hid_t obj_id) const +bool IdComponent::p_valid_id(const hid_t obj_id) const { H5I_type_t id_type = H5Iget_type(obj_id); if (id_type <= H5I_BADID || id_type >= H5I_NTYPES) diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index e50eb2a..33fa7d2 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -25,24 +25,25 @@ namespace H5 { class H5_DLLCPP IdComponent { public: // Increment reference counter. - void incRefCount(hid_t obj_id) const; + void incRefCount(const hid_t obj_id) const; void incRefCount() const; // Decrement reference counter. - void decRefCount(hid_t obj_id) const; + void decRefCount(const hid_t obj_id) const; void decRefCount() const; // Get the reference counter to this identifier. - int getCounter(hid_t obj_id) const; + int getCounter(const hid_t obj_id) const; int getCounter() const; + // Returns an HDF object type, given the object id. + static H5I_type_t getHDFObjType(const hid_t obj_id); + // Assignment operator. IdComponent& operator=( const IdComponent& rhs ); - //void reset(); - // Sets the identifier of this object to a new value. - void setId( hid_t new_id ); + void setId(const hid_t new_id); // Creates an object to hold an HDF5 identifier. IdComponent( const hid_t h5_id ); @@ -57,6 +58,14 @@ class H5_DLLCPP IdComponent { // Pure virtual function for there are various H5*close for the // subclasses. virtual void close() = 0; + + // Makes and returns the string "<class-name>::<func_name>"; + // <class-name> is returned by fromClass(). + string inMemFunc(const char* func_name) const; + + // Returns this class name. + virtual string fromClass() const {return ("IdComponent");} + #endif // DOXYGEN_SHOULD_SKIP_THIS // Destructor @@ -89,7 +98,7 @@ class H5_DLLCPP IdComponent { hid_t p_get_region(void *ref, H5R_type_t ref_type) const; // Verifies that the given id is valid. - bool p_valid_id(hid_t obj_id) const; + bool p_valid_id(const hid_t obj_id) const; #endif // DOXYGEN_SHOULD_SKIP_THIS diff --git a/c++/src/H5IntType.h b/c++/src/H5IntType.h index efbed39..ab43d0f 100644 --- a/c++/src/H5IntType.h +++ b/c++/src/H5IntType.h @@ -33,6 +33,9 @@ class H5_DLLCPP IntType : public AtomType { // Sets the sign proprety for an integer type. void setSign( H5T_sign_t sign ) const; + // Returns this class name + virtual string fromClass () const { return("IntType"); } + // Default constructor IntType(); diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 2ef3345..2ca26c9 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -327,7 +327,12 @@ void H5Object::flush(H5F_scope_t scope ) const //-------------------------------------------------------------------------- string H5Object::getFileName() const { - return(p_get_file_name()); + try { + return(p_get_file_name()); + } + catch (IdComponentException E) { + throw FileIException("H5Object::getFileName", E.getDetailMsg()); + } } //-------------------------------------------------------------------------- diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index c4b96c7..b448830 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -112,6 +112,7 @@ void PropList::copy( const PropList& like_plist ) // Function: PropList::operator= ///\brief Assignment operator. ///\param rhs - IN: Reference to the existing property list +///\return Reference to PropList instance ///\exception H5::PropListIException // Description // Makes a copy of the property list on the right hand side @@ -320,6 +321,7 @@ void PropList::getProperty(const char* name, void* value) const /// accepts. ///\param name - IN: Name of property to query - \c char pointer ///\return The property that is a \c std::string. +///\exception H5::PropListIException // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- string PropList::getProperty(const char* name) const @@ -344,7 +346,7 @@ string PropList::getProperty(const char* name) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function only in what arguments it /// accepts. -///\param name - IN: Name of property to query - \c str::string +///\param name - IN: Name of property to query - \c std::string ///\param value - OUT: Pointer to the buffer for the property value // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- diff --git a/c++/src/H5StrType.h b/c++/src/H5StrType.h index 9e4483e..fbf4ac4 100644 --- a/c++/src/H5StrType.h +++ b/c++/src/H5StrType.h @@ -46,6 +46,9 @@ class H5_DLLCPP StrType : public AtomType { // Defines the storage mechanism for character strings. void setStrpad(H5T_str_t strpad) const; + // Returns this class name + virtual string fromClass () const { return ("StrType"); } + // default constructor StrType(); diff --git a/c++/src/H5VarLenType.h b/c++/src/H5VarLenType.h index ded95c6..e93e6fb 100644 --- a/c++/src/H5VarLenType.h +++ b/c++/src/H5VarLenType.h @@ -28,6 +28,9 @@ class H5_DLLCPP VarLenType : public DataType { // on the specified base type. VarLenType(const DataType* base_type); + // Returns this class name + virtual string fromClass () const { return ("VarLenType"); } + // Copy constructor: makes copy of the original object. VarLenType( const VarLenType& original ); |