diff options
Diffstat (limited to 'c++/src')
-rw-r--r-- | c++/src/H5AbstractDs.cpp | 1 | ||||
-rw-r--r-- | c++/src/H5ArrayType.cpp | 148 | ||||
-rw-r--r-- | c++/src/H5ArrayType.h | 13 | ||||
-rw-r--r-- | c++/src/H5CompType.cpp | 3 |
4 files changed, 55 insertions, 110 deletions
diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index 6dee337..51d5f88 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -145,7 +145,6 @@ ArrayType AbstractDs::getArrayType() const // problem described in the JIRA issue HDFFV-7947 ArrayType arraytype; f_DataType_setId(&arraytype, p_get_type()); - arraytype.setArrayInfo(); return(arraytype); } catch (DataSetIException& E) { diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 37cd8c1..e11227a 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -35,7 +35,7 @@ namespace H5 { ///\brief Default constructor: Creates a stub ArrayType // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -ArrayType::ArrayType() : DataType(), rank(-1), dimensions(NULL) {} +ArrayType::ArrayType() : DataType() {} //-------------------------------------------------------------------------- // Function: ArrayType overloaded constructor @@ -44,23 +44,14 @@ ArrayType::ArrayType() : DataType(), rank(-1), dimensions(NULL) {} ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id ) -{ - setArrayInfo(); -} +ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id ) {} //-------------------------------------------------------------------------- // Function: ArrayType copy constructor ///\brief Copy constructor: makes a copy of the original ArrayType object. // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -ArrayType::ArrayType( const ArrayType& original ) : DataType( original ), rank(original.rank) -{ - // Allocate space then copy the dimensions from the original array - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = original.dimensions[i]; -} +ArrayType::ArrayType(const ArrayType& original) : DataType(original) {} //-------------------------------------------------------------------------- // Function: ArrayType overloaded constructor @@ -79,14 +70,8 @@ ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims) if (new_type_id < 0) throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed"); - // Set the id and rank for this object + // Set the id for this object id = new_type_id; - rank = ndims; - - // Allocate space then set the dimensions as provided by caller - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = dims[i]; } //-------------------------------------------------------------------------- @@ -115,26 +100,21 @@ ArrayType& ArrayType::operator=(const ArrayType& rhs) catch (Exception& close_error) { throw DataTypeIException(inMemFunc("operator="), close_error.getDetailMsg()); } - - // Copy the rank of the rhs array - rank = rhs.rank; - - // Allocate space then copy the dimensions from the rhs array - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = rhs.dimensions[i]; } return(*this); } //-------------------------------------------------------------------------- -// Function: ArrayType::setArrayInfo -///\brief Retrieves the rank and dimensions from the array datatype -/// and store the info in this ArrayType object. +// Function: ArrayType::getArrayNDims +///\brief Returns the number of dimensions for an array datatype. +///\return Number of dimensions ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - January 2016 +// Programmer Binh-Minh Ribler - May 2004 +// Modification +// Apr, 2016 +// Became const. //-------------------------------------------------------------------------- -void ArrayType::setArrayInfo() +int ArrayType::getArrayNDims() const { // Get the rank of the array type specified by id from the C API int ndims = H5Tget_array_ndims(id); @@ -143,52 +123,24 @@ void ArrayType::setArrayInfo() throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_ndims failed"); } - // Get the dimensions from the C API - hsize_t* dims; - dims = new hsize_t[ndims]; - if (dims != NULL) - { - // Get the dimensions - ndims = H5Tget_array_dims2(id, dims); - if (ndims < 0) - throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_dims2 failed"); - - // Store the array's info in memory - rank = ndims; - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = dims[i]; - delete []dims; - } -} // setArrayInfo - -//-------------------------------------------------------------------------- + return(ndims); +} +//---------------------------- Deprecated ---------------------------------- // Function: ArrayType::getArrayNDims -///\brief Returns the number of dimensions for an array datatype. -///\return Number of dimensions -///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - May 2004 -// Modification -// Modified to use setArrayInfo(). -// If rank is positive, return rank -// If rank is invalid but object has a valid identifier, obtain the -// rank and dimensions, store them in the object, and return rank -// Otherwise, i.e., rank is invalid and object doesn't have a -// valid identifier, throw an exception +// This non-const version of the above method is here for compatibility +// purposes and may be removed in the future. +// -BMR, Apr 2016 //-------------------------------------------------------------------------- int ArrayType::getArrayNDims() { - // Validate the id first, this object could be a default object - if (!p_valid_id(id)) - throw DataTypeIException("ArrayType::getArrayNDims", "ArrayType object is not a valid array type."); - - // If the array's info has not been stored, i.e. "rank" still has its - // initial value, -1, and "dimensions" is still NULL, retrieve rank and - // dimensions via the C API and store them in this ArrayType object. - if (rank < 0 && dimensions == NULL) - setArrayInfo(); + // Get the rank of the array type specified by id from the C API + int ndims = H5Tget_array_ndims(id); + if (ndims < 0) + { + throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_ndims failed"); + } - return(rank); + return(ndims); } //-------------------------------------------------------------------------- @@ -199,29 +151,34 @@ int ArrayType::getArrayNDims() ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - May 2004 // Modification -// Jan, 2016 -// Modified to use setArrayInfo(). -// If the array information has not been stored, retrieve rank and -// dimensions of the array type identified by "id" via the C API. -// Copy "dimensions" to the user's buffer +// Apr, 2016 +// Became const. //-------------------------------------------------------------------------- -int ArrayType::getArrayDims(hsize_t* dims) +int ArrayType::getArrayDims(hsize_t* dims) const { - // Validate the id first, this object could be a default object - if (!p_valid_id(id)) - throw DataTypeIException("ArrayType::getArrayDims", "ArrayType object is not a valid array type."); - - // If the array's info has not been stored, i.e. "rank" still has its - // initial value, -1, and "dimensions" is still NULL, retrieve rank and - // dimensions via the C API and store them in this ArrayType object. - if (rank < 0 && dimensions == NULL) - setArrayInfo(); + // Get the dimensions + int ndims = H5Tget_array_dims2(id, dims); + if (ndims < 0) + throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_dims2 failed"); - // Copy what's in "dimensions" to user's buffer "dims" - for (int i = 0; i < rank; i++) - dims[i] = dimensions[i]; + // Return the number of dimensions + return(ndims); +} +//---------------------------- Deprecated ---------------------------------- +// Function: ArrayType::getArrayDims +// This non-const version of the above method is here for compatibility +// purposes and may be removed in the future. +// -BMR, Apr 2016 +//-------------------------------------------------------------------------- +int ArrayType::getArrayDims(hsize_t* dims) +{ + // Get the dimensions + int ndims = H5Tget_array_dims2(id, dims); + if (ndims < 0) + throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_dims2 failed"); - return(rank); + // Return the number of dimensions + return(ndims); } //-------------------------------------------------------------------------- @@ -229,12 +186,7 @@ int ArrayType::getArrayDims(hsize_t* dims) ///\brief Properly terminates access to this array datatype. // Programmer Binh-Minh Ribler - May 2004 //-------------------------------------------------------------------------- -ArrayType::~ArrayType() -{ - // Free allocated memory - if (dimensions != NULL) - delete []dimensions; -} +ArrayType::~ArrayType() {} #ifndef H5_NO_NAMESPACE } // end namespace diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index ddbb5e2..eee430e 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -34,14 +34,13 @@ class H5_DLLCPP ArrayType : public DataType { // Assignment operator ArrayType& operator=(const ArrayType& rhs); - // Stores the rank and dimensions in memory. - void setArrayInfo(); - // Returns the number of dimensions of this array datatype. - int getArrayNDims(); + int getArrayNDims() const; + int getArrayNDims(); // deprecated // Returns the sizes of dimensions of this array datatype. - int getArrayDims(hsize_t* dims); + int getArrayDims(hsize_t* dims) const; + int getArrayDims(hsize_t* dims); // deprecated ///\brief Returns this class name. virtual H5std_string fromClass () const { return("ArrayType"); } @@ -57,10 +56,6 @@ class H5_DLLCPP ArrayType : public DataType { // Default constructor ArrayType(); - - private: - int rank; // Rank of the array - hsize_t* dimensions; // Sizes of the array dimensions }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 5668ec3..4585516 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -249,9 +249,8 @@ DataType CompType::getMemberDataType( unsigned member_num ) const ArrayType CompType::getMemberArrayType( unsigned member_num ) const { try { - ArrayType arraytype; + ArrayType arraytype(p_get_member_type(member_num)); f_DataType_setId(&arraytype, p_get_member_type(member_num)); - arraytype.setArrayInfo(); return(arraytype); } catch (DataTypeIException& E) { |