From cd3bd5576f048ce1ca413921c76dcacf137d2110 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Wed, 28 Dec 2016 08:44:01 -0600 Subject: Purpose: Add new wrappers Description: Added wrappers H5Location::exists() for H5Lexists. Added wrapper H5Object::objVersion() to return the header version of an HDF5 object. Added new class LinkAccPropList to be used by H5Location::exists() Added new exception: ObjHeaderIException for H5Object::objVersion() Rearranged source files in Makefile.am Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test) --- c++/src/H5AbstractDs.cpp | 1 + c++/src/H5ArrayType.cpp | 1 + c++/src/H5AtomType.cpp | 1 + c++/src/H5Attribute.cpp | 1 + c++/src/H5Classes.h | 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/H5Exception.cpp | 3 +- c++/src/H5Exception.h | 3 +- c++/src/H5File.cpp | 1 + c++/src/H5FloatType.cpp | 1 + c++/src/H5Group.cpp | 1 + c++/src/H5IntType.cpp | 1 + c++/src/H5LaccProp.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++ c++/src/H5LaccProp.h | 67 +++++++++++++++++++++++++++ c++/src/H5Library.cpp | 14 +++--- c++/src/H5Location.cpp | 8 ++-- c++/src/H5Location.h | 12 +++-- c++/src/H5Object.cpp | 34 ++++++++++++++ c++/src/H5Object.h | 21 +++++---- c++/src/H5PredType.cpp | 1 + c++/src/H5StrType.cpp | 1 + c++/src/H5VarLenType.cpp | 1 + c++/src/Makefile.am | 35 ++++++++++----- c++/test/tfile.cpp | 12 +++-- c++/test/tlinks.cpp | 8 ++-- c++/test/tobject.cpp | 115 ++++++++++++++++++++++++++++++++++++++--------- 32 files changed, 391 insertions(+), 74 deletions(-) create mode 100644 c++/src/H5LaccProp.cpp create mode 100644 c++/src/H5LaccProp.h diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp index 49de4bb..9e76b55 100644 --- a/c++/src/H5AbstractDs.cpp +++ b/c++/src/H5AbstractDs.cpp @@ -24,6 +24,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataSpace.h" diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 46ac021..ecce591 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.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 fa47e0c..22b163a 100644 --- a/c++/src/H5AtomType.cpp +++ b/c++/src/H5AtomType.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.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 c71c035..dfd2b28 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/H5Classes.h b/c++/src/H5Classes.h index bed0cae..03faa1a 100644 --- a/c++/src/H5Classes.h +++ b/c++/src/H5Classes.h @@ -25,6 +25,7 @@ namespace H5 { class PropList; class FileCreatPropList; class FileAccPropList; + class LinkAccPropList; class DSetCreatPropList; class DSetMemXferPropList; class DTypePropList; diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 018d3a2..5f7971f 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -24,6 +24,7 @@ #include "H5DxferProp.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5Alltypes.h" diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 0562e75..babda34 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -22,6 +22,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.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 90f0a2a..b86e0f3 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -27,6 +27,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.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 d3bf017..7c5b994 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -30,6 +30,7 @@ #include "H5OcreatProp.h" #include "H5DxferProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 3955ebf..372b2c9 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -30,6 +30,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5DcreatProp.cpp b/c++/src/H5DcreatProp.cpp index b307bde..8ab38dc 100644 --- a/c++/src/H5DcreatProp.cpp +++ b/c++/src/H5DcreatProp.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.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 a9f0b41..5e1f0bd 100644 --- a/c++/src/H5EnumType.cpp +++ b/c++/src/H5EnumType.cpp @@ -24,6 +24,7 @@ #include "H5DcreatProp.h" #include "H5DxferProp.h" #include "H5DataSpace.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index 9c383a2..335bb20 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -424,7 +424,7 @@ DataTypeIException::DataTypeIException(const H5std_string& func, const H5std_str //-------------------------------------------------------------------------- DataTypeIException::~DataTypeIException() throw() {} - /* //-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- // Subclass: ObjHeaderIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- @@ -446,7 +446,6 @@ ObjHeaderIException::ObjHeaderIException(const H5std_string& func, const H5std_s ///\brief Noop destructor. //-------------------------------------------------------------------------- ObjHeaderIException::~ObjHeaderIException() throw() {} - */ //-------------------------------------------------------------------------- // Subclass: PropListIException diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index 81068f5..7112995 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -120,13 +120,12 @@ class H5_DLLCPP DataTypeIException : public Exception { virtual ~DataTypeIException() throw(); }; - /* class H5_DLLCPP ObjHeaderIException : public Exception { +class H5_DLLCPP ObjHeaderIException : public Exception { public: ObjHeaderIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); ObjHeaderIException(); virtual ~ObjHeaderIException() throw(); }; - */ class H5_DLLCPP PropListIException : public Exception { public: diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 79f5471..fcf4e1c 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -29,6 +29,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/H5FloatType.cpp b/c++/src/H5FloatType.cpp index abc382d..73e8072 100644 --- a/c++/src/H5FloatType.cpp +++ b/c++/src/H5FloatType.cpp @@ -22,6 +22,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 4325a68..c976b00 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -29,6 +29,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.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 a60bcf3..38e2a7d 100644 --- a/c++/src/H5IntType.cpp +++ b/c++/src/H5IntType.cpp @@ -22,6 +22,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.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..e225b36 --- /dev/null +++ b/c++/src/H5LaccProp.cpp @@ -0,0 +1,114 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 - 2015 +//-------------------------------------------------------------------------- +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 - 2015 +//-------------------------------------------------------------------------- +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 - 2000 +//-------------------------------------------------------------------------- +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 - 2000 +//-------------------------------------------------------------------------- +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 - 2000 +//-------------------------------------------------------------------------- +LinkAccPropList::LinkAccPropList(const hid_t plist_id) : PropList(plist_id) {} + +//-------------------------------------------------------------------------- +// Function: LinkAccPropList destructor +///\brief Noop destructor +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +LinkAccPropList::~LinkAccPropList() {} + +} // end namespace diff --git a/c++/src/H5LaccProp.h b/c++/src/H5LaccProp.h new file mode 100644 index 0000000..2a84ffb --- /dev/null +++ b/c++/src/H5LaccProp.h @@ -0,0 +1,67 @@ +// 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); + + // 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 + +}; +} +#endif // __H5LinkAccPropList_H diff --git a/c++/src/H5Library.cpp b/c++/src/H5Library.cpp index 30be367..0ee6b4d 100644 --- a/c++/src/H5Library.cpp +++ b/c++/src/H5Library.cpp @@ -26,6 +26,7 @@ #include "H5OcreatProp.h" #include "H5DxferProp.h" #include "H5DcreatProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -185,28 +186,27 @@ void H5Library::initH5cpp() if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating PropList::deleteConstants failed"); - /* ret_value = std::atexit(LinkAccPropList::deleteConstants); + ret_value = std::atexit(LinkAccPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating LinkAccPropList::deleteConstants failed"); - */ - ret_value = std::atexit(FileAccPropList::deleteConstants); + ret_value = std::atexit(FileAccPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating FileAccPropList::deleteConstants failed"); - ret_value = std::atexit(FileCreatPropList::deleteConstants); + ret_value = std::atexit(FileCreatPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating FileCreatPropList::deleteConstants failed"); - ret_value = std::atexit(DSetMemXferPropList::deleteConstants); + ret_value = std::atexit(DSetMemXferPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating DSetMemXferPropList::deleteConstants failed"); - ret_value = std::atexit(DSetCreatPropList::deleteConstants); + ret_value = std::atexit(DSetCreatPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating DSetCreatPropList::deleteConstants failed"); - ret_value = std::atexit(ObjCreatPropList::deleteConstants); + ret_value = std::atexit(ObjCreatPropList::deleteConstants); if (ret_value != 0) throw LibraryIException("H5Library::initH5cpp", "Registrating ObjCreatPropList::deleteConstants failed"); diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index 91de0f5..a3e6738 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -26,6 +26,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -76,7 +77,7 @@ H5Location::H5Location() : IdComponent() {} #endif // DOXYGEN_SHOULD_SKIP_THIS - /* //-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- // Function: H5Location::exists ///\brief Checks if a link of a given name exists in a location ///\param name - IN: Searched name @@ -96,11 +97,9 @@ bool H5Location::exists(const char* name, const LinkAccPropList& lapl) const { throwException("exists", "H5Lexists failed"); } - return false; // warning: control reaches end of non-void function } - */ - /* //-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- // Function: H5Location::exists ///\brief Checks if a link of a given name exists in a location ///\param name - IN: Searched name @@ -113,7 +112,6 @@ bool H5Location::exists(const H5std_string& name, const LinkAccPropList& lapl) c { return(exists(name.c_str(), lapl)); } - */ //-------------------------------------------------------------------------- // Function: H5Location::flush diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index 795e7a7..6a449dc 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -33,15 +33,13 @@ namespace H5 { */ // Class forwarding class H5_DLLCPP ArrayType; - /* class H5_DLLCPP LinkAccPropList; // remove when done - */ +class H5_DLLCPP LinkAccPropList; class H5_DLLCPP VarLenType; class H5_DLLCPP H5Location : public IdComponent { public: - /* // Checks if a link of a given name exists in a location + // Checks if a link of a given name exists in a location bool exists(const char* name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; bool exists(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; @@ -213,9 +211,9 @@ class H5_DLLCPP H5Location : public IdComponent { // Retrieves the type of object that an object reference points to. H5O_type_t p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const; - // 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); + // 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); #endif // DOXYGEN_SHOULD_SKIP_THIS diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index d656ccf..48d81f8 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -25,6 +25,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.h" +#include "H5LaccProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -257,6 +258,39 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_da } //-------------------------------------------------------------------------- +// Function: H5Object::objVersion +///\brief Returns the header version of this HDF5 object. +///\return Object version, which can have the following values: +/// \li \c H5O_VERSION_1 +/// \li \c H5O_VERSION_2 +///\exception H5::ObjHeaderIException +/// Exception will be thrown when: +/// - an error returned by the C API +/// - version number is not one of the valid values above +// Programmer Binh-Minh Ribler - December, 2016 +//-------------------------------------------------------------------------- +unsigned H5Object::objVersion() const +{ + H5O_info_t objinfo; + unsigned version = 0; + + // Use C API to get information of the object + herr_t ret_value = H5Oget_info(getId(), &objinfo); + + // Throw exception if C API returns failure + if (ret_value < 0) + throw Exception(inMemFunc("objVersion"), "H5Oget_info failed"); + // Return a valid version or throw an exception for invalid value + else + { + version = objinfo.hdr.version; + if (version != H5O_VERSION_1 && version != H5O_VERSION_2) + throw ObjHeaderIException("objVersion", "Invalid version for object"); + } + return(version); +} + +//-------------------------------------------------------------------------- // Function: H5Object::getNumAttrs ///\brief Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 72a9f50..5ea8937 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -77,6 +77,9 @@ class H5_DLLCPP H5Object : public H5Location { // Iterate user's function over the attributes of this object. int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); + // Returns the object header version of an object + unsigned objVersion() const; + // Determines the number of attributes belong to this object. int getNumAttrs() const; @@ -106,12 +109,12 @@ class H5_DLLCPP H5Object : public H5Location { // Default constructor H5Object(); - // *** Deprecation warning *** - // The following two constructors are no longer appropriate after the - // data member "id" had been moved to the sub-classes. - // The copy constructor is a noop and is removed in 1.8.15 and the - // other will be removed from 1.10 release, and then from 1.8 if its - // removal does not raise any problems in two 1.10 releases. + // *** Deprecation warning *** + // The following two constructors are no longer appropriate after the + // data member "id" had been moved to the sub-classes. + // The copy constructor is a noop and is removed in 1.8.15 and the + // other will be removed from 1.10 release, and then from 1.8 if its + // removal does not raise any problems in two 1.10 releases. // Creates a copy of an existing object giving the object id H5Object( const hid_t object_id ); @@ -119,9 +122,9 @@ class H5_DLLCPP H5Object : public H5Location { // Copy constructor: makes copy of an H5Object object. // H5Object(const H5Object& original); - // 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; + // 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; // Noop destructor. virtual ~H5Object(); diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp index 0711020..e2eed18 100644 --- a/c++/src/H5PredType.cpp +++ b/c++/src/H5PredType.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.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 ca0ad56..50c9e45 100644 --- a/c++/src/H5StrType.cpp +++ b/c++/src/H5StrType.cpp @@ -22,6 +22,7 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5DxferProp.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 e14e1ce..5ecc39b 100644 --- a/c++/src/H5VarLenType.cpp +++ b/c++/src/H5VarLenType.cpp @@ -21,6 +21,7 @@ #include "H5PropList.h" #include "H5OcreatProp.h" #include "H5DcreatProp.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..6a3092e 100644 --- a/c++/src/Makefile.am +++ b/c++/src/Makefile.am @@ -33,25 +33,36 @@ 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 + +#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 # 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 \ + 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 + 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++/test/tfile.cpp b/c++/test/tfile.cpp index 47b9a85..e9c865f 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -639,6 +639,10 @@ const H5std_string SUBGROUP3("/G1/G3"); static void test_libver_bounds_real( H5F_libver_t libver_create, unsigned oh_vers_create, H5F_libver_t libver_mod, unsigned oh_vers_mod) + /* (H5F_LIBVER_EARLIEST, H5O_VERSION_1, H5F_LIBVER_LATEST, H5O_VERSION_2); +(H5F_LIBVER_LATEST, H5O_VERSION_2, H5F_LIBVER_EARLIEST, H5O_VERSION_2); + */ + { try { @@ -674,8 +678,8 @@ static void test_libver_bounds_real( */ Group group = file.createGroup(GROUP1); - obj_version = file.childObjVersion(GROUP1); - verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__); + obj_version = group.objVersion(); + verify_val(obj_version, oh_vers_mod, "Group::objVersion", __LINE__, __FILE__); group.close(); // close "/G1" @@ -685,8 +689,8 @@ static void test_libver_bounds_real( */ group = file.createGroup(SUBGROUP3); - obj_version = group.childObjVersion(SUBGROUP3); - verify_val(obj_version, oh_vers_mod, "H5File::childObjVersion", __LINE__, __FILE__); + obj_version = group.objVersion(); + verify_val(obj_version, oh_vers_mod, "Group::objVersion", __LINE__, __FILE__); group.close(); // close "/G1/G3" diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index 1f7d14e..3acf4e1 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -419,10 +419,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.exists("dset1", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::exists", "dset1 doesn't exist"); + if(file.exists("grp1/soft", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::exists", "grp1/soft doesn't exist"); // Verify link values H5std_string softlink_val = file.getLinkval("grp1/soft"); diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index e142f02..72dc106 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -23,6 +23,8 @@ #else #include #endif +using std::cerr; +using std::endl; #include #include "H5Cpp.h" // C++ API header file @@ -41,16 +43,26 @@ const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2"); const H5std_string DSET_DEFAULT_NAME("default"); const H5std_string DSET_IN_FILE("Dataset in File"); const H5std_string DSET_IN_FILE_PATH("/Dataset in File"); -const H5std_string DSET_IN_GRP1("Dataset in Group 1"); -const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset in Group 1"); -const H5std_string DSET_IN_GRP1_2("Dataset in Group 1.2"); -const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset in Group 1.2"); +const H5std_string DSET_IN_GRP1("Dataset_in_Group_1"); +const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset_in_Group_1"); +const H5std_string DSET_IN_GRP1_2("Dataset_in_Group_1.2"); +const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset_in_Group_1.2"); /*------------------------------------------------------------------------- * Function: test_get_objname * * Purpose: Tests getting object name of groups and datasets. * + * Description: + * File structure: + * GROUP1 + * GROUP1_1 + * GROUP1_2 + * DSET_IN_GRP1_2 + * DSET_IN_GRP1 + * DSET_IN_FILE + * + * * Return: Success: 0 * Failure: -1 * @@ -143,6 +155,81 @@ static void test_get_objname() issue_fail_msg("test_get_objname", __LINE__, __FILE__); } } // test_get_objname +/*------------------------------------------------------------------------- + * Function: test_existance + * + * Purpose: Tests getting object name of groups and datasets. + * + * Description: + * File structure: + * GROUP1 + * GROUP1_1 + * GROUP1_2 + * DSET_IN_GRP1_2 + * DSET_IN_GRP1 + * DSET_IN_FILE + * + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Binh-Minh Ribler + * Friday, March 4, 2014 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void test_existance() +{ + SUBTEST("H5File::exists and Group::exists"); + + try { + // Open file + H5File file(FILE_OBJECTS, H5F_ACC_RDONLY); + + // Check if GROUP1 exists in the file + bool exists = file.exists(GROUP1); + + // Open GROUP1 + Group grp1 = file.openGroup(GROUP1); + + // Check if GROUP1_1 and GROUP1_2 exist in GROUP1 + exists = grp1.exists(GROUP1_1); + verify_val(exists, TRUE, "Group::exists GROUP1_1", __LINE__, __FILE__); + exists = grp1.exists(GROUP1_2); + verify_val(exists, TRUE, "Group::exists GROUP1_2", __LINE__, __FILE__); + + // Check if DSET_IN_GRP1 exists in GROUP1 + exists = grp1.exists(DSET_IN_GRP1); + verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); + + // Open GROUP1_2 + Group grp1_2 = grp1.openGroup(GROUP1_2); + + // Check if DSET_IN_GRP1_2 exists in GROUP1_2 + exists = grp1_2.exists(DSET_IN_GRP1_2); + verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1_2", __LINE__, __FILE__); + + // Check if a dataset exists given dataset as location with full path name + DataSet dset1 = file.openDataSet(DSET_IN_FILE); + exists = dset1.exists("/Top Group/Dataset_in_Group_1"); + verify_val(exists, TRUE, "Group::exists given dataset with full path name", __LINE__, __FILE__); + + exists = grp1_2.exists(DSET_IN_GRP1); + verify_val(exists, FALSE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); + + // Everything will be closed as they go out of scope + + PASSED(); + } // try block + + // catch all other exceptions + catch (Exception& E) + { + issue_fail_msg("test_existance", __LINE__, __FILE__); + } +} // test_existance /*------------------------------------------------------------------------- * Function: test_get_objname_ontypes @@ -182,16 +269,6 @@ static void test_get_objname_ontypes() H5std_string inttype_name = inttype.getObjName(); verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - // Close the type then open it again to test getting its name with - // the constructor - inttype.close(); - IntType newtype(file, "INT type of STD_B8LE"); - - // Get and verify its name - H5std_string type_name = newtype.getObjName(); - verify_val(type_name, "/INT type of STD_B8LE", "DataType::getObjName tests constructor", __LINE__, __FILE__); - newtype.close(); - // Make copy of a predefined type and save it DataType dtype(PredType::STD_B8LE); dtype.commit(file, "STD_B8LE"); @@ -205,14 +282,7 @@ static void test_get_objname_ontypes() dtype = file.openDataType("STD_B8LE"); // Get and verify its name - type_name = dtype.getObjName(); - verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Repeat the test with openDataType's replacement - DataType dtype2(file, "STD_B8LE"); - - // Get and verify its name - type_name = dtype2.getObjName(); + H5std_string type_name = dtype.getObjName(); verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); // Test getting type's name from copied type @@ -333,6 +403,7 @@ void test_object() MESSAGE(5, ("Testing Object Functions\n")); test_get_objname(); // Test get object name from groups/datasets + test_existance(); // Test check for object existance test_get_objname_ontypes(); // Test get object name from types test_get_objtype(); // Test get object type -- cgit v0.12