From 8df5c966e09c34524c39d4afe71029ef6664d687 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Wed, 10 May 2017 10:20:28 -0500 Subject: Improvement of class hierarchy Description: - Moved class Attribute to be derived from class H5Location instead of IdComponent because an attribute id can be used as loc_id in C APIs. - Copied wrappers of H5A APIs in H5Location into H5Object because H5A functions do not take an attribute id as loc_id. The original wrappers will be deprecated in future releases. - Revised comments Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test) --- c++/src/H5Attribute.cpp | 6 +- c++/src/H5Attribute.h | 4 +- c++/src/H5IdComponent.h | 2 - c++/src/H5Location.cpp | 36 ++++++--- c++/src/H5Location.h | 47 ++++++----- c++/src/H5Object.cpp | 210 +++++++++++++++++++++++++++++++++++++++++++++++- c++/src/H5Object.h | 24 ++++++ c++/test/tfile.cpp | 12 +++ 8 files changed, 298 insertions(+), 43 deletions(-) diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index cb0186a..55ccfe7 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -49,7 +49,7 @@ namespace H5 { ///\brief Default constructor: Creates a stub attribute // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- -Attribute::Attribute() : AbstractDs(), IdComponent(), id(H5I_INVALID_HID) {} +Attribute::Attribute() : AbstractDs(), H5Location(), id(H5I_INVALID_HID) {} //-------------------------------------------------------------------------- // Function: Attribute copy constructor @@ -57,7 +57,7 @@ Attribute::Attribute() : AbstractDs(), IdComponent(), id(H5I_INVALID_HID) {} ///\param original - IN: Original Attribute object to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Attribute::Attribute(const Attribute& original) : AbstractDs(), IdComponent(), id(original.id) +Attribute::Attribute(const Attribute& original) : AbstractDs(), H5Location(), id(original.id) { incRefCount(); // increment number of references to this id } @@ -70,7 +70,7 @@ Attribute::Attribute(const Attribute& original) : AbstractDs(), IdComponent(), i ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -Attribute::Attribute(const hid_t existing_id) : AbstractDs(), IdComponent(), id(existing_id) +Attribute::Attribute(const hid_t existing_id) : AbstractDs(), H5Location(), id(existing_id) { incRefCount(); // increment number of references to this id } diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index 10f46ae..33145bc 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -27,8 +27,8 @@ namespace H5 { inherits from IdComponent because an attribute is an HDF5 component that is identified by an identifier. */ -// Inheritance: multiple IdComponent/AbstractDs -class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { +// Inheritance: multiple H5Location/AbstractDs +class H5_DLLCPP Attribute : public AbstractDs, public H5Location { public: // Copy constructor: makes a copy of an existing Attribute object. diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 0f83168..e9d0c84 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -19,8 +19,6 @@ namespace H5 { -//class DataSpace; - /*! \class IdComponent \brief Class IdComponent provides wrappers of the C functions that operate on an HDF5 identifier. diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index 855e6d2..60f9c3b 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -84,9 +84,19 @@ H5Location::H5Location() : IdComponent() {} #endif // DOXYGEN_SHOULD_SKIP_THIS +/*************************************************************************** + Notes for H5A wrappers + ====================== +May, 2017 (1.8.19) + These H5A wrappers are copied from H5Object to prevent an attribute + id being passed in to H5A APIs. The original H5A wrapper functions + here will be deprecated in future releases. + +***************************************************************************/ + //-------------------------------------------------------------------------- // Function: H5Location::createAttribute -///\brief Creates an attribute for a group, dataset, or named datatype. +///\brief Deprecated - Creates an attribute for a group, dataset, or named datatype. ///\param name - IN: Name of the attribute ///\param data_type - IN: Datatype for the attribute ///\param data_space - IN: Dataspace for the attribute - only simple @@ -125,7 +135,7 @@ Attribute H5Location::createAttribute(const char* name, const DataType& data_typ //-------------------------------------------------------------------------- // Function: H5Location::createAttribute -///\brief This is an overloaded member function, provided for convenience. +///\brief Deprecated - This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 @@ -137,7 +147,7 @@ Attribute H5Location::createAttribute(const H5std_string& name, const DataType& //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief Opens an attribute given its name. +///\brief Deprecated - Opens an attribute given its name. ///\param name - IN: Name of the attribute ///\return Attribute instance ///\exception H5::AttributeIException @@ -160,7 +170,7 @@ Attribute H5Location::openAttribute(const char* name) const //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief This is an overloaded member function, provided for convenience. +///\brief Deprecated - This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 @@ -172,7 +182,7 @@ Attribute H5Location::openAttribute(const H5std_string& name) const //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief Opens an attribute given its index. +///\brief Deprecated - Opens an attribute given its index. ///\param idx - IN: Index of the attribute, a 0-based, non-negative integer ///\return Attribute instance ///\exception H5::AttributeIException @@ -196,7 +206,7 @@ Attribute H5Location::openAttribute(const unsigned int idx) const //-------------------------------------------------------------------------- // Function: H5Location::iterateAttrs -///\brief Iterates a user's function over all the attributes of an H5 +///\brief Deprecated - Iterates a user's function over all the attributes of an H5 /// object, which may be a group, dataset or named datatype. ///\param user_op - IN: User's function to operate on each attribute ///\param _idx - IN/OUT: Starting (IN) and ending (OUT) attribute indices @@ -241,7 +251,7 @@ int H5Location::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_d //-------------------------------------------------------------------------- // Function: H5Location::getNumAttrs -///\brief Returns the number of attributes attached to this HDF5 object. +///\brief Deprecated - Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 @@ -258,7 +268,7 @@ int H5Location::getNumAttrs() const //-------------------------------------------------------------------------- // Function: H5Location::attrExists -///\brief Checks whether the named attribute exists at this location. +///\brief Deprecated - Checks whether the named attribute exists at this location. ///\param name - IN: Name of the attribute to be queried ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2013 @@ -279,7 +289,7 @@ bool H5Location::attrExists(const char* name) const //-------------------------------------------------------------------------- // Function: H5Location::attrExists -///\brief This is an overloaded member function, provided for convenience. +///\brief Deprecated - This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 @@ -291,7 +301,7 @@ bool H5Location::attrExists(const H5std_string& name) const //-------------------------------------------------------------------------- // Function: H5Location::removeAttr -///\brief Removes the named attribute from this object. +///\brief Deprecated - Removes the named attribute from this object. ///\param name - IN: Name of the attribute to be removed ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 @@ -305,7 +315,7 @@ void H5Location::removeAttr(const char* name) const //-------------------------------------------------------------------------- // Function: H5Location::removeAttr -///\brief This is an overloaded member function, provided for convenience. +///\brief Deprecated - This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for \a name. // Programmer Binh-Minh Ribler - 2000 @@ -317,7 +327,7 @@ void H5Location::removeAttr(const H5std_string& name) const //-------------------------------------------------------------------------- // Function: H5Location::renameAttr -///\brief Renames the named attribute from this object. +///\brief Deprecated - Renames the named attribute from this object. ///\param oldname - IN: Name of the attribute to be renamed ///\param newname - IN: New name ame of the attribute ///\exception H5::AttributeIException @@ -332,7 +342,7 @@ void H5Location::renameAttr(const char* oldname, const char* newname) const //-------------------------------------------------------------------------- // Function: H5Location::renameAttr -///\brief This is an overloaded member function, provided for convenience. +///\brief Deprecated - This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes /// a reference to an \c H5std_string for the names. // Programmer Binh-Minh Ribler - Mar, 2005 diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index c49b23b..edc2b53 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -36,33 +36,26 @@ class UserData4Aiterate { // user data for attribute iteration }; /*! \class H5Location - \brief H5Location is an abstract base class, added in version 1.8.12. - - It provides a collection of wrappers for the C functions that take a - location identifier to specify the HDF5 object. The location identifier - can be either file, group, dataset, attribute, or named datatype. + \brief H5Location is an abstract base class, providing a collection of + wrappers of the C functions that take a location identifier, which can be + either file, group, dataset, attribute, or named datatype. */ // Inheritance: IdComponent - -// Most of these methods were in H5Object but are now moved here because -// a location can be a file, group, dataset, or named datatype. -BMR, 2013-10-1 -// Wrappers for H5A functions that operate existing attributes are in H5Object. -// -BMR, 2017-05-04 class H5_DLLCPP H5Location : public IdComponent { public: // Creates an attribute for the specified object at this location // PropList is currently not used, so always be default. - Attribute createAttribute(const char* name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; - Attribute createAttribute(const H5std_string& name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; + virtual Attribute createAttribute(const char* name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; + virtual Attribute createAttribute(const H5std_string& name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; // Given its name, opens the attribute that belongs to an object at // this location. - Attribute openAttribute(const char* name) const; - Attribute openAttribute(const H5std_string& name) const; + virtual Attribute openAttribute(const char* name) const; + virtual Attribute openAttribute(const H5std_string& name) const; // Given its index, opens the attribute that belongs to an object at // this location. - Attribute openAttribute(const unsigned int idx) const; + virtual Attribute openAttribute(const unsigned int idx) const; // Flushes all buffers associated with this location to disk. void flush(H5F_scope_t scope) const; @@ -84,19 +77,19 @@ class H5_DLLCPP H5Location : public IdComponent { // misleading, so getRefObjType is used in the new function instead. // Iterate user's function over the attributes at this location. - int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); + virtual int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); // Checks whether the named attribute exists at this location. - bool attrExists(const char* name) const; - bool attrExists(const H5std_string& name) const; + virtual bool attrExists(const char* name) const; + virtual bool attrExists(const H5std_string& name) const; // Renames the named attribute to a new name. - void renameAttr(const char* oldname, const char* newname) const; - void renameAttr(const H5std_string& oldname, const H5std_string& newname) const; + virtual void renameAttr(const char* oldname, const char* newname) const; + virtual void renameAttr(const H5std_string& oldname, const H5std_string& newname) const; // Removes the named attribute from this location. - void removeAttr(const char* name) const; - void removeAttr(const H5std_string& name) const; + virtual void removeAttr(const char* name) const; + virtual void removeAttr(const H5std_string& name) const; // Sets the comment for an HDF5 object specified by its name. void setComment(const char* name, const char* comment) const; @@ -177,3 +170,13 @@ class H5_DLLCPP H5Location : public IdComponent { } // namespace H5 #endif // __H5Location_H + +// Modification +// Oct 1, 2013 -BMR +// H5Location is added in version 1.8.12. +// Most of these methods were in H5Object but are now moved here +// because a location can be a file, group, dataset, or named datatype. +// May 04, 2017 -BMR +// Wrappers for H5A functions are copied to H5Object because H5A +// functions do not take an attribute id as loc_id. The original +// wrappers will be deprecated in future releases. diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 60e7afb..933e8ec 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -22,8 +22,8 @@ #include "H5PropList.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" -#include "H5Attribute.h" #include "H5Location.h" +#include "H5Attribute.h" #include "H5Object.h" #include "H5DataType.h" @@ -64,6 +64,214 @@ H5Object::H5Object() : H5Location() {} //-------------------------------------------------------------------------- // H5Object::H5Object(const H5Object& original) : H5Location() {} +/*************************************************************************** + Notes for H5A wrappers + ====================== +May, 2017 (1.8.19) + These H5A wrappers are copied from H5Location to prevent an attribute + id being passed in to H5A APIs. The original H5A wrapper functions + in H5Location will be deprecated in future releases. + +***************************************************************************/ + +//-------------------------------------------------------------------------- +// Function: H5Object::createAttribute +///\brief Creates an attribute for a group, dataset, or named datatype. +///\param name - IN: Name of the attribute +///\param data_type - IN: Datatype for the attribute +///\param data_space - IN: Dataspace for the attribute - only simple +/// dataspaces are allowed at this time +///\param create_plist - IN: Creation property list - default to +/// PropList::DEFAULT +///\return Attribute instance +///\exception H5::AttributeIException +///\par Description +/// The attribute name specified in \a name must be unique. +/// Attempting to create an attribute with the same name as an +/// existing attribute will raise an exception, leaving the +/// pre-existing attribute intact. To overwrite an existing +/// attribute with a new attribute of the same name, first +/// delete the existing one with \c H5Object::removeAttr, then +/// recreate it with this function. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Object::createAttribute(const char* name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist) const +{ + 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 = H5Acreate2(getId(), name, type_id, space_id, plist_id, H5P_DEFAULT); + + // If the attribute id is valid, create and return the Attribute object + if (attr_id > 0) + { + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return(attr); + } + else + throw AttributeIException(inMemFunc("createAttribute"), "H5Acreate2 failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::createAttribute +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Object::createAttribute(const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist) const +{ + return(createAttribute(name.c_str(), data_type, data_space, create_plist)); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::openAttribute +///\brief Opens an attribute given its name. +///\param name - IN: Name of the attribute +///\return Attribute instance +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Object::openAttribute(const char* name) const +{ + hid_t attr_id = H5Aopen(getId(), name, H5P_DEFAULT); + if (attr_id > 0) + { + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return(attr); + } + else + { + throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Object::openAttribute +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Object::openAttribute(const H5std_string& name) const +{ + return(openAttribute(name.c_str())); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::openAttribute +///\brief Opens an attribute given its index. +///\param idx - IN: Index of the attribute, a 0-based, non-negative integer +///\return Attribute instance +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Object::openAttribute(const unsigned int idx) const +{ + hid_t attr_id = H5Aopen_by_idx(getId(), ".", H5_INDEX_CRT_ORDER, + H5_ITER_INC, static_cast(idx), H5P_DEFAULT, H5P_DEFAULT); + if (attr_id > 0) + { + Attribute attr; + f_Attribute_setId(&attr, attr_id); + return(attr); + } + else + { + throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen_by_idx failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Object::attrExists +///\brief Checks whether the named attribute exists at this location. +///\param name - IN: Name of the attribute to be queried +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2013 +//-------------------------------------------------------------------------- +bool H5Object::attrExists(const char* name) const +{ + // Call C routine H5Aexists to determine whether an attribute exists + // at this location, which could be specified by a file, group, dataset, + // or named datatype. + herr_t ret_value = H5Aexists(getId(), name); + if(ret_value > 0) + return true; + else if(ret_value == 0) + return false; + else // Raise exception when H5Aexists returns a negative value + throw AttributeIException(inMemFunc("attrExists"), "H5Aexists failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::attrExists +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +bool H5Object::attrExists(const H5std_string& name) const +{ + return(attrExists(name.c_str())); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::removeAttr +///\brief Removes the named attribute from this object. +///\param name - IN: Name of the attribute to be removed +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void H5Object::removeAttr(const char* name) const +{ + herr_t ret_value = H5Adelete(getId(), name); + if(ret_value < 0) + throw AttributeIException(inMemFunc("removeAttr"), "H5Adelete failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::removeAttr +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void H5Object::removeAttr(const H5std_string& name) const +{ + removeAttr(name.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::renameAttr +///\brief Renames the named attribute from this object. +///\param oldname - IN: Name of the attribute to be renamed +///\param newname - IN: New name ame of the attribute +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - Mar, 2005 +//-------------------------------------------------------------------------- +void H5Object::renameAttr(const char* oldname, const char* newname) const +{ + herr_t ret_value = H5Arename(getId(), oldname, newname); + if (ret_value < 0) + throw AttributeIException(inMemFunc("renameAttr"), "H5Arename failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Object::renameAttr +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for the names. +// Programmer Binh-Minh Ribler - Mar, 2005 +//-------------------------------------------------------------------------- +void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newname) const +{ + renameAttr (oldname.c_str(), newname.c_str()); +} + +// end of Notes for H5A wrappers + //-------------------------------------------------------------------------- // Function: getObjName ///\brief Given an id, returns the type of the object. diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index fa9e8a9..b118bb8 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -37,6 +37,30 @@ namespace H5 { // Inheritance: H5Location -> IdComponent class H5_DLLCPP H5Object : public H5Location { public: + // Creates an attribute for the specified object + // PropList is currently not used, so always be default. + Attribute createAttribute(const char* name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; + Attribute createAttribute(const H5std_string& name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT) const; + + // Given its name, opens the attribute that belongs to this object. + Attribute openAttribute(const char* name) const; + Attribute openAttribute(const H5std_string& name) const; + + // Given its index, opens the attribute that belongs to this object. + Attribute openAttribute(const unsigned int idx) const; + + // Checks whether the named attribute exists for this object. + bool attrExists(const char* name) const; + bool attrExists(const H5std_string& name) const; + + // Renames the named attribute of this object to a new name. + void renameAttr(const char* oldname, const char* newname) const; + void renameAttr(const H5std_string& oldname, const H5std_string& newname) const; + + // Removes the named attribute from this object. + void removeAttr(const char* name) const; + void removeAttr(const H5std_string& name) const; + // Gets the name of this HDF5 object, i.e., Group, DataSet, or // DataType. ssize_t getObjName(char *obj_name, size_t buf_size = 0) const; diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index bd229d7..6e12dfd 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -601,6 +601,18 @@ static void test_file_attribute() n_attrs = dataset.getNumAttrs(); verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__); + // Get and verify the number of attributes at the location specified + // by a dataset's attribute + n_attrs = 0; + n_attrs = dattr.getNumAttrs(); + verify_val(n_attrs, 1, "Attribute::getNumAttrs()", __LINE__, __FILE__); + + // Get and verify the number of attributes at the location specified + // by a file's attribute + n_attrs = 0; + n_attrs = fattr1.getNumAttrs(); + verify_val(n_attrs, 2, "Attribute::getNumAttrs()", __LINE__, __FILE__); + // Read back attribute's data HDmemset(rdata, 0, sizeof(rdata)); dattr.read(PredType::NATIVE_INT, rdata); -- cgit v0.12 From 8b1a53896565cafca3795d139a37148f89bf928d Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Sat, 13 May 2017 06:00:33 -0500 Subject: Add H5Lexists wrappers Description: Added wrappers H5Location::exists() for H5Lexists. Added new class LinkAccPropList to be used by H5Location::exists() Rearranged source files in Makefile.am Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test) --- MANIFEST | 2 + c++/src/H5AbstractDs.cpp | 1 + c++/src/H5ArrayType.cpp | 1 + c++/src/H5AtomType.cpp | 1 + c++/src/H5Attribute.cpp | 1 + c++/src/H5CommonFG.cpp | 1 + c++/src/H5CompType.cpp | 1 + c++/src/H5Cpp.h | 1 + c++/src/H5DataSet.cpp | 1 + c++/src/H5DataType.cpp | 1 + c++/src/H5DcreatProp.cpp | 1 + c++/src/H5EnumType.cpp | 1 + c++/src/H5File.cpp | 1 + c++/src/H5FloatType.cpp | 1 + c++/src/H5Group.cpp | 1 + c++/src/H5IntType.cpp | 1 + c++/src/H5LaccProp.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++++ c++/src/H5LaccProp.h | 75 +++++++++++++++++++++++ c++/src/H5Library.cpp | 6 ++ c++/src/H5Location.cpp | 37 ++++++++++++ c++/src/H5Location.h | 4 ++ c++/src/H5Object.cpp | 1 + c++/src/H5PredType.cpp | 1 + c++/src/H5StrType.cpp | 1 + c++/src/H5VarLenType.cpp | 1 + c++/src/Makefile.am | 29 +++++---- c++/src/Makefile.in | 44 +++++++------- c++/test/tattr.cpp | 11 +++- c++/test/tlinks.cpp | 8 +-- 29 files changed, 348 insertions(+), 38 deletions(-) create mode 100644 c++/src/H5LaccProp.cpp create mode 100644 c++/src/H5LaccProp.h diff --git a/MANIFEST b/MANIFEST index 24e00a8..8436591 100644 --- a/MANIFEST +++ b/MANIFEST @@ -392,6 +392,8 @@ ./c++/src/H5IntType.h ./c++/src/H5Library.cpp ./c++/src/H5Library.h +./c++/src/H5LaccProp.cpp +./c++/src/H5LaccProp.h ./c++/src/H5Location.cpp ./c++/src/H5Location.h ./c++/src/H5Object.cpp diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index 4763bf2..4536afb 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5Alltypes.h" diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 4dc0a74..018eed5 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5AtomType.cpp b/c++/src/H5AtomType.cpp index 0e57676..c9c1b46 100644 --- a/c++/src/H5AtomType.cpp +++ b/c++/src/H5AtomType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 55ccfe7..353a15c 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -29,6 +29,7 @@ #include "H5FcreatProp.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index d9a66e2..f1e45b8 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -25,6 +25,7 @@ #include "H5OcreatProp.h" #include "H5DxferProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5CommonFG.h" diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 96fabd4..aff89f2 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5Alltypes.h" diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index 4e82ee3..42f925a 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -22,6 +22,7 @@ #include "H5IdComponent.h" #include "H5DataSpace.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 75d45b4..7b449d8 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -25,6 +25,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5OcreatProp.h" diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 625feaf..84e59e8 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -24,6 +24,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DxferProp.h" diff --git a/c++/src/H5DcreatProp.cpp b/c++/src/H5DcreatProp.cpp index 53a96d1..0cd9458 100644 --- a/c++/src/H5DcreatProp.cpp +++ b/c++/src/H5DcreatProp.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp index 9403cb8..acfae4e 100644 --- a/c++/src/H5EnumType.cpp +++ b/c++/src/H5EnumType.cpp @@ -20,6 +20,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 768ac5e..4d7177a 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -28,6 +28,7 @@ #include "H5FcreatProp.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5CommonFG.h" diff --git a/c++/src/H5FloatType.cpp b/c++/src/H5FloatType.cpp index 9e64972..0a0bc1d 100644 --- a/c++/src/H5FloatType.cpp +++ b/c++/src/H5FloatType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 16a715c..a5d052c 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -26,6 +26,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5IntType.cpp b/c++/src/H5IntType.cpp index a9bb146..673bd7a 100644 --- a/c++/src/H5IntType.cpp +++ b/c++/src/H5IntType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5LaccProp.cpp b/c++/src/H5LaccProp.cpp new file mode 100644 index 0000000..e457e83 --- /dev/null +++ b/c++/src/H5LaccProp.cpp @@ -0,0 +1,151 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include + +#include "H5Include.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5PropList.h" +#include "H5LaccProp.h" + +namespace H5 { + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control +// the order of creation and deletion of the global constants. See Design Notes +// in "H5PredType.cpp" for information. + +// Initialize a pointer for the constant +LinkAccPropList* LinkAccPropList::DEFAULT_ = 0; + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList::getConstant +// Creates a LinkAccPropList object representing the HDF5 constant +// H5P_LINK_ACCESS, pointed to by LinkAccPropList::DEFAULT_ +// exception H5::PropListIException +// Description +// If LinkAccPropList::DEFAULT_ already points to an allocated +// object, throw a PropListIException. This scenario should not +// happen. +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +LinkAccPropList* LinkAccPropList::getConstant() +{ + // Tell the C library not to clean up, H5Library::termH5cpp will call + // H5close - more dependency if use H5Library::dontAtExit() + if (!IdComponent::H5dontAtexit_called) + { + (void) H5dont_atexit(); + IdComponent::H5dontAtexit_called = true; + } + + // If the constant pointer is not allocated, allocate it. Otherwise, + // throw because it shouldn't be. + if (DEFAULT_ == 0) + DEFAULT_ = new LinkAccPropList(H5P_LINK_ACCESS); + else + throw PropListIException("LinkAccPropList::getConstant", "LinkAccPropList::getConstant is being invoked on an allocated DEFAULT_"); + return(DEFAULT_); +} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList::deleteConstants +// Purpose: Deletes the constant object that LinkAccPropList::DEFAULT_ +// points to. +// exception H5::PropListIException +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +void LinkAccPropList::deleteConstants() +{ + if (DEFAULT_ != 0) + delete DEFAULT_; +} + +//-------------------------------------------------------------------------- +// Purpose: Constant for default property +//-------------------------------------------------------------------------- +const LinkAccPropList& LinkAccPropList::DEFAULT = *getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: Default Constructor +///\brief Creates a file access property list +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +LinkAccPropList::LinkAccPropList() : PropList(H5P_LINK_ACCESS) {} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList copy constructor +///\brief Copy Constructor: makes a copy of the original +///\param original - IN: LinkAccPropList instance to copy +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +LinkAccPropList::LinkAccPropList(const LinkAccPropList& original) : PropList(original) {} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList overloaded constructor +///\brief Creates a file access property list using the id of an +/// existing one. +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +LinkAccPropList::LinkAccPropList(const hid_t plist_id) : PropList(plist_id) {} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList::setNumLinks +///\brief Set the number of soft or user-defined link traversals allowed +/// before the library assumes it has found a cycle and aborts the +/// traversal. +///\exception H5::PropListIException +// Programmer Binh-Minh Ribler - March 1, 2017 +//-------------------------------------------------------------------------- +void LinkAccPropList::setNumLinks(size_t nlinks) const +{ + herr_t ret_value = H5Pset_nlinks(id, nlinks); + // Throw exception if H5Pset_nlinks returns failure + if (ret_value < 0) + { + throw PropListIException("setNumLinks", "H5Pset_nlinks failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList::getNumLinks +///\brief Gets the number of soft or user-defined links that can be +/// traversed before a failure occurs. +///\exception H5::PropListIException +// Programmer Binh-Minh Ribler - March 1, 2017 +//-------------------------------------------------------------------------- +size_t LinkAccPropList::getNumLinks() const +{ + size_t nlinks = 0; + herr_t ret_value = H5Pget_nlinks(id, &nlinks); + // Throw exception if H5Pget_nlinks returns failure + if (ret_value < 0) + { + throw PropListIException("getNumLinks", "H5Pget_nlinks failed"); + } + return(nlinks); +} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList destructor +///\brief Noop destructor +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +LinkAccPropList::~LinkAccPropList() {} + +} // end namespace diff --git a/c++/src/H5LaccProp.h b/c++/src/H5LaccProp.h new file mode 100644 index 0000000..f31c3fc --- /dev/null +++ b/c++/src/H5LaccProp.h @@ -0,0 +1,75 @@ +// C++ informative line for the emacs editor: -*- C++ -*- +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +// Class LinkAccPropList represents the HDF5 file access property list and +// inherits from DataType. + +#ifndef __H5LinkAccPropList_H +#define __H5LinkAccPropList_H + +namespace H5 { + +/*! \class LinkAccPropList + \brief Class LinkAccPropList inherits from PropList and provides + wrappers for the HDF5 file access property list. + + Inheritance: PropList -> IdComponent +*/ +class H5_DLLCPP LinkAccPropList : public PropList { + public: + ///\brief Default file access property list. + static const LinkAccPropList& DEFAULT; + + // Creates a file access property list. + LinkAccPropList(); + + ///\brief Returns this class name. + virtual H5std_string fromClass () const { return("LinkAccPropList"); } + + // Copy constructor: creates a copy of a LinkAccPropList object. + LinkAccPropList(const LinkAccPropList& original); + + // Creates a copy of an existing file access property list + // using the property list id. + LinkAccPropList (const hid_t plist_id); + + // Sets the number of soft or user-defined links that can be + // traversed before a failure occurs. + void setNumLinks(size_t nlinks) const; + + // Gets the number of soft or user-defined link traversals allowed + size_t getNumLinks() const; + + // Noop destructor + virtual ~LinkAccPropList(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + + // Deletes the global constant, should only be used by the library + static void deleteConstants(); + + private: + static LinkAccPropList* DEFAULT_; + + // Creates the global constant, should only be used by the library + static LinkAccPropList* getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +}; // end of LinkAccPropList +} // namespace H5 + +#endif // __H5LinkAccPropList_H diff --git a/c++/src/H5Library.cpp b/c++/src/H5Library.cpp index b25dc90..7adc508 100644 --- a/c++/src/H5Library.cpp +++ b/c++/src/H5Library.cpp @@ -26,6 +26,8 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -185,6 +187,10 @@ void H5Library::initH5cpp() if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating PropList::deleteConstants failed"); + ret_value = std::atexit(LinkAccPropList::deleteConstants); + if (ret_value != 0) + throw LibraryIException("H5Library::initH5cpp", "Registrating LinkAccPropList::deleteConstants failed"); + ret_value = std::atexit(FileAccPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating FileAccPropList::deleteConstants failed"); diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index 60f9c3b..f10ad0d 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -20,6 +20,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -353,6 +354,42 @@ void H5Location::renameAttr(const H5std_string& oldname, const H5std_string& new } //-------------------------------------------------------------------------- +// Function: H5Location::nameExists +///\brief Checks if a link of a given name exists in a location +///\param name - IN: Searched name +///\param lapl - IN: Link access property list +///\exception H5::LocationException +// Programmer Binh-Minh Ribler - Nov, 2016 +// Modification +//-------------------------------------------------------------------------- +bool H5Location::nameExists(const char* name, const LinkAccPropList& lapl) const +{ + htri_t ret_value = H5Lexists(getId(), name, lapl.getId()); + if (ret_value > 0) + return true; + else if (ret_value == 0) + return false; + else // Raise exception when H5Lexists returns a negative value + { + throw LocationException(inMemFunc("nameExists"), "H5Lexists failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::nameExists +///\brief Checks if a link of a given name exists in a location +///\param name - IN: Searched name +///\param lapl - IN: Link access property list +///\exception H5::LocationException +// Programmer Binh-Minh Ribler - Dec, 2016 +// Modification +//-------------------------------------------------------------------------- +bool H5Location::nameExists(const H5std_string& name, const LinkAccPropList& lapl) const +{ + return(nameExists(name.c_str(), lapl)); +} + +//-------------------------------------------------------------------------- // Function: H5Location::flush ///\brief Flushes all buffers associated with a location to disk. ///\param scope - IN: Specifies the scope of the flushing action, diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index edc2b53..11f8f87 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -57,6 +57,10 @@ class H5_DLLCPP H5Location : public IdComponent { // this location. virtual Attribute openAttribute(const unsigned int idx) const; + // Checks if a link of a given name exists in this location + bool nameExists(const char* name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + bool nameExists(const H5std_string& name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; + // Flushes all buffers associated with this location to disk. void flush(H5F_scope_t scope) const; diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 933e8ec..91d0f82 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -22,6 +22,7 @@ #include "H5PropList.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Attribute.h" #include "H5Object.h" diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp index 52334ef..109f221 100644 --- a/c++/src/H5PredType.cpp +++ b/c++/src/H5PredType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5StrType.cpp b/c++/src/H5StrType.cpp index 4335ea7..e5355ff 100644 --- a/c++/src/H5StrType.cpp +++ b/c++/src/H5StrType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5VarLenType.cpp b/c++/src/H5VarLenType.cpp index 32a5bd8..fc6d2ba 100644 --- a/c++/src/H5VarLenType.cpp +++ b/c++/src/H5VarLenType.cpp @@ -19,6 +19,7 @@ #include "H5Exception.h" #include "H5IdComponent.h" #include "H5PropList.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/Makefile.am b/c++/src/Makefile.am index 6cd4768..f06b801 100644 --- a/c++/src/Makefile.am +++ b/c++/src/Makefile.am @@ -33,25 +33,28 @@ libhdf5_cpp_la_LDFLAGS= -version-info $(LT_CXX_VERS_INTERFACE):$(LT_CXX_VERS_REV bin_SCRIPTS=h5c++ # Source files for the library -libhdf5_cpp_la_SOURCES=H5Exception.cpp H5IdComponent.cpp H5Library.cpp \ - H5Attribute.cpp H5Location.cpp H5Object.cpp H5PropList.cpp \ - H5FaccProp.cpp H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp \ - H5OcreatProp.cpp H5DataType.cpp H5DataSpace.cpp H5AbstractDs.cpp \ - H5AtomType.cpp H5PredType.cpp H5EnumType.cpp H5IntType.cpp \ - H5FloatType.cpp H5StrType.cpp H5ArrayType.cpp H5VarLenType.cpp \ - H5CompType.cpp H5DataSet.cpp H5CommonFG.cpp H5Group.cpp H5File.cpp +libhdf5_cpp_la_SOURCES=H5Exception.cpp H5IdComponent.cpp \ + H5DataSpace.cpp H5PropList.cpp H5Library.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5LaccProp.cpp \ + H5DxferProp.cpp H5DcreatProp.cpp H5Location.cpp \ + H5AbstractDs.cpp H5Attribute.cpp H5Object.cpp \ + H5OcreatProp.cpp H5DataType.cpp H5AtomType.cpp \ + H5PredType.cpp H5EnumType.cpp H5IntType.cpp \ + H5FloatType.cpp H5StrType.cpp H5ArrayType.cpp \ + H5VarLenType.cpp H5CompType.cpp H5DataSet.cpp \ + H5CommonFG.cpp H5Group.cpp H5File.cpp # HDF5 C++ library depends on HDF5 Library. libhdf5_cpp_la_LIBADD=$(LIBHDF5) # Public headers include_HEADERS=H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.h \ - H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ - H5OcreatProp.h H5DcreatProp.h H5DxferProp.h H5EnumType.h \ - H5Exception.h H5FaccProp.h H5FcreatProp.h H5File.h H5FloatType.h \ - H5Group.h H5IdComponent.h H5Include.h H5IntType.h H5Library.h \ - H5Location.h H5Object.h H5PredType.h H5PropList.h H5StrType.h \ - H5CppDoc.h H5ArrayType.h H5VarLenType.h + H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ + H5OcreatProp.h H5DcreatProp.h H5DxferProp.h H5EnumType.h \ + H5Exception.h H5FaccProp.h H5FcreatProp.h H5File.h H5FloatType.h \ + H5Group.h H5IdComponent.h H5Include.h H5IntType.h H5LaccProp.h \ + H5Library.h H5Location.h H5Object.h H5PredType.h H5PropList.h \ + H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h # h5c++ and libhdf5.settings are generated during configure. Remove only when # distclean. diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in index 669a33d..cc6682e 100644 --- a/c++/src/Makefile.in +++ b/c++/src/Makefile.in @@ -152,13 +152,13 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ LTLIBRARIES = $(lib_LTLIBRARIES) libhdf5_cpp_la_DEPENDENCIES = $(LIBHDF5) am_libhdf5_cpp_la_OBJECTS = H5Exception.lo H5IdComponent.lo \ - H5Library.lo H5Attribute.lo H5Location.lo H5Object.lo \ - H5PropList.lo H5FaccProp.lo H5FcreatProp.lo H5DcreatProp.lo \ - H5DxferProp.lo H5OcreatProp.lo H5DataType.lo H5DataSpace.lo \ - H5AbstractDs.lo H5AtomType.lo H5PredType.lo H5EnumType.lo \ - H5IntType.lo H5FloatType.lo H5StrType.lo H5ArrayType.lo \ - H5VarLenType.lo H5CompType.lo H5DataSet.lo H5CommonFG.lo \ - H5Group.lo H5File.lo + H5DataSpace.lo H5PropList.lo H5Library.lo H5FaccProp.lo \ + H5FcreatProp.lo H5LaccProp.lo H5DxferProp.lo H5DcreatProp.lo \ + H5Location.lo H5AbstractDs.lo H5Attribute.lo H5Object.lo \ + H5OcreatProp.lo H5DataType.lo H5AtomType.lo H5PredType.lo \ + H5EnumType.lo H5IntType.lo H5FloatType.lo H5StrType.lo \ + H5ArrayType.lo H5VarLenType.lo H5CompType.lo H5DataSet.lo \ + H5CommonFG.lo H5Group.lo H5File.lo libhdf5_cpp_la_OBJECTS = $(am_libhdf5_cpp_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -712,13 +712,16 @@ libhdf5_cpp_la_LDFLAGS = -version-info $(LT_CXX_VERS_INTERFACE):$(LT_CXX_VERS_RE bin_SCRIPTS = h5c++ # Source files for the library -libhdf5_cpp_la_SOURCES = H5Exception.cpp H5IdComponent.cpp H5Library.cpp \ - H5Attribute.cpp H5Location.cpp H5Object.cpp H5PropList.cpp \ - H5FaccProp.cpp H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp \ - H5OcreatProp.cpp H5DataType.cpp H5DataSpace.cpp H5AbstractDs.cpp \ - H5AtomType.cpp H5PredType.cpp H5EnumType.cpp H5IntType.cpp \ - H5FloatType.cpp H5StrType.cpp H5ArrayType.cpp H5VarLenType.cpp \ - H5CompType.cpp H5DataSet.cpp H5CommonFG.cpp H5Group.cpp H5File.cpp +libhdf5_cpp_la_SOURCES = H5Exception.cpp H5IdComponent.cpp \ + H5DataSpace.cpp H5PropList.cpp H5Library.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5LaccProp.cpp \ + H5DxferProp.cpp H5DcreatProp.cpp H5Location.cpp \ + H5AbstractDs.cpp H5Attribute.cpp H5Object.cpp \ + H5OcreatProp.cpp H5DataType.cpp H5AtomType.cpp \ + H5PredType.cpp H5EnumType.cpp H5IntType.cpp \ + H5FloatType.cpp H5StrType.cpp H5ArrayType.cpp \ + H5VarLenType.cpp H5CompType.cpp H5DataSet.cpp \ + H5CommonFG.cpp H5Group.cpp H5File.cpp # HDF5 C++ library depends on HDF5 Library. @@ -726,12 +729,12 @@ libhdf5_cpp_la_LIBADD = $(LIBHDF5) # Public headers include_HEADERS = H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.h \ - H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ - H5OcreatProp.h H5DcreatProp.h H5DxferProp.h H5EnumType.h \ - H5Exception.h H5FaccProp.h H5FcreatProp.h H5File.h H5FloatType.h \ - H5Group.h H5IdComponent.h H5Include.h H5IntType.h H5Library.h \ - H5Location.h H5Object.h H5PredType.h H5PropList.h H5StrType.h \ - H5CppDoc.h H5ArrayType.h H5VarLenType.h + H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ + H5OcreatProp.h H5DcreatProp.h H5DxferProp.h H5EnumType.h \ + H5Exception.h H5FaccProp.h H5FcreatProp.h H5File.h H5FloatType.h \ + H5Group.h H5IdComponent.h H5Include.h H5IntType.h H5LaccProp.h \ + H5Library.h H5Location.h H5Object.h H5PredType.h H5PropList.h \ + H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h # h5c++ and libhdf5.settings are generated during configure. Remove only when @@ -896,6 +899,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Group.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5IdComponent.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5IntType.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5LaccProp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Library.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Location.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Object.Plo@am__quote@ diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index bb33b2b..70c4003 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -1561,11 +1561,20 @@ static void test_attr_exists() // Open a group. Group group = fid1.openGroup(GROUP1_NAME); - // Check for existence of attribute + // Check for existence of attribute, Group::attrExists attr_exists = group.attrExists(ATTR2_NAME); if (attr_exists == false) throw InvalidActionException("H5File::attrExists", "group, ATTR2_NAMEAttribute should exist but does not"); + // Open attribute + Attribute attr = group.openAttribute(ATTR2_NAME); + + // Test the existence of a name using attribute as location, + // Attribute::nameExists + bool name_exists = attr.nameExists(GROUP1_NAME); + if (name_exists == false) + throw InvalidActionException("Attribute::nameExists", "group GROUP1_NAME should exist but does not"); + PASSED(); } // end try block diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index bb1ea17..0786bb5 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -422,10 +422,10 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) H5File file(filename, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl); // Verify link existence - if(H5Lexists(file.getId(), "dset1", H5P_DEFAULT) != TRUE) - throw InvalidActionException("H5Lexists", "dset1 doesn't exist"); - if(H5Lexists(file.getId(), "grp1/soft", H5P_DEFAULT) != TRUE) - throw InvalidActionException("H5Lexists", "grp1/soft doesn't exist"); + if(file.nameExists("dset1", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::nameExists", "dset1 doesn't exist"); + if(file.nameExists("grp1/soft", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::nameExists", "grp1/soft doesn't exist"); // Verify link values H5std_string softlink_val = file.getLinkval("grp1/soft"); -- cgit v0.12