//-------------------------------------------------------------------------- // Function: AbstractDs::getTypeClass ///\brief Returns the class of the datatype that is used by this /// object, which can be a dataset or an attribute. ///\return Datatype class identifier ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- 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 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_id); if( type_class != H5T_NO_CLASS ) return( type_class ); else { if (fromClass() == "DataSet") throw DataTypeIException("DataSet::getTypeClass", "H5Tget_class returns H5T_NO_CLASS"); else if (fromClass() == "Attribute") throw DataTypeIException("Attribute::getTypeClass", "H5Tget_class returns H5T_NO_CLASS"); } }
//-------------------------------------------------------------------------- // Function: FloatType::getFields ///\brief Retrieves floating point datatype bit field information. ///\param spos - OUT: Retrieved floating-point sign bit ///\param epos - OUT: Retrieved exponent bit-position ///\param esize - OUT: Retrieved size of exponent, in bits ///\param mpos - OUT: Retrieved mantissa bit-position ///\param msize - OUT: Retrieved size of mantissa, in bits ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void FloatType::getFields(size_t& spos, size_t& epos, size_t& esize, size_t& mpos, size_t& msize) const { herr_t ret_value = H5Tget_fields(id, &spos, &epos, &esize, &mpos, &msize); if (ret_value < 0) { throw DataTypeIException("FloatType::getFields", "H5Tget_fields failed"); } }
//-------------------------------------------------------------------------- // Function: FloatType::setFields ///\brief Sets locations and sizes of floating point bit fields. ///\param spos - OUT: Sign position, i.e., the bit offset of the /// floating-point sign bit. ///\param epos - OUT: Exponent bit position ///\param esize - OUT: Size of exponent, in bits ///\param mpos - OUT: Mantissa bit-position ///\param msize - OUT: Size of mantissa, in bits ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void FloatType::setFields(size_t spos, size_t epos, size_t esize, size_t mpos, size_t msize) const { herr_t ret_value = H5Tset_fields(id, spos, epos, esize, mpos, msize); if (ret_value < 0) { throw DataTypeIException("FloatType::setFields", "H5Tset_fields failed"); } }
//-------------------------------------------------------------------------- // Function: FloatType::setNorm ///\brief Sets the mantissa normalization of a floating-point datatype. ///\param norm - IN: Mantissa normalization type ///\exception H5::DataTypeIException ///\par Description /// Valid values for normalization type include: /// \li \c H5T_NORM_IMPLIED (0) - MSB of mantissa is not stored /// \li \c H5T_NORM_MSBSET (1) - MSB of mantissa is always 1 /// \li \c H5T_NORM_NONE (2) - Mantissa is not normalized // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void FloatType::setNorm(H5T_norm_t norm) const { herr_t ret_value = H5Tset_norm(id, norm); if (ret_value < 0) { throw DataTypeIException("FloatType::setNorm", "H5Tset_norm failed"); } }
//-------------------------------------------------------------------------- // Function: FloatType::setEbias ///\brief Sets the exponent bias of a floating-point type. ///\param ebias - Exponent bias value ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void FloatType::setEbias(size_t ebias) const { herr_t ret_value = H5Tset_ebias(id, ebias); if (ret_value < 0) { throw DataTypeIException("FloatType::setEbias", "H5Tset_ebias failed"); } }
//-------------------------------------------------------------------------- // Function: AbstractDs::getVarLenType ///\brief Returns the floating-point datatype of this abstract dataset, /// which can be a dataset or an attribute. ///\return VarLenType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - Jul, 2005 //-------------------------------------------------------------------------- VarLenType AbstractDs::getVarLenType() const { // 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()); } }
//-------------------------------------------------------------------------- // Function: ArrayType overloaded constructor ///\brief Creates an ArrayType object using an existing id. ///\param existing_id - IN: Id of an existing datatype ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id ) { // Get the rank of the existing array and store it in this array rank = H5Tget_array_ndims(existing_id); if (rank < 0) { throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims failed"); } // Allocate space for the dimensions dimensions = new hsize_t[rank]; // Get the dimensions of the existing array and store it in this array int ret_value = H5Tget_array_dims2(id, dimensions); if (ret_value < 0) throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_dims2 failed"); }
//-------------------------------------------------------------------------- // Function: FloatType::setInpad ///\brief Fills unused internal floating point bits. ///\param inpad - IN: Internal padding type ///\exception H5::DataTypeIException ///\par Description /// If any internal bits of a floating point type are unused /// (that is, those significant bits which are not part of the /// sign, exponent, or mantissa), then they will be filled /// according to the padding value provided by \a inpad. ///\par /// Valid values for normalization type include: /// \li \c H5T_PAD_ZERO (0) - Set background to zeros /// \li \c H5T_PAD_ONE (1) - Set background to ones /// \li \c H5T_PAD_BACKGROUND (2) - Leave background alone // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void FloatType::setInpad(H5T_pad_t inpad) const { herr_t ret_value = H5Tset_inpad(id, inpad); if (ret_value < 0) { throw DataTypeIException("FloatType::setInpad", "H5Tset_inpad failed"); } }
//-------------------------------------------------------------------------- // Function: EnumType::getMemberValue ///\brief Retrieves the value of a member in this enumeration datatype, /// given the member's index. ///\param memb_no - IN: Index of the queried member ///\param value - OUT: Pointer to the retrieved value ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void EnumType::getMemberValue( unsigned memb_no, void *value ) const { // Call C routine H5Tget_member_value to get the datatype member's value hid_t ret_value = H5Tget_member_value( id, memb_no, value ); if( ret_value < 0 ) { throw DataTypeIException("EnumType::getMemberValue", "H5Tget_member_value failed"); } }
//-------------------------------------------------------------------------- // Function: EnumType::valueOf ///\brief Retrieves the value corresponding to a member of this /// enumeration datatype, given the member's name. ///\param name - IN: Name of the queried member ///\param value - OUT: Pointer to the retrieved value ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void EnumType::valueOf( const char* name, void *value ) const { // Calls C routine H5Tenum_valueof to get the enum datatype value herr_t ret_value = H5Tenum_valueof( id, name, value ); if( ret_value < 0 ) { throw DataTypeIException("EnumType::valueOf", "H5Tenum_valueof failed"); } }
//-------------------------------------------------------------------------- // Function: EnumType::insert ///\brief Inserts a new member to this enumeration datatype. ///\param name - IN: Name of the new member ///\param value - IN: Pointer to the value of the new member ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void EnumType::insert( const char* name, void *value ) const { // Calls C routine H5Tenum_insert to insert the new enum datatype member. herr_t ret_value = H5Tenum_insert( id, name, value ); if( ret_value < 0 ) { throw DataTypeIException("EnumType::insert", "H5Tenum_insert failed"); } }
//-------------------------------------------------------------------------- // Function: AbstractDs::getEnumType ///\brief Returns the enumeration datatype of this abstract dataset which /// can be a dataset or an attribute. ///\return EnumType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- EnumType AbstractDs::getEnumType() const { // 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; f_DataType_setId(&enumtype, p_get_type()); return(enumtype); } catch (DataSetIException& E) { throw DataTypeIException("DataSet::getEnumType", E.getDetailMsg()); } catch (AttributeIException& E) { throw DataTypeIException("Attribute::getEnumType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: StrType::setStrpad ///\brief Defines the storage mechanism for this string datatype. ///\param strpad - IN: String padding type ///\exception H5::DataTypeIException ///\par Description /// For detail, please refer to the C layer Reference Manual at: /// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5T.html#Datatype-SetStrpad // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void StrType::setStrpad( H5T_str_t strpad ) const { herr_t ret_value = H5Tset_strpad( id, strpad ); if( ret_value < 0 ) { throw DataTypeIException("StrType::setStrpad", "H5Tset_strpad failed"); } }
//-------------------------------------------------------------------------- // Function: VarLenType overloaded constructor ///\brief Creates a new variable-length datatype based on the specified /// \a base_type. ///\param base_type - IN: Pointer to existing datatype ///\exception H5::DataTypeIException // Description // DataType passed by pointer to avoid clashing with copy // constructor. // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- VarLenType::VarLenType(const DataType* base_type) : DataType() { id = H5Tvlen_create(base_type->getId()); if (id < 0) { throw DataTypeIException("VarLenType constructor", "H5Tvlen_create returns negative value"); } }
//-------------------------------------------------------------------------- // Function: StrType::setCset ///\brief Sets character set to be used. ///\param cset - IN: character set type, which can be: /// \li \c H5T_CSET_ASCII (0) - Character set is US ASCII. ///\note /// ASCII and UTF-8 Unicode are the only currently supported character /// encodings. Extended ASCII encodings (for example, ISO 8859) are not /// supported. This encoding policy is not enforced by the HDF5 Library. /// Using encodings other than ASCII and UTF-8 can lead to compatibility /// and usability problems. See the C API entry H5Pset_char_encoding for /// more information. ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void StrType::setCset( H5T_cset_t cset ) const { herr_t ret_value = H5Tset_cset( id, cset ); if( ret_value < 0 ) { throw DataTypeIException("StrType::setCset", "H5Tset_cset failed"); } }
//-------------------------------------------------------------------------- // Function: IntType::getSign ///\brief Sets the sign property for an integer type. ///\param sign - IN: Sign type ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void IntType::setSign( H5T_sign_t sign ) const { // Call C routine to set the sign property herr_t ret_value = H5Tset_sign( id, sign ); if( ret_value < 0 ) { throw DataTypeIException("IntType::setSign", "H5Tset_sign failed"); } }
//-------------------------------------------------------------------------- // Function: CompType::setSize ///\brief Sets the total size for this compound datatype. ///\param size - IN: Size to set ///\exception H5::DataTypeIException // Note // H5Tset_size works on atom datatypes and compound datatypes only // Programmer Binh-Minh Ribler - 2014 //-------------------------------------------------------------------------- void CompType::setSize(size_t size) const { // Call C routine H5Tset_size to set the total size herr_t ret_value = H5Tset_size(id, size); if (ret_value < 0) { throw DataTypeIException("CompType::setSize", "H5Tset_size failed"); } }
//-------------------------------------------------------------------------- // Function: CompType::pack ///\brief Recursively removes padding from within a compound datatype. /// ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void CompType::pack() const { // Calls C routine H5Tpack to remove padding herr_t ret_value = H5Tpack( id ); if( ret_value < 0 ) { throw DataTypeIException("CompType::pack", "H5Tpack failed"); } }
//-------------------------------------------------------------------------- // Function: FloatType::getEbias ///\brief Retrieves the exponent bias of a floating-point type. ///\return Exponent bias ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- size_t FloatType::getEbias() const { size_t ebias = H5Tget_ebias(id); // Returns the bias if successful if (ebias == 0) { throw DataTypeIException("FloatType::getEbias", "H5Tget_ebias failed - returned exponent bias as 0"); } return(ebias); }
//-------------------------------------------------------------------------- // Function: CompType::getMemberIndex ///\brief Returns the index of a member in this compound datatype. ///\param name - IN: Name of the member ///\return Index of member ///\exception H5::DataTypeIException ///\par Description /// Members are stored in no particular order with numbers 0 /// through N-1, where N is the value returned by the member /// function \c CompType::getNmembers. // Programmer Binh-Minh Ribler - May 16, 2002 //-------------------------------------------------------------------------- int CompType::getMemberIndex(const char* name) const { int member_index = H5Tget_member_index(id, name); if( member_index < 0 ) { throw DataTypeIException("CompType::getMemberIndex", "H5Tget_member_index returns negative value"); } return( member_index ); }
//-------------------------------------------------------------------------- // Function: CompType::getMemberClass ///\brief Gets the type class of the specified member. ///\param member_num - IN: Zero-based index of the member ///\return Type class of the member ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 // Modification // Modified to use H5Tget_member_class instead. - Jul, 2005 //-------------------------------------------------------------------------- H5T_class_t CompType::getMemberClass( unsigned member_num ) const { H5T_class_t member_class = H5Tget_member_class(id, member_num); if( member_class == H5T_NO_CLASS ) { throw DataTypeIException("CompType::getMemberClass", "H5Tget_member_class returns H5T_NO_CLASS"); } return(member_class); }
//-------------------------------------------------------------------------- // Function: CompType::getNmembers ///\brief Returns the number of members in this compound datatype. ///\return Number of members ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- int CompType::getNmembers() const { int num_members = H5Tget_nmembers( id ); if( num_members < 0 ) { throw DataTypeIException("CompType::getNmembers", "H5Tget_nmembers returns negative number of members"); } return( num_members ); }
//-------------------------------------------------------------------------- // Function: CompType::getMemberVarLenType ///\brief Returns the variable length datatype of the specified member /// in this compound datatype. ///\param member_num - IN: Zero-based index of the member ///\return VarLenType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - Jul, 2005 //-------------------------------------------------------------------------- VarLenType CompType::getMemberVarLenType( unsigned member_num ) const { try { VarLenType varlentype(p_get_member_type(member_num)); return(varlentype); } catch (DataTypeIException E) { throw DataTypeIException("CompType::getMemberVarLenType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: CompType::getMemberStrType ///\brief Returns the string datatype of the specified member in this /// compound datatype. ///\param member_num - IN: Zero-based index of the member ///\return StrType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- StrType CompType::getMemberStrType( unsigned member_num ) const { try { StrType strtype(p_get_member_type(member_num)); return(strtype); } catch (DataTypeIException E) { throw DataTypeIException("CompType::getMemberStrType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: StrType::getCset ///\brief Retrieves the character set type of this string datatype. ///\return Character set type, which can be: /// \li \c H5T_CSET_ASCII (0) - Character set is US ASCII. ///\note /// ASCII and UTF-8 Unicode are the only currently supported character /// encodings. Extended ASCII encodings (for example, ISO 8859) are not /// supported. This encoding policy is not enforced by the HDF5 Library. /// Using encodings other than ASCII and UTF-8 can lead to compatibility /// and usability problems. See the C API entry H5Pset_char_encoding for /// more information. ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5T_cset_t StrType::getCset() const { H5T_cset_t cset = H5Tget_cset( id ); // Returns a valid character set type if successful if( cset == H5T_CSET_ERROR ) { throw DataTypeIException("StrType::getCset", "H5Tget_cset failed"); } return( cset ); }
//-------------------------------------------------------------------------- // Function: AbstractDs::getArrayType ///\brief Returns the array datatype of this abstract dataset which /// can be a dataset or an attribute. ///\return ArrayType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - Jul, 2005 //-------------------------------------------------------------------------- ArrayType AbstractDs::getArrayType() const { // 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 { // Create ArrayType and set values this way to work around the // problem described in the JIRA issue HDFFV-7947 ArrayType arraytype; f_DataType_setId(&arraytype, p_get_type()); return(arraytype); } catch (DataSetIException& E) { throw DataTypeIException("DataSet::getArrayType", E.getDetailMsg()); } catch (AttributeIException& E) { throw DataTypeIException("Attribute::getArrayType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: CompType::getMemberFloatType ///\brief Returns the floating-point datatype of the specified member /// in this compound datatype. ///\param member_num - IN: Zero-based index of the member ///\return FloatType instance ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- 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) { throw DataTypeIException("CompType::getMemberFloatType", E.getDetailMsg()); } }
//-------------------------------------------------------------------------- // Function: IntType::getSign ///\brief Retrieves the sign type for an integer type. ///\return Valid sign type ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5T_sign_t IntType::getSign() const { H5T_sign_t type_sign = H5Tget_sign( id ); // C routine // Returns a valid sign type if no errors if( type_sign == H5T_SGN_ERROR ) { throw DataTypeIException("IntType::getSign", "H5Tget_sign failed - returned H5T_SGN_ERROR for the sign type"); } return( type_sign ); }
//-------------------------------------------------------------------------- // Function: StrType::getStrpad ///\brief Retrieves the storage mechanism for of this string datatype. ///\return String storage mechanism, which can be: /// \li \c H5T_STR_NULLTERM (0) - Null terminate (as C does) /// \li \c H5T_STR_NULLPAD (0) - Pad with zeros /// \li \c H5T_STR_SPACEPAD (0) - pad with spaces (as FORTRAN does) ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5T_str_t StrType::getStrpad() const { H5T_str_t strpad = H5Tget_strpad( id ); // Returns a valid string padding type if successful if( strpad == H5T_STR_ERROR ) { throw DataTypeIException("StrType::getStrpad", "H5Tget_strpad failed - returned H5T_STR_ERROR"); } return( strpad ); }
//-------------------------------------------------------------------------- // Function: CompType::getMemberName ///\brief Returns the name of a member in this compound datatype. ///\param member_num - IN: Zero-based index of the member ///\return Name of member ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5std_string CompType::getMemberName( unsigned member_num ) const { char* member_name_C = H5Tget_member_name( id, member_num ); if( member_name_C == NULL ) // NULL means failure { throw DataTypeIException("CompType::getMemberName", "H5Tget_member_name returns NULL for member name"); } H5std_string member_name = H5std_string(member_name_C); // convert C string to string H5free_memory(member_name_C); // free the C string return( member_name ); // return the member name string }