summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2008-08-19 05:08:48 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2008-08-19 05:08:48 (GMT)
commitaa27e356e96e0f04e41e59f364fad884214d8fd0 (patch)
treebecaa4bc925f377f74d476c9ae57abb4d90e51bc /c++
parent3fa7ae10059b34c74ffadb5b5aa1621aa84ddfbf (diff)
downloadhdf5-aa27e356e96e0f04e41e59f364fad884214d8fd0.zip
hdf5-aa27e356e96e0f04e41e59f364fad884214d8fd0.tar.gz
hdf5-aa27e356e96e0f04e41e59f364fad884214d8fd0.tar.bz2
[svn-r15482] Description:
Added missing wrappers for H5Rdereference. Also, for these wrappers, improved exception handlings to report specific overloaded functions, where failure occurs. Will do the same for more functions later... Platforms tested: Linux 2.6 (kagiso) SunOS 5.10 (linew) FreeBSD (duty)
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5AbstractDs.cpp7
-rw-r--r--c++/src/H5AbstractDs.h3
-rw-r--r--c++/src/H5Attribute.cpp41
-rw-r--r--c++/src/H5CommonFG.h10
-rw-r--r--c++/src/H5DataSet.cpp70
-rw-r--r--c++/src/H5DataSet.h3
-rw-r--r--c++/src/H5DataSpace.cpp6
-rw-r--r--c++/src/H5DataType.cpp69
-rw-r--r--c++/src/H5DataType.h3
-rw-r--r--c++/src/H5DcreatProp.cpp16
-rw-r--r--c++/src/H5DxferProp.cpp2
-rw-r--r--c++/src/H5File.cpp14
-rw-r--r--c++/src/H5Group.cpp61
-rw-r--r--c++/src/H5Group.h3
-rw-r--r--c++/src/H5IdComponent.cpp20
-rw-r--r--c++/src/H5IdComponent.h9
-rw-r--r--c++/src/H5Object.cpp186
-rw-r--r--c++/src/H5Object.h18
-rw-r--r--c++/src/H5PropList.cpp6
19 files changed, 367 insertions, 180 deletions
diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp
index 26bf5ad..69b34f6 100644
--- a/c++/src/H5AbstractDs.cpp
+++ b/c++/src/H5AbstractDs.cpp
@@ -37,13 +37,6 @@ namespace H5 {
AbstractDs::AbstractDs(){}
//--------------------------------------------------------------------------
-// Function: AbstractDs default constructor
-///\brief Creates an AbstractDs instance using an existing id.
-// Programmer Binh-Minh Ribler - 2000
-//--------------------------------------------------------------------------
-//AbstractDs::AbstractDs(const hid_t ds_id){}
-
-//--------------------------------------------------------------------------
// Function: AbstractDs copy constructor
///\brief Copy constructor: makes a copy of the original AbstractDs object.
// Programmer Binh-Minh Ribler - 2000
diff --git a/c++/src/H5AbstractDs.h b/c++/src/H5AbstractDs.h
index 2d04b43..af8680e 100644
--- a/c++/src/H5AbstractDs.h
+++ b/c++/src/H5AbstractDs.h
@@ -75,9 +75,6 @@ class H5_DLLCPP AbstractDs {
// Default constructor
AbstractDs();
- // Constructor that takes an attribute id or a dataset id.
- //AbstractDs( const hid_t ds_id );
-
private:
// This member function is implemented by DataSet and Attribute.
virtual hid_t p_get_type() const = 0;
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 3f8fae9..8b42299 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -62,7 +62,7 @@ Attribute::Attribute() : AbstractDs(), IdComponent(), id(0) {}
// Jul, 08 No longer inherit data member 'id' from IdComponent.
// - bugzilla 1068
//--------------------------------------------------------------------------
-Attribute::Attribute( const Attribute& original ) : AbstractDs(), IdComponent()
+Attribute::Attribute(const Attribute& original) : AbstractDs(), IdComponent()
{
id = original.getId();
incRefCount(); // increment number of references to this id
@@ -160,6 +160,7 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
void Attribute::read( const DataType& mem_type, H5std_string& strg ) const
{
// Get the attribute size and allocate temporary C-string for C API
+ // NOTE: will be changed to use dataspace information instead of this API
hsize_t attr_size = H5Aget_storage_size(id);
if (attr_size <= 0)
{
@@ -287,6 +288,7 @@ H5std_string Attribute::getName( size_t buf_size ) const
H5std_string attr_name;
ssize_t name_size = getName( buf_size, attr_name );
return( attr_name );
+ // let caller catch exception if any
}
//--------------------------------------------------------------------------
@@ -300,7 +302,6 @@ H5std_string Attribute::getName( size_t buf_size ) const
//--------------------------------------------------------------------------
H5std_string Attribute::getName() const
{
-
// Try with 0 and NULL to get the name size
ssize_t name_size = H5Aget_name(id, 0, NULL);
@@ -328,36 +329,6 @@ H5std_string Attribute::getName() const
return(attr_name);
}
-#if 0
-//--------------------------------------------------------------------------
-// Function: Attribute::getObjType
-///\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, valid values are:
-/// \li \c H5R_OBJECT \tReference is an object reference.
-/// \li \c H5R_DATASET_REGION \tReference is a dataset region reference.
-///\return An object type, which can be one of the following:
-/// \li \c H5G_LINK (0) \tObject is a symbolic link.
-/// \li \c H5G_GROUP (1) \tObject is a group.
-/// \li \c H5G_DATASET (2) \tObject is a dataset.
-/// \li \c H5G_TYPE Object (3) \tis a named datatype
-///\exception H5::AttributeIException
-// Programmer Binh-Minh Ribler - Jul, 2008
-// Note:
-// H5G_loc checks args in H5Rget_obj_type, so attribute must
-// also be included.
-//--------------------------------------------------------------------------
-H5G_obj_t Attribute::getObjType(void *ref, H5R_type_t ref_type) const
-{
- try {
- return(p_get_refobj_type(ref, ref_type));
- }
- catch (IdComponentException E) {
- throw AttributeIException("Attribute::getObjType", E.getDetailMsg());
- }
-}
-#endif
-
//--------------------------------------------------------------------------
// Function: Attribute::getRefObjType
///\brief Retrieves the type of object that an object reference points to.
@@ -470,8 +441,10 @@ void Attribute::close()
{
throw AttributeIException("Attribute::close", "H5Aclose failed");
}
- // reset the id because the attribute that it represents is now closed
- id = 0;
+ // reset the id when the attribute that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h
index e80857e..d9aa285 100644
--- a/c++/src/H5CommonFG.h
+++ b/c++/src/H5CommonFG.h
@@ -69,6 +69,11 @@ class H5_DLLCPP CommonFG {
// Returns the number of objects in this group.
hsize_t getNumObjs() const;
+ // Retrieves the name of an object in this group, given the
+ // object's index.
+ ssize_t getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const;
+ H5std_string getObjnameByIdx(hsize_t idx) const;
+
// Returns the type of an object in this group, given the
// object's index.
H5G_obj_t getObjTypeByIdx(hsize_t idx) const;
@@ -81,11 +86,6 @@ class H5_DLLCPP CommonFG {
void getObjinfo(const char* name, H5G_stat_t& statbuf) const;
void getObjinfo(const H5std_string& name, H5G_stat_t& statbuf) const;
- // Retrieves the name of an object in this group, given the
- // object's index.
- ssize_t getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) const;
- H5std_string getObjnameByIdx(hsize_t idx) const;
-
// Iterates over the elements of this group - not implemented in
// C++ style yet.
int iterateElems(const char* name, int *idx, H5G_iterate_t op, void *op_data);
diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp
index 0151107..0539484 100644
--- a/c++/src/H5DataSet.cpp
+++ b/c++/src/H5DataSet.cpp
@@ -35,6 +35,7 @@
#include "H5DataSpace.h"
#include "H5AbstractDs.h"
#include "H5File.h"
+#include "H5Attribute.h"
#include "H5DataSet.h"
#ifndef H5_NO_NAMESPACE
@@ -66,7 +67,7 @@ DataSet::DataSet(const hid_t existing_id) : AbstractDs(), H5Object(), id(existin
///\param original - IN: DataSet instance to copy
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object()
+DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object(original)
{
id = original.getId();
incRefCount(); // increment number of references to this id
@@ -74,24 +75,75 @@ DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object()
//--------------------------------------------------------------------------
// Function: DataSet overload constructor - dereference
-///\brief Given a reference to some object, returns that dataset
+///\brief Given a reference, ref, to an hdf5 dataset, creates a
+/// DataSet object
///\param obj - IN: Dataset reference object is in or location of
-/// object that the dataset is located within.
+/// object that the dataset is located within.
///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
///\exception H5::DataSetIException
///\par Description
/// \c obj can be DataSet, Group, H5File, or named DataType, that
/// is a datatype that has been named by DataType::commit.
// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
//--------------------------------------------------------------------------
DataSet::DataSet(H5Object& obj, void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object()
{
- dereference(obj, ref, ref_type);
+ try {
+ id = p_dereference(obj.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataSet constructor - located by object",
+ deref_error.getDetailMsg());
+ }
}
+//--------------------------------------------------------------------------
+// Function: DataSet overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 dataset, creates a
+/// DataSet object
+///\param h5file - IN: Location referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::DataSetIException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
+//--------------------------------------------------------------------------
DataSet::DataSet(H5File& h5file, void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object()
{
- dereference(h5file, ref, ref_type);
+ try {
+ id = p_dereference(h5file.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataSet constructor - located by HDF5 file",
+ deref_error.getDetailMsg());
+ }
+}
+
+//--------------------------------------------------------------------------
+// Function: DataSet overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 dataset, creates a
+/// DataSet object
+///\param attr - IN: Specifying location where the referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
+//--------------------------------------------------------------------------
+DataSet::DataSet(Attribute& attr, void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object()
+{
+ try {
+ id = p_dereference(attr.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataSet constructor - located by attribute",
+ deref_error.getDetailMsg());
+ }
}
//--------------------------------------------------------------------------
@@ -586,8 +638,10 @@ void DataSet::close()
{
throw DataSetIException("DataSet::close", "H5Dclose failed");
}
- // reset the id because the dataset that it represents is now closed
- id = 0;
+ // reset the id when the dataset that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
@@ -607,7 +661,7 @@ DataSet::~DataSet()
close();
}
catch (Exception close_error) {
- cerr << "DataSet::~DataSet" << close_error.getDetailMsg() << endl;
+ cerr << "DataSet::~DataSet - " << close_error.getDetailMsg() << endl;
}
}
diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h
index 2d625f0..87156ff 100644
--- a/c++/src/H5DataSet.h
+++ b/c++/src/H5DataSet.h
@@ -84,7 +84,8 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs {
// Creates a dataset by way of dereference.
DataSet(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT);
- DataSet(H5File& file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ DataSet(H5File& h5file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ DataSet(Attribute& attr, void* ref, H5R_type_t ref_type = H5R_OBJECT);
// Default constructor.
DataSet();
diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp
index e755685..902513b 100644
--- a/c++/src/H5DataSpace.cpp
+++ b/c++/src/H5DataSpace.cpp
@@ -609,8 +609,10 @@ void DataSpace::close()
{
throw DataSpaceIException("DataSpace::close", "H5Sclose failed");
}
- // reset the id because the dataspace that it represents is now closed
- id = 0;
+ // reset the id when the dataspace that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index 96adf8e..badefc2 100644
--- a/c++/src/H5DataType.cpp
+++ b/c++/src/H5DataType.cpp
@@ -38,6 +38,7 @@
#include "H5AbstractDs.h"
#include "H5DataSet.h"
#include "H5File.h"
+#include "H5Attribute.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -85,22 +86,74 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object()
//--------------------------------------------------------------------------
// Function: DataType overload constructor - dereference
-///\brief Given a reference to some object, returns that datatype
-///\param obj - IN: Location reference object is in
+///\brief Given a reference, ref, to an hdf5 group, creates a
+/// DataType object
+///\param obj - IN: Specifying location referenced object is in
///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
///\par Description
-/// \c obj can be DataSet, Group, H5File, or named DataType, that
+/// \c obj can be DataSet, Group, or named DataType, that
/// is a datatype that has been named by DataType::commit.
// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
//--------------------------------------------------------------------------
DataType::DataType(H5Object& obj, void* ref, H5R_type_t ref_type) : H5Object()
{
- dereference(obj, ref, ref_type);
+ try {
+ id = p_dereference(obj.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataType constructor - located by an H5Object",
+ deref_error.getDetailMsg());
+ }
}
+//--------------------------------------------------------------------------
+// Function: DataType overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 group, creates a
+/// DataType object
+///\param h5file - IN: Location referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
+//--------------------------------------------------------------------------
DataType::DataType(H5File& h5file, void* ref, H5R_type_t ref_type) : H5Object()
{
- dereference(h5file, ref, ref_type);
+ try {
+ id = p_dereference(h5file.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataType constructor - located by an H5File",
+ deref_error.getDetailMsg());
+ }
+}
+
+//--------------------------------------------------------------------------
+// Function: DataType overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 group, creates a
+/// DataType object
+///\param attr - IN: Specifying location where the referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// Jul, 2008
+// Added for application convenience.
+//--------------------------------------------------------------------------
+DataType::DataType(Attribute& attr, void* ref, H5R_type_t ref_type) : H5Object()
+{
+ try {
+ id = p_dereference(attr.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("DataType constructor - located by an Attribute",
+ deref_error.getDetailMsg());
+ }
}
//--------------------------------------------------------------------------
@@ -769,8 +822,10 @@ void DataType::close()
{
throw DataTypeIException(inMemFunc("close"), "H5Tclose failed");
}
- // reset the id because the datatype that it represents is now closed
- id = 0;
+ // reset the id when the datatype that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h
index 57a0345..cb7aa22 100644
--- a/c++/src/H5DataType.h
+++ b/c++/src/H5DataType.h
@@ -31,7 +31,8 @@ class H5_DLLCPP DataType : public H5Object {
// Creates a datatype by way of dereference.
DataType(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT);
- DataType(H5File& file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ DataType(H5File& h5file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ DataType(Attribute& attr, void* ref, H5R_type_t ref_type = H5R_OBJECT);
// Closes this datatype.
virtual void close();
diff --git a/c++/src/H5DcreatProp.cpp b/c++/src/H5DcreatProp.cpp
index 656956f..c13f1be 100644
--- a/c++/src/H5DcreatProp.cpp
+++ b/c++/src/H5DcreatProp.cpp
@@ -343,14 +343,14 @@ int DSetCreatPropList::getNfilters() const
//--------------------------------------------------------------------------
// Function: DSetCreatPropList::getFilter
///\brief Returns information about a filter in a pipeline
-///\param filter_number - IN: Filter to get, range [0..N-1], where
-/// N is returned by H5Pget_nfilters()
-///\param flags - OUT: General properties of the filter
-///\param cd_nelmts - IN/OUT: Number of elements in \a cd_values /Number
-/// of values defined by the filter
-///\param cd_values - OUT: Array to hold the data; allocated by the user
-///\param namelen - OUT: Length of \a name
-///\param name - OUT: Name of the filter
+///\param filter_number - IN: Filter to get, range [0..N-1], where
+/// N is returned by H5Pget_nfilters()
+///\param flags - OUT: General properties of the filter
+///\param cd_nelmts - IN/OUT: Number of elements in \a cd_values /Number
+/// of values defined by the filter
+///\param cd_values - OUT: Array to hold the data; allocated by the user
+///\param namelen - OUT: Length of \a name
+///\param name - OUT: Name of the filter
///\return Filter id
///\exception H5::PropListIException
///\par Description
diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp
index 49cad88..ab76e49 100644
--- a/c++/src/H5DxferProp.cpp
+++ b/c++/src/H5DxferProp.cpp
@@ -31,7 +31,7 @@ namespace H5 {
const DSetMemXferPropList DSetMemXferPropList::DEFAULT;
//--------------------------------------------------------------------------
-// Function DSetMemXferPropList default constructor
+// Function DSetMemXferPropList default constructor
///\brief Default constructor: creates a stub dataset memory and
/// transfer property list object.
// Programmer: Binh-Minh Ribler - 2000
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp
index 8931021..4a48e38 100644
--- a/c++/src/H5File.cpp
+++ b/c++/src/H5File.cpp
@@ -252,7 +252,7 @@ void H5File::openFile(const H5std_string& name, unsigned int flags, const FileAc
// If this object has represented another HDF5 file, the previous
// HDF5 file need to be closed first.
// Programmer Binh-Minh Ribler - 2000
-// Note: This wrapper doesn't seem right regarding the 'id' and should
+// Note: This wrapper doesn't seem right regarding the 'id' and should
// be investigated. BMR - 2/20/2005
// Modification
// - Replaced resetIdComponent() with decRefCount() to use C
@@ -586,7 +586,7 @@ hsize_t H5File::getFileSize() const
//--------------------------------------------------------------------------
// Function: H5File::p_reference (protected)
-// Purpose Creates a reference to an HDF5 object or a dataset region.
+// Purpose: Creates a reference to an HDF5 object or a dataset region.
// Parameters
// name - IN: Name of the object to be referenced
// dataspace - IN: Dataspace with selection
@@ -667,7 +667,7 @@ void H5File::reference(void* ref, const H5std_string& name) const
#if 0
//--------------------------------------------------------------------------
// Function: H5File::p_get_obj_type (protected)
-// Purpose Retrieves the type of object that an object reference points to.
+// Purpose: Retrieves the type of object that an object reference points to.
// Parameters
// ref - IN: Reference to query
// ref_type - IN: Type of reference to query
@@ -700,7 +700,7 @@ H5G_obj_t H5Object::p_get_obj_type(void *ref, H5R_type_t ref_type) const
#endif
//--------------------------------------------------------------------------
// Function: H5File::p_get_region (protected)
-// Purpose Retrieves a dataspace with the region pointed to selected.
+// Purpose: Retrieves a dataspace with the region pointed to selected.
// Parameters
// ref_type - IN: Type of reference to get region of - default
// to H5R_DATASET_REGION
@@ -789,8 +789,10 @@ void H5File::close()
{
throw FileIException("H5File::close", "H5Fclose failed");
}
- // reset the id because the file that it represents is now closed
- id = 0;
+ // reset the id when the file that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp
index 16b0fee..47750e7 100644
--- a/c++/src/H5Group.cpp
+++ b/c++/src/H5Group.cpp
@@ -33,6 +33,7 @@
#include "H5DataSpace.h"
#include "H5DataSet.h"
#include "H5CommonFG.h"
+#include "H5Attribute.h"
#include "H5Group.h"
#include "H5File.h"
#include "H5Alltypes.h"
@@ -50,7 +51,7 @@ namespace H5 {
///\brief Default constructor: creates a stub Group.
// Programmer Binh-Minh Ribler - 2000
// Modification
-// 2008 08 No longer inherit data member 'id' from IdComponent.
+// Jul, 08 No longer inherit data member 'id' from IdComponent.
// - bugzilla 1068
//--------------------------------------------------------------------------
Group::Group() : H5Object(), id(0) {}
@@ -97,22 +98,62 @@ Group::Group(const hid_t existing_id) : H5Object()
//--------------------------------------------------------------------------
// Function: Group overload constructor - dereference
-///\brief Given a reference to some object or a file, returns that group
-///\param obj - IN: Location reference object is in
-/// ref - IN: Reference pointer
+///\brief Given a reference, ref, to an hdf5 group, creates a Group object
+///\param obj - IN: Specifying location referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
///\par Description
-/// \c obj can be DataSet, Group, H5File, or named DataType, that
+/// \c obj can be DataSet, Group, or named DataType, that
/// is a datatype that has been named by DataType::commit.
// Programmer Binh-Minh Ribler - Oct, 2006
//--------------------------------------------------------------------------
Group::Group(H5Object& obj, void* ref, H5R_type_t ref_type) : H5Object()
{
- dereference(obj, ref, ref_type);
+ try {
+ id = p_dereference(obj.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("Group constructor - located by an H5Object",
+ deref_error.getDetailMsg());
+ }
}
+//--------------------------------------------------------------------------
+// Function: Group overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 group, creates a Group object
+///\param h5file - IN: Location referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+//--------------------------------------------------------------------------
Group::Group(H5File& h5file, void* ref, H5R_type_t ref_type) : H5Object()
{
- dereference(h5file, ref, ref_type);
+ try {
+ id = p_dereference(h5file.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("Group constructor - located by an H5File",
+ deref_error.getDetailMsg());
+ }
+}
+
+//--------------------------------------------------------------------------
+// Function: Group overload constructor - dereference
+///\brief Given a reference, ref, to an hdf5 group, creates a Group object
+///\param attr - IN: Specifying location where the referenced object is in
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type - default to H5R_OBJECT
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+//--------------------------------------------------------------------------
+Group::Group(Attribute& attr, void* ref, H5R_type_t ref_type) : H5Object()
+{
+ try {
+ id = p_dereference(attr.getId(), ref, ref_type);
+ } catch (ReferenceException deref_error) {
+ throw ReferenceException("Group constructor - located by an Attribute",
+ deref_error.getDetailMsg());
+ }
}
//--------------------------------------------------------------------------
@@ -204,8 +245,10 @@ void Group::close()
{
throw GroupIException("Group::close", "H5Gclose failed");
}
- // reset the id because the group that it represents is now closed
- id = 0;
+ // reset the id when the group that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}
diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h
index 2c4fd10..c3641af 100644
--- a/c++/src/H5Group.h
+++ b/c++/src/H5Group.h
@@ -43,7 +43,8 @@ class H5_DLLCPP Group : public H5Object, public CommonFG {
// Creates a group by way of dereference.
Group(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT);
- Group(H5File& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ Group(H5File& h5file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ Group(Attribute& attr, void* ref, H5R_type_t ref_type = H5R_OBJECT);
// default constructor
Group();
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index 0fb744f..e152d23 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -291,26 +291,6 @@ H5std_string IdComponent::p_get_file_name() const
}
//--------------------------------------------------------------------------
-// Function: IdComponent::p_dereference (protected)
-// Purpose Opens the HDF5 object referenced.
-// Parameters
-// ref - IN: Reference pointer
-// Exception H5::IdComponentException
-// Programmer Binh-Minh Ribler - Oct, 2006
-//--------------------------------------------------------------------------
-#if 0
-hid_t IdComponent::p_dereference(hid_t obj_id, void* ref) const
-{
- hid_t temp_id = H5Rdereference(obj_id, H5R_OBJECT, ref);
- if (temp_id < 0)
- {
- throw ReferenceException("", "H5Rdereference failed");
- }
- return(temp_id);
-}
-#endif
-
-//--------------------------------------------------------------------------
// Function: IdComponent::p_get_refobj_type (protected)
// Purpose Retrieves the type of object that an object reference points to.
// Parameters
diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h
index 3333f3a..ec86d11 100644
--- a/c++/src/H5IdComponent.h
+++ b/c++/src/H5IdComponent.h
@@ -74,9 +74,6 @@ class H5_DLLCPP IdComponent {
virtual ~IdComponent();
protected:
- /* hid_t p_dereference(hid_t obj_id, void* ref) const;
- hid_t p_dereference(void* ref) const {return 0;};
- */
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// Default constructor.
@@ -85,6 +82,9 @@ class H5_DLLCPP IdComponent {
// Gets the name of the file, in which an HDF5 object belongs.
H5std_string p_get_file_name() const;
+ // Retrieves the type of object that an object reference points to.
+ H5G_obj_t p_get_refobj_type(void *ref, H5R_type_t ref_type) const;
+
// Verifies that the given id is valid.
static bool p_valid_id(const hid_t obj_id);
@@ -94,9 +94,6 @@ class H5_DLLCPP IdComponent {
// Opens the HDF5 object referenced.
- // Retrieves the type of object that an object reference points to.
- H5G_obj_t p_get_refobj_type(void *ref, H5R_type_t ref_type) const;
-
#endif // DOXYGEN_SHOULD_SKIP_THIS
}; // end class IdComponent
diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp
index 73d473c..23eab96 100644
--- a/c++/src/H5Object.cpp
+++ b/c++/src/H5Object.cpp
@@ -59,7 +59,7 @@ extern "C" herr_t userAttrOpWrpr( hid_t loc_id, const char* attr_name, void* op_
// set it to a valid HDF5 id.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-H5Object::H5Object() : IdComponent(0) {}
+H5Object::H5Object() : IdComponent() {}
//--------------------------------------------------------------------------
// Function: H5Object overloaded constructor (protected)
@@ -68,7 +68,7 @@ H5Object::H5Object() : IdComponent(0) {}
// Parameters object_id - IN: Id of an existing HDF5 object
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-H5Object::H5Object( const hid_t object_id ) : IdComponent( object_id ) {}
+//H5Object::H5Object( const hid_t object_id ) : IdComponent(), id(object_id) {}
#endif // DOXYGEN_SHOULD_SKIP_THIS
@@ -338,13 +338,13 @@ H5std_string H5Object::getFileName() const
}
//--------------------------------------------------------------------------
-// Function: H5Object::p_reference (protected)
-// Purpose Creates a reference to an HDF5 object or a dataset region.
+// Function: H5Object::p_reference (protected)
+// Purpose Creates a reference to an HDF5 object or a dataset region.
// Parameters
-// name - IN: Name of the object to be referenced
-// dataspace - IN: Dataspace with selection
-// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION
-// Exception H5::IdComponentException
+// name - IN: Name of the object to be referenced
+// dataspace - IN: Dataspace with selection
+// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION
+// Exception H5::ReferenceException
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void H5Object::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const
@@ -352,20 +352,20 @@ void H5Object::p_reference(void* ref, const char* name, hid_t space_id, H5R_type
herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id);
if (ret_value < 0)
{
- throw IdComponentException("", "H5Rcreate failed");
+ throw ReferenceException("", "H5Rcreate failed");
}
}
//--------------------------------------------------------------------------
-// Function: H5Object::reference
+// Function: H5Object::reference
///\brief Creates a reference to an HDF5 object or a dataset region.
///\param ref - IN: Reference pointer
///\param name - IN: Name of the object to be referenced
///\param dataspace - IN: Dataspace with selection
///\param ref_type - IN: Type of reference to query, valid values are:
-/// \li \c H5R_OBJECT \tReference is an object reference.
-/// \li \c H5R_DATASET_REGION \tReference is a dataset region
-/// reference. - this is the default
+/// \li \c H5R_OBJECT \tReference is an object reference.
+/// \li \c H5R_DATASET_REGION \tReference is a dataset region
+/// reference. - this is the default
///\exception H5::IdComponentException
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
@@ -374,43 +374,63 @@ void H5Object::reference(void* ref, const char* name, const DataSpace& dataspace
try {
p_reference(ref, name, dataspace.getId(), ref_type);
}
- catch (IdComponentException E) {
- throw IdComponentException("H5Object::reference", E.getDetailMsg());
+ catch (ReferenceException E) {
+ throw ReferenceException("H5Object::reference - dataset region", E.getDetailMsg());
}
}
//--------------------------------------------------------------------------
-// Function: H5Object::reference
-///\brief This is an overloaded function, provided for your convenience.
-/// It differs from the above function in that it only creates
-/// a reference to an HDF5 object, not to a dataset region.
+// Function: H5Object::reference
+///\brief This is an overloaded function, provided for your convenience.
+/// It differs from the above function in that it takes an
+/// \c H5std_string for the object's name.
///\param ref - IN: Reference pointer
-///\param name - IN: Name of the object to be referenced - \c char pointer
+///\param name - IN: Name of the object to be referenced
+///\param dataspace - IN: Dataspace with selection
+///\param ref_type - IN: Type of reference to query, valid values are:
+/// \li \c H5R_OBJECT \tReference is an object reference.
+/// \li \c H5R_DATASET_REGION \tReference is a dataset region
+/// reference. - this is the default
///\exception H5::IdComponentException
-///\par Description
-// This function passes H5R_OBJECT and -1 to the protected
-// function for it to pass to the C API H5Rcreate
-// to create a reference to the named object.
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
+void H5Object::reference(void* ref, const H5std_string& name, const DataSpace& dataspace, H5R_type_t ref_type) const
+{
+ reference(ref, name.c_str(), dataspace, ref_type);
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::reference
+///\brief This is an overloaded function, provided for your convenience.
+/// It differs from the above function in that it only creates
+/// a reference to an HDF5 object, not to a dataset region.
+///\param ref - IN: Reference pointer
+///\param name - IN: Name of the object to be referenced - \c char pointer
+///\exception H5::IdComponentException
+///\par Description
+// This function passes H5R_OBJECT and -1 to the protected
+// function for it to pass to the C API H5Rcreate
+// to create a reference to the named object.
+// Programmer Binh-Minh Ribler - May, 2004
+//--------------------------------------------------------------------------
void H5Object::reference(void* ref, const char* name) const
{
try {
p_reference(ref, name, -1, H5R_OBJECT);
}
- catch (IdComponentException E) {
- throw IdComponentException("H5Object::reference", E.getDetailMsg());
+ catch (ReferenceException E) {
+ throw ReferenceException("H5Object::reference - HDF5 object", E.getDetailMsg());
}
}
//--------------------------------------------------------------------------
-// Function: H5Object::reference
-///\brief This is an overloaded function, provided for your convenience.
-/// It differs from the above function in that it takes an
-/// \c H5std_string for the object's name.
-///\param ref - IN: Reference pointer
-///\param name - IN: Name of the object to be referenced - \c H5std_string
-// Programmer Binh-Minh Ribler - May, 2004
+// Function: H5Object::reference
+///\brief This is an overloaded function, provided for your convenience.
+/// It differs from the above function in that it takes an
+/// \c H5std_string for the object's name.
+///\param ref - IN: Reference pointer
+///\param name - IN: Name of the object to be referenced - \c H5std_string
+// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void H5Object::reference(void* ref, const H5std_string& name) const
{
@@ -418,39 +438,101 @@ void H5Object::reference(void* ref, const H5std_string& name) const
}
//--------------------------------------------------------------------------
-// Function: H5Object::dereference
-// Purpose Dereference a ref into an hdf5 object.
+// Function: H5Object::p_dereference (protected)
+// Purpose Dereference a ref into an hdf5 object.
// Parameters
-// ref - IN: Reference pointer
-// Exception H5::IdComponentException
-// Programmer Binh-Minh Ribler - Oct, 2006
+// loc_id - IN: An hdf5 identifier specifying the location of the
+// referenced object
+// ref - IN: Reference pointer
+// ref_type - IN: Reference type
+// Exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
// Modification
// May 2008 - BMR
-// Moved from IdComponent into H5File and H5Object
+// Moved from IdComponent.
//--------------------------------------------------------------------------
-void H5Object::dereference(H5Object& obj, void* ref, H5R_type_t ref_type)
+hid_t H5Object::p_dereference(hid_t loc_id, void* ref, H5R_type_t ref_type)
{
hid_t temp_id;
- temp_id = H5Rdereference(obj.getId(), ref_type, ref);
+ temp_id = H5Rdereference(loc_id, ref_type, ref);
if (temp_id < 0)
{
- throw (inMemFunc("dereference"), "H5Rdereference failed");
+ throw ReferenceException("", "H5Rdereference failed");
}
// No failure, set id to the object
+ return(temp_id);
+}
+
+//--------------------------------------------------------------------------
+// Function: H5Object::dereference
+///\brief Dereferences a reference into an HDF5 object, given an HDF5 object.
+///\param obj - IN: Object specifying the location of the referenced object
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// May, 2008
+// Corrected missing parameters. - BMR
+//--------------------------------------------------------------------------
+void H5Object::dereference(H5Object& obj, void* ref, H5R_type_t ref_type)
+{
+ hid_t temp_id;
+ try {
+ temp_id = p_dereference(obj.getId(), ref, ref_type);
+ }
+ catch (ReferenceException E) {
+ throw ReferenceException("H5Object::dereference - located by object", E.getDetailMsg());
+ }
p_setId(temp_id);
}
+//--------------------------------------------------------------------------
+// Function: H5Object::dereference
+///\brief Dereferences a reference into an HDF5 object, given an HDF5 file.
+///\param h5file - IN: HDF5 file specifying the location of the referenced object
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// May, 2008
+// Corrected missing parameters. - BMR
+//--------------------------------------------------------------------------
void H5Object::dereference(H5File& h5file, void* ref, H5R_type_t ref_type)
{
hid_t temp_id;
- temp_id = H5Rdereference(h5file.getId(), ref_type, ref);
- if (temp_id < 0)
- {
- throw (inMemFunc("dereference"), "H5Rdereference failed");
+ try {
+ temp_id = p_dereference(h5file.getId(), ref, ref_type);
+ }
+ catch (ReferenceException E) {
+ throw ReferenceException("H5Object::dereference - located by file", E.getDetailMsg());
}
+ p_setId(temp_id);
+}
- // No failure, set id to the object
+//--------------------------------------------------------------------------
+// Function: H5Object::dereference
+///\brief Dereferences a reference into an HDF5 object, given an attribute.
+///\param attr - IN: Attribute specifying the location of the referenced object
+///\param ref - IN: Reference pointer
+///\param ref_type - IN: Reference type
+///\exception H5::ReferenceException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// May, 2008
+// Corrected missing parameters. - BMR
+//--------------------------------------------------------------------------
+void H5Object::dereference(Attribute& attr, void* ref, H5R_type_t ref_type)
+{
+ hid_t temp_id;
+ try {
+ temp_id = p_dereference(attr.getId(), ref, ref_type);
+ }
+ catch (ReferenceException E) {
+ throw ReferenceException("H5Object::dereference - located by attribute", E.getDetailMsg());
+ }
p_setId(temp_id);
}
@@ -515,12 +597,12 @@ H5G_obj_t H5Object::p_get_refobj_type(void *ref, H5R_type_t ref_type) const
#endif
//--------------------------------------------------------------------------
-// Function: H5Object::p_get_region (protected)
-// Purpose Retrieves a dataspace with the region pointed to selected.
+// Function: H5Object::p_get_region (protected)
+// Purpose Retrieves a dataspace with the region pointed to selected.
// Parameters
-// ref_type - IN: Type of reference to get region of - default
-// to H5R_DATASET_REGION
-// ref - IN: Reference to get region of
+// ref_type - IN: Type of reference to get region of - default
+// to H5R_DATASET_REGION
+// ref - IN: Reference to get region of
// Return Dataspace id
// Exception H5::IdComponentException
// Programmer Binh-Minh Ribler - May, 2004
diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h
index 1b1f656..ecaf41a 100644
--- a/c++/src/H5Object.h
+++ b/c++/src/H5Object.h
@@ -83,16 +83,20 @@ class H5_DLLCPP H5Object : public IdComponent {
void renameAttr(const char* oldname, const char* newname) const;
void renameAttr(const H5std_string& oldname, const H5std_string& newname) const;
- // Creates a reference to a named Hdf5 object or to a dataset region
- // in this object.
+ // Creates a reference to a dataset region in this object.
void reference(void* ref, const char* name, const DataSpace& dataspace,
- H5R_type_t ref_type = H5R_DATASET_REGION) const;
+ H5R_type_t ref_type = H5R_DATASET_REGION) const;
+ void reference(void* ref, const H5std_string& name, const DataSpace&
+ dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const;
+
+ // Creates a reference to a named HDF5 object.
void reference(void* ref, const char* name) const;
void reference(void* ref, const H5std_string& name) const;
// Open a referenced HDF5 object.
void dereference(H5File& h5file, void* ref, H5R_type_t ref_type = H5R_OBJECT);
void dereference(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT);
+ void dereference(Attribute& attr, void* ref, H5R_type_t ref_type = H5R_OBJECT);
// Copy constructor: makes copy of an H5Object object.
H5Object(const H5Object& original);
@@ -105,17 +109,17 @@ class H5_DLLCPP H5Object : public IdComponent {
// Default constructor
H5Object();
- // Creates a copy of an existing object giving the object id
- H5Object( const hid_t object_id );
-
// Gets the id of the H5 file in which the given object is located.
hid_t p_get_file_id();
// Creates a reference to an HDF5 object or a dataset region.
void p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const;
+ // Dereferences a ref into an hdf5 object.
+ hid_t p_dereference(hid_t loc_id, void* ref, H5R_type_t ref_type);
+
// Retrieves the type of object that an object reference points to.
- //H5G_obj_t p_get_refobj_type(void *ref, H5R_type_t ref_type) const;
+// H5G_obj_t p_get_refobj_type(void *ref, H5R_type_t ref_type) const;
// Retrieves a dataspace with the region pointed to selected.
hid_t p_get_region(void *ref, H5R_type_t ref_type) const;
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 14987f3..9fa031d 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -263,8 +263,10 @@ void PropList::close()
{
throw PropListIException(inMemFunc("close"), "H5Pclose failed");
}
- // reset the id because the property list that it represents is now closed
- id = 0;
+ // reset the id when the property list that it represents is no longer
+ // referenced
+ if (getCounter() == 0)
+ id = 0;
}
}