diff options
author | lrknox <lrknox> | 2018-05-11 16:06:02 (GMT) |
---|---|---|
committer | lrknox <lrknox> | 2018-05-11 16:06:02 (GMT) |
commit | fb55d82aa44309df76d4c3e6a8a3d5f2c2ac7792 (patch) | |
tree | 921f8be559f9c871f9afcaeb5dcd21bdcb585b1a | |
parent | aa52644d1f9e5a1103e4f670b56074c4e46a04f2 (diff) | |
parent | 731737845c15958cbe1ceb9141cbaf9e4acf4813 (diff) | |
download | hdf5-fb55d82aa44309df76d4c3e6a8a3d5f2c2ac7792.zip hdf5-fb55d82aa44309df76d4c3e6a8a3d5f2c2ac7792.tar.gz hdf5-fb55d82aa44309df76d4c3e6a8a3d5f2c2ac7792.tar.bz2 |
Merge branch 'hdf5_1_8' of https://bitbucket.hdfgroup.org/scm/~lrknox/hdf5_lrk into hdf5_1_8
41 files changed, 1006 insertions, 312 deletions
@@ -345,6 +345,8 @@ ./c++/src/H5AbstractDs.cpp ./c++/src/H5AbstractDs.h +./c++/src/H5AcreatProp.cpp +./c++/src/H5AcreatProp.h ./c++/src/H5Alltypes.h ./c++/src/H5ArrayType.cpp ./c++/src/H5ArrayType.h @@ -392,6 +394,8 @@ ./c++/src/H5Library.h ./c++/src/H5LaccProp.cpp ./c++/src/H5LaccProp.h +./c++/src/H5LcreatProp.cpp +./c++/src/H5LcreatProp.h ./c++/src/H5Location.cpp ./c++/src/H5Location.h ./c++/src/H5Object.cpp @@ -402,6 +406,8 @@ ./c++/src/H5PredType.h ./c++/src/H5PropList.cpp ./c++/src/H5PropList.h +./c++/src/H5StrcreatProp.cpp +./c++/src/H5StrcreatProp.h ./c++/src/H5StrType.cpp ./c++/src/H5StrType.h ./c++/src/H5VarLenType.cpp diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 5b36137..9b9b745 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -13,6 +13,7 @@ configure_file (${HDF_RESOURCES_DIR}/H5cxx_config.h.in #----------------------------------------------------------------------------- set (CPP_SRCS ${HDF5_CPP_SRC_SOURCE_DIR}/H5AbstractDs.cpp + ${HDF5_CPP_SRC_SOURCE_DIR}/H5AcreatProp.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5ArrayType.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5AtomType.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5Attribute.cpp @@ -33,18 +34,21 @@ set (CPP_SRCS ${HDF5_CPP_SRC_SOURCE_DIR}/H5IdComponent.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5IntType.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5LaccProp.cpp + ${HDF5_CPP_SRC_SOURCE_DIR}/H5LcreatProp.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5Library.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5Location.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5Object.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5OcreatProp.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5PredType.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5PropList.cpp + ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrcreatProp.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrType.cpp ${HDF5_CPP_SRC_SOURCE_DIR}/H5VarLenType.cpp ) set (CPP_HDRS ${HDF5_CPP_SRC_SOURCE_DIR}/H5AbstractDs.h + ${HDF5_CPP_SRC_SOURCE_DIR}/H5AcreatProp.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5Alltypes.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5ArrayType.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5AtomType.h @@ -70,12 +74,14 @@ set (CPP_HDRS ${HDF5_CPP_SRC_SOURCE_DIR}/H5Include.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5IntType.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5LaccProp.h + ${HDF5_CPP_SRC_SOURCE_DIR}/H5LcreatProp.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5Library.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5Location.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5Object.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5OcreatProp.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5PredType.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5PropList.h + ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrcreatProp.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5StrType.h ${HDF5_CPP_SRC_SOURCE_DIR}/H5VarLenType.h ) diff --git a/c++/src/H5AcreatProp.cpp b/c++/src/H5AcreatProp.cpp new file mode 100644 index 0000000..825d230 --- /dev/null +++ b/c++/src/H5AcreatProp.cpp @@ -0,0 +1,113 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include <string> + +#include "H5Include.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5PropList.h" +#include "H5StrcreatProp.h" +#include "H5AcreatProp.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 +AttrCreatPropList* AttrCreatPropList::DEFAULT_ = 0; + +//-------------------------------------------------------------------------- +// Function: AttrCreatPropList::getConstant +// Creates a AttrCreatPropList object representing the HDF5 constant +// H5P_ATTRIBUTE_CREATE, pointed to by AttrCreatPropList::DEFAULT_ +// exception H5::PropListIException +// Description +// If AttrCreatPropList::DEFAULT_ already points to an allocated +// object, throw a PropListIException. This scenario should not +// happen. +// May 2018 +//-------------------------------------------------------------------------- +AttrCreatPropList* AttrCreatPropList::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 AttrCreatPropList(H5P_ATTRIBUTE_CREATE); + else + throw PropListIException("AttrCreatPropList::getConstant", "AttrCreatPropList::getConstant is being invoked on an allocated DEFAULT_"); + return(DEFAULT_); +} + +//-------------------------------------------------------------------------- +// Function: AttrCreatPropList::deleteConstants +// Purpose: Deletes the constant object that AttrCreatPropList::DEFAULT_ +// points to. +// exception H5::PropListIException +// May 2018 +//-------------------------------------------------------------------------- +void AttrCreatPropList::deleteConstants() +{ + if (DEFAULT_ != 0) + delete DEFAULT_; +} + +//-------------------------------------------------------------------------- +// Purpose: Constant for default link creation property +//-------------------------------------------------------------------------- +const AttrCreatPropList& AttrCreatPropList::DEFAULT = *getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: Default Constructor +///\brief Creates a file access property list +// May 2018 +//-------------------------------------------------------------------------- +AttrCreatPropList::AttrCreatPropList() : StrCreatPropList(H5P_ATTRIBUTE_CREATE) {} + +//-------------------------------------------------------------------------- +// Function: AttrCreatPropList copy constructor +///\brief Copy constructor: same HDF5 object as \a original +///\param original - IN: AttrCreatPropList instance to copy +// May 2018 +//-------------------------------------------------------------------------- +AttrCreatPropList::AttrCreatPropList(const AttrCreatPropList& original) : StrCreatPropList(original) {} + +//-------------------------------------------------------------------------- +// Function: AttrCreatPropList overloaded constructor +///\brief Creates a file access property list using the id of an +/// existing one. +// May 2018 +//-------------------------------------------------------------------------- +AttrCreatPropList::AttrCreatPropList(const hid_t plist_id) : StrCreatPropList(plist_id) {} + +//-------------------------------------------------------------------------- +// Function: AttrCreatPropList destructor +///\brief Noop destructor +// May 2018 +//-------------------------------------------------------------------------- +AttrCreatPropList::~AttrCreatPropList() {} + +} // end namespace diff --git a/c++/src/H5AcreatProp.h b/c++/src/H5AcreatProp.h new file mode 100644 index 0000000..9f81897 --- /dev/null +++ b/c++/src/H5AcreatProp.h @@ -0,0 +1,62 @@ +// 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __H5AttrCreatPropList_H +#define __H5AttrCreatPropList_H + +namespace H5 { + +/*! \class AttrCreatPropList + \brief Class AttrCreatPropList inherits from StrCreatPropList and provides + wrappers for the HDF5 attribute creation property list. +*/ +// Inheritance: StrCreatPropList -> PropList -> IdComponent +class H5_DLLCPP AttrCreatPropList : public StrCreatPropList { + public: + ///\brief Default attribute creation property list. + static const AttrCreatPropList& DEFAULT; + + // Creates a attribute creation property list. + AttrCreatPropList(); + + ///\brief Returns this class name. + virtual H5std_string fromClass () const { return("AttrCreatPropList"); } + + // Copy constructor: same as the original AttrCreatPropList. + AttrCreatPropList(const AttrCreatPropList& original); + + // Creates a copy of an existing attribute creation property list + // using the property list id. + AttrCreatPropList(const hid_t acpl_id); + + // Noop destructor + virtual ~AttrCreatPropList(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + + // Deletes the global constant, should only be used by the library + static void deleteConstants(); + + private: + static AttrCreatPropList* DEFAULT_; + + // Creates the global constant, should only be used by the library + static AttrCreatPropList* getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS +}; // end of AttrCreatPropList + +} // namespace H5 + +#endif // __H5AttrCreatPropList_H diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 6be1a1f..b0d65b0 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -117,7 +117,6 @@ ArrayType::ArrayType(const H5Location& loc, const H5std_string& type_name) : Dat // Closes the id on the lhs object first with setId, then copies // each data member from the rhs object. (Issue HDFFV-9562) // Programmer Binh-Minh Ribler - Mar 2016 -// Modification //-------------------------------------------------------------------------- ArrayType& ArrayType::operator=(const ArrayType& rhs) { diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 3733736..739cda7 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -278,23 +278,6 @@ DataSpace Attribute::getSpace() const } //-------------------------------------------------------------------------- -// Function: Attribute::getFileName -///\brief Gets the name of the file, in which this attribute belongs. -///\return File name -///\exception H5::IdComponentException -// Programmer Binh-Minh Ribler - Jul, 2004 -//-------------------------------------------------------------------------- -H5std_string Attribute::getFileName() const -{ - try { - return(p_get_file_name()); - } - catch (IdComponentException& E) { - throw FileIException("Attribute::getFileName", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- // Function: Attribute::getName ///\brief Gets the name of this attribute, returning its length. ///\param attr_name - OUT: Buffer for the name string as char* @@ -633,6 +616,20 @@ void Attribute::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } + +//-------------------------------------------------------------------------- +// Function: Attribute::throwException +///\brief Throws H5::AttributeIException. +///\param func_name - Name of the function where failure occurs +///\param msg - Message describing the failure +///\exception H5::AttributeIException +// May 2018 +//-------------------------------------------------------------------------- +void Attribute::throwException(const H5std_string& func_name, const H5std_string& msg) const +{ + throw AttributeIException(inMemFunc(func_name.c_str()), msg); +} + #endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index 98883e2..9ac21b5 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -41,9 +41,6 @@ class H5_DLLCPP Attribute : public AbstractDs, public H5Location { // Closes this attribute. virtual void close(); - // Gets the name of the file, in which this attribute belongs. - H5std_string getFileName() const; - // Gets the name of this attribute. ssize_t getName(char* attr_name, size_t buf_size = 0) const; H5std_string getName(size_t len) const; @@ -80,6 +77,9 @@ class H5_DLLCPP Attribute : public AbstractDs, public H5Location { // Gets the attribute id. virtual hid_t getId() const; + // Throw group exception. + virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const; + // Destructor: properly terminates access to this attribute. virtual ~Attribute(); diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 684090f..97900f6 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -24,6 +24,8 @@ #include "H5DxferProp.h" #include "H5DcreatProp.h" #include "H5LaccProp.h" +#include "H5StrcreatProp.h" +#include "H5LcreatProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5CommonFG.h" @@ -53,9 +55,11 @@ namespace H5 { // Function: CommonFG::createGroup ///\brief Creates a new group at this location which can be a file /// or another group. -///\param name - IN: Name of the group to create +///\param name - IN: Name of the group to create ///\param size_hint - IN: Indicates the number of bytes to reserve for -/// the names that will appear in the group +/// the names that will appear in the group - default to 0 +///\param lcpl - IN: Link creation property list - default to +/// LinkCreatPropList::DEFAULT ///\return Group instance ///\exception H5::FileIException or H5::GroupIException ///\par Description @@ -63,9 +67,12 @@ namespace H5 { /// reserve for storing the names that will appear in this new /// group. If a non-positive value is provided for the \a size_hint /// then a default size is chosen. -// Programmer Binh-Minh Ribler - 2000 +// 2000 +// Modification: +// May 2018 - 1.8.21 +// - Added an argument with default value LinkCreatPropList::DEFAULT //-------------------------------------------------------------------------- -Group CommonFG::createGroup(const char* name, size_t size_hint) const +Group CommonFG::createGroup(const char* name, size_t size_hint, const LinkCreatPropList& lcpl) const { // Group creation property list for size hint hid_t gcpl_id = 0; @@ -85,7 +92,7 @@ Group CommonFG::createGroup(const char* name, size_t size_hint) const // Call C routine H5Gcreate2 to create the named group, giving the // location id which can be a file id or a group id - hid_t group_id = H5Gcreate2(getLocId(), name, H5P_DEFAULT, gcpl_id, H5P_DEFAULT); + hid_t group_id = H5Gcreate2(getLocId(), name, lcpl.getId(), gcpl_id, H5P_DEFAULT); // Close the group creation property list, if necessary if(gcpl_id > 0) @@ -107,11 +114,13 @@ Group CommonFG::createGroup(const char* name, size_t size_hint) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 +// Modification: +// May 2018 - 1.8.21 +// - Added LinkCreatPropList& with default value LinkCreatPropList::DEFAULT //-------------------------------------------------------------------------- -Group CommonFG::createGroup(const H5std_string& name, size_t size_hint) const +Group CommonFG::createGroup(const H5std_string& name, size_t size_hint, const LinkCreatPropList& lcpl) const { - return(createGroup(name.c_str(), size_hint)); + return(createGroup(name.c_str(), size_hint, lcpl)); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 81a9a29..5e43d8c 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -30,8 +30,8 @@ class H5_DLLCPP CommonFG { public: // Creates a new group at this location which can be a file // or another group. - Group createGroup(const char* name, size_t size_hint = 0) const; - Group createGroup(const H5std_string& name, size_t size_hint = 0) const; + Group createGroup(const char* name, size_t size_hint = 0, const LinkCreatPropList& lc_plist = LinkCreatPropList::DEFAULT) const; + Group createGroup(const H5std_string& name, size_t size_hint = 0, const LinkCreatPropList& lc_plist = LinkCreatPropList::DEFAULT) const; // Opens an existing group in a location which can be a file // or another group. diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp index 6d879bd..903a7c4 100644 --- a/c++/src/H5CompType.cpp +++ b/c++/src/H5CompType.cpp @@ -31,7 +31,7 @@ namespace H5 { //-------------------------------------------------------------------------- // Function: CompType default constructor ///\brief Default constructor: Creates a stub compound datatype -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::CompType() : DataType() {} @@ -39,7 +39,7 @@ CompType::CompType() : DataType() {} // Function: CompType copy constructor ///\brief Copy constructor: makes copy of the original CompType object ///\param original - IN: Original CompType instance -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::CompType(const CompType& original) : DataType(original) {} @@ -47,7 +47,7 @@ CompType::CompType(const CompType& original) : DataType(original) {} // Function: CompType overloaded constructor ///\brief Creates a CompType object using the id of an existing datatype. ///\param existing_id - IN: Id of an existing compound datatype -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::CompType(const hid_t existing_id) : DataType(existing_id) {} @@ -59,7 +59,7 @@ CompType::CompType(const hid_t existing_id) : DataType(existing_id) {} // Description // The DataType constructor calls the C API H5Tcreate to create // the compound datatype. -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::CompType(size_t size) : DataType(H5T_COMPOUND, size) {} @@ -69,7 +69,7 @@ CompType::CompType(size_t size) : DataType(H5T_COMPOUND, size) {} ///\param dataset - IN: Dataset that this enum datatype associates with ///\return CompType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::CompType(const DataSet& dataset) : DataType() { @@ -90,7 +90,7 @@ CompType::CompType(const DataSet& dataset) : DataType() ///\param loc - IN: Location of the type ///\param type_name - IN: Compound type name ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - Sept 2017 +// Sept 2017 // Description // In 1.8.20, this constructor was introduced and may replace the // existing function CommonFG::openCompType(const char*) to @@ -109,7 +109,7 @@ CompType::CompType(const H5Location& loc, const char *type_name) : DataType() ///\param loc - IN: Location of the type ///\param type_name - IN: Compound type name ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - Sept 2017 +// Sept 2017 // Description // In 1.8.20, this constructor was introduced and may replace the // existing function CommonFG::openCompType(const H5std_string&) to @@ -126,7 +126,7 @@ CompType::CompType(const H5Location& loc, const H5std_string& type_name) : DataT ///\brief Returns a CompType object via DataType* by decoding the /// binary object description of this datatype. ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - Sept 2017 +// Sept 2017 //-------------------------------------------------------------------------- DataType* CompType::decode() const { @@ -147,7 +147,7 @@ DataType* CompType::decode() const ///\brief Returns the number of members in this compound datatype. ///\return Number of members ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- int CompType::getNmembers() const { @@ -166,7 +166,7 @@ int CompType::getNmembers() const ///\param member_num - IN: Zero-based index of the member ///\return Name of member ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- H5std_string CompType::getMemberName(unsigned member_num) const { @@ -184,14 +184,14 @@ H5std_string CompType::getMemberName(unsigned member_num) const //-------------------------------------------------------------------------- // Function: CompType::getMemberIndex ///\brief Returns the index of a member in this compound datatype. -///\param name - IN: Name of the member +///\param name - IN: Name of the member - \c char* ///\return Index of member ///\exception H5::DataTypeIException ///\par Description /// Members are stored in no particular order with numbers 0 /// through N-1, where N is the value returned by the member /// function \c CompType::getNmembers. -// Programmer Binh-Minh Ribler - May 16, 2002 +// May 2002 //-------------------------------------------------------------------------- int CompType::getMemberIndex(const char* name) const { @@ -203,6 +203,21 @@ int CompType::getMemberIndex(const char* name) const } return(member_index); } + +//-------------------------------------------------------------------------- +// Function: CompType::getMemberIndex +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +///\param name - IN: Name of the member - \c H5std_string +///\return Index of member +///\exception H5::DataTypeIException +///\par Description +/// Members are stored in no particular order with numbers 0 +/// through N-1, where N is the value returned by the member +/// function \c CompType::getNmembers. +// Apr 2018 +//-------------------------------------------------------------------------- int CompType::getMemberIndex(const H5std_string& name) const { return(getMemberIndex(name.c_str())); @@ -214,14 +229,14 @@ int CompType::getMemberIndex(const H5std_string& name) const /// respect to the beginning of the compound data type datum. ///\param member_num - IN: Zero-based index of the member ///\return Byte offset -// Programmer Binh-Minh Ribler - 2000 +// 2000 // Description /// Members are stored in no particular order with numbers 0 /// through N-1, where N is the value returned by the member /// function \c CompType::getNmembers. // // Note that byte offset being returned as 0 doesn't indicate -// a failure. (According to Quincey) +// a failure. //-------------------------------------------------------------------------- size_t CompType::getMemberOffset(unsigned member_num) const { @@ -235,7 +250,7 @@ size_t CompType::getMemberOffset(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return Type class of the member ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 // Modification // Modified to use H5Tget_member_class instead. - Jul, 2005 //-------------------------------------------------------------------------- @@ -275,7 +290,7 @@ hid_t CompType::p_get_member_type(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return DataType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- DataType CompType::getMemberDataType(unsigned member_num) const { @@ -296,12 +311,12 @@ DataType CompType::getMemberDataType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return ArrayType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - Jul, 2005 +// Jul 2005 //-------------------------------------------------------------------------- ArrayType CompType::getMemberArrayType(unsigned member_num) const { try { - ArrayType arraytype(p_get_member_type(member_num)); + ArrayType arraytype; f_DataType_setId(&arraytype, p_get_member_type(member_num)); return(arraytype); } @@ -317,12 +332,12 @@ ArrayType CompType::getMemberArrayType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return CompType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType CompType::getMemberCompType(unsigned member_num) const { try { - CompType comptype(p_get_member_type(member_num)); + CompType comptype; f_DataType_setId(&comptype, p_get_member_type(member_num)); return(comptype); } @@ -338,12 +353,12 @@ CompType CompType::getMemberCompType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return EnumType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- EnumType CompType::getMemberEnumType(unsigned member_num) const { try { - EnumType enumtype(p_get_member_type(member_num)); + EnumType enumtype; f_DataType_setId(&enumtype, p_get_member_type(member_num)); return(enumtype); } @@ -359,12 +374,12 @@ EnumType CompType::getMemberEnumType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return IntType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- IntType CompType::getMemberIntType(unsigned member_num) const { try { - IntType inttype(p_get_member_type(member_num)); + IntType inttype; f_DataType_setId(&inttype, p_get_member_type(member_num)); return(inttype); } @@ -380,12 +395,12 @@ IntType CompType::getMemberIntType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return FloatType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- FloatType CompType::getMemberFloatType(unsigned member_num) const { try { - FloatType floatype(p_get_member_type(member_num)); + FloatType floatype; f_DataType_setId(&floatype, p_get_member_type(member_num)); return(floatype); } @@ -401,12 +416,12 @@ FloatType CompType::getMemberFloatType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return StrType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- StrType CompType::getMemberStrType(unsigned member_num) const { try { - StrType strtype(p_get_member_type(member_num)); + StrType strtype; f_DataType_setId(&strtype, p_get_member_type(member_num)); return(strtype); } @@ -422,12 +437,12 @@ StrType CompType::getMemberStrType(unsigned member_num) const ///\param member_num - IN: Zero-based index of the member ///\return VarLenType instance ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - Jul, 2005 +// Jul 2005 //-------------------------------------------------------------------------- VarLenType CompType::getMemberVarLenType(unsigned member_num) const { try { - VarLenType varlentype(p_get_member_type(member_num)); + VarLenType varlentype; f_DataType_setId(&varlentype, p_get_member_type(member_num)); return(varlentype); } @@ -476,7 +491,7 @@ void CompType::getMemberType(unsigned member_num, StrType& strtype) const ///\param offset - IN: Offset in memory structure of the field to insert ///\param new_member - IN: New member to be inserted ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- void CompType::insertMember(const H5std_string& name, size_t offset, const DataType& new_member) const { @@ -499,7 +514,7 @@ void CompType::insertMember(const H5std_string& name, size_t offset, const DataT ///\brief Recursively removes padding from within a compound datatype. /// ///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- void CompType::pack() const { @@ -518,7 +533,7 @@ void CompType::pack() const ///\exception H5::DataTypeIException // Note // H5Tset_size works on atom datatypes and compound datatypes only -// Programmer Binh-Minh Ribler - 2014 +// March 2014 //-------------------------------------------------------------------------- void CompType::setSize(size_t size) const { @@ -533,7 +548,7 @@ void CompType::setSize(size_t size) const //-------------------------------------------------------------------------- // Function: CompType destructor ///\brief Properly terminates access to this compound datatype. -// Programmer Binh-Minh Ribler - 2000 +// 2000 //-------------------------------------------------------------------------- CompType::~CompType() {} diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index dcf3a17..af7d1e5fa 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -27,11 +27,15 @@ #include "H5Attribute.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" +#include "H5StrcreatProp.h" +#include "H5AcreatProp.h" +#include "H5LcreatProp.h" #include "H5CommonFG.h" #include "H5DataType.h" #include "H5DxferProp.h" #include "H5FaccProp.h" #include "H5FcreatProp.h" +#include "H5LaccProp.h" #include "H5AtomType.h" #include "H5PredType.h" #include "H5EnumType.h" diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index 14dd607..1dce28e 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -826,6 +826,19 @@ void DataSet::close() } //-------------------------------------------------------------------------- +// Function: DataSet::throwException +///\brief Throws H5::DataSetIException. +///\param func_name - Name of the function where failure occurs +///\param msg - Message describing the failure +///\exception H5::DataSetIException +// May 2018 +//-------------------------------------------------------------------------- +void DataSet::throwException(const H5std_string& func_name, const H5std_string& msg) const +{ + throw DataSetIException(inMemFunc(func_name.c_str()), msg); +} + +//-------------------------------------------------------------------------- // Function: DataSet destructor ///\brief Properly terminates access to this dataset. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index 09aab08..f0178f4 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -85,6 +85,9 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataSet"); } + // Throw DataSetIException. + virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const; + // Creates a dataset by way of dereference. DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT); DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 7b385d2..dc9b422 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -924,6 +924,19 @@ void DataType::close() } //-------------------------------------------------------------------------- +// Function: DataType::throwException +///\brief Throws H5::DataTypeIException. +///\param func_name - Name of the function where failure occurs +///\param msg - Message describing the failure +///\exception H5::DataTypeIException +// May 2018 +//-------------------------------------------------------------------------- +void DataType::throwException(const H5std_string& func_name, const H5std_string& msg) const +{ + throw DataTypeIException(inMemFunc(func_name.c_str()), msg); +} + +//-------------------------------------------------------------------------- // Function: DataType destructor ///\brief Properly terminates access to this datatype. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 29cc990..efb0c14 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -122,6 +122,9 @@ class H5_DLLCPP DataType : public H5Object { ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataType"); } + // Throw DataTypeIException. + virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const; + // Creates a copy of an existing DataType using its id DataType(const hid_t type_id); diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp index da66ec6..f303e95 100644 --- a/c++/src/H5DxferProp.cpp +++ b/c++/src/H5DxferProp.cpp @@ -92,7 +92,7 @@ DSetMemXferPropList::DSetMemXferPropList() : PropList(H5P_DATASET_XFER) {} // Function DSetMemXferPropList constructor ///\brief Creates a dataset transfer property list with transform /// expression. -// Programmer: Binh-Minh Ribler - 2000 +// March 2014 //-------------------------------------------------------------------------- DSetMemXferPropList::DSetMemXferPropList(const char* exp) : PropList(H5P_DATASET_XFER) { diff --git a/c++/src/H5DxferProp.h b/c++/src/H5DxferProp.h index 370b271..a8b1fa9 100644 --- a/c++/src/H5DxferProp.h +++ b/c++/src/H5DxferProp.h @@ -21,7 +21,7 @@ namespace H5 { \brief Class DSetCreatPropList inherits from PropList and provides wrappers for the HDF5 dataset memory and transfer property list. */ -// Inheritance: ObjCreatPropList -> PropList -> IdComponent +// Inheritance: PropList -> IdComponent class H5_DLLCPP DSetMemXferPropList : public PropList { public: ///\brief Default dataset memory and transfer property list. diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index 0bb15bc..e5cc7b2 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -331,27 +331,27 @@ void Exception::printError(FILE* stream) const Exception::~Exception() throw() {} //-------------------------------------------------------------------------- -// Subclass: FileIException -// Programmer Binh-Minh Ribler - 2000 +// Subclass: LocationException +// Programmer Binh-Minh Ribler - 2014 //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- -// Function: FileIException default constructor +// Function: LocationException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -FileIException::FileIException():Exception(){} +LocationException::LocationException() : Exception(){} //-------------------------------------------------------------------------- -// Function: FileIException overloaded constructor -///\brief Creates a FileIException with the name of the function, +// Function: LocationException overloaded constructor +///\brief Creates a LocationException with the name of the function, /// in which the failure occurs, and an optional detailed message. ///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -FileIException::FileIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +LocationException::LocationException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} //-------------------------------------------------------------------------- -// Function: FileIException destructor +// Function: LocationException destructor ///\brief Noop destructor. //-------------------------------------------------------------------------- -FileIException::~FileIException() throw() {} +LocationException::~LocationException() throw() {} //-------------------------------------------------------------------------- // Subclass: GroupIException @@ -361,7 +361,7 @@ FileIException::~FileIException() throw() {} // Function: GroupIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -GroupIException::GroupIException():Exception(){} +GroupIException::GroupIException() : LocationException(){} //-------------------------------------------------------------------------- // Function: GroupIException overloaded constructor ///\brief Creates a GroupIException with the name of the function, @@ -369,7 +369,7 @@ GroupIException::GroupIException():Exception(){} ///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -GroupIException::GroupIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +GroupIException::GroupIException(const H5std_string& func, const H5std_string& message) : LocationException(func, message) {} //-------------------------------------------------------------------------- // Function: GroupIException destructor ///\brief Noop destructor. @@ -377,6 +377,29 @@ GroupIException::GroupIException(const H5std_string& func, const H5std_string& m GroupIException::~GroupIException() throw() {} //-------------------------------------------------------------------------- +// Subclass: FileIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- +// Function: FileIException default constructor +///\brief Default constructor. +//-------------------------------------------------------------------------- +FileIException::FileIException():GroupIException(){} +//-------------------------------------------------------------------------- +// Function: FileIException overloaded constructor +///\brief Creates a FileIException with the name of the function, +/// in which the failure occurs, and an optional detailed message. +///\param func - IN: Name of the function where failure occurs +///\param message - IN: Message on the failure +//-------------------------------------------------------------------------- +FileIException::FileIException(const H5std_string& func, const H5std_string& message) : GroupIException(func, message) {} +//-------------------------------------------------------------------------- +// Function: FileIException destructor +///\brief Noop destructor. +//-------------------------------------------------------------------------- +FileIException::~FileIException() throw() {} + +//-------------------------------------------------------------------------- // Subclass: DataSpaceIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- @@ -384,7 +407,7 @@ GroupIException::~GroupIException() throw() {} // Function: DataSpaceIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -DataSpaceIException::DataSpaceIException():Exception(){} +DataSpaceIException::DataSpaceIException() : Exception(){} //-------------------------------------------------------------------------- // Function: DataSpaceIException overloaded constructor ///\brief Creates a DataSpaceIException with the name of the function, @@ -407,7 +430,7 @@ DataSpaceIException::~DataSpaceIException() throw() {} // Function: DataTypeIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -DataTypeIException::DataTypeIException():Exception(){} +DataTypeIException::DataTypeIException() : LocationException(){} //-------------------------------------------------------------------------- // Function: DataTypeIException overloaded constructor ///\brief Creates a DataTypeIException with the name of the function, @@ -415,7 +438,7 @@ DataTypeIException::DataTypeIException():Exception(){} ///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -DataTypeIException::DataTypeIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +DataTypeIException::DataTypeIException(const H5std_string& func, const H5std_string& message) : LocationException(func, message) {} //-------------------------------------------------------------------------- // Function: DataTypeIException destructor ///\brief Noop destructor. @@ -430,7 +453,7 @@ DataTypeIException::~DataTypeIException() throw() {} // Function: PropListIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -PropListIException::PropListIException():Exception(){} +PropListIException::PropListIException() : Exception(){} //-------------------------------------------------------------------------- // Function: PropListIException overloaded constructor ///\brief Creates a PropListIException with the name of the function, @@ -453,7 +476,7 @@ PropListIException::~PropListIException() throw() {} // Function: DataSetIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -DataSetIException::DataSetIException():Exception(){} +DataSetIException::DataSetIException() : LocationException(){} //-------------------------------------------------------------------------- // Function: DataSetIException overloaded constructor ///\brief Creates a DataSetIException with the name of the function, @@ -461,7 +484,7 @@ DataSetIException::DataSetIException():Exception(){} ///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -DataSetIException::DataSetIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +DataSetIException::DataSetIException(const H5std_string& func, const H5std_string& message) : LocationException(func, message) {} //-------------------------------------------------------------------------- // Function: DataSetIException destructor ///\brief Noop destructor. @@ -476,7 +499,7 @@ DataSetIException::~DataSetIException() throw() {} // Function: AttributeIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -AttributeIException::AttributeIException():Exception(){} +AttributeIException::AttributeIException() : LocationException(){} //-------------------------------------------------------------------------- // Function: AttributeIException overloaded constructor ///\brief Creates an AttributeIException with the name of the function, @@ -484,7 +507,7 @@ AttributeIException::AttributeIException():Exception(){} ///\param func - IN: Name of the function where failure occurs ///\param message - IN: Message on the failure //-------------------------------------------------------------------------- -AttributeIException::AttributeIException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} +AttributeIException::AttributeIException(const H5std_string& func, const H5std_string& message) : LocationException(func, message) {} //-------------------------------------------------------------------------- // Function: AttributeIException destructor ///\brief Noop destructor. @@ -499,7 +522,7 @@ AttributeIException::~AttributeIException() throw() {} // Function: ReferenceException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -ReferenceException::ReferenceException():Exception(){} +ReferenceException::ReferenceException() : Exception(){} //-------------------------------------------------------------------------- // Function: ReferenceException overloaded constructor ///\brief Creates a ReferenceException with the name of the function, @@ -522,7 +545,7 @@ ReferenceException::~ReferenceException() throw() {} // Function: LibraryIException default constructor ///\brief Default constructor. //-------------------------------------------------------------------------- -LibraryIException::LibraryIException():Exception(){} +LibraryIException::LibraryIException() : Exception(){} //-------------------------------------------------------------------------- // Function: LibraryIException overloaded constructor ///\brief Creates a LibraryIException with the name of the function, @@ -538,29 +561,6 @@ LibraryIException::LibraryIException(const H5std_string& func, const H5std_strin LibraryIException::~LibraryIException() throw() {} //-------------------------------------------------------------------------- -// Subclass: LocationException -// Programmer Binh-Minh Ribler - 2014 -//-------------------------------------------------------------------------- -//-------------------------------------------------------------------------- -// Function: LocationException default constructor -///\brief Default constructor. -//-------------------------------------------------------------------------- -LocationException::LocationException():Exception(){} -//-------------------------------------------------------------------------- -// Function: LocationException overloaded constructor -///\brief Creates a LocationException with the name of the function, -/// in which the failure occurs, and an optional detailed message. -///\param func - IN: Name of the function where failure occurs -///\param message - IN: Message on the failure -//-------------------------------------------------------------------------- -LocationException::LocationException(const H5std_string& func, const H5std_string& message) : Exception(func, message) {} -//-------------------------------------------------------------------------- -// Function: LocationException destructor -///\brief Noop destructor. -//-------------------------------------------------------------------------- -LocationException::~LocationException() throw() {} - -//-------------------------------------------------------------------------- // Subclass: IdComponentException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index 7315e11..e15d81c 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -91,20 +91,27 @@ class H5_DLLCPP Exception { H5std_string func_name; }; -class H5_DLLCPP FileIException : public Exception { +class H5_DLLCPP LocationException : public Exception { public: - FileIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); - FileIException(); - virtual ~FileIException() throw(); + LocationException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); + LocationException(); + virtual ~LocationException() throw(); }; -class H5_DLLCPP GroupIException : public Exception { +class H5_DLLCPP GroupIException : public LocationException { public: GroupIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); GroupIException(); virtual ~GroupIException() throw(); }; +class H5_DLLCPP FileIException : public GroupIException { + public: + FileIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); + FileIException(); + virtual ~FileIException() throw(); +}; + class H5_DLLCPP DataSpaceIException : public Exception { public: DataSpaceIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); @@ -112,7 +119,7 @@ class H5_DLLCPP DataSpaceIException : public Exception { virtual ~DataSpaceIException() throw(); }; -class H5_DLLCPP DataTypeIException : public Exception { +class H5_DLLCPP DataTypeIException : public LocationException { public: DataTypeIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); DataTypeIException(); @@ -126,14 +133,14 @@ class H5_DLLCPP PropListIException : public Exception { virtual ~PropListIException() throw(); }; -class H5_DLLCPP DataSetIException : public Exception { +class H5_DLLCPP DataSetIException : public LocationException { public: DataSetIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); DataSetIException(); virtual ~DataSetIException() throw(); }; -class H5_DLLCPP AttributeIException : public Exception { +class H5_DLLCPP AttributeIException : public LocationException { public: AttributeIException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); AttributeIException(); @@ -154,13 +161,6 @@ class H5_DLLCPP LibraryIException : public Exception { virtual ~LibraryIException() throw(); }; -class H5_DLLCPP LocationException : public Exception { - public: - LocationException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); - LocationException(); - virtual ~LocationException() throw(); -}; - class H5_DLLCPP IdComponentException : public Exception { public: IdComponentException(const H5std_string& func_name, const H5std_string& message = DEFAULT_MSG); diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 395077d..7b19c7e 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -27,6 +27,8 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5LaccProp.h" +#include "H5StrcreatProp.h" +#include "H5LcreatProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5CommonFG.h" @@ -229,7 +231,7 @@ bool H5File::isHdf5(const H5std_string& name) /// will be reopened. Absence of this flag /// implies read-only access. /// -/// H5F_ACC_RDONLY: Open with read only access. - default +/// H5F_ACC_RDONLY: Open with read only access. /// // Programmer Binh-Minh Ribler - Oct, 2005 //-------------------------------------------------------------------------- @@ -632,23 +634,15 @@ void H5File::close() //-------------------------------------------------------------------------- // Function: H5File::throwException -///\brief Throws file exception - initially implemented for CommonFG +///\brief Throws H5::FileIException. ///\param func_name - Name of the function where failure occurs ///\param msg - Message describing the failure ///\exception H5::FileIException -// Description -// This function is used in CommonFG implementation so that -// proper exception can be thrown for file or group. The -// argument func_name is a member of CommonFG and "H5File::" -// will be inserted to indicate the function called is an -// implementation of H5File. -// Programmer Binh-Minh Ribler - 2000 +// December 2000 //-------------------------------------------------------------------------- void H5File::throwException(const H5std_string& func_name, const H5std_string& msg) const { - H5std_string full_name = func_name; - full_name.insert(0, "H5File::"); - throw FileIException(full_name, msg); + throw FileIException(inMemFunc(func_name.c_str()), msg); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 00a69d6..dd2dd48 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -25,6 +25,8 @@ #include "H5OcreatProp.h" #include "H5DcreatProp.h" #include "H5LaccProp.h" +#include "H5StrcreatProp.h" +#include "H5LcreatProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" @@ -163,7 +165,7 @@ void Group::p_setId(const hid_t new_id) ///\brief Closes this group. /// ///\exception H5::GroupIException -// Programmer Binh-Minh Ribler - Mar 9, 2005 +// March 2005 //-------------------------------------------------------------------------- void Group::close() { @@ -185,19 +187,11 @@ void Group::close() ///\param func_name - Name of the function where failure occurs ///\param msg - Message describing the failure ///\exception H5::GroupIException -// Description -// This function is used in CommonFG implementation so that -// proper exception can be thrown for file or group. The -// argument func_name is a member of CommonFG and "Group::" -// will be inserted to indicate the function called is an -// implementation of Group. -// Programmer Binh-Minh Ribler - 2000 +// December 2000 //-------------------------------------------------------------------------- void Group::throwException(const H5std_string& func_name, const H5std_string& msg) const { - H5std_string full_name = func_name; - full_name.insert(0, "Group::"); - throw GroupIException(full_name, msg); + throw GroupIException(inMemFunc(func_name.c_str()), msg); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index ef17b38..c54e901 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -299,11 +299,7 @@ IdComponent::IdComponent() // Function: IdComponent::p_get_file_name (protected) // Purpose: Gets the name of the file, in which this object belongs. // Exception: H5::IdComponentException -// Description: -// This function is protected so that the user applications can -// only have access to its code via allowable classes, namely, -// Attribute and H5Location subclasses. -// Programmer Binh-Minh Ribler - Jul, 2004 +// July 2004 //-------------------------------------------------------------------------- H5std_string IdComponent::p_get_file_name() const { @@ -312,7 +308,7 @@ H5std_string IdComponent::p_get_file_name() const // Preliminary call to H5Fget_name to get the length of the file name ssize_t name_size = H5Fget_name(temp_id, NULL, 0); - // If H5Aget_name returns a negative value, raise an exception, + // If H5Fget_name returns a negative value, raise an exception, if(name_size < 0) { throw IdComponentException("", "H5Fget_name failed"); diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 9a45634..744a780 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -72,6 +72,10 @@ class H5_DLLCPP IdComponent { // Gets the identifier of this object. virtual hid_t getId () const = 0; + // For subclasses to throw appropriate exception, used in H5Location, + // H5CommonFG, and H5Object. + virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const {}; + // Pure virtual function for there are various H5*close for the // subclasses. virtual void close() = 0; diff --git a/c++/src/H5LaccProp.cpp b/c++/src/H5LaccProp.cpp index 1267286..d5e7a1c 100644 --- a/c++/src/H5LaccProp.cpp +++ b/c++/src/H5LaccProp.cpp @@ -116,7 +116,7 @@ void LinkAccPropList::setNumLinks(size_t nlinks) const // Throw exception if H5Pset_nlinks returns failure if (ret_value < 0) { - throw PropListIException("setNumLinks", "H5Pset_nlinks failed"); + throw PropListIException("LinkAccPropList::setNumLinks", "H5Pset_nlinks failed"); } } @@ -134,7 +134,7 @@ size_t LinkAccPropList::getNumLinks() const // Throw exception if H5Pget_nlinks returns failure if (ret_value < 0) { - throw PropListIException("getNumLinks", "H5Pget_nlinks failed"); + throw PropListIException("LinkAccPropList::getNumLinks", "H5Pget_nlinks failed"); } return(nlinks); } diff --git a/c++/src/H5LaccProp.h b/c++/src/H5LaccProp.h index 9772cde..9e7802f 100644 --- a/c++/src/H5LaccProp.h +++ b/c++/src/H5LaccProp.h @@ -12,9 +12,6 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -// Class LinkAccPropList represents the HDF5 file access property list and -// inherits from DataType. - #ifndef __H5LinkAccPropList_H #define __H5LinkAccPropList_H @@ -22,16 +19,16 @@ namespace H5 { /*! \class LinkAccPropList \brief Class LinkAccPropList inherits from PropList and provides - wrappers for the HDF5 file access property list. + wrappers for the HDF5 link access property list. Inheritance: PropList -> IdComponent */ class H5_DLLCPP LinkAccPropList : public PropList { public: - ///\brief Default file access property list. + ///\brief Default link access property list. static const LinkAccPropList& DEFAULT; - // Creates a file access property list. + // Creates a link access property list. LinkAccPropList(); ///\brief Returns this class name. @@ -40,9 +37,9 @@ class H5_DLLCPP LinkAccPropList : public PropList { // Copy constructor: creates a copy of a LinkAccPropList object. LinkAccPropList(const LinkAccPropList& original); - // Creates a copy of an existing file access property list + // Creates a copy of an existing link access property list // using the property list id. - LinkAccPropList (const hid_t plist_id); + LinkAccPropList(const hid_t lapl_id); // Sets the number of soft or user-defined links that can be // traversed before a failure occurs. diff --git a/c++/src/H5LcreatProp.cpp b/c++/src/H5LcreatProp.cpp new file mode 100644 index 0000000..1f17f88 --- /dev/null +++ b/c++/src/H5LcreatProp.cpp @@ -0,0 +1,113 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include <string> + +#include "H5Include.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5PropList.h" +#include "H5StrcreatProp.h" +#include "H5LcreatProp.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 +LinkCreatPropList* LinkCreatPropList::DEFAULT_ = 0; + +//-------------------------------------------------------------------------- +// Function: LinkCreatPropList::getConstant +// Creates a LinkCreatPropList object representing the HDF5 constant +// H5P_LINK_CREATE, pointed to by LinkCreatPropList::DEFAULT_ +// exception H5::PropListIException +// Description +// If LinkCreatPropList::DEFAULT_ already points to an allocated +// object, throw a PropListIException. This scenario should not +// happen. +// May 2018 +//-------------------------------------------------------------------------- +LinkCreatPropList* LinkCreatPropList::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 LinkCreatPropList(H5P_LINK_CREATE); + else + throw PropListIException("LinkCreatPropList::getConstant", "LinkCreatPropList::getConstant is being invoked on an allocated DEFAULT_"); + return(DEFAULT_); +} + +//-------------------------------------------------------------------------- +// Function: LinkCreatPropList::deleteConstants +// Purpose: Deletes the constant object that LinkCreatPropList::DEFAULT_ +// points to. +// exception H5::PropListIException +// May 2018 +//-------------------------------------------------------------------------- +void LinkCreatPropList::deleteConstants() +{ + if (DEFAULT_ != 0) + delete DEFAULT_; +} + +//-------------------------------------------------------------------------- +// Purpose: Constant for default link creation property +//-------------------------------------------------------------------------- +const LinkCreatPropList& LinkCreatPropList::DEFAULT = *getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: Default Constructor +///\brief Creates a file access property list +// May 2018 +//-------------------------------------------------------------------------- +LinkCreatPropList::LinkCreatPropList() : StrCreatPropList(H5P_LINK_CREATE) {} + +//-------------------------------------------------------------------------- +// Function: LinkCreatPropList copy constructor +///\brief Copy constructor: same HDF5 object as \a original +///\param original - IN: LinkCreatPropList instance to copy +// May 2018 +//-------------------------------------------------------------------------- +LinkCreatPropList::LinkCreatPropList(const LinkCreatPropList& original) : StrCreatPropList(original) {} + +//-------------------------------------------------------------------------- +// Function: LinkCreatPropList overloaded constructor +///\brief Creates a file access property list using the id of an +/// existing one. +// May 2018 +//-------------------------------------------------------------------------- +LinkCreatPropList::LinkCreatPropList(const hid_t plist_id) : StrCreatPropList(plist_id) {} + +//-------------------------------------------------------------------------- +// Function: LinkCreatPropList destructor +///\brief Noop destructor +// May 2018 +//-------------------------------------------------------------------------- +LinkCreatPropList::~LinkCreatPropList() {} + +} // end namespace diff --git a/c++/src/H5LcreatProp.h b/c++/src/H5LcreatProp.h new file mode 100644 index 0000000..2a3b700 --- /dev/null +++ b/c++/src/H5LcreatProp.h @@ -0,0 +1,62 @@ +// 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __H5LinkCreatPropList_H +#define __H5LinkCreatPropList_H + +namespace H5 { + +/*! \class LinkCreatPropList + \brief Class LinkCreatPropList inherits from StrCreatPropList and provides + wrappers for the HDF5 link creation property list. +*/ +// Inheritance: StrCreatPropList -> PropList -> IdComponent +class H5_DLLCPP LinkCreatPropList : public StrCreatPropList { + public: + ///\brief Default link creation property list. + static const LinkCreatPropList& DEFAULT; + + // Creates a link creation property list. + LinkCreatPropList(); + + ///\brief Returns this class name. + virtual H5std_string fromClass () const { return("LinkCreatPropList"); } + + // Copy constructor: same as the original LinkCreatPropList. + LinkCreatPropList(const LinkCreatPropList& original); + + // Creates a copy of an existing link creation property list + // using the property list id. + LinkCreatPropList(const hid_t lcpl_id); + + // Noop destructor + virtual ~LinkCreatPropList(); + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + + // Deletes the global constant, should only be used by the library + static void deleteConstants(); + + private: + static LinkCreatPropList* DEFAULT_; + + // Creates the global constant, should only be used by the library + static LinkCreatPropList* getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS +}; // end of LinkCreatPropList + +} // namespace H5 + +#endif // __H5LinkCreatPropList_H diff --git a/c++/src/H5Library.cpp b/c++/src/H5Library.cpp index cedb74c..3813b79 100644 --- a/c++/src/H5Library.cpp +++ b/c++/src/H5Library.cpp @@ -25,6 +25,9 @@ #include "H5DcreatProp.h" #include "H5DxferProp.h" #include "H5LaccProp.h" +#include "H5StrcreatProp.h" +#include "H5AcreatProp.h" +#include "H5LcreatProp.h" #include "H5Location.h" #include "H5Object.h" #include "H5DataType.h" @@ -174,43 +177,51 @@ void H5Library::initH5cpp() int ret_value = 0; ret_value = std::atexit(termH5cpp); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating termH5cpp failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering termH5cpp failed"); ret_value = std::atexit(PredType::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating PredType::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering PredType::deleteConstants failed"); ret_value = std::atexit(PropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating PropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering PropList::deleteConstants failed"); ret_value = std::atexit(LinkAccPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating LinkAccPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering LinkAccPropList::deleteConstants failed"); + + ret_value = std::atexit(LinkCreatPropList::deleteConstants); + if (ret_value != 0) + throw LibraryIException("H5Library::initH5cpp", "Registering LinkCreatPropList::deleteConstants failed"); + + ret_value = std::atexit(AttrCreatPropList::deleteConstants); + if (ret_value != 0) + throw LibraryIException("H5Library::initH5cpp", "Registering AttrCreatPropList::deleteConstants failed"); ret_value = std::atexit(FileAccPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating FileAccPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering FileAccPropList::deleteConstants failed"); ret_value = std::atexit(FileCreatPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating FileCreatPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering FileCreatPropList::deleteConstants failed"); ret_value = std::atexit(DSetMemXferPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating DSetMemXferPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering DSetMemXferPropList::deleteConstants failed"); ret_value = std::atexit(DSetCreatPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating DSetCreatPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering DSetCreatPropList::deleteConstants failed"); ret_value = std::atexit(ObjCreatPropList::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating ObjCreatPropList::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering ObjCreatPropList::deleteConstants failed"); ret_value = std::atexit(DataSpace::deleteConstants); if (ret_value != 0) - throw LibraryIException("H5Library::initH5cpp", "Registrating DataSpace::deleteConstants failed"); + throw LibraryIException("H5Library::initH5cpp", "Registering DataSpace::deleteConstants failed"); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index afeaca7..43ba34c 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -95,7 +95,7 @@ May, 2017 (1.8.19) //-------------------------------------------------------------------------- // Function: H5Location::createAttribute -///\brief Deprecated - replaced by H5Object::createAttribute +///\brief Deprecated - replaced by 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 @@ -114,6 +114,8 @@ May, 2017 (1.8.19) /// delete the existing one with \c H5Location::removeAttr, then /// recreate it with this function. // Programmer Binh-Minh Ribler - 2000 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- Attribute H5Location::createAttribute(const char* name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist) const { @@ -135,11 +137,13 @@ Attribute H5Location::createAttribute(const char* name, const DataType& data_typ //-------------------------------------------------------------------------- // Function: H5Location::createAttribute -///\brief Deprecated - replaced by H5Object::createAttribute +///\brief Deprecated - replaced by 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 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- Attribute H5Location::createAttribute(const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist) const { @@ -148,12 +152,14 @@ Attribute H5Location::createAttribute(const H5std_string& name, const DataType& //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief Deprecated - replaced by H5Object::openAttribute +///\brief Deprecated - replaced by 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 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- Attribute H5Location::openAttribute(const char* name) const { @@ -172,12 +178,14 @@ Attribute H5Location::openAttribute(const char* name) const //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief Deprecated - replaced by H5Object::openAttribute +///\brief Deprecated - replaced by 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. ///\param name - IN: Name of the attribute // Programmer Binh-Minh Ribler - 2000 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- Attribute H5Location::openAttribute(const H5std_string& name) const { @@ -186,12 +194,14 @@ Attribute H5Location::openAttribute(const H5std_string& name) const //-------------------------------------------------------------------------- // Function: H5Location::openAttribute -///\brief Deprecated - replaced by H5Object::openAttribute +///\brief Deprecated - replaced by 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 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- Attribute H5Location::openAttribute(const unsigned int idx) const { @@ -225,7 +235,6 @@ Attribute H5Location::openAttribute(const unsigned int idx) const /// For information, please refer to the C layer Reference Manual /// at: /// https://support.hdfgroup.org/HDF5/doc/RM/RM_H5A.html#Annot-Iterate -// Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- int H5Location::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_data) { @@ -261,6 +270,8 @@ int H5Location::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_d ///\param name - IN: Name of the attribute to be queried ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2013 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- bool H5Location::attrExists(const char* name) const { @@ -284,6 +295,8 @@ bool H5Location::attrExists(const char* name) const // a reference to an \c H5std_string for \a name. ///\param name - IN: Name of the attribute to be queried // Programmer Binh-Minh Ribler - 2013 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- bool H5Location::attrExists(const H5std_string& name) const { @@ -297,6 +310,8 @@ bool H5Location::attrExists(const H5std_string& name) const ///\param name - IN: Name of the attribute to be removed ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- void H5Location::removeAttr(const char* name) const { @@ -313,6 +328,8 @@ void H5Location::removeAttr(const char* name) const // a reference to an \c H5std_string for \a name. ///\param name - IN: Name of the attribute to be removed // Programmer Binh-Minh Ribler - 2000 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- void H5Location::removeAttr(const H5std_string& name) const { @@ -327,6 +344,8 @@ void H5Location::removeAttr(const H5std_string& name) const ///\param newname - IN: New name ame of the attribute ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - Mar, 2005 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- void H5Location::renameAttr(const char* oldname, const char* newname) const { @@ -346,6 +365,8 @@ void H5Location::renameAttr(const char* oldname, const char* newname) const ///\param newname - IN: New name ame of the attribute ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - Mar, 2005 +// Modification +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- void H5Location::renameAttr(const H5std_string& oldname, const H5std_string& newname) const { @@ -358,16 +379,16 @@ void H5Location::renameAttr(const H5std_string& oldname, const H5std_string& new // brief Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes ///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 +// 2000 // Modification -// - Moved to H5Object in 1.8.20. -BMR +// - Moved to H5Object in 1.8.19. -BMR //-------------------------------------------------------------------------- int H5Location::getNumAttrs() const { H5O_info_t objinfo; /* Object info */ if(H5Oget_info(getId(), &objinfo) < 0) - throw AttributeIException(inMemFunc("getNumAttrs"), "H5Oget_info failed"); + throwException("getNumAttrs", "H5Oget_info failed"); else return(static_cast<int>(objinfo.num_attrs)); } @@ -377,9 +398,13 @@ int H5Location::getNumAttrs() const ///\brief Checks if a link of a given name exists in a location. ///\param name - IN: Searched name - \c char* ///\param lapl - IN: Link access property list -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - Nov, 2016 -// Modification +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// Nov 2016 //-------------------------------------------------------------------------- bool H5Location::nameExists(const char* name, const LinkAccPropList& lapl) const { @@ -390,7 +415,7 @@ bool H5Location::nameExists(const char* name, const LinkAccPropList& lapl) const return false; else // Raise exception when H5Lexists returns a negative value { - throw LocationException(inMemFunc("nameExists"), "H5Lexists failed"); + throwException("nameExists", "H5Lexists failed"); } } @@ -415,10 +440,15 @@ bool H5Location::nameExists(const H5std_string& name, const LinkAccPropList& lap /// which can be either of these values: /// \li \c H5F_SCOPE_GLOBAL - Flushes the entire virtual file /// \li \c H5F_SCOPE_LOCAL - Flushes only the specified file -///\exception H5::LocationException +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException ///\par Description /// This location is used to identify the file to be flushed. -// Programmer Binh-Minh Ribler - 2012 +// December 2005 // Modification // Sep 2012 - BMR // Moved from H5File/H5Object @@ -428,7 +458,7 @@ void H5Location::flush(H5F_scope_t scope) const herr_t ret_value = H5Fflush(getId(), scope); if(ret_value < 0) { - throw LocationException(inMemFunc("flush"), "H5Fflush failed"); + throwException("flush", "H5Fflush failed"); } } @@ -436,39 +466,56 @@ void H5Location::flush(H5F_scope_t scope) const // Function: H5Location::getFileName ///\brief Gets the name of the file, in which this HDF5 object belongs. ///\return File name -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - Jul, 2004 +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// July 2004 //-------------------------------------------------------------------------- H5std_string H5Location::getFileName() const { try { return(p_get_file_name()); } - catch (LocationException& E) { - throw FileIException(inMemFunc("getFileName"), E.getDetailMsg()); + catch (IdComponentException& E) { + throwException("getFileName", E.getDetailMsg()); } } //-------------------------------------------------------------------------- // Function: H5Location::getObjectInfo ///\brief Retrieve information about an object, specified by location. -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - Aug, 2017 +/// +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// August 2017 //-------------------------------------------------------------------------- void H5Location::getObjectInfo(H5O_info_t *objinfo) const { herr_t ret_value = H5Oget_info(getId(), objinfo); if (ret_value < 0) { - throw LocationException(inMemFunc("getObjectInfo"), "H5Oget_info failed"); + throwException("getObjectInfo", "H5Oget_info failed"); } } //-------------------------------------------------------------------------- // Function: H5Location::getObjectInfo ///\brief Retrieve information about an object, specified by name. -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - Aug, 2017 +/// +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// August 2017 //-------------------------------------------------------------------------- void H5Location::getObjectInfo(const char *name, H5O_info_t *objinfo, const LinkAccPropList& lapl) const @@ -476,15 +523,21 @@ void H5Location::getObjectInfo(const char *name, H5O_info_t *objinfo, herr_t ret_value = H5Oget_info_by_name(getId(), name, objinfo, lapl.getId()); if (ret_value < 0) { - throw LocationException(inMemFunc("getObjectInfo"), "H5Oget_info_by_name failed"); + throwException("getObjectInfo", "H5Oget_info_by_name failed"); } } //-------------------------------------------------------------------------- // Function: H5Location::getObjectInfo ///\brief Retrieve information about an object, specified by name. -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - Aug, 2017 +/// +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// August 2017 //-------------------------------------------------------------------------- void H5Location::getObjectInfo(const H5std_string& name, H5O_info_t *objinfo, const LinkAccPropList& lapl) const @@ -492,7 +545,7 @@ void H5Location::getObjectInfo(const H5std_string& name, H5O_info_t *objinfo, herr_t ret_value = H5Oget_info_by_name(getId(), name.c_str(), objinfo, lapl.getId()); if (ret_value < 0) { - throw LocationException(inMemFunc("getObjectInfo"), "H5Oget_info_by_name failed"); + throwException("getObjectInfo", "H5Oget_info_by_name failed"); } } @@ -502,11 +555,16 @@ void H5Location::getObjectInfo(const H5std_string& name, H5O_info_t *objinfo, ///\return Object version, which can have the following values: /// \li \c H5O_VERSION_1 /// \li \c H5O_VERSION_2 -///\exception H5::LocationException +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException /// 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 - May, 2017 +// August 2017 //-------------------------------------------------------------------------- unsigned H5Location::objVersion() const { @@ -518,13 +576,13 @@ unsigned H5Location::objVersion() const // Throw exception if C API returns failure if (ret_value < 0) - throw LocationException(inMemFunc("objVersion"), "H5Oget_info failed"); + throwException("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 LocationException(inMemFunc("objVersion"), "Invalid version for object"); + throwException("objVersion", "Invalid version for object"); } return(version); } @@ -534,7 +592,12 @@ unsigned H5Location::objVersion() const ///\brief Sets or resets the comment for an object specified by its name. ///\param name - IN: Name of the object ///\param comment - IN: New comment -///\exception H5::LocationException +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException ///\par Description /// If \a comment is an empty string or a null pointer, the comment /// message is removed from the object. @@ -542,18 +605,15 @@ unsigned H5Location::objVersion() const /// strings. They can be attached to any object that has an /// object header, e.g., data sets, groups, named data types, /// and data spaces, but not symbolic links. -// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +// July 2004 // Modification -// 2007: QAK modified to use H5O APIs; however the first parameter is -// no longer just file or group, this function should be moved -// to another class to accommodate attribute, dataset, and named -// datatype. - BMR +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- void H5Location::setComment(const char* name, const char* comment) const { herr_t ret_value = H5Oset_comment_by_name(getId(), name, comment, H5P_DEFAULT); if(ret_value < 0) - throw LocationException(inMemFunc("setComment"), "H5Oset_comment_by_name failed"); + throwException("setComment", "H5Oset_comment_by_name failed"); } //-------------------------------------------------------------------------- @@ -561,7 +621,9 @@ void H5Location::setComment(const char* name, const char* comment) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name and \a comment. -// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +// July 2004 +// Modification +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- void H5Location::setComment(const H5std_string& name, const H5std_string& comment) const { @@ -573,14 +635,19 @@ void H5Location::setComment(const H5std_string& name, const H5std_string& commen ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it doesn't take /// an object name. -// Programmer Binh-Minh Ribler - Sep 2013 -// Modification +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// Sep 2013 //-------------------------------------------------------------------------- void H5Location::setComment(const char* comment) const { herr_t ret_value = H5Oset_comment_by_name(getId(), ".", comment, H5P_DEFAULT); if(ret_value < 0) - throw LocationException(inMemFunc("setComment"), "H5Oset_comment_by_name failed"); + throwException("setComment", "H5Oset_comment_by_name failed"); } //-------------------------------------------------------------------------- @@ -588,7 +655,7 @@ void H5Location::setComment(const char* comment) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a comment. -// Programmer Binh-Minh Ribler - Sep 2013 +// Sep 2013 //-------------------------------------------------------------------------- void H5Location::setComment(const H5std_string& comment) const { @@ -599,18 +666,21 @@ void H5Location::setComment(const H5std_string& comment) const // Function: H5Location::removeComment ///\brief Removes the comment from an object specified by its name. ///\param name - IN: Name of the object -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - May 2005 (moved from CommonFG, Sep 2013) -// 2007: QAK modified to use H5O APIs; however the first parameter is -// no longer just file or group, this function should be moved -// to another class to accommodate attribute, dataset, and named -// datatype. - BMR +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// July 2004 +// Modification +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- void H5Location::removeComment(const char* name) const { herr_t ret_value = H5Oset_comment_by_name(getId(), name, NULL, H5P_DEFAULT); if(ret_value < 0) - throw LocationException(inMemFunc("removeComment"), "H5Oset_comment_by_name failed"); + throwException("removeComment", "H5Oset_comment_by_name failed"); } //-------------------------------------------------------------------------- @@ -618,11 +688,13 @@ void H5Location::removeComment(const char* name) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - May 2005 (moved from CommonFG, Sep 2013) +// July 2004 +// Modification +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- void H5Location::removeComment(const H5std_string& name) const { - removeComment (name.c_str()); + removeComment(name.c_str()); } //-------------------------------------------------------------------------- @@ -632,13 +704,18 @@ void H5Location::removeComment(const H5std_string& name) const ///\param buf_size - IN: Length of the comment to retrieve ///\param comment - OUT: Retrieved comment ///\return Actual length of the comment -///\exception H5::LocationException +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException ///\par Description /// This function retrieves \a buf_size characters of the comment /// including the null terminator. Thus, if the actual length /// of the comment is more than buf_size-1, the retrieved comment /// will be truncated to accommodate the null terminator. -// Programmer Binh-Minh Ribler - Mar 2014 +// March 2014 //-------------------------------------------------------------------------- ssize_t H5Location::getComment(const char* name, size_t buf_size, char* comment) const { @@ -650,7 +727,7 @@ ssize_t H5Location::getComment(const char* name, size_t buf_size, char* comment) // If H5Oget_comment_by_name returns a negative value, raise an exception if (comment_len < 0) { - throw LocationException(inMemFunc("getComment"), "H5Oget_comment_by_name failed"); + throwException("getComment", "H5Oget_comment_by_name failed"); } // If the comment is longer than the provided buffer size, the C library // will not null terminate it @@ -668,8 +745,15 @@ ssize_t H5Location::getComment(const char* name, size_t buf_size, char* comment) ///\param name - IN: Name of the object ///\param buf_size - IN: Length of the comment to retrieve, default to 0 ///\return Comment string -///\exception H5::LocationException -// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException +// July 2004 +// Modification +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- H5std_string H5Location::getComment(const char* name, size_t buf_size) const { @@ -683,7 +767,7 @@ H5std_string H5Location::getComment(const char* name, size_t buf_size) const // If H5Oget_comment_by_name returns a negative value, raise an exception if (comment_len < 0) { - throw LocationException(inMemFunc("getComment"), "H5Oget_comment_by_name failed"); + throwException("getComment", "H5Oget_comment_by_name failed"); } // If comment exists, calls C routine again to get it @@ -704,7 +788,7 @@ H5std_string H5Location::getComment(const char* name, size_t buf_size) const if (temp_len < 0) { delete []comment_C; - throw LocationException(inMemFunc("getComment"), "H5Oget_comment_by_name failed"); + throwException("getComment", "H5Oget_comment_by_name failed"); } // Convert the C comment to return @@ -723,7 +807,9 @@ H5std_string H5Location::getComment(const char* name, size_t buf_size) const ///\brief This is an overloaded member function, provided for convenience. /// It differs from the above function in that it takes an /// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +// July 2004 +// Modification +// Moved from CommonFG, Sep 2013 //-------------------------------------------------------------------------- H5std_string H5Location::getComment(const H5std_string& name, size_t buf_size) const { @@ -734,21 +820,25 @@ H5std_string H5Location::getComment(const H5std_string& name, size_t buf_size) c // Function: H5Location::openObjId ///\brief Opens an object without knowing the object type. ///\param obj_name - IN: Path to the object -///\param lapl - IN: Access property list for the link pointing -/// to the object -///\exception H5::LocationException +///\param lapl - IN: Access plist for the link pointing to the object +///\exception One of the following: +/// H5::GroupIException +/// H5::FileIException +/// H5::DataSetIException +/// H5::DataTypeIException +/// H5::AttributeIException ///\par Description /// This function opens an object at this location, using /// H5Oopen. Thus, an object can be opened without knowing -/// the object's type. -// Programmer Binh-Minh Ribler - May, 2017 +/// its type. +// May 2017 //-------------------------------------------------------------------------- hid_t H5Location::openObjId(const char* obj_name, const LinkAccPropList& lapl) const { hid_t ret_value = H5Oopen(getId(), obj_name, lapl.getId()); if (ret_value < 0) { - throw LocationException(inMemFunc("openObjId"), "H5Oopen failed"); + throwException("openObjId", "H5Oopen failed"); } return(ret_value); } @@ -761,7 +851,7 @@ hid_t H5Location::openObjId(const char* obj_name, const LinkAccPropList& lapl) c ///\param lapl - IN: Access property list for the link pointing to /// the object ///\exception H5::LocationException -// Programmer Binh-Minh Ribler - May, 2017 +// May 2017 //-------------------------------------------------------------------------- hid_t H5Location::openObjId(const H5std_string& obj_name, const LinkAccPropList& lapl) const { @@ -773,14 +863,14 @@ hid_t H5Location::openObjId(const H5std_string& obj_name, const LinkAccPropList& ///\brief Closes an object, which was opened with H5Location::openObjId /// ///\exception H5::LocationException -// Programmer Binh-Minh Ribler - May, 2017 +// May 2017 //-------------------------------------------------------------------------- -void H5Location::closeObjId(hid_t obj_id) const +void H5Location::closeObjId(hid_t obj_id) { herr_t ret_value = H5Oclose(obj_id); if (ret_value < 0) { - throw LocationException(inMemFunc("closeObjId"), "H5Oclose failed"); + throw LocationException("closeObjId", "H5Oclose failed"); } } diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index 12c3e8a..0316a53 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -115,8 +115,8 @@ class H5_DLLCPP H5Location : public IdComponent { hid_t openObjId(const char* name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; hid_t openObjId(const H5std_string& name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; - // Closes an object opened by openObjId(). - void closeObjId(hid_t obj_id) const; + // Closes an object opened by openObjId() + static void closeObjId(hid_t obj_id); ///\brief Returns an identifier. (pure virtual) virtual hid_t getId() const = 0; diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 8fe8e56..4697d9c 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -11,6 +11,12 @@ * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#ifdef OLD_HEADER_FILENAME +#include <iostream.h> +#else +#include <iostream> +#endif + #include <string> #include "H5private.h" // for HDmemset @@ -28,6 +34,11 @@ namespace H5 { +#ifndef H5_NO_STD + using std::cerr; + using std::endl; +#endif // H5_NO_STD + #ifndef DOXYGEN_SHOULD_SKIP_THIS // userAttrOpWrpr simply interfaces between the user's function and the // C library function H5Aiterate2; used to resolve the different prototype @@ -299,10 +310,10 @@ void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newna //-------------------------------------------------------------------------- int H5Object::getNumAttrs() const { - H5O_info_t oinfo; /* Object info */ + H5O_info_t oinfo; /* Object info */ if(H5Oget_info(getId(), &oinfo) < 0) - throw AttributeIException(inMemFunc("getNumAttrs"), "H5Oget_info failed"); + throwException("getNumAttrs", "H5Oget_info failed"); else return(static_cast<int>(oinfo.num_attrs)); } @@ -321,11 +332,11 @@ ssize_t H5Object::getObjName(char *obj_name, size_t buf_size) const // If H5Iget_name returns a negative value, raise an exception if (name_size < 0) { - throw Exception(inMemFunc("getObjName"), "H5Iget_name failed"); + throwException("getObjName", "H5Iget_name failed"); } else if (name_size == 0) { - throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0"); + throwException("getObjName", "Object must have a name, but name length is 0"); } // Return length of the name return(name_size); @@ -337,7 +348,6 @@ ssize_t H5Object::getObjName(char *obj_name, size_t buf_size) const ///\return Name of the object ///\exception H5::Exception // Programmer Binh-Minh Ribler - Mar, 2014 -// Modification //-------------------------------------------------------------------------- H5std_string H5Object::getObjName() const { @@ -349,11 +359,11 @@ H5std_string H5Object::getObjName() const // If H5Iget_name failed, throw exception if (name_size < 0) { - throw Exception(inMemFunc("getObjName"), "H5Iget_name failed"); + throwException("getObjName", "H5Iget_name failed"); } else if (name_size == 0) { - throw Exception(inMemFunc("getObjName"), "Object must have a name, but name length is 0"); + throwException("getObjName", "Object must have a name, but name length is 0"); } // Object's name exists, retrieve it else if (name_size > 0) diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index afeea7d..4d40415 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -48,6 +48,9 @@ class H5_DLLCPP H5Object : public H5Location { // Given its index, opens the attribute that belongs to this object. Attribute openAttribute(const unsigned int idx) const; + // Determines the number of attributes belong to this object. + int getNumAttrs() const; + // Checks whether the named attribute exists for this object. bool attrExists(const char* name) const; bool attrExists(const H5std_string& name) const; @@ -60,9 +63,6 @@ class H5_DLLCPP H5Object : public H5Location { void removeAttr(const char* name) const; void removeAttr(const H5std_string& name) const; - // Determines the number of attributes belong to this object. - int getNumAttrs() 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++/src/H5StrcreatProp.cpp b/c++/src/H5StrcreatProp.cpp new file mode 100644 index 0000000..79749d8 --- /dev/null +++ b/c++/src/H5StrcreatProp.cpp @@ -0,0 +1,58 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include <string> + +#include "H5Include.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5PropList.h" +#include "H5StrcreatProp.h" + +namespace H5 { + +//-------------------------------------------------------------------------- +// Function: StrCreatPropList::setCharEncoding +///\brief Sets the character encoding of the string. +///\exception H5::PropListIException +// March 2018 +//-------------------------------------------------------------------------- +void StrCreatPropList::setCharEncoding(H5T_cset_t encoding) const +{ + herr_t ret_value = H5Pset_char_encoding(id, encoding); + // Throw exception if H5Pset_char_encoding returns failure + if (ret_value < 0) + { + throw PropListIException("StrCreatPropList::setCharEncoding", "H5Pset_char_encoding failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: StrCreatPropList::getCharEncoding +///\brief Gets the character encoding of the string. +///\exception H5::PropListIException +// March 2018 +//-------------------------------------------------------------------------- +H5T_cset_t StrCreatPropList::getCharEncoding() const +{ + H5T_cset_t encoding; + herr_t ret_value = H5Pget_char_encoding(id, &encoding); + // Throw exception if H5Pget_char_encoding returns failure + if (ret_value < 0) + { + throw PropListIException("StrCreatPropList::getCharEncoding", "H5Pget_char_encoding failed"); + } + return(encoding); +} + +} // end namespace diff --git a/c++/src/H5StrcreatProp.h b/c++/src/H5StrcreatProp.h new file mode 100644 index 0000000..7b07dd6 --- /dev/null +++ b/c++/src/H5StrcreatProp.h @@ -0,0 +1,57 @@ +// 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 COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __H5StrCreatPropList_H +#define __H5StrCreatPropList_H + +namespace H5 { + +// Class StrCreatPropList is not user-accessible. It provides +// wrappers for the HDF5 string creation properties. + +// Inheritance: PropList -> IdComponent +class H5_DLLCPP StrCreatPropList : public PropList { + public: + // There is no StrCreatPropList::DEFAULT; + + // Returns this class name. + virtual H5std_string fromClass () const { return("StrCreatPropList"); } + + // Sets the character encoding of the string. + void setCharEncoding(H5T_cset_t encoding) const; + + // Gets the character encoding of the string. + H5T_cset_t getCharEncoding() const; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS + protected: + // Creates a link creation property list. + StrCreatPropList() {}; + + // Copy constructor: same as the original StrCreatPropList. + StrCreatPropList(const StrCreatPropList& original) {}; + + // Creates a copy of an existing link creation property list + // using the property list id. + StrCreatPropList(const hid_t plist_id) {}; + + // Noop destructor + virtual ~StrCreatPropList() {}; + +#endif // DOXYGEN_SHOULD_SKIP_THIS +}; // end of StrCreatPropList + +} // namespace H5 + +#endif // __H5StrCreatPropList_H diff --git a/c++/src/Makefile.am b/c++/src/Makefile.am index 976d503..416a3d3 100644 --- a/c++/src/Makefile.am +++ b/c++/src/Makefile.am @@ -32,14 +32,15 @@ bin_SCRIPTS=h5c++ # Source files for the library 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 \ + H5DataSpace.cpp H5PropList.cpp H5Library.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5LaccProp.cpp \ + H5StrcreatProp.cpp H5LcreatProp.cpp H5AcreatProp.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. @@ -51,6 +52,7 @@ include_HEADERS=H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.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 \ + H5StrcreatProp.h H5LcreatProp.h H5AcreatProp.h \ H5Library.h H5Location.h H5Object.h H5PredType.h H5PropList.h \ H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in index a566368..59ec075 100644 --- a/c++/src/Makefile.in +++ b/c++/src/Makefile.in @@ -151,7 +151,8 @@ LTLIBRARIES = $(lib_LTLIBRARIES) libhdf5_cpp_la_DEPENDENCIES = $(LIBHDF5) am_libhdf5_cpp_la_OBJECTS = H5Exception.lo H5IdComponent.lo \ H5DataSpace.lo H5PropList.lo H5Library.lo H5FaccProp.lo \ - H5FcreatProp.lo H5LaccProp.lo H5DxferProp.lo H5DcreatProp.lo \ + H5FcreatProp.lo H5LaccProp.lo H5StrcreatProp.lo \ + H5LcreatProp.lo H5AcreatProp.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 \ @@ -713,14 +714,15 @@ bin_SCRIPTS = h5c++ # Source files for the library 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 \ + H5DataSpace.cpp H5PropList.cpp H5Library.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5LaccProp.cpp \ + H5StrcreatProp.cpp H5LcreatProp.cpp H5AcreatProp.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 @@ -733,6 +735,7 @@ include_HEADERS = H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.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 \ + H5StrcreatProp.h H5LcreatProp.h H5AcreatProp.h \ H5Library.h H5Location.h H5Object.h H5PredType.h H5PropList.h \ H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h @@ -881,6 +884,7 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5AbstractDs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5AcreatProp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5ArrayType.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5AtomType.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Attribute.Plo@am__quote@ @@ -901,6 +905,7 @@ distclean-compile: @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)/H5LcreatProp.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@ @@ -908,6 +913,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5PredType.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5PropList.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5StrType.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5StrcreatProp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5VarLenType.Plo@am__quote@ .cpp.o: diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 8d2618b..0a187ef 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -68,6 +68,8 @@ static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, * *------------------------------------------------------------------------- */ +const H5std_string DSET_COMMENT ("This is a dataset"); +const H5std_string NON_EXISTING_DSET ("does_not_exist"); static herr_t test_create( H5File& file) { @@ -83,13 +85,12 @@ test_create( H5File& file) DataSpace space (2, dims, NULL); // Create a dataset using the default dataset creation properties. - // We're not sure what they are, so we won't check. dataset = new DataSet (file.createDataSet (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space)); // Add a comment to the dataset - file.setComment (DSET_DEFAULT_NAME, "This is a dataset"); + file.setComment (DSET_DEFAULT_NAME, DSET_COMMENT); // Close the dataset delete dataset; @@ -120,7 +121,7 @@ test_create( H5File& file) // Get and verify the comment from this dataset, using // H5std_string getComment(const H5std_string& name, <buf_size=0, by default>) H5std_string comment = file.getComment(DSET_DEFAULT_NAME); - verify_val(comment, "This is a dataset", "DataSet::getComment", __LINE__, __FILE__); + verify_val(comment, DSET_COMMENT, "DataSet::getComment", __LINE__, __FILE__); // Close the dataset when accessing is completed delete dataset; @@ -132,24 +133,24 @@ test_create( H5File& file) // exception is not thrown for this action by openDataSet, then // display failure information and throw an exception. try { - dataset = new DataSet (file.openDataSet( "does_not_exist" )); + dataset = new DataSet (file.openDataSet(NON_EXISTING_DSET)); // continuation here, that means no exception has been thrown throw InvalidActionException("H5File::openDataSet", "Attempted to open a non-existent dataset"); } - catch (FileIException& E ) // catching creating non-existent dataset + catch (FileIException& E ) // catching opening non-existent dataset {} // do nothing, exception expected - // Create a new dataset that uses chunked storage instead of the default - // layout. + // Create a new dataset that uses chunked storage instead of the + // default layout. DSetCreatPropList create_parms; - hsize_t csize[2]; + hsize_t csize[2]; csize[0] = 5; csize[1] = 100; create_parms.setChunk( 2, csize ); dataset = new DataSet (file.createDataSet - (DSET_CHUNKED_NAME, PredType::NATIVE_DOUBLE, space, create_parms)); + (DSET_CHUNKED_NAME, PredType::NATIVE_DOUBLE, space, create_parms)); // Note: this one has no error message in C when failure occurs? // clean up and return with success diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index d97d478..25b5ff8 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -653,7 +653,8 @@ static void test_attr_compound_read() verify_val((long)dims[1], (long)ATTR4_DIM2, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); // Get the class of the datatype that is used by attr - H5T_class_t type_class = attr.getTypeClass(); + H5T_class_t type_class; + type_class = attr.getTypeClass(); // Verify that the type is of compound datatype verify_val(type_class, H5T_COMPOUND, "Attribute::getTypeClass", __LINE__, __FILE__); @@ -1289,6 +1290,7 @@ static void test_attr_dtype_shared() // Retrieve and verify information about the type H5O_info_t oinfo; + dtype.getObjectInfo(TYPE1_NAME, &oinfo); fid1.getObjectInfo(TYPE1_NAME, &oinfo); if (oinfo.type != H5O_TYPE_NAMED_DATATYPE) TestErrPrintf("Line %d: object type wrong!\n", __LINE__); @@ -1402,6 +1404,14 @@ static void test_attr_dtype_shared() PASSED(); } // end try block + catch (DataTypeIException& E) + { + issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); + } + catch (FileIException& E) + { + issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); + } catch (Exception& E) { issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index 059c548..d5278d5 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -336,9 +336,12 @@ static void test_file_open() // Truncating should succeed now. H5File file3(FILE2, H5F_ACC_TRUNC); - // Opening another file to file3 object, FILE2 should be closed, so - // the next attempt to truncate FILE2 should succeed. + // Opening another file to file3 object. file3.openFile(FILE1, H5F_ACC_RDONLY); + + // In the previous statement, openFile closes FILE2 first before + // opening FILE1, so when H5File constructs file4 with an + // attempt to truncate FILE2, it should succeed. H5File file4(FILE2, H5F_ACC_TRUNC); PASSED(); @@ -493,6 +496,12 @@ static void test_file_name() // Get and verify file name via a committed datatype. comp_type.getFileName(); verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__); + + // Get the file's version information. + H5F_info_t finfo; + file4.getFileInfo(finfo); + verify_val(finfo.sohm.hdr_size, 0, "H5File::getFileInfo", __LINE__, __FILE__); + PASSED(); } // end of try block @@ -503,6 +512,15 @@ static void test_file_name() } // test_file_name() +/*------------------------------------------------------------------------- + * + * Function: test_file_attribute + * + * Purpose Test file attributes + * + * Return None + *------------------------------------------------------------------------- + */ const int RANK1 = 1; const int ATTR1_DIM1 = 3; const H5std_string FILE5("tfattrs.h5"); @@ -619,6 +637,11 @@ static void test_file_attribute() PASSED(); } // end of try block + // Catch creating existing attribute + catch (AttributeIException& E) + {} // do nothing, exception expected + + // Catch all other exceptions catch (Exception& E) { issue_fail_msg("test_file_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index b38ed39..356bc1b 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -326,11 +326,9 @@ static const char *FILENAME[] = { * Purpose: Test building a file with assorted links. * * Return: Success: 0 - * * Failure: -1 * - * Programmer: Binh-Minh Ribler - * October 16, 2009 + * October, 2009 * *------------------------------------------------------------------------- */ @@ -369,7 +367,6 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) // Because these are not implemented in the C++ API yet, they are // used so CommonFG::getLinkval can be tested. - // Create a hard link if(H5Lcreate_hard( file_id, "dset1", H5L_SAME_LOC, "grp1/hard1", H5P_DEFAULT, H5P_DEFAULT) < 0) @@ -433,7 +430,7 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) { issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg()); } -} +} // test_basic_links /*------------------------------------------------------------------------- * Function: test_num_links @@ -441,12 +438,9 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) * Purpose: Test setting and getting limit of number of links * * Return: Success: 0 - * * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Mar, 2017 - * + * March, 2017 *------------------------------------------------------------------------- */ static void test_num_links(hid_t fapl_id, hbool_t new_format) @@ -535,9 +529,12 @@ void test_links() test_basic_links(my_fapl_id, new_format); test_num_links(my_fapl_id, new_format); #if 0 + // these tests are from the C test links.c and left here for future // implementation of H5L API - nerrors += test_basic_links(fapl_id, new_format) < 0 ? 1 : 0; + test_move(my_fapl_id, new_format); + test_copy(my_fapl_id, new_format); + test_lcpl(my_fapl_id, new_format); nerrors += cklinks(my_fapl, new_format) < 0 ? 1 : 0; nerrors += new_links(my_fapl, new_format) < 0 ? 1 : 0; nerrors += ck_new_links(my_fapl, new_format) < 0 ? 1 : 0; @@ -545,9 +542,6 @@ void test_links() nerrors += toomany(my_fapl, new_format) < 0 ? 1 : 0; /* Test new H5L link creation routine */ - nerrors += test_lcpl(my_fapl, new_format); - nerrors += test_move(my_fapl, new_format); - nerrors += test_copy(my_fapl, new_format); nerrors += test_move_preserves(my_fapl, new_format); #ifndef H5_NO_DEPRECATED_SYMBOLS nerrors += test_deprec(my_fapl, new_format); diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index c053604..b5e9ff0 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -73,6 +73,19 @@ static void test_get_objname() Group grp1_1 = grp1.createGroup(GROUP1_1, 0); Group grp1_2 = grp1.createGroup(GROUP1_2, 0); + // Attempted to create a same group to generate a failure, which should + // be caught with sub-class exception clause, if available. + try { + Group grp1_2 = grp1.createGroup(GROUP1_2, 0); + } + catch (GroupIException& E) + {} // do nothing, exception expected + catch (Exception& E) + { + cerr << "Exception should have been caught by the previous catch" << endl; + issue_fail_msg("test_get_objname", __LINE__, __FILE__); + } + // Get part of the group's name, random length using // ssize_t getObjName(char* comment, size_t buf_size) @@ -302,6 +315,7 @@ static void test_get_objtype() *------------------------------------------------------------------------- */ const H5std_string GROUPNAME("group"); +const H5std_string NOGROUPNAME("non-existent-group"); const H5std_string DTYPENAME("group/datatype"); const H5std_string DTYPENAME_INGRP("datatype"); const H5std_string DSETNAME("dataset"); @@ -323,22 +337,25 @@ static void test_open_object_header() // Create a group in the root group Group grp(file1.createGroup(GROUPNAME)); - grp.close(); // Commit the type inside the file IntType dtype(PredType::NATIVE_INT); dtype.commit(file1, DTYPENAME); dtype.close(); - // Create a new dataset + // Create a new dataset in the file dims[0] = DIM0; dims[1] = DIM1; DataSpace dspace(RANK, dims); DataSet dset(file1.createDataSet(DSETNAME, PredType::NATIVE_INT, dspace)); - // Close dataset and dataspace + // Create a dataset in the group + DataSet dsingrp(grp.createDataSet(DSET_IN_GRP1, PredType::NATIVE_INT, dspace)); + + // Close dataset, dataspace, and group dset.close(); dspace.close(); + grp.close(); // Now make sure that openObjId can open all three types of objects hid_t obj_grp = file1.openObjId(GROUPNAME); @@ -357,12 +374,12 @@ static void test_open_object_header() Group grp2(obj_grp); hsize_t num_objs = grp2.getNumObjs(); - verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__); - // There should be one object, the datatype + verify_val(num_objs, 2, "H5Gget_info", __LINE__, __FILE__); // Close datatype object opened from the file - file1.closeObjId(obj_dtype); + H5Location::closeObjId(obj_dtype); + // Do a few things using the dset object identifier dset.setId(obj_dset); dspace = dset.getSpace(); bool is_simple = dspace.isSimple(); @@ -371,24 +388,38 @@ static void test_open_object_header() // Open datatype object from the group obj_dtype = grp2.openObjId(DTYPENAME_INGRP); + // Do a few things using the datatype object identifier dtype.setId(obj_dtype); H5T_class_t type_class = dtype.getClass(); verify_val(type_class, H5T_INTEGER, "H5Tget_class", __LINE__, __FILE__); dtype.close(); // Close datatype object - grp2.closeObjId(obj_dtype); + H5Location::closeObjId(obj_dtype); // Close the group object - file1.closeObjId(obj_grp); + H5Location::closeObjId(obj_grp); // Try doing something with group, the ID should still work num_objs = grp2.getNumObjs(); - verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__); + verify_val(num_objs, 2, "H5Gget_info", __LINE__, __FILE__); // Close the cloned group grp2.close(); + // Attempted to open a non-existing group, which should + // be caught with sub-class exception clause, if available. + try { + Group grp3 = dsingrp.openObjId(NOGROUPNAME); + } + catch (DataSetIException& E) + {} // do nothing, exception expected and caught correctly + catch (Exception& E) + { + cerr << "Exception should have been caught by the previous catch" << endl; + issue_fail_msg("test_get_objname", __LINE__, __FILE__); + } + PASSED(); } // end of try block // catch invalid action exception @@ -401,7 +432,6 @@ static void test_open_object_header() // catch all other exceptions catch (Exception& E) { - cerr << " in Exception" << endl; issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); } } /* test_open_object_header() */ @@ -454,7 +484,6 @@ static void test_is_valid() // catch all other exceptions catch (Exception& E) { - cerr << " in catch " << endl; issue_fail_msg("test_get_objtype", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_is_valid |