From 4c280b326676380411eecedd03288bd335372565 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sun, 27 Jul 2008 16:48:11 -0500 Subject: [svn-r15412] 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. Also change changed subclasses' setId to p_setId for internal uses, and added setId to IdComponent for public API. Platforms tested: SunOS 5.10 (linew) Linux 2.6 (kagiso) FreeBSD (duty) --- c++/src/H5AbstractDs.cpp | 12 ++- c++/src/H5AbstractDs.h | 7 +- c++/src/H5Attribute.cpp | 160 +++++++++++++++++++++++++++-- c++/src/H5Attribute.h | 30 ++++-- c++/src/H5Classes.h | 1 - c++/src/H5CommonFG.h | 10 +- c++/src/H5DataSet.cpp | 143 +++++++++++++++----------- c++/src/H5DataSet.h | 36 +++---- c++/src/H5DataSpace.cpp | 53 +++++++++- c++/src/H5DataSpace.h | 10 ++ c++/src/H5DataType.cpp | 137 +++++++++++++------------ c++/src/H5DataType.h | 21 ++-- c++/src/H5DcreatProp.cpp | 2 +- c++/src/H5DxferProp.cpp | 2 +- c++/src/H5FaccProp.cpp | 2 +- c++/src/H5File.cpp | 246 +++++++++++++++++++++++++++++++++++--------- c++/src/H5File.h | 36 ++++++- c++/src/H5Group.cpp | 138 +++++++++++++++---------- c++/src/H5Group.h | 24 +++-- c++/src/H5IdComponent.cpp | 223 ++++++++-------------------------------- c++/src/H5IdComponent.h | 36 +++---- c++/src/H5Object.cpp | 253 +++++++++++++++++++++++++++++++++++++++++++--- c++/src/H5Object.h | 30 +++++- c++/src/H5PropList.cpp | 63 ++++++++++-- c++/src/H5PropList.h | 9 ++ 25 files changed, 1149 insertions(+), 535 deletions(-) diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index 5596b99..26bf5ad 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -34,21 +34,21 @@ namespace H5 { ///\brief Default constructor // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -AbstractDs::AbstractDs() : H5Object() {} +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 ) : H5Object( ds_id ) {} +//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 //-------------------------------------------------------------------------- -AbstractDs::AbstractDs( const AbstractDs& original ) : H5Object( original ) {} +AbstractDs::AbstractDs(const AbstractDs& original){} //-------------------------------------------------------------------------- // Function: AbstractDs::getTypeClass @@ -80,8 +80,10 @@ H5T_class_t AbstractDs::getTypeClass() const return( type_class ); else { - throw DataTypeIException(inMemFunc("getTypeClass"), - "H5Tget_class returns H5T_NO_CLASS"); + if (fromClass() == "DataSet") + throw DataTypeIException("DataSet::getTypeClass", "H5Tget_class returns H5T_NO_CLASS"); + else if (fromClass() == "Attribute") + throw DataTypeIException("Attribute::getTypeClass", "H5Tget_class returns H5T_NO_CLASS"); } } diff --git a/c++/src/H5AbstractDs.h b/c++/src/H5AbstractDs.h index 2f4e520..2d04b43 100644 --- a/c++/src/H5AbstractDs.h +++ b/c++/src/H5AbstractDs.h @@ -33,7 +33,7 @@ class FloatType; class IntType; class StrType; class VarLenType; -class H5_DLLCPP AbstractDs : public H5Object { +class H5_DLLCPP AbstractDs { public: // Gets a copy the datatype of that this abstract dataset uses. // Note that this datatype is a generic one and can only be accessed @@ -62,6 +62,9 @@ class H5_DLLCPP AbstractDs : public H5Object { // dataset - pure virtual. virtual hsize_t getStorageSize() const = 0; + // Returns this class name + virtual H5std_string fromClass() const = 0; + // Copy constructor AbstractDs( const AbstractDs& original ); @@ -73,7 +76,7 @@ class H5_DLLCPP AbstractDs : public H5Object { AbstractDs(); // Constructor that takes an attribute id or a dataset id. - AbstractDs( const hid_t ds_id ); + //AbstractDs( const hid_t ds_id ); private: // This member function is implemented by DataSet and Attribute. diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 10601fc..3f8fae9 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 { @@ -45,16 +47,26 @@ namespace H5 { // Function: Attribute default constructor ///\brief Default constructor: Creates a stub attribute // Programmer Binh-Minh Ribler - May, 2004 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -Attribute::Attribute() : AbstractDs() {} +Attribute::Attribute() : AbstractDs(), IdComponent(), id(0) {} //-------------------------------------------------------------------------- // Function: Attribute copy constructor ///\brief Copy constructor: makes a copy of the original Attribute object. ///\param original - IN: Original Attribute object to copy // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -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 @@ -63,8 +75,14 @@ Attribute::Attribute( const Attribute& original ) : AbstractDs( original ) {} ///\param existing_id - IN: Id of an existing attribute ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -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 @@ -135,8 +153,8 @@ void Attribute::read( const DataType& mem_type, void *buf ) const // Programmer Binh-Minh Ribler - Apr, 2003 // Modification // Mar 2008 -// Corrected a misunderstanding that H5Aread would allocate -// space for the buffer. Obtained the attribute size and +// Corrected a misunderstanding that H5Aread would allocate +// space for the buffer. Obtained the attribute size and // allocated memory properly. - BMR //-------------------------------------------------------------------------- void Attribute::read( const DataType& mem_type, H5std_string& strg ) const @@ -211,6 +229,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 @@ -293,6 +328,73 @@ 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. +///\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 - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t Attribute::getRefObjType(void *ref, H5R_type_t ref_type) const +{ + try { + return(p_get_refobj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw AttributeIException("Attribute::getRefObjType", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: Attribute::getObjType +///\brief This function was misnamed and will be deprecated in favor of +/// Attribute::getRefObjType; please use getRefObjType instead. +// Programmer Binh-Minh Ribler - May, 2004 +// Note: Replaced by getRefObjType. - BMR - Jul, 2008 +//-------------------------------------------------------------------------- +H5G_obj_t Attribute::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(getRefObjType(ref, ref_type)); +} + //-------------------------------------------------------------------------- // Function: Attribute::getStorageSize ///\brief Returns the amount of storage size required for this attribute. @@ -309,6 +411,50 @@ hsize_t Attribute::getStorageSize() const } //-------------------------------------------------------------------------- +// Function: Attribute::getId +// Purpose: Get the id of this group +// 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 Attribute::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: Attribute::p_setId +///\brief Sets the identifier of this group to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the +/// currently open group 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 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 +//-------------------------------------------------------------------------- +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. /// diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index 513b6ab..59b9051 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -21,11 +21,14 @@ namespace H5 { #endif -class H5_DLLCPP Attribute : public AbstractDs { +class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { public: // Closes this attribute. virtual void close(); + // Gets the name of the file, in which this attribute belongs. + H5std_string getFileName() const; + // Gets the name of this attribute. ssize_t getName( size_t buf_size, H5std_string& attr_name ) const; H5std_string getName( size_t buf_size ) const; // returns name, not its length @@ -45,11 +48,17 @@ class H5_DLLCPP Attribute : public AbstractDs { void write(const DataType& mem_type, const void *buf ) const; void write(const DataType& mem_type, const H5std_string& strg ) const; + // Retrieves the type of object that an object reference points to. + H5G_obj_t getRefObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; + + // Deprecated in favor of getRefObjType. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; + // Returns this class name virtual H5std_string fromClass () const { return("Attribute"); } - // Creates a copy of an existing attribute using the attribute id - Attribute( const hid_t attr_id ); + // Creates a copy of an existing attribute using the attribute id + Attribute( const hid_t attr_id ); // Copy constructor: makes a copy of an existing Attribute object. Attribute( const Attribute& original ); @@ -57,21 +66,24 @@ class H5_DLLCPP Attribute : public AbstractDs { // Default constructor Attribute(); + // Gets the attribute id. + virtual hid_t getId() const; + // Destructor: properly terminates access to this attribute. virtual ~Attribute(); + protected: + // Sets the attribute id. + virtual void p_setId(const hid_t new_id); + private: + hid_t id; // HDF5 attribute id + // This function contains the common code that is used by // getTypeClass and various API functions getXxxType // defined in AbstractDs for generic datatype and specific // sub-types virtual hid_t p_get_type() const; - - // do not inherit H5Object::iterateAttrs - int iterateAttrs() { return 0; } - - // do not inherit H5Object::renameAttr - void renameAttr() {} }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5Classes.h b/c++/src/H5Classes.h index 03f1257..f691548 100644 --- a/c++/src/H5Classes.h +++ b/c++/src/H5Classes.h @@ -21,7 +21,6 @@ namespace H5 { #endif class Exception; - class ReferenceCounter; class IdComponent; class H5Object; class PropList; diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 5c75989..e80857e 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; + // Returns the type of an object in this group, given the + // object's index. + H5G_obj_t getObjTypeByIdx(hsize_t idx) const; + H5G_obj_t getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const; + // Returns information about an HDF5 object, given by its name, // at this location. void getObjinfo(const char* name, hbool_t follow_link, H5G_stat_t& statbuf) const; @@ -81,11 +86,6 @@ class H5_DLLCPP CommonFG { 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; - H5G_obj_t getObjTypeByIdx(hsize_t idx, H5std_string& type_name) 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 af03e87..0151107 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -28,10 +28,13 @@ #include "H5PropList.h" #include "H5DxferProp.h" #include "H5DcreatProp.h" +#include "H5FaccProp.h" +#include "H5FcreatProp.h" #include "H5CommonFG.h" #include "H5DataType.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" +#include "H5File.h" #include "H5DataSet.h" #ifndef H5_NO_NAMESPACE @@ -47,7 +50,7 @@ namespace H5 { ///\brief Default constructor: creates a stub DataSet. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet() : AbstractDs() {} +DataSet::DataSet() : AbstractDs(), H5Object(), id(0) {} //-------------------------------------------------------------------------- // Function: DataSet overloaded constructor @@ -55,7 +58,7 @@ DataSet::DataSet() : AbstractDs() {} ///\param existing_id - IN: Id of an existing dataset // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet(const hid_t existing_id) : AbstractDs(existing_id) {} +DataSet::DataSet(const hid_t existing_id) : AbstractDs(), H5Object(), id(existing_id) {} //-------------------------------------------------------------------------- // Function: DataSet copy constructor @@ -63,13 +66,17 @@ DataSet::DataSet(const hid_t existing_id) : AbstractDs(existing_id) {} ///\param original - IN: DataSet instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSet::DataSet( const DataSet& original ) : AbstractDs( original ) {} +DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object() +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: DataSet overload constructor - dereference ///\brief Given a reference to some object, returns that dataset ///\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 ///\exception H5::DataSetIException ///\par Description @@ -77,9 +84,14 @@ DataSet::DataSet( const DataSet& original ) : AbstractDs( original ) {} /// is a datatype that has been named by DataType::commit. // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -DataSet::DataSet(IdComponent& obj, void* ref) : AbstractDs() +DataSet::DataSet(H5Object& obj, void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object() { - IdComponent::dereference(obj, ref); + dereference(obj, ref, ref_type); +} + +DataSet::DataSet(H5File& h5file, void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object() +{ + dereference(h5file, ref, ref_type); } //-------------------------------------------------------------------------- @@ -245,7 +257,7 @@ void DataSet::vlenReclaim(const DataType& type, const DataSpace& space, const DS ///\param buf - IN: Pointer to the buffer to be reclaimed ///\exception H5::DataSetIException // Programmer Binh-Minh Ribler - 2000 -//\parDescription +//\par Description // This function has better prototype for the users than the // other, which might be removed at some point. BMR - 2006/12/20 //-------------------------------------------------------------------------- @@ -457,75 +469,43 @@ void DataSet::fillMemBuf(void *buf, DataType& buf_type, DataSpace& space) } } +#if 0 //-------------------------------------------------------------------------- -// Function: DataSet::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use -/// DataSet::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* DataSet::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 DataSetIException("DataSet::Reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: DataSet::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// DataSet::reference instead! +// Function: DataSet::getRefObjType +///\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::DataSetIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- -void* DataSet::Reference(const char* name) const +H5G_obj_t DataSet::getRefObjType(void *ref, H5R_type_t ref_type) const { try { - return(p_reference(name, -1, H5R_OBJECT)); + return(p_get_refobj_type(ref, ref_type)); } catch (IdComponentException E) { - throw DataSetIException("DataSet::Reference", E.getDetailMsg()); + throw DataSetIException("DataSet::getRefObjType", E.getDetailMsg()); } } - -//-------------------------------------------------------------------------- -// Function: DataSet::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// DataSet::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* DataSet::Reference(const H5std_string& name) const -{ - return(Reference(name.c_str())); -} +#endif //-------------------------------------------------------------------------- // Function: DataSet::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 - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. -///\return An object type, which can be one of the following: -/// \li \c H5G_LINK (0) - Object is a symbolic link. -/// \li \c H5G_GROUP (1) - Object is a group. -/// \li \c H5G_DATASET (2) - Object is a dataset. -/// \li \c H5G_TYPE Object (3) - is a named datatype -///\exception H5::DataSetIException +///\brief This function was misnamed and will be deprecated in favor of +/// H5Object::getRefObjType; please use getRefObjType instead. // Programmer Binh-Minh Ribler - May, 2004 +// Note: Replaced by getRefObjType. - BMR - Jul, 2008 //-------------------------------------------------------------------------- H5G_obj_t DataSet::getObjType(void *ref, H5R_type_t ref_type) const { - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw DataSetIException("DataSet::getObjType", E.getDetailMsg()); - } + return(getRefObjType(ref, ref_type)); } //-------------------------------------------------------------------------- @@ -550,6 +530,47 @@ DataSpace DataSet::getRegion(void *ref, H5R_type_t ref_type) const } //-------------------------------------------------------------------------- +// Function: DataSet::getId +// Purpose: Get the id of this dataset +// 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 DataSet::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: DataSet::p_setId +///\brief Sets the identifier of this dataset to a new value. +/// +///\exception H5::DataSetIException when the attempt to close the +/// currently open dataset 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 DataSet::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw DataSetIException("DataSet::p_setId", close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: DataSet::close ///\brief Closes this dataset. /// @@ -586,7 +607,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 24e52ab..2d625f0 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -23,7 +23,7 @@ namespace H5 { #endif -class H5_DLLCPP DataSet : public AbstractDs { +class H5_DLLCPP DataSet : public H5Object, public AbstractDs { public: // Close this dataset. virtual void close(); @@ -62,16 +62,16 @@ class H5_DLLCPP DataSet : public AbstractDs { // The memory and file dataspaces and the transferring property list // can be defaults. void read( void* buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; - void read( H5std_string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; + void read( H5std_string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; // Writes the buffered data to this dataset. // The memory and file dataspaces and the transferring property list // can be defaults. void write( const void* buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; - void write( const H5std_string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; + void write( const H5std_string& buf, const DataType& mem_type, const DataSpace& mem_space = DataSpace::ALL, const DataSpace& file_space = DataSpace::ALL, const DSetMemXferPropList& xfer_plist = DSetMemXferPropList::DEFAULT ) const; // Iterates the selected elements in the specified dataspace - not implemented in C++ style yet - int iterateElems( void* buf, const DataType& type, const DataSpace& space, H5D_operator_t op, void* op_data = NULL ); + int iterateElems( void* buf, const DataType& type, const DataSpace& space, H5D_operator_t op, void* op_data = NULL ); // Retrieves the type of object that an object reference points to. H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; @@ -79,19 +79,12 @@ class H5_DLLCPP DataSet : public AbstractDs { // Retrieves a dataspace with the region pointed to selected. DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - // Creates a reference to a named Hdf5 object or to a dataset region - // in this object. - void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - // Creates a reference to a named Hdf5 object in this object. - void* Reference(const char* name) const; // will be obsolete - void* Reference(const H5std_string& name) const; // will be obsolete - // Returns this class name virtual H5std_string fromClass () const { return("DataSet"); } // Creates a dataset by way of dereference. - DataSet(IdComponent& obj, void* ref); + DataSet(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataSet(H5File& file, void* ref, H5R_type_t ref_type = H5R_OBJECT); // Default constructor. DataSet(); @@ -102,14 +95,23 @@ class H5_DLLCPP DataSet : public AbstractDs { // Creates a copy of an existing DataSet using its id. DataSet(const hid_t existing_id); + // Gets the dataset id. + virtual hid_t getId() const; + // Destructor: properly terminates access to this dataset. virtual ~DataSet(); + protected: + // Sets the dataset id. + virtual void p_setId(const hid_t new_id); + private: - // This function contains the common code that is used by - // getTypeClass and various API functions getXxxType - // defined in AbstractDs for generic datatype and specific - // sub-types + hid_t id; // HDF5 dataset id + + // This function contains the common code that is used by + // getTypeClass and various API functions getXxxType + // defined in AbstractDs for generic datatype and specific + // sub-types virtual hid_t p_get_type() const; }; #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp index e5ef816..e755685 100644 --- a/c++/src/H5DataSpace.cpp +++ b/c++/src/H5DataSpace.cpp @@ -47,7 +47,7 @@ const DataSpace DataSpace::ALL( H5S_ALL ); ///\exception H5::DataSpaceIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSpace::DataSpace( H5S_class_t type ) : IdComponent(0) +DataSpace::DataSpace( H5S_class_t type ) : IdComponent() { id = H5Screate( type ); if( id < 0 ) @@ -65,7 +65,7 @@ DataSpace::DataSpace( H5S_class_t type ) : IdComponent(0) ///\exception H5::DataSpaceIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent(0) +DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : IdComponent() { id = H5Screate_simple( rank, dims, maxdims ); if( id < 0 ) @@ -82,7 +82,7 @@ DataSpace::DataSpace( int rank, const hsize_t * dims, const hsize_t * maxdims) : ///\exception H5::DataSpaceIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSpace::DataSpace(const hid_t existing_id) : IdComponent(existing_id) {} +DataSpace::DataSpace(const hid_t existing_id) : IdComponent(), id(existing_id) {} //-------------------------------------------------------------------------- // Function: DataSpace copy constructor @@ -90,7 +90,11 @@ DataSpace::DataSpace(const hid_t existing_id) : IdComponent(existing_id) {} ///\param original - IN: DataSpace object to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DataSpace::DataSpace( const DataSpace& original ) : IdComponent( original ) {} +DataSpace::DataSpace(const DataSpace& original) : IdComponent(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: DataSpace::copy @@ -548,6 +552,47 @@ void DataSpace::selectHyperslab( H5S_seloper_t op, const hsize_t *count, const h } //-------------------------------------------------------------------------- +// Function: DataSpace::getId +// Purpose: Get the id of this dataspace +// 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 DataSpace::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: DataSpace::p_setId +///\brief Sets the identifier of this dataspace to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the +/// currently open dataspace 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 DataSpace::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw GroupIException("DataSpace::p_setId", close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: DataSpace::close ///\brief Closes this dataspace. /// diff --git a/c++/src/H5DataSpace.h b/c++/src/H5DataSpace.h index e1c5ba4..e78e544 100644 --- a/c++/src/H5DataSpace.h +++ b/c++/src/H5DataSpace.h @@ -112,8 +112,18 @@ class H5_DLLCPP DataSpace : public IdComponent { // Copy constructor: makes a copy of the original DataSpace object. DataSpace(const DataSpace& original); + // Gets the dataspace id. + virtual hid_t getId() const; + // Destructor: properly terminates access to this dataspace. virtual ~DataSpace(); + + protected: + // Sets the dataspace id. + virtual void p_setId(const hid_t new_id); + + private: + hid_t id; // HDF5 dataspace id }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 8e5af5f..96adf8e 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -60,7 +60,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 @@ -90,24 +93,39 @@ 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(H5Object& obj, void* ref, H5R_type_t ref_type) : H5Object() +{ + dereference(obj, ref, ref_type); +} + +DataType::DataType(H5File& h5file, void* ref, H5R_type_t ref_type) : H5Object() { - IdComponent::dereference(obj, ref); + dereference(h5file, ref, ref_type); } //-------------------------------------------------------------------------- // Function: DataType default constructor ///\brief Default constructor: Creates a stub datatype // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -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 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -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 @@ -660,72 +678,15 @@ 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())); -} - -//-------------------------------------------------------------------------- // Function: DataType::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 -///\return Object type, which can be one of the following: -/// \li \c H5G_LINK Object is a symbolic link. -/// \li \c H5G_GROUP Object is a group. -/// \li \c H5G_DATASET Object is a dataset. -/// \li \c H5G_TYPE Object is a named datatype -///\exception H5::DataTypeIException +///\brief This function was misnamed and will be deprecated in favor of +/// H5Object::getRefObjType; please use getRefObjType instead. // Programmer Binh-Minh Ribler - May, 2004 +// Note: Replaced by getRefObjType. - BMR - Jul, 2008 //-------------------------------------------------------------------------- H5G_obj_t DataType::getObjType(void *ref, H5R_type_t ref_type) const { - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw DataTypeIException(inMemFunc("getObjType"), E.getDetailMsg()); - } + return(getRefObjType(ref, ref_type)); } //-------------------------------------------------------------------------- @@ -749,6 +710,50 @@ DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const } //-------------------------------------------------------------------------- +// Function: DataType::getId +// Purpose: Get the id of this datatype +// 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::p_setId +///\brief Sets the identifier of this datatype to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the +/// currently open datatype 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 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 +//-------------------------------------------------------------------------- +void DataType::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw DataTypeIException(inMemFunc("p_setId"), close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: DataType::close ///\brief Closes the datatype if it is not a predefined type. /// diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 3c53050..57a0345 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -30,7 +30,8 @@ class H5_DLLCPP DataType : public H5Object { DataType( const DataType& original ); // Creates a datatype by way of dereference. - DataType(IdComponent& obj, void* ref); + DataType(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataType(H5File& file, void* ref, H5R_type_t ref_type = H5R_OBJECT); // Closes this datatype. virtual void close(); @@ -105,14 +106,6 @@ class H5_DLLCPP DataType : public H5Object { // Checks whether this datatype is a variable-length string. bool isVariableStr() const; - // Creates a reference to a named HDF5 object or to a dataset region - // in this object. - void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; // will be obsolete - - // Creates a reference to a named HDF5 object in this object. - void* Reference(const char* name) const; // will be obsolete - void* Reference(const H5std_string& name) const; // will be obsolete - // Retrieves the type of object that an object reference points to. H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; @@ -128,8 +121,18 @@ class H5_DLLCPP DataType : public H5Object { // Default constructor DataType(); + // Gets the datatype id. + virtual hid_t getId() const; + // Destructor: properly terminates access to this datatype. virtual ~DataType(); + + protected: + hid_t id; // HDF5 datatype id + + // Sets the datatype id. + virtual void p_setId(const hid_t new_id); + private: void p_commit(hid_t loc_id, const char* name); }; diff --git a/c++/src/H5DcreatProp.cpp b/c++/src/H5DcreatProp.cpp index e498ee4..656956f 100644 --- a/c++/src/H5DcreatProp.cpp +++ b/c++/src/H5DcreatProp.cpp @@ -54,7 +54,7 @@ DSetCreatPropList::DSetCreatPropList( const DSetCreatPropList& orig ) : PropList /// existing dataset creation property list. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -DSetCreatPropList::DSetCreatPropList(const hid_t plist_id) : PropList( plist_id ) {} +DSetCreatPropList::DSetCreatPropList(const hid_t plist_id) : PropList(plist_id) {} //-------------------------------------------------------------------------- // Function: DSetCreatPropList::setChunk diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp index b2467b9..49cad88 100644 --- a/c++/src/H5DxferProp.cpp +++ b/c++/src/H5DxferProp.cpp @@ -31,7 +31,7 @@ namespace H5 { const DSetMemXferPropList DSetMemXferPropList::DEFAULT; //-------------------------------------------------------------------------- -// Function 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/H5FaccProp.cpp b/c++/src/H5FaccProp.cpp index 7c9b33a..3a8e855 100644 --- a/c++/src/H5FaccProp.cpp +++ b/c++/src/H5FaccProp.cpp @@ -225,7 +225,7 @@ void FileAccPropList::getFamily(hsize_t& memb_size, FileAccPropList& memb_plist) { throw PropListIException("FileAccPropList::getFamily", "H5Pget_fapl_family failed"); } - memb_plist.setId(memb_plist_id); + memb_plist.p_setId(memb_plist_id); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 37bb65a..8931021 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() : IdComponent(0) {} +H5File::H5File() : IdComponent(), id(0) {} //-------------------------------------------------------------------------- // Function: H5File overloaded constructor @@ -79,7 +79,7 @@ H5File::H5File() : IdComponent(0) {} /// ../RM_H5F.html#File-Create // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent(0) +H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() { p_get_file(name, flags, create_plist, access_plist); } @@ -97,7 +97,7 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c /// FileCreatPropList::DEFAULT // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent(0) +H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() { p_get_file(name.c_str(), flags, create_plist, access_plist); } @@ -140,7 +140,11 @@ void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPro ///\param original - IN: H5File instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const H5File& original ) : IdComponent( original ) {} +H5File::H5File(const H5File& original) : IdComponent(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: H5File::flush @@ -503,58 +507,24 @@ H5std_string H5File::getFileName() const } //-------------------------------------------------------------------------- -// Function: H5File::Reference -///\brief Important!!! - This functions does not work correctly, it -/// will be removed in the near future. Please use -/// H5File::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* H5File::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 FileIException("H5File::Reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5File::Reference -///\brief Important!!! - This functions does not work correctly, it -/// will be removed in the near future. Please use similar -/// H5File::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* H5File::Reference(const char* name) const -{ - try { - return(p_reference(name, -1, H5R_OBJECT)); - } - catch (IdComponentException E) { - throw FileIException("H5File::Reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5File::Reference -///\brief Important!!! - This functions does not work correctly, it -/// will be removed in the near future. Please use similar -/// H5File::reference instead! +// Function: H5File::getObjType +///\brief This function was misnamed and will be deprecated in favor of +/// H5File::getRefObjType; please use getRefObjType instead. // Programmer Binh-Minh Ribler - May, 2004 +// Note: Replaced by getRefObjType. - BMR - Jul, 2008 //-------------------------------------------------------------------------- -void* H5File::Reference(const H5std_string& name) const +H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const { - return(Reference(name.c_str())); + return(getRefObjType(ref, ref_type)); } //-------------------------------------------------------------------------- -// Function: H5File::getObjType +// Function: H5File::getRefObjType ///\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, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. +/// \li \c H5R_OBJECT \tReference is an object reference. +/// \li \c H5R_DATASET_REGION \tReference is a dataset region reference. ///\return Object type, which can be one of the following: /// \li \c H5G_LINK - Object is a symbolic link. /// \li \c H5G_GROUP - Object is a group. @@ -563,13 +533,13 @@ void* H5File::Reference(const H5std_string& name) const ///\exception H5::FileIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- -H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const +H5G_obj_t H5File::getRefObjType(void *ref, H5R_type_t ref_type) const { try { - return(p_get_obj_type(ref, ref_type)); + return(p_get_refobj_type(ref, ref_type)); } catch (IdComponentException E) { - throw FileIException("H5File::getObjType", E.getDetailMsg()); + throw FileIException("H5File::getRefObjType", E.getDetailMsg()); } } @@ -615,6 +585,141 @@ hsize_t H5File::getFileSize() const } //-------------------------------------------------------------------------- +// Function: H5File::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 +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5File::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const +{ + herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); + if (ret_value < 0) + { + throw IdComponentException("", "H5Rcreate failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5File::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 +///\exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5File::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const +{ + try { + p_reference(ref, name, dataspace.getId(), ref_type); + } + catch (IdComponentException E) { + throw IdComponentException("H5File::reference", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5File::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 H5File::reference(void* ref, const char* name) const +{ + try { + p_reference(ref, name, -1, H5R_OBJECT); + } + catch (IdComponentException E) { + throw IdComponentException("H5File::reference", E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5File::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 H5File::reference(void* ref, const H5std_string& name) const +{ + reference(ref, name.c_str()); +} + +#if 0 +//-------------------------------------------------------------------------- +// Function: H5File::p_get_obj_type (protected) +// 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 +// Return An object type, which can be one of the following: +// H5G_LINK Object is a symbolic link. +// H5G_GROUP Object is a group. +// H5G_DATASET Object is a dataset. +// H5G_TYPE Object is a named datatype +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t H5Object::p_get_obj_type(void *ref, H5R_type_t ref_type) const +{ +#ifdef H5_WANT_H5_V1_4_COMPAT + H5G_obj_t obj_type = H5Rget_object_type(getId(), ref); +#else + H5G_obj_t obj_type = H5Rget_obj_type(getId(), ref_type, ref); +#endif + + if (obj_type == H5G_UNKNOWN) + { +#ifdef H5_WANT_H5_V1_4_COMPAT + throw IdComponentException("", "H5Rget_object_type failed"); +#else + throw IdComponentException("", "H5Rget_obj_type failed"); +#endif + } + return(obj_type); +} +#endif +//-------------------------------------------------------------------------- +// Function: H5File::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 +// Return Dataspace id +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +hid_t H5File::p_get_region(void *ref, H5R_type_t ref_type) const +{ + hid_t space_id = H5Rget_region(getId(), ref_type, ref); + if (space_id < 0) + { + throw IdComponentException("", "H5Rget_region failed"); + } + return(space_id); +} + +//-------------------------------------------------------------------------- // Function: H5File::getLocId // Purpose: Get the id of this file // Description @@ -628,6 +733,47 @@ hid_t H5File::getLocId() const } //-------------------------------------------------------------------------- +// Function: H5File::getId +// Purpose: Get the id of this HDF5 file +// 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 H5File::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: H5File::p_setId +///\brief Sets the identifier of this HDF5 file 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 H5File::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw FileIException("H5File::p_setId", close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: H5File::close ///\brief Closes this HDF5 file. /// diff --git a/c++/src/H5File.h b/c++/src/H5File.h index ba6e1cc..f5d8dea 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -68,6 +68,9 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { void getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const; // Retrieves the type of object that an object reference points to. + H5G_obj_t getRefObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; + + // Deprecated in favor of getRefObjType H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; // Retrieves a dataspace with the region pointed to selected. @@ -87,11 +90,10 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // Creates a reference to a named HDF5 object or to a dataset region // in this object. - void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - // Creates a reference to a named Hdf5 object in this object. - void* Reference(const char* name) const; // will be obsolete - void* Reference(const H5std_string& name) const; // will be obsolete + void reference(void* ref, const char* name, const DataSpace& dataspace, + H5R_type_t ref_type = H5R_DATASET_REGION) const; + void reference(void* ref, const char* name) const; + void reference(void* ref, const H5std_string& name) const; // Returns this class name virtual H5std_string fromClass () const { return("H5File"); } @@ -108,14 +110,38 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // Copy constructor: makes a copy of the original H5File object. H5File(const H5File& original); + // Gets the HDF5 file id. + virtual hid_t getId() const; + // H5File destructor. virtual ~H5File(); + protected: + // Sets the HDF5 file id. + virtual void p_setId(const hid_t new_id); + private: + hid_t id; // HDF5 file id + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + // This function is private and contains common code between the // constructors taking a string or a char* void p_get_file( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ); + // 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; + +#ifndef H5_NO_DEPRECATED_SYMBOLS + // Retrieves the type of object that an object reference points to. + H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const; +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + + // Retrieves a dataspace with the region pointed to selected. + hid_t p_get_region(void *ref, H5R_type_t ref_type) const; + +#endif // DOXYGEN_SHOULD_SKIP_THIS + }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index aaddd85..57da96d 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -49,16 +49,26 @@ namespace H5 { // Function: Group default constructor ///\brief Default constructor: creates a stub Group. // Programmer Binh-Minh Ribler - 2000 +// Modification +// 2008 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -Group::Group() : H5Object() {} +Group::Group() : H5Object(), id(0) {} //-------------------------------------------------------------------------- // Function: Group copy constructor ///\brief Copy constructor: makes a copy of the original Group object. ///\param original - IN: Original group to copy // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -Group::Group( const Group& original ) : H5Object( original ) {} +Group::Group(const Group& original) : H5Object(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: Group::getLocId @@ -76,77 +86,43 @@ hid_t Group::getLocId() const ///\brief Creates a Group object using the id of an existing group. ///\param group_id - IN: Id of an existing group // Programmer Binh-Minh Ribler - 2000 +// Modification +// Jul, 08 No longer inherit data member 'id' from IdComponent. +// - bugzilla 1068 //-------------------------------------------------------------------------- -Group::Group( const hid_t group_id ) : H5Object( group_id ) {} +Group::Group(const hid_t existing_id) : H5Object() +{ + id = existing_id; +} //-------------------------------------------------------------------------- // Function: Group overload constructor - dereference -///\brief Given a reference to some object, returns that group +///\brief Given a reference to some object or a file, returns that group ///\param obj - IN: Location reference object is in -///\param ref - IN: Reference pointer +/// ref - IN: Reference pointer ///\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 //-------------------------------------------------------------------------- -Group::Group(IdComponent& obj, void* ref) : H5Object() +Group::Group(H5Object& obj, void* ref, H5R_type_t ref_type) : H5Object() { - IdComponent::dereference(obj, ref); -} - -//-------------------------------------------------------------------------- -// Function: Group::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// Group::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* Group::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 GroupIException("Group::Reference", E.getDetailMsg()); - } + dereference(obj, ref, ref_type); } -//-------------------------------------------------------------------------- -// Function: Group::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// Group::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* Group::Reference(const char* name) const +Group::Group(H5File& h5file, void* ref, H5R_type_t ref_type) : H5Object() { - try { - return(p_reference(name, -1, H5R_OBJECT)); - } - catch (IdComponentException E) { - throw GroupIException("Group::Reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: Group::Reference -///\brief Important!!! - This functions may not work correctly, it -/// will be removed in the near future. Please use similar -/// Group::reference instead! -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* Group::Reference(const H5std_string& name) const -{ - return(Reference(name.c_str())); + dereference(h5file, ref, ref_type); } +#if 0 // remove after verifying with tests //-------------------------------------------------------------------------- // Function: Group::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 - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. +/// 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: /// H5G_LINK Object is a symbolic link. /// H5G_GROUP Object is a group. @@ -164,12 +140,25 @@ H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const throw GroupIException("Group::getObjType", E.getDetailMsg()); } } +#endif + +//-------------------------------------------------------------------------- +// Function: H5File::getObjType +///\brief This function was misnamed and will be deprecated in favor of +/// H5Object::getRefObjType; please use getRefObjType instead. +// Programmer Binh-Minh Ribler - May, 2004 +// Note: Replaced by getRefObjType. - BMR - Jul, 2008 +//-------------------------------------------------------------------------- +H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const +{ + return(getRefObjType(ref, ref_type)); +} //-------------------------------------------------------------------------- // Function: Group::getRegion ///\brief Retrieves a dataspace with the region pointed to selected. ///\param ref - IN: Reference to get region of -///\param ref_type - IN: Type of reference to get region of - default +/// ref_type - IN: Type of reference to get region of - default ///\return DataSpace instance ///\exception H5::GroupIException // Programmer Binh-Minh Ribler - May, 2004 @@ -186,6 +175,47 @@ DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const } //-------------------------------------------------------------------------- +// Function: Group::getId +// Purpose: Get the id of this group +// 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 Group::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: Group::p_setId +///\brief Sets the identifier of this group to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the +/// currently open group 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 Group::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw GroupIException("Group::p_setId", close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: Group::close ///\brief Closes this group. /// diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index d7e7dec..2c4fd10 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -32,14 +32,6 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Retrieves a dataspace with the region pointed to selected. DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - // Creates a reference to a named Hdf5 object or to a dataset region - // in this object. - void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; // will be obsolete - - // Creates a reference to a named Hdf5 object in this object. - void* Reference(const char* name) const; // will be obsolete - void* Reference(const H5std_string& name) const; // will be obsolete - // Returns this class name virtual H5std_string fromClass () const { return("Group"); } @@ -50,7 +42,8 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { virtual hid_t getLocId() const; // Creates a group by way of dereference. - Group(IdComponent& obj, void* ref); + Group(H5Object& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT); + Group(H5File& obj, void* ref, H5R_type_t ref_type = H5R_OBJECT); // default constructor Group(); @@ -58,12 +51,21 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Copy constructor: makes a copy of the original object Group(const Group& original); - // Destructor - virtual ~Group(); + // Gets the group id. + virtual hid_t getId() const; // Creates a copy of an existing group using its id. Group( const hid_t group_id ); + // Destructor + virtual ~Group(); + + protected: + // Sets the group id. + virtual void p_setId(const hid_t new_id); + + private: + hid_t id; // HDF5 group id }; #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 15f0d33..0fb744f 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -32,7 +32,7 @@ namespace H5 { ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {} +IdComponent::IdComponent(const hid_t h5_id) {} //-------------------------------------------------------------------------- // Function: IdComponent copy constructor @@ -40,11 +40,7 @@ IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {} ///\param original - IN: IdComponent instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent( const IdComponent& original ) -{ - id = original.id; - incRefCount(); // increment number of references to this id -} +IdComponent::IdComponent( const IdComponent& original ) {} //-------------------------------------------------------------------------- // Function: IdComponent::incRefCount @@ -65,7 +61,7 @@ void IdComponent::incRefCount(const hid_t obj_id) const //-------------------------------------------------------------------------- void IdComponent::incRefCount() const { - incRefCount(id); + incRefCount(getId()); } //-------------------------------------------------------------------------- @@ -95,7 +91,7 @@ void IdComponent::decRefCount(const hid_t obj_id) const //-------------------------------------------------------------------------- void IdComponent::decRefCount() const { - decRefCount(id); + decRefCount(getId()); } //-------------------------------------------------------------------------- @@ -124,7 +120,7 @@ int IdComponent::getCounter(const hid_t obj_id) const //-------------------------------------------------------------------------- int IdComponent::getCounter() const { - return (getCounter(id)); + return (getCounter(getId())); } //-------------------------------------------------------------------------- @@ -177,10 +173,9 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) } // copy the data members from the rhs object - id = rhs.id; - - // increment the reference counter - incRefCount(); + p_setId(rhs.getId()); + incRefCount(getId()); // a = b, so there are two objects with the same + // hdf5 id } return *this; } @@ -192,40 +187,31 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) ///\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. +// 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 +// Modification +// 2008/7/23 - BMR +// Changed all subclasses' setId to p_setId and put back setId +// here. p_setId is used in the library where the id provided +// by a C API passed on to user's application in the form of a +// C++ API object, which will be destroyed properly, and so +// p_setId does not call incRefCount. On the other hand, the +// public version setId is used by other applications, in which +// the id passed to setId already has a reference count, so setId +// must call incRefCount. //-------------------------------------------------------------------------- void IdComponent::setId(const hid_t new_id) { - // handling references to this old id - try { - close(); - } - catch (Exception close_error) { - throw IdComponentException(inMemFunc("copy"), close_error.getDetailMsg()); - } - - // reset object's id to the given id - id = new_id; + // set to new_id + p_setId(new_id); // increment the reference counter of the new id incRefCount(); } //-------------------------------------------------------------------------- -// Function: IdComponent::getId -///\brief Returns the id of this object -///\return HDF5 id -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -hid_t IdComponent::getId () const -{ - return(id); -} - -//-------------------------------------------------------------------------- // Function: IdComponent destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 @@ -263,7 +249,7 @@ H5std_string IdComponent::inMemFunc(const char* func_name) const ///\brief Default constructor. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -IdComponent::IdComponent() : id(-1) {} +IdComponent::IdComponent() {} //-------------------------------------------------------------------------- // Function: IdComponent::p_get_file_name (protected) @@ -277,10 +263,12 @@ IdComponent::IdComponent() : id(-1) {} //-------------------------------------------------------------------------- H5std_string IdComponent::p_get_file_name() const { + hid_t temp_id = getId(); + // Preliminary call to H5Fget_name to get the length of the file name - ssize_t name_size = H5Fget_name(id, NULL, 0); + ssize_t name_size = H5Fget_name(temp_id, NULL, 0); - // If H5Aget_name returns a negative value, raise an exception, + // If H5Fget_name returns a negative value, raise an exception, if( name_size < 0 ) { throw IdComponentException("", "H5Fget_name failed"); @@ -288,7 +276,7 @@ H5std_string IdComponent::p_get_file_name() const // Call H5Fget_name again to get the actual file name char* name_C = new char[name_size+1]; // temporary C-string for C API - name_size = H5Fget_name(id, name_C, name_size+1); + name_size = H5Fget_name(temp_id, name_C, name_size+1); // Check for failure again if( name_size < 0 ) @@ -303,131 +291,27 @@ H5std_string IdComponent::p_get_file_name() const } //-------------------------------------------------------------------------- -// Function: IdComponent::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 -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void IdComponent::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const -{ - herr_t ret_value = H5Rcreate(ref, id, name, ref_type, space_id); - if (ret_value < 0) - { - throw IdComponentException("", "H5Rcreate failed"); - } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 -///\exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void IdComponent::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const -{ - try { - p_reference(ref, name, dataspace.getId(), ref_type); - } - catch (IdComponentException E) { - throw IdComponentException("IdComponent::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 IdComponent::reference(void* ref, const char* name) const -{ - try { - p_reference(ref, name, -1, H5R_OBJECT); - } - catch (IdComponentException E) { - throw IdComponentException("IdComponent::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 IdComponent::reference(void* ref, const H5std_string& name) const -{ - reference(ref, name.c_str()); -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::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 -// Return A reference -// Exception H5::IdComponentException -// Notes This function is incorrect, and will be removed in the near -// future after notifying users of the new APIs ::reference's. -// BMR - Oct 8, 2006 -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void* IdComponent::p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const -{ - hobj_ref_t ref; - herr_t ret_value = H5Rcreate(&ref, id, name, ref_type, space_id); - if (ret_value < 0) - { - throw IdComponentException("", "H5Rcreate failed"); - } - return (reinterpret_cast(ref)); -} - -//-------------------------------------------------------------------------- -// Function: IdComponent::dereference +// Function: IdComponent::p_dereference (protected) // Purpose Opens the HDF5 object referenced. // Parameters -// obj - IN: Dataset reference object is in or location of -// object that the dataset is located within. // ref - IN: Reference pointer // Exception H5::IdComponentException // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -void IdComponent::dereference(IdComponent& obj, void* ref) +#if 0 +hid_t IdComponent::p_dereference(hid_t obj_id, void* ref) const { - id = H5Rdereference(obj.getId(), H5R_OBJECT, ref); - if (id < 0) + hid_t temp_id = H5Rdereference(obj_id, H5R_OBJECT, ref); + if (temp_id < 0) { - throw IdComponentException("", "H5Rdereference failed"); + throw ReferenceException("", "H5Rdereference failed"); } + return(temp_id); } +#endif //-------------------------------------------------------------------------- -// Function: IdComponent::p_get_obj_type (protected) +// Function: IdComponent::p_get_refobj_type (protected) // Purpose Retrieves the type of object that an object reference points to. // Parameters // ref - IN: Reference to query @@ -435,17 +319,17 @@ void IdComponent::dereference(IdComponent& obj, void* ref) // Return An object type, which can be one of the following: // H5G_LINK Object is a symbolic link. // H5G_GROUP Object is a group. -// H5G_DATASET Object is a dataset. +// H5G_DATASET Object is a dataset. // H5G_TYPE Object is a named datatype // Exception H5::IdComponentException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- -H5G_obj_t IdComponent::p_get_obj_type(void *ref, H5R_type_t ref_type) const +H5G_obj_t IdComponent::p_get_refobj_type(void *ref, H5R_type_t ref_type) const { #ifdef H5_WANT_H5_V1_4_COMPAT - H5G_obj_t obj_type = H5Rget_object_type(id, ref); + H5G_obj_t obj_type = H5Rget_object_type(getId(), ref); #else - H5G_obj_t obj_type = H5Rget_obj_type(id, ref_type, ref); + H5G_obj_t obj_type = H5Rget_obj_type(getId(), ref_type, ref); #endif if (obj_type == H5G_UNKNOWN) @@ -459,27 +343,6 @@ H5G_obj_t IdComponent::p_get_obj_type(void *ref, H5R_type_t ref_type) const return(obj_type); } -//-------------------------------------------------------------------------- -// Function: IdComponent::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 -// Return Dataspace id -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const -{ - hid_t space_id = H5Rget_region(id, ref_type, ref); - if (space_id < 0) - { - throw IdComponentException("", "H5Rget_region failed"); - } - return(space_id); -} - // // Local functions used in this class // @@ -491,7 +354,7 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const // Return true if id is valid, false, otherwise // Programmer Binh-Minh Ribler - May, 2005 //-------------------------------------------------------------------------- -bool IdComponent::p_valid_id(const hid_t obj_id) const +bool IdComponent::p_valid_id(const hid_t obj_id) { H5I_type_t id_type = H5Iget_type(obj_id); if (id_type <= H5I_BADID || id_type >= H5I_NGROUPS) diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 503217b..3333f3a 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -44,13 +44,8 @@ class H5_DLLCPP IdComponent { // Assignment operator. IdComponent& operator=( const IdComponent& rhs ); - void reference(void* ref, const char* name, const DataSpace& dataspace, - H5R_type_t ref_type = H5R_DATASET_REGION) const; - void reference(void* ref, const char* name) const; - void reference(void* ref, const H5std_string& name) const; - - // Open a referenced HDF5 object. - void dereference(IdComponent& obj, void* ref); + // Gets the identifier of this object. + virtual hid_t getId () const = 0; // Sets the identifier of this object to a new value. void setId(const hid_t new_id); @@ -61,9 +56,6 @@ class H5_DLLCPP IdComponent { // Copy constructor: makes copy of the original IdComponent object. IdComponent( const IdComponent& original ); - // Gets the value of IdComponent's data member. - virtual hid_t getId () const; - #ifndef DOXYGEN_SHOULD_SKIP_THIS // Pure virtual function for there are various H5*close for the // subclasses. @@ -82,8 +74,10 @@ 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 - hid_t id; // HDF5 object id // Default constructor. IdComponent(); @@ -91,21 +85,17 @@ class H5_DLLCPP IdComponent { // Gets the name of the file, in which an HDF5 object belongs. H5std_string p_get_file_name() const; - // Gets the id of the H5 file in which the given object is located. - hid_t p_get_file_id(); + // Verifies that the given id is valid. + static bool p_valid_id(const hid_t obj_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; - void* p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const; // will be removed + // Sets the identifier of this object to a new value. - this one + // doesn't increment reference count + virtual void p_setId(const hid_t new_id) = 0; - // Retrieves the type of object that an object reference points to. - H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const; + // Opens the HDF5 object referenced. - // Retrieves a dataspace with the region pointed to selected. - hid_t p_get_region(void *ref, H5R_type_t ref_type) const; - - // Verifies that the given id is valid. - bool p_valid_id(const hid_t obj_id) 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; #endif // DOXYGEN_SHOULD_SKIP_THIS diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index c49abaf..f58c5c4 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -21,10 +21,15 @@ #include "H5PropList.h" #include "H5Object.h" #include "H5DcreatProp.h" +#include "H5DxferProp.h" +#include "H5FaccProp.h" +#include "H5FcreatProp.h" #include "H5CommonFG.h" #include "H5DataType.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" +#include "H5File.h" +#include "H5DataSet.h" #include "H5Attribute.h" #ifndef H5_NO_NAMESPACE @@ -102,7 +107,7 @@ Attribute H5Object::createAttribute( const char* name, const DataType& data_type hid_t type_id = data_type.getId(); hid_t space_id = data_space.getId(); hid_t plist_id = create_plist.getId(); - hid_t attr_id = H5Acreate( id, name, type_id, space_id, plist_id ); + hid_t attr_id = H5Acreate(getId(), name, type_id, space_id, plist_id ); // If the attribute id is valid, create and return the Attribute object if( attr_id > 0 ) @@ -138,7 +143,7 @@ Attribute H5Object::createAttribute( const H5std_string& name, const DataType& d //-------------------------------------------------------------------------- Attribute H5Object::openAttribute( const char* name ) const { - hid_t attr_id = H5Aopen_name( id, name ); + hid_t attr_id = H5Aopen_name(getId(), name ); if( attr_id > 0 ) { Attribute attr( attr_id ); @@ -172,7 +177,7 @@ Attribute H5Object::openAttribute( const H5std_string& name ) const //-------------------------------------------------------------------------- Attribute H5Object::openAttribute( const unsigned int idx ) const { - hid_t attr_id = H5Aopen_idx( id, idx ); + hid_t attr_id = H5Aopen_idx(getId(), idx ); if( attr_id > 0 ) { Attribute attr( attr_id ); @@ -210,7 +215,7 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned * idx, void *op_da userData->object = this; // call the C library routine H5Aiterate to iterate the attributes - int ret_value = H5Aiterate( id, idx, userAttrOpWrpr, (void *) userData ); + int ret_value = H5Aiterate(getId(), idx, userAttrOpWrpr, (void *) userData ); // release memory delete userData; @@ -231,7 +236,7 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned * idx, void *op_da //-------------------------------------------------------------------------- int H5Object::getNumAttrs() const { - int num_attrs = H5Aget_num_attrs( id ); + int num_attrs = H5Aget_num_attrs(getId()); if( num_attrs < 0 ) { throw AttributeIException(inMemFunc("getNumAttrs"), @@ -250,11 +255,9 @@ int H5Object::getNumAttrs() const //-------------------------------------------------------------------------- void H5Object::removeAttr( const char* name ) const { - herr_t ret_value = H5Adelete( id, name ); + herr_t ret_value = H5Adelete(getId(), name); if( ret_value < 0 ) - { throw AttributeIException(inMemFunc("removeAttr"), "H5Adelete failed"); - } } //-------------------------------------------------------------------------- @@ -279,11 +282,9 @@ void H5Object::removeAttr( const H5std_string& name ) const //-------------------------------------------------------------------------- void H5Object::renameAttr(const char* oldname, const char* newname) const { - herr_t ret_value = H5Arename(id, oldname, newname); + herr_t ret_value = H5Arename(getId(), oldname, newname); if (ret_value < 0) - { throw AttributeIException(inMemFunc("renameAttr"), "H5Arename failed"); - } } //-------------------------------------------------------------------------- @@ -310,9 +311,9 @@ void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newna /// This object is used to identify the file to be flushed. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -void H5Object::flush(H5F_scope_t scope ) const +void H5Object::flush(H5F_scope_t scope) const { - herr_t ret_value = H5Fflush( id, scope ); + herr_t ret_value = H5Fflush(getId(), scope); if( ret_value < 0 ) { throw FileIException(inMemFunc("flush"), "H5Fflush failed"); @@ -337,6 +338,232 @@ H5std_string H5Object::getFileName() const } //-------------------------------------------------------------------------- +// 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 +// 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 +{ + herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); + if (ret_value < 0) + { + throw IdComponentException("", "H5Rcreate failed"); + } +} + +//-------------------------------------------------------------------------- +// 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 +///\exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Object::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const +{ + try { + p_reference(ref, name, dataspace.getId(), ref_type); + } + catch (IdComponentException E) { + throw IdComponentException("H5Object::reference", 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. +///\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()); + } +} + +//-------------------------------------------------------------------------- +// 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 +{ + reference(ref, name.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::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 and H5Object +//-------------------------------------------------------------------------- +#if 0 +void H5Object::dereference(H5File& h5file, void* ref) +{ + hid_t temp_id; + try { + temp_id = p_dereference(h5file.getId(), ref); + } + catch (ReferenceException ref_err) { + throw (inMemFunc("dereference"), ref_err.getDetailMsg()); + } + + // No failure, set id to the object + p_setId(temp_id); +} +void H5Object::dereference(H5Object& obj, void* ref) +{ + hid_t temp_id; + try { + temp_id = p_dereference(obj.getId(), ref); + } + catch (ReferenceException ref_err) { + throw (inMemFunc("dereference"), ref_err.getDetailMsg()); + } + + // No failure, set id to the object + p_setId(temp_id); +} + +#endif +void H5Object::dereference(H5Object& obj, void* ref, H5R_type_t ref_type) +{ + hid_t temp_id; + temp_id = H5Rdereference(obj.getId(), ref_type, ref); + if (temp_id < 0) + { + throw (inMemFunc("dereference"), "H5Rdereference failed"); + } + + // No failure, set id to the object + p_setId(temp_id); +} + +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"); + } + + // No failure, set id to the object + p_setId(temp_id); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::getRefObjType +///\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::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t H5Object::getRefObjType(void *ref, H5R_type_t ref_type) const +{ + try { + return(p_get_refobj_type(ref, ref_type)); + } + catch (IdComponentException E) { + throw IdComponentException("H5Object::getRefObjType", E.getDetailMsg()); + } +} + +#if 0 +//-------------------------------------------------------------------------- +// Function: H5Object::p_get_refobj_type (protected) +// 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 +// Return An object type, which can be one of the following: +// H5G_LINK Object is a symbolic link. +// H5G_GROUP Object is a group. +// H5G_DATASET Object is a dataset. +// H5G_TYPE Object is a named datatype +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t H5Object::p_get_refobj_type(void *ref, H5R_type_t ref_type) const +{ +#ifdef H5_WANT_H5_V1_4_COMPAT + H5G_obj_t obj_type = H5Rget_object_type(getId(), ref); +#else + H5G_obj_t obj_type = H5Rget_obj_type(getId(), ref_type, ref); +#endif + + if (obj_type == H5G_UNKNOWN) + { +#ifdef H5_WANT_H5_V1_4_COMPAT + throw IdComponentException("", "H5Rget_object_type failed"); +#else + throw IdComponentException("", "H5Rget_obj_type failed"); +#endif + } + return(obj_type); +} +#endif + +//-------------------------------------------------------------------------- +// 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 +// Return Dataspace id +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +hid_t H5Object::p_get_region(void *ref, H5R_type_t ref_type) const +{ + hid_t space_id = H5Rget_region(getId(), ref_type, ref); + if (space_id < 0) + { + throw IdComponentException("", "H5Rget_region failed"); + } + return(space_id); +} +//-------------------------------------------------------------------------- // Function: H5Object destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index b576621..1b1f656 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -20,8 +20,7 @@ #include "H5Classes.h" // constains forward class declarations // H5Object is a baseclass. It has these subclasses: -// Group, AbstractDs, and DataType. -// AbstractDs, in turn, has subclasses DataSet and Attribute. +// Group, DataSet, and DataType. // DataType, in turn, has several specific datatypes as subclasses. #ifndef H5_NO_NAMESPACE @@ -70,6 +69,9 @@ class H5_DLLCPP H5Object : public IdComponent { // Determines the number of attributes attached to this object. int getNumAttrs() const; + // Retrieves the type of object that an object reference points to. + H5G_obj_t getRefObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; + // Iterate user's function over the attributes of this object int iterateAttrs( attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL ); @@ -81,6 +83,17 @@ 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. + void reference(void* ref, const char* name, const DataSpace& dataspace, + H5R_type_t ref_type = H5R_DATASET_REGION) const; + 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); + // Copy constructor: makes copy of an H5Object object. H5Object(const H5Object& original); @@ -94,6 +107,19 @@ class H5_DLLCPP H5Object : public IdComponent { // 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; + + // 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; + + // Retrieves a dataspace with the region pointed to selected. + hid_t p_get_region(void *ref, H5R_type_t ref_type) const; + #endif // DOXYGEN_SHOULD_SKIP_THIS }; /* end class H5Object */ diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index 7cbc6ad..14987f3 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -18,12 +18,14 @@ #else #include #endif + #include #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5private.h" // for HDfree #ifndef H5_NO_NAMESPACE namespace H5 { @@ -43,7 +45,7 @@ const PropList PropList::DEFAULT( H5P_DEFAULT ); ///\brief Default constructor: creates a stub property list object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList() : IdComponent( 0 ) {} +PropList::PropList() : IdComponent(), id(0) {} //-------------------------------------------------------------------------- // Function: PropList copy constructor @@ -51,7 +53,11 @@ PropList::PropList() : IdComponent( 0 ) {} ///\param original - IN: The original property list to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList( const PropList& original ) : IdComponent( original ) {} +PropList::PropList(const PropList& original) : IdComponent(original) +{ + id = original.getId(); + incRefCount(); // increment number of references to this id +} //-------------------------------------------------------------------------- // Function: PropList overloaded constructor @@ -67,7 +73,7 @@ PropList::PropList( const PropList& original ) : IdComponent( original ) {} // description was what I came up with from reading the code. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -PropList::PropList( const hid_t plist_id ) : IdComponent(0) +PropList::PropList( const hid_t plist_id ) : IdComponent() { if (H5I_GENPROP_CLS == H5Iget_type(plist_id)) { // call C routine to create the new property @@ -202,6 +208,46 @@ void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name } //-------------------------------------------------------------------------- +// Function: PropList::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 PropList::getId() const +{ + return(id); +} + +//-------------------------------------------------------------------------- +// Function: PropList::p_setId +///\brief Sets the identifier of this property list to a new value. +/// +///\exception H5::IdComponentException when the attempt to close the +/// currently open property list 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 PropList::p_setId(const hid_t new_id) +{ + // handling references to this old id + try { + close(); + } + catch (Exception close_error) { + throw PropListIException(inMemFunc("p_setId"), close_error.getDetailMsg()); + } + // reset object's id to the given id + id = new_id; +} + +//-------------------------------------------------------------------------- // Function: PropList::close ///\brief Closes the property list if it is not a default one. /// @@ -342,7 +388,7 @@ H5std_string PropList::getProperty(const char* name) const } // Return propety value as a string after deleting temp C-string - H5std_string prop_strg = H5std_string(prop_strg_C); + H5std_string prop_strg(prop_strg_C); delete []prop_strg_C; return (prop_strg); } @@ -420,12 +466,13 @@ size_t PropList::getPropSize(const H5std_string& name) const H5std_string PropList::getClassName() const { char* temp_str; - temp_str = H5Pget_class_name(id); + temp_str = H5Pget_class_name(id); // this API specified that temp_str must + // be freed. if (temp_str != NULL) { - H5std_string class_name = H5std_string(temp_str); - free(temp_str); + H5std_string class_name(temp_str); + HDfree(temp_str); return(class_name); } else @@ -632,7 +679,7 @@ PropList::~PropList() close(); } catch (Exception close_error) { - cerr << "PropList::~PropList - " << close_error.getDetailMsg() << endl; + cerr << inMemFunc("~PropList - ") << close_error.getDetailMsg() << endl; } } diff --git a/c++/src/H5PropList.h b/c++/src/H5PropList.h index 09ea6f1..5dfa538 100644 --- a/c++/src/H5PropList.h +++ b/c++/src/H5PropList.h @@ -103,8 +103,17 @@ class H5_DLLCPP PropList : public IdComponent { // Copy constructor: creates a copy of a PropList object. PropList(const PropList& original); + // Gets the property list id. + virtual hid_t getId() const; + // Destructor: properly terminates access to this property list. virtual ~PropList(); + + protected: + hid_t id; // HDF5 property list id + + // Sets the property list id. + virtual void p_setId(const hid_t new_id); }; #ifndef H5_NO_NAMESPACE -- cgit v0.12