summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2014-10-02 04:05:38 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2014-10-02 04:05:38 (GMT)
commit9c9326c7debc3b4f32602ec21cc67cfccafa6fc0 (patch)
tree5860b1568bae4fb51cd4051191e48a729e368cbc /c++/src
parent40c17513405c1056c90b7324a954df2a217efd65 (diff)
downloadhdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.zip
hdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.tar.gz
hdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.tar.bz2
[svn-r25653] Purpose: Fixed HDFFV-4259
Description: - Used H5I_INVALID_HID instead of 0 to initialized member "id" in classes that represent HDF5 objects. For PropList, H5P_DEFAULT has to be used instead of H5I_INVALID_HID. - Added try/catch block to some dynamically allocating memory code and re-throw the bad_alloc exception with a message informing the location of the failure. (merged from trunk-r25640) Purpose: Fixed HDFFV-8852 Description: H5F_ACC_CREAT was included in the C++ API while the C library doesn't allow it yet. Possibly, in the future, but not now. In addition, the two flags H5F_ACC_RDONLY and H5F_ACC_RDWR were missing from the documentation, causing confusion that appending is not supported. Solution: - Removed H5F_ACC_CREAT from the function until the C library support it - Added H5F_ACC_RDONLY and H5F_ACC_RDWR to the comments to update the documentation (merged from trunk-r25632) Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) SunOS 5.11 (emu)
Diffstat (limited to 'c++/src')
-rw-r--r--c++/src/H5ArrayType.cpp53
-rw-r--r--c++/src/H5Attribute.cpp12
-rw-r--r--c++/src/H5CommonFG.cpp3
-rw-r--r--c++/src/H5DataSet.cpp8
-rw-r--r--c++/src/H5DataSpace.cpp2
-rw-r--r--c++/src/H5DataSpace.h12
-rw-r--r--c++/src/H5DataType.cpp8
-rw-r--r--c++/src/H5File.cpp18
-rw-r--r--c++/src/H5Group.cpp8
-rw-r--r--c++/src/H5IdComponent.cpp4
-rw-r--r--c++/src/H5Location.cpp3
-rw-r--r--c++/src/H5PropList.cpp6
12 files changed, 80 insertions, 57 deletions
diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp
index 852658b..8807dca 100644
--- a/c++/src/H5ArrayType.cpp
+++ b/c++/src/H5ArrayType.cpp
@@ -54,15 +54,16 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
rank = H5Tget_array_ndims(existing_id);
if (rank < 0)
{
- throw DataTypeIException("ArrayType overloaded constructor", "H5Tget_array_ndims failed");
+ throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims failed");
}
- // Get the dimensions of the existing array and store it in this array
- dimensions = new hsize_t[rank];
- //hsize_t rdims2[H5S_MAX_RANK];
- int ret_value = H5Tget_array_dims2(id, dimensions);
- if (ret_value < 0)
- throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 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");
}
//--------------------------------------------------------------------------
@@ -72,10 +73,13 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
//--------------------------------------------------------------------------
ArrayType::ArrayType( const ArrayType& original ) : DataType( original )
{
- rank = original.rank;
- dimensions = new hsize_t[rank];
- for (int i = 0; i < rank; i++)
- dimensions[i] = original.dimensions[i];
+ // Copy the rank of the original array
+ 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];
}
//--------------------------------------------------------------------------
@@ -90,14 +94,19 @@ ArrayType::ArrayType( const ArrayType& original ) : DataType( original )
//--------------------------------------------------------------------------
ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims) : DataType()
{
- hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims);
- if (new_type_id < 0)
- throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed");
- id = new_type_id;
- rank = ndims;
- dimensions = new hsize_t[rank];
- for (int i = 0; i < rank; i++)
- dimensions[i] = dims[i];
+ // Call C API to create an array data type
+ hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims);
+ if (new_type_id < 0)
+ throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed");
+
+ // Set the id and rank 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];
}
//--------------------------------------------------------------------------
@@ -132,19 +141,19 @@ int ArrayType::getArrayNDims()
//--------------------------------------------------------------------------
int ArrayType::getArrayDims(hsize_t* dims)
{
- // if the array's dimensions have not been stored, retrieve them via C API
+ // If the array's dimensions have not been stored, retrieve them via C API
if (dimensions == NULL)
{
int ndims = H5Tget_array_dims2(id, dims);
if (ndims < 0)
throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed");
- // store the array's info in memory
+ // 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];
}
- // otherwise, simply copy what's in 'dimensions' to 'dims'
+ // Otherwise, simply copy what's in 'dimensions' to 'dims'
for (int i = 0; i < rank; i++)
dims[i] = dimensions[i];
return(rank);
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 1182b69..0c135a9 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -50,7 +50,7 @@ class H5_DLLCPP H5Object; // forward declaration for UserData4Aiterate
///\brief Default constructor: Creates a stub attribute
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
-Attribute::Attribute() : AbstractDs(), IdComponent(), id(0) {}
+Attribute::Attribute() : AbstractDs(), IdComponent(), id(H5I_INVALID_HID) {}
//--------------------------------------------------------------------------
// Function: Attribute copy constructor
@@ -162,13 +162,13 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
// Mar 2008
// Corrected a misunderstanding that H5Aread would allocate
// space for the buffer. Obtained the attribute size and
-// allocated memory properly. - BMR
+// allocated memory properly. -BMR
// Apr 2009
-// Used getInMemDataSize to get attribute data size. - BMR
+// Used getInMemDataSize to get attribute data size. -BMR
// Jul 2009
// Divided into specific private functions for fixed- and
// variable-len string data: p_read_fixed_len and
-// p_read_variable_len. This should improve readability.
+// p_read_variable_len. This should improve readability. -BMR
//--------------------------------------------------------------------------
void Attribute::read(const DataType& mem_type, H5std_string& strg) const
{
@@ -586,7 +586,7 @@ void Attribute::p_read_fixed_len(const DataType& mem_type, H5std_string& strg) c
// Modification
// Jul 2009
// Separated the variable length case from the original
-// Attribute::read
+// Attribute::read. -BMR
//--------------------------------------------------------------------------
void Attribute::p_read_variable_len(const DataType& mem_type, H5std_string& strg) const
{
@@ -648,7 +648,7 @@ void Attribute::close()
throw AttributeIException("Attribute::close", "H5Aclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp
index d296db4..8ee88d6 100644
--- a/c++/src/H5CommonFG.cpp
+++ b/c++/src/H5CommonFG.cpp
@@ -33,6 +33,9 @@
#include "H5Alltypes.h"
#include "H5private.h" // for HDstrcpy
+#include <iostream>
+using namespace std;
+
// There are a few comments that are common to most of the functions
// defined in this file so they are listed here.
// - getLocId is called by all functions, that call a C API, to get
diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp
index 5e4a682..83621f5 100644
--- a/c++/src/H5DataSet.cpp
+++ b/c++/src/H5DataSet.cpp
@@ -52,7 +52,7 @@ namespace H5 {
///\brief Default constructor: creates a stub DataSet.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataSet::DataSet() : AbstractDs(), H5Object(), id(0) {}
+DataSet::DataSet() : AbstractDs(), H5Object(), id(H5I_INVALID_HID) {}
//--------------------------------------------------------------------------
// Function: DataSet overloaded constructor
@@ -94,7 +94,7 @@ DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object(origi
// Jul, 2008
// Added for application convenience.
//--------------------------------------------------------------------------
-DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(0)
+DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereferenced");
}
@@ -112,7 +112,7 @@ DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type) :
// Jul, 2008
// Added for application convenience.
//--------------------------------------------------------------------------
-DataSet::DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(0)
+DataSet::DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference");
}
@@ -786,7 +786,7 @@ void DataSet::close()
throw DataSetIException("DataSet::close", "H5Dclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index 6ad8c8d..20b4e5e 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -630,7 +630,7 @@ void DataSpace::close()
throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5DataSpace.h b/c++/src/H5DataSpace.h
index 75d4ff8..fd4b1d6 100644
--- a/c++/src/H5DataSpace.h
+++ b/c++/src/H5DataSpace.h
@@ -33,6 +33,12 @@ class H5_DLLCPP DataSpace : public IdComponent {
// Creates a simple dataspace
DataSpace(int rank, const hsize_t * dims, const hsize_t * maxdims = NULL);
+ // Creates a DataSpace object using an existing dataspace id.
+ DataSpace(const hid_t space_id);
+
+ // Copy constructor: makes a copy of the original DataSpace object.
+ DataSpace(const DataSpace& original);
+
// Assignment operator
DataSpace& operator=( const DataSpace& rhs );
@@ -109,12 +115,6 @@ class H5_DLLCPP DataSpace : public IdComponent {
///\brief Returns this class name.
virtual H5std_string fromClass () const { return("DataSpace"); }
- // Creates a DataSpace object using an existing dataspace id.
- DataSpace(const hid_t space_id);
-
- // Copy constructor: makes a copy of the original DataSpace object.
- DataSpace(const DataSpace& original);
-
// Gets the dataspace id.
virtual hid_t getId() const;
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index 08d1778..0d7d61b 100644
--- a/c++/src/H5DataType.cpp
+++ b/c++/src/H5DataType.cpp
@@ -53,7 +53,7 @@ namespace H5 {
///\brief Default constructor: Creates a stub datatype
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataType::DataType() : H5Object(), id(0) {}
+DataType::DataType() : H5Object(), id(H5I_INVALID_HID) {}
//--------------------------------------------------------------------------
// Function: DataType overloaded constructor
@@ -104,7 +104,7 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object()
// Jul, 2008
// Added for application convenience.
//--------------------------------------------------------------------------
-DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(0)
+DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereference");
}
@@ -122,7 +122,7 @@ DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type)
// Jul, 2008
// Added for application convenience.
//--------------------------------------------------------------------------
-DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(0)
+DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference");
}
@@ -708,7 +708,7 @@ void DataType::close()
throw DataTypeIException(inMemFunc("close"), "H5Tclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp
index 6e04fc1..0620070 100644
--- a/c++/src/H5File.cpp
+++ b/c++/src/H5File.cpp
@@ -50,7 +50,7 @@ namespace H5 {
///\brief Default constructor: creates a stub H5File object.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-H5File::H5File() : H5Location(), id(0) {}
+H5File::H5File() : H5Location(), id(H5I_INVALID_HID) {}
//--------------------------------------------------------------------------
// Function: H5File overloaded constructor
@@ -69,6 +69,10 @@ H5File::H5File() : H5Location(), id(0) {}
/// the file.
/// \li \c H5F_ACC_EXCL - Fail if file already exists.
/// \c H5F_ACC_TRUNC and \c H5F_ACC_EXCL are mutually exclusive
+/// \li \c H5F_ACC_RDONLY - Open file as read-only, if it already
+/// exists, and fail, otherwise
+/// \li \c H5F_ACC_RDWR - Open file for read/write, if it already
+/// exists, and fail, otherwise
/// \li \c H5F_ACC_DEBUG - print debug information. This flag is
/// used only by HDF5 library developers; it is neither
/// tested nor supported for use in applications.
@@ -82,7 +86,7 @@ H5File::H5File() : H5Location(), id(0) {}
// to catch then re-throw it. -BMR 2013/03/21
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(0)
+H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(H5I_INVALID_HID)
{
try {
p_get_file(name, flags, create_plist, access_plist);
@@ -107,7 +111,7 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c
// to catch then re-throw it. -BMR 2013/03/21
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(0)
+H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(H5I_INVALID_HID)
{
try {
p_get_file(name.c_str(), flags, create_plist, access_plist);
@@ -121,12 +125,15 @@ H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPro
// This function is private and contains common code between the
// constructors taking a string or a char*
// Programmer Binh-Minh Ribler - 2000
+// Modification
+// - removed H5F_ACC_CREAT because H5Fcreate will fail with
+// H5F_ACC_CREAT. - BMR, Sep 17, 2014
//--------------------------------------------------------------------------
void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist)
{
// These bits only set for creation, so if any of them are set,
// create the file.
- if( flags & (H5F_ACC_CREAT|H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG))
+ if( flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG))
{
hid_t create_plist_id = create_plist.getId();
hid_t access_plist_id = access_plist.getId();
@@ -147,6 +154,7 @@ void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPro
}
}
}
+
#endif // DOXYGEN_SHOULD_SKIP_THIS
//--------------------------------------------------------------------------
@@ -598,7 +606,7 @@ void H5File::close()
throw FileIException("H5File::close", "H5Fclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp
index 38f8b9f..41e7fc6 100644
--- a/c++/src/H5Group.cpp
+++ b/c++/src/H5Group.cpp
@@ -51,7 +51,7 @@ namespace H5 {
///\brief Default constructor: creates a stub Group.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-Group::Group() : H5Object(), id(0) {}
+Group::Group() : H5Object(), id(H5I_INVALID_HID) {}
//--------------------------------------------------------------------------
// Function: Group copy constructor
@@ -99,7 +99,7 @@ Group::Group(const hid_t existing_id) : H5Object()
/// is a datatype that has been named by DataType::commit.
// Programmer Binh-Minh Ribler - Oct, 2006
//--------------------------------------------------------------------------
-Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(0)
+Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereference");
}
@@ -113,7 +113,7 @@ Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Ob
///\exception H5::ReferenceException
// Programmer Binh-Minh Ribler - Oct, 2006
//--------------------------------------------------------------------------
-Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(0)
+Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(H5I_INVALID_HID)
{
id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference");
}
@@ -179,7 +179,7 @@ void Group::close()
throw GroupIException("Group::close", "H5Gclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index 99a8dc4..64297ee 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -145,7 +145,7 @@ int IdComponent::getCounter() const
//--------------------------------------------------------------------------
H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id)
{
- if (obj_id == 0)
+ if (obj_id <= 0)
return H5I_BADID; // invalid
H5I_type_t id_type = H5Iget_type(obj_id);
if (id_type <= H5I_BADID || id_type >= H5I_NTYPES)
@@ -339,7 +339,7 @@ H5std_string IdComponent::p_get_file_name() const
//--------------------------------------------------------------------------
bool IdComponent::p_valid_id(const hid_t obj_id)
{
- if (obj_id == 0)
+ if (obj_id <= 0)
return false;
H5I_type_t id_type = H5Iget_type(obj_id);
diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp
index 80e1462..169ddf5 100644
--- a/c++/src/H5Location.cpp
+++ b/c++/src/H5Location.cpp
@@ -33,6 +33,9 @@
#include "H5DataSet.h"
#include "H5Attribute.h"
#include "H5private.h" // for HDmemset
+#include <iostream>
+using namespace std;
+
#ifndef H5_NO_NAMESPACE
namespace H5 {
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 0b740d8..56743f7 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -46,7 +46,7 @@ const PropList PropList::DEFAULT;
///\brief Default constructor: creates a stub property list object.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-PropList::PropList() : IdComponent(), id(0) {}
+PropList::PropList() : IdComponent(), id(H5P_DEFAULT) {}
//--------------------------------------------------------------------------
// Function: PropList copy constructor
@@ -74,7 +74,7 @@ PropList::PropList(const PropList& original) : IdComponent(original)
//--------------------------------------------------------------------------
PropList::PropList( const hid_t plist_id ) : IdComponent()
{
- if (plist_id == 0)
+ if (plist_id <= 0)
id = H5P_DEFAULT;
H5I_type_t id_type = H5Iget_type(plist_id);
@@ -277,7 +277,7 @@ void PropList::close()
throw PropListIException(inMemFunc("close"), "H5Pclose failed");
}
// reset the id
- id = 0;
+ id = H5I_INVALID_HID;
}
}