summaryrefslogtreecommitdiffstats
path: root/c++/src/H5DataType.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2008-07-02 14:56:42 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2008-07-02 14:56:42 (GMT)
commite5df9bb33aa8b88bd0df21479942c1156ffd52aa (patch)
tree48c4dc2f0e08512addab592c0306fa57ded0898a /c++/src/H5DataType.cpp
parentd9533d055c7f306e66e5f972068c77c939d6fc16 (diff)
downloadhdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.zip
hdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.tar.gz
hdf5-e5df9bb33aa8b88bd0df21479942c1156ffd52aa.tar.bz2
[svn-r15309] Purpose: Fixed bugs
Description: The class hierarchy was revised to address the problem reported in bugzilla #1068. Classes AbstractDS and Attribute are moved out of H5Object. Class Attribute now multiply inherits from IdComponent and AbstractDs and class DataSet from H5Object and AbstractDs. In addition, data member IdComponent::id was moved into subclasses: Attribute, DataSet, DataSpace, DataType, H5File, Group, and PropList. Platforms tested: SunOS 5.10 (linew) Linux 2.6 (kagiso) FreeBSD (duty)
Diffstat (limited to 'c++/src/H5DataType.cpp')
-rw-r--r--c++/src/H5DataType.cpp133
1 files changed, 77 insertions, 56 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp
index c31395e..592d800 100644
--- a/c++/src/H5DataType.cpp
+++ b/c++/src/H5DataType.cpp
@@ -62,7 +62,10 @@ namespace H5 {
// - BMR 5/2004
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataType::DataType(const hid_t existing_id) : H5Object(existing_id) {}
+DataType::DataType(const hid_t existing_id) : H5Object()
+{
+ id = existing_id;
+}
//--------------------------------------------------------------------------
// Function: DataType overloaded constructor
@@ -92,9 +95,19 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object()
/// is a datatype that has been named by DataType::commit.
// Programmer Binh-Minh Ribler - Oct, 2006
//--------------------------------------------------------------------------
-DataType::DataType(IdComponent& obj, void* ref) : H5Object()
+ /* DataType::DataType(IdComponent& obj, void* ref) : H5Object()
+{
+ H5Object::dereference(obj, ref);
+}
+ */
+DataType::DataType(H5Object& obj, void* ref) : H5Object()
{
- IdComponent::dereference(obj, ref);
+ id = obj.p_dereference(ref);
+}
+
+DataType::DataType(H5File& file, void* ref) : H5Object()
+{
+ id = file.p_dereference(ref);
}
//--------------------------------------------------------------------------
@@ -102,14 +115,18 @@ DataType::DataType(IdComponent& obj, void* ref) : H5Object()
///\brief Default constructor: Creates a stub datatype
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataType::DataType() : H5Object() {}
+DataType::DataType() : H5Object(), id(0) {}
//--------------------------------------------------------------------------
// Function: DataType copy constructor
///\brief Copy constructor: makes a copy of the original DataType object.
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-DataType::DataType(const DataType& original) : H5Object(original) {}
+DataType::DataType(const DataType& original) : H5Object(original)
+{
+ id = original.getId();
+ incRefCount(); // increment number of references to this id
+}
//--------------------------------------------------------------------------
// Function: DataType::copy
@@ -616,52 +633,6 @@ bool DataType::isVariableStr() const
}
}
-//--------------------------------------------------------------------------
-// Function: DataType::Reference
-///\brief Important!!! - This functions may not work correctly, it
-/// will be removed in the near future. Please use similar
-/// DataType::reference instead!
-// Programmer Binh-Minh Ribler - May, 2004
-//--------------------------------------------------------------------------
-void* DataType::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const
-{
- try {
- return(p_reference(name, dataspace.getId(), ref_type));
- }
- catch (IdComponentException E) {
- throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg());
- }
-}
-
-//--------------------------------------------------------------------------
-// Function: DataType::Reference
-///\brief Important!!! - This functions may not work correctly, it
-/// will be removed in the near future. Please use similar
-/// DataType::reference instead!
-// Programmer Binh-Minh Ribler - May, 2004
-//--------------------------------------------------------------------------
-void* DataType::Reference(const char* name) const
-{
- try {
- return(p_reference(name, -1, H5R_OBJECT));
- }
- catch (IdComponentException E) {
- throw DataTypeIException(inMemFunc("Reference"), E.getDetailMsg());
- }
-}
-
-//--------------------------------------------------------------------------
-// Function: DataType::Reference
-///\brief Important!!! - This functions may not work correctly, it
-/// will be removed in the near future. Please use similar
-/// DataType::reference instead!
-// Programmer Binh-Minh Ribler - May, 2004
-//--------------------------------------------------------------------------
-void* DataType::Reference(const H5std_string& name) const
-{
- return(Reference(name.c_str()));
-}
-
#ifndef H5_NO_DEPRECATED_SYMBOLS
//--------------------------------------------------------------------------
// Function: DataType::getObjType
@@ -708,6 +679,50 @@ DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const
}
//--------------------------------------------------------------------------
+// Function: DataType::getId
+// Purpose: Get the id of this attribute
+// Modification:
+// May 2008 - BMR
+// Class hierarchy is revised to address bugzilla 1068. Class
+// AbstractDS and Attribute are moved out of H5Object. In
+// addition, member IdComponent::id is moved into subclasses, and
+// IdComponent::getId now becomes pure virtual function.
+// Programmer Binh-Minh Ribler - May, 2008
+//--------------------------------------------------------------------------
+hid_t DataType::getId() const
+{
+ return(id);
+}
+
+//--------------------------------------------------------------------------
+// Function: DataType::setId
+///\brief Sets the identifier of this object to a new value.
+///
+///\exception H5::IdComponentException when the attempt to close the HDF5
+/// object fails
+// Description:
+// The underlaying reference counting in the C library ensures
+// that the current valid id of this object is properly closed.
+// Then the object's id is reset to the new id.
+// Programmer Binh-Minh Ribler - 2000
+//--------------------------------------------------------------------------
+void DataType::setId(const hid_t new_id)
+{
+ // handling references to this old id
+ try {
+ close();
+ }
+ catch (Exception close_error) {
+ throw DataTypeIException(inMemFunc("setId"), close_error.getDetailMsg());
+ }
+ // reset object's id to the given id
+ id = new_id;
+
+ // increment the reference counter of the new id
+ incRefCount();
+}
+
+//--------------------------------------------------------------------------
// Function: DataType::close
///\brief Closes the datatype if it is not a predefined type.
///
@@ -740,14 +755,20 @@ void DataType::close()
//--------------------------------------------------------------------------
DataType::~DataType()
{
- try {
- close();
+ int counter = getCounter(id);
+ if (counter > 1)
+ {
+ decRefCount(id);
}
- catch (Exception close_error) {
- cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl;
+ else if (counter == 1)
+ {
+ try {
+ close();
+ } catch (Exception close_error) {
+ cerr << inMemFunc("~DataType - ") << close_error.getDetailMsg() << endl;
+ }
}
}
-
#ifndef H5_NO_NAMESPACE
} // end namespace
#endif