summaryrefslogtreecommitdiffstats
path: root/c++/src/H5Attribute.cpp
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2008-10-21 19:10:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2008-10-21 19:10:01 (GMT)
commit27ae4bccfd866a9bf334dc191631499d3cea1b19 (patch)
tree828abaa9099bc36b176c8440f0d905ae267d5b02 /c++/src/H5Attribute.cpp
parent22378dbd24c08d7153f4f295b5bca057191edc38 (diff)
downloadhdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.zip
hdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.tar.gz
hdf5-27ae4bccfd866a9bf334dc191631499d3cea1b19.tar.bz2
[svn-r15922] Description:
Bring revisions 15289:15457 from trunk into metadata journaling branch. Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.5.2 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode
Diffstat (limited to 'c++/src/H5Attribute.cpp')
-rw-r--r--c++/src/H5Attribute.cpp103
1 files changed, 96 insertions, 7 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 043dc4d..64993a2 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -26,12 +26,14 @@
#include "H5PropList.h"
#include "H5Object.h"
#include "H5AbstractDs.h"
-#include "H5Attribute.h"
+#include "H5FaccProp.h"
+#include "H5FcreatProp.h"
#include "H5DcreatProp.h"
#include "H5CommonFG.h"
#include "H5DataType.h"
#include "H5DataSpace.h"
-#include "H5private.h"
+#include "H5File.h"
+#include "H5Attribute.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -46,7 +48,7 @@ namespace H5 {
///\brief Default constructor: Creates a stub attribute
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
-Attribute::Attribute() : AbstractDs() {}
+Attribute::Attribute() : AbstractDs(), IdComponent(), id(0) {}
//--------------------------------------------------------------------------
// Function: Attribute copy constructor
@@ -54,7 +56,11 @@ Attribute::Attribute() : AbstractDs() {}
///\param original - IN: Original Attribute object to copy
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-Attribute::Attribute( const Attribute& original ) : AbstractDs( original ) {}
+Attribute::Attribute(const Attribute& original) : AbstractDs(), IdComponent()
+{
+ id = original.getId();
+ incRefCount(); // increment number of references to this id
+}
//--------------------------------------------------------------------------
// Function: Attribute overloaded constructor
@@ -64,7 +70,10 @@ Attribute::Attribute( const Attribute& original ) : AbstractDs( original ) {}
///\exception H5::AttributeIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
-Attribute::Attribute(const hid_t existing_id) : AbstractDs(existing_id) {}
+Attribute::Attribute(const hid_t existing_id) : AbstractDs(), IdComponent()
+{
+ id = existing_id;
+}
//--------------------------------------------------------------------------
// Function: Attribute::write
@@ -208,6 +217,23 @@ hid_t Attribute::p_get_type() const
}
//--------------------------------------------------------------------------
+// Function: Attribute::getFileName
+///\brief Gets the name of the file, in which this attribute belongs.
+///\return File name
+///\exception H5::IdComponentException
+// Programmer Binh-Minh Ribler - Jul, 2004
+//--------------------------------------------------------------------------
+H5std_string Attribute::getFileName() const
+{
+ try {
+ return(p_get_file_name());
+ }
+ catch (IdComponentException E) {
+ throw FileIException("Attribute::getFileName", E.getDetailMsg());
+ }
+}
+
+//--------------------------------------------------------------------------
// Function: Attribute::getName
///\brief Gets the name of this attribute, returning its length.
///\param buf_size - IN: Desired length of the name
@@ -297,6 +323,67 @@ hsize_t Attribute::getStorageSize() const
}
//--------------------------------------------------------------------------
+// Function: Attribute::dereference
+// Purpose Dereference a ref into a DataSet object.
+// Parameters
+// ref - IN: Reference pointer
+// Exception H5::IdComponentException
+// Programmer Binh-Minh Ribler - Oct, 2006
+// Modification
+// May 2008 - BMR
+// Moved from IdComponent into H5File, H5Object, and Attribute
+//--------------------------------------------------------------------------
+Attribute::Attribute(H5Object& obj, void* ref) : AbstractDs(), IdComponent()
+{
+ id = obj.p_dereference(ref);
+}
+
+Attribute::Attribute(H5File& h5file, void* ref) : AbstractDs(), IdComponent()
+{
+ id = h5file.p_dereference(ref);
+}
+
+//--------------------------------------------------------------------------
+// Function: Attribute::getId
+// Purpose: Get the id of this attribute
+// Description:
+// 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 Attribute::getId() const
+{
+ return(id);
+}
+
+//--------------------------------------------------------------------------
+// Function: Attribute::p_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 Attribute::p_setId(const hid_t new_id)
+{
+ // handling references to this old id
+ try {
+ close();
+ }
+ catch (Exception close_error) {
+ throw AttributeIException("Attribute::p_setId", close_error.getDetailMsg());
+ }
+ // reset object's id to the given id
+ id = new_id;
+}
+
+//--------------------------------------------------------------------------
// Function: Attribute::close
///\brief Closes this attribute.
///
@@ -312,8 +399,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;
}
}