diff options
Diffstat (limited to 'c++')
-rw-r--r-- | c++/Makefile.in | 8 | ||||
-rw-r--r-- | c++/examples/Makefile.in | 6 | ||||
-rw-r--r-- | c++/src/H5Attribute.cpp | 183 | ||||
-rw-r--r-- | c++/src/H5Attribute.h | 3 | ||||
-rw-r--r-- | c++/src/Makefile.am | 4 | ||||
-rw-r--r-- | c++/src/Makefile.in | 40 | ||||
-rw-r--r-- | c++/test/Makefile.in | 8 | ||||
-rw-r--r-- | c++/test/dsets.cpp | 2 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 90 | ||||
-rw-r--r-- | c++/test/tfilter.cpp | 2 |
10 files changed, 276 insertions, 70 deletions
diff --git a/c++/Makefile.in b/c++/Makefile.in index 8796ca7..1016377 100644 --- a/c++/Makefile.in +++ b/c++/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -347,8 +347,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -454,7 +454,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS diff --git a/c++/examples/Makefile.in b/c++/examples/Makefile.in index 63cce0a..e5749e6 100644 --- a/c++/examples/Makefile.in +++ b/c++/examples/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -364,8 +364,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index c90076c..a844b77 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -34,6 +34,7 @@ #include "H5DataSpace.h" #include "H5File.h" #include "H5Attribute.h" +#include "H5private.h" // for HDfree #ifndef H5_NO_NAMESPACE namespace H5 { @@ -95,23 +96,40 @@ void Attribute::write( const DataType& mem_type, const void *buf ) const //-------------------------------------------------------------------------- // Function: Attribute::write ///\brief This is an overloaded member function, provided for convenience. -/// It writes a \a std::string to this attribute. +/// It writes a \a H5std_string to this attribute. ///\param mem_type - IN: Attribute datatype (in memory) ///\param strg - IN: Data to be written ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - Apr, 2003 //-------------------------------------------------------------------------- -void Attribute::write( const DataType& mem_type, const H5std_string& strg ) const +void Attribute::write(const DataType& mem_type, const H5std_string& strg) const { - // Convert string to C-string - const char* strg_C; - strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + // Check if this attribute has variable-len string or fixed-len string and + // proceed appropriately. + htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); + if (is_variable_len < 0) + { + throw AttributeIException("Attribute::write", "H5Tis_variable_str failed"); + } + // Convert string to C-string + const char* strg_C; + strg_C = strg.c_str(); // strg_C refers to the contents of strg as a C-str + herr_t ret_value = 0; - herr_t ret_value = H5Awrite( id, mem_type.getId(), &strg_C ); - if( ret_value < 0 ) - { - throw AttributeIException("Attribute::write", "H5Awrite failed"); - } + // Pass string in differently depends on variable or fixed length + if (!is_variable_len) + { + ret_value = H5Awrite(id, mem_type.getId(), strg_C); + } + else + { + // passing third argument by address + ret_value = H5Awrite(id, mem_type.getId(), &strg_C); + } + if (ret_value < 0) + { + throw AttributeIException("Attribute::write", "H5Awrite failed"); + } } //-------------------------------------------------------------------------- @@ -127,14 +145,58 @@ void Attribute::read( const DataType& mem_type, void *buf ) const herr_t ret_value = H5Aread( id, mem_type.getId(), buf ); if( ret_value < 0 ) { - throw AttributeIException("Attribute::read", "H5Aread failed"); + throw AttributeIException("Attribute::read", "H5Aread failed"); } } //-------------------------------------------------------------------------- +// Function: Attribute::getInMemDataSize +///\brief Gets the size in memory of the attribute's data. +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +size_t Attribute::getInMemDataSize() const +{ + // Get the data type of this attribute + hid_t mem_type_id = H5Aget_type(id); + if (mem_type_id <= 0) + { + throw AttributeIException("Attribute::getDataSize", "H5Aget_type failed"); + } + + // Get the data type's size + hid_t native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT); + if (native_type < 0) + { + throw AttributeIException("Attribute::read", "H5Tget_native_type failed"); + } + size_t type_size = H5Tget_size(native_type); + if (type_size == 0) + { + throw AttributeIException("Attribute::read", "H5Tget_size failed"); + } + + // Get number of elements of the attribute + hid_t space_id = H5Aget_space(id); + if (space_id < 0) + { + throw AttributeIException("Attribute::read", "H5Aget_space failed"); + } + hssize_t num_elements = H5Sget_simple_extent_npoints(space_id); + if (num_elements < 0) + { + throw AttributeIException("Attribute::read", "H5Sget_simple_extent_npoints failed"); + } + + // Calculate and return the size of the data + size_t data_size = type_size * num_elements; + return(data_size); +} + +//-------------------------------------------------------------------------- // Function: Attribute::read ///\brief This is an overloaded member function, provided for convenience. -/// It reads a \a std::string from this attribute. +/// It reads a \a H5std_string from this attribute. ///\param mem_type - IN: Attribute datatype (in memory) ///\param strg - IN: Buffer for read string ///\exception H5::AttributeIException @@ -145,31 +207,72 @@ void Attribute::read( const DataType& mem_type, void *buf ) const // space for the buffer. Obtained the attribute size and // allocated memory properly. - BMR //-------------------------------------------------------------------------- -void Attribute::read( const DataType& mem_type, H5std_string& strg ) const +void Attribute::read(const DataType& mem_type, H5std_string& strg) const { - // Get the attribute size and allocate temporary C-string for C API - hsize_t attr_size = H5Aget_storage_size(id); - if (attr_size <= 0) - { - throw AttributeIException("Attribute::read", "Unable to get attribute size before reading"); - } - char* strg_C = new char [(size_t)attr_size+1]; - if (strg_C == NULL) - { - throw AttributeIException("Attribute::read", "Unable to allocate buffer to read the attribute"); - } - // Call C API to get the attribute data, a string of chars - herr_t ret_value = H5Aread(id, mem_type.getId(), &strg_C); - if( ret_value < 0 ) - { - throw AttributeIException("Attribute::read", "H5Aread failed"); - } + // Check if this attribute has variable-len string or fixed-len string and + // proceed appropriately. + htri_t is_variable_len = H5Tis_variable_str(mem_type.getId()); + if (is_variable_len < 0) + { + throw AttributeIException("Attribute::write", "H5Tis_variable_str failed"); + } + + // Prepare and call C API to read attribute. + char *strg_C; + herr_t ret_value = 0; + size_t attr_size; + if (!is_variable_len) // only allocate for fixed-len string + { + // Get the size of the attribute's data + attr_size = getInMemDataSize(); + + if (attr_size > 0) + { + strg_C = new char [(size_t)attr_size+1]; + if (strg_C == NULL) + { + throw AttributeIException("Attribute::read", + "Unable to allocate buffer to read the attribute"); + } + ret_value = H5Aread(id, mem_type.getId(), strg_C); + } + else + HDstrcpy(strg_C, ""); + } + else + { + // no allocation for variable-len string; C library will + ret_value = H5Aread(id, mem_type.getId(), &strg_C); + } + if( ret_value < 0 ) + { + if (!is_variable_len) // only de-allocate for fixed-len string + delete []strg_C; + throw AttributeIException("Attribute::read", "H5Aread failed"); + } - // Get 'string' from the C char* and release resource - strg_C[attr_size] = '\0'; - strg = strg_C; - delete []strg_C; + if( ret_value < 0 ) + { + if (!is_variable_len) // only de-allocate for fixed-len string + delete []strg_C; + throw AttributeIException("Attribute::read", "H5Aread failed"); + } + + // Get string from the C char* and release resource allocated locally + if (!is_variable_len) + { + if (strg_C != "") + strg_C[attr_size] = '\0'; + strg = strg_C; + delete []strg_C; + } + // Get string from the C char* and release resource allocated by C API + else + { + strg = strg_C; + HDfree(strg_C); + } } //-------------------------------------------------------------------------- @@ -342,21 +445,21 @@ hid_t Attribute::getId() const ///\brief Sets the identifier of this object to a new value. /// ///\exception H5::IdComponentException when the attempt to close the HDF5 -/// object fails +/// object fails // Description: -// The underlaying reference counting in the C library ensures -// that the current valid id of this object is properly closed. -// Then the object's id is reset to the new id. +// The underlaying reference counting in the C library ensures +// that the current valid id of this object is properly closed. +// Then the object's id is reset to the new id. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void Attribute::p_setId(const hid_t new_id) { // handling references to this old id try { - close(); + close(); } catch (Exception close_error) { - throw AttributeIException("Attribute::p_setId", close_error.getDetailMsg()); + throw AttributeIException("Attribute::p_setId", close_error.getDetailMsg()); } // reset object's id to the given id id = new_id; diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index 9cf91ba..00a08a5 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -40,6 +40,9 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { // Returns the amount of storage size required for this attribute. hsize_t getStorageSize() const; + // Returns the in memory size of this attribute's data. + size_t getInMemDataSize() const; + // Reads data from this attribute. void read( const DataType& mem_type, void *buf ) const; void read( const DataType& mem_type, H5std_string& strg ) const; diff --git a/c++/src/Makefile.am b/c++/src/Makefile.am index 3b1ed0d..c18b990 100644 --- a/c++/src/Makefile.am +++ b/c++/src/Makefile.am @@ -19,6 +19,7 @@ # include $(top_srcdir)/config/commence.am +include $(top_srcdir)/config/lt_vers.am # Include src directory INCLUDES=-I$(top_srcdir)/src @@ -26,6 +27,9 @@ INCLUDES=-I$(top_srcdir)/src # This is our main target lib_LTLIBRARIES=libhdf5_cpp.la +# Add libtool numbers to the HDF5 C++ library (from config/lt_vers.am) +libhdf5_cpp_la_LDFLAGS= -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) + # Shared C++ libraries aren't universally supported. if CXX_SHARED_CONDITIONAL else diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in index 9d50223..abe8590 100644 --- a/c++/src/Makefile.in +++ b/c++/src/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -54,7 +54,8 @@ host_triplet = @host@ DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ $(srcdir)/Makefile.in $(srcdir)/h5c++.in \ $(top_srcdir)/config/commence.am \ - $(top_srcdir)/config/conclude.am + $(top_srcdir)/config/conclude.am \ + $(top_srcdir)/config/lt_vers.am TESTS = subdir = c++/src ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -83,6 +84,9 @@ am_libhdf5_cpp_la_OBJECTS = H5Exception.lo H5IdComponent.lo \ H5StrType.lo H5ArrayType.lo H5VarLenType.lo H5CompType.lo \ H5DataSet.lo H5CommonFG.lo H5Group.lo H5File.lo libhdf5_cpp_la_OBJECTS = $(am_libhdf5_cpp_la_OBJECTS) +libhdf5_cpp_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(libhdf5_cpp_la_LDFLAGS) $(LDFLAGS) -o $@ binSCRIPT_INSTALL = $(INSTALL_SCRIPT) SCRIPTS = $(bin_SCRIPTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src @@ -353,12 +357,21 @@ TRACE = perl $(top_srcdir)/bin/trace # *.clog are from the MPE option. CHECK_CLEANFILES = *.chkexe *.chklog *.clog +# Add libtool shared library version numbers to the HDF5 library +# See libtool versioning documentation online. +LT_VERS_INTERFACE = 6 +LT_VERS_REVISION = 29 +LT_VERS_AGE = 0 + # Include src directory INCLUDES = -I$(top_srcdir)/src # This is our main target lib_LTLIBRARIES = libhdf5_cpp.la +# Add libtool numbers to the HDF5 C++ library (from config/lt_vers.am) +libhdf5_cpp_la_LDFLAGS = -version-info $(LT_VERS_INTERFACE):$(LT_VERS_REVISION):$(LT_VERS_AGE) + # Shared C++ libraries aren't universally supported. @CXX_SHARED_CONDITIONAL_FALSE@AM_LDFLAGS = -static bin_SCRIPTS = h5c++ @@ -408,12 +421,12 @@ all: all-am .SUFFIXES: .SUFFIXES: .cpp .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/config/commence.am $(top_srcdir)/config/conclude.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/config/commence.am $(top_srcdir)/config/lt_vers.am $(top_srcdir)/config/conclude.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -467,7 +480,7 @@ clean-libLTLIBRARIES: rm -f "$${dir}/so_locations"; \ done libhdf5_cpp.la: $(libhdf5_cpp_la_OBJECTS) $(libhdf5_cpp_la_DEPENDENCIES) - $(CXXLINK) -rpath $(libdir) $(libhdf5_cpp_la_OBJECTS) $(libhdf5_cpp_la_LIBADD) $(LIBS) + $(libhdf5_cpp_la_LINK) -rpath $(libdir) $(libhdf5_cpp_la_OBJECTS) $(libhdf5_cpp_la_LIBADD) $(LIBS) install-binSCRIPTS: $(bin_SCRIPTS) @$(NORMAL_INSTALL) test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" @@ -570,7 +583,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS @@ -762,6 +775,19 @@ uninstall-am: uninstall-binSCRIPTS uninstall-includeHEADERS \ help: @$(top_srcdir)/bin/makehelp +# Copyright by The HDF Group. +# Copyright by the Board of Trustees of the University of Illinois. +# All rights reserved. +# +# This file is part of HDF5. The full HDF5 copyright notice, including +# terms governing use, modification, and redistribution, is contained in +# the files COPYING and Copyright.html. COPYING can be found at the root +# of the source code distribution tree; Copyright.html can be found at the +# root level of an installed copy of the electronic HDF5 document set and +# is linked from the top-level documents page. It can also be found at +# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have +# access to either file, you may request a copy from help@hdfgroup.org. + # Some C++ compilers/linkers (PGI?) create a directory named "ii_files" that # holds *.ii files, which are template entity instantiations. # This entire directory should be cleaned. diff --git a/c++/test/Makefile.in b/c++/test/Makefile.in index 9bbb475..0452ea0 100644 --- a/c++/test/Makefile.in +++ b/c++/test/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. +# Makefile.in generated by automake 1.10.2 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -382,8 +382,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ @@ -471,7 +471,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in files) print i; }; }'`; \ mkid -fID $$unique tags: TAGS diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 319f894..6a5f223 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -352,7 +352,7 @@ test_tconv( H5File& file) } // test_tconv /* This message derives from H5Z */ -const H5Z_class_t H5Z_BOGUS[1] = {{ +const H5Z_class2_t H5Z_BOGUS[1] = {{ H5Z_CLASS_T_VERS, /* H5Z_class_t version number */ H5Z_FILTER_BOGUS, /* Filter id number */ 1, 1, /* Encode and decode enabled */ diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 73b5a91..48a3200 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -356,7 +356,7 @@ static void test_attr_basic_read() for(i=0; i<ATTR2_DIM1; i++) for(j=0; j<ATTR2_DIM2; j++) if(attr_data2[i][j]!=read_data2[i][j]) { - TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data1[i]); + TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data2[i][j]); } PASSED(); } // end try block @@ -1180,20 +1180,26 @@ static void test_attr_dtype_shared() ** ****************************************************************/ /* Info for a string attribute */ -const H5std_string ATTRSTR_NAME("String_attr"); +const H5std_string ATTR1_FL_STR_NAME("String_attr 1"); +const H5std_string ATTR2_FL_STR_NAME("String_attr 2"); +const H5std_string ATTR_VL_STR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); +const int ATTR_LEN = 17; static void test_string_attr() { // Output message about test being performed - SUBTEST("Testing Basic Attribute Writing Functions"); + SUBTEST("Testing I/O on FL and VL String Attributes"); try { // Create file H5File fid1(FILENAME, H5F_ACC_RDWR); - // Create a variable length string datatype to refer to. - StrType type(0, H5T_VARIABLE); + // + // Fixed-lenth string attributes + // + // Create a fixed-length string datatype to refer to. + StrType fls_type(0, ATTR_LEN); // Open the root group. Group root = fid1.openGroup("/"); @@ -1201,24 +1207,88 @@ static void test_string_attr() // Create dataspace for the attribute. DataSpace att_space (H5S_SCALAR); + /* Test Attribute::write(...,const void *buf) with Fixed len string */ + + // Create an attribute for the root group. + Attribute gr_flattr1 = root.createAttribute(ATTR1_FL_STR_NAME, fls_type, att_space); + + // Write data to the attribute. + gr_flattr1.write(fls_type, ATTRSTR_DATA.c_str()); + + /* Test Attribute::write(...,const H5std_string& strg) with FL string */ + + // Create an attribute for the root group. + Attribute gr_flattr2 = root.createAttribute(ATTR2_FL_STR_NAME, fls_type, att_space); + + // Write data to the attribute. + gr_flattr2.write(fls_type, ATTRSTR_DATA); + + /* Test Attribute::read(...,void *buf) with FL string */ + + // Read and verify the attribute string as a string of chars. + char flstring_att_check[ATTR_LEN]; + gr_flattr1.read(fls_type, flstring_att_check); + if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); + + // Read and verify the attribute string as a string of chars; buffer + // is dynamically allocated. + size_t attr_size = gr_flattr1.getInMemDataSize(); + char *fl_dyn_string_att_check; + fl_dyn_string_att_check = new char[attr_size+1]; + gr_flattr1.read(fls_type, fl_dyn_string_att_check); + if(HDstrcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), fl_dyn_string_att_check); + delete []fl_dyn_string_att_check; + + /* Test Attribute::read(...,H5std_string& strg) with FL string */ + + // Read and verify the attribute string as an std::string. + H5std_string read_flstr1; + gr_flattr1.read(fls_type, read_flstr1); + if (read_flstr1 != ATTRSTR_DATA) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr1=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr1.c_str()); + + // Read and verify the attribute string as a string of chars. + HDstrcpy(flstring_att_check, ""); + gr_flattr2.read(fls_type, flstring_att_check); + if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); + + /* Test Attribute::read(...,H5std_string& strg) with FL string */ + + // Read and verify the attribute string as an std::string. + H5std_string read_flstr2; + gr_flattr2.read(fls_type, read_flstr2); + if (read_flstr2 != ATTRSTR_DATA) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr2=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr2.c_str()); + + // + // Variable-lenth string attributes + // + // Create a variable length string datatype to refer to. + StrType vls_type(0, H5T_VARIABLE); + // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, type, att_space); + Attribute gr_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space); // Write data to the attribute. - gr_attr.write(type, ATTRSTR_DATA); + gr_vlattr.write(vls_type, ATTRSTR_DATA); + /* Test Attribute::read(...,void *buf) with Variable len string */ // Read and verify the attribute string as a string of chars. char *string_att_check; - gr_attr.read(type, &string_att_check); + gr_vlattr.read(vls_type, &string_att_check); if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); + HDfree(string_att_check); + /* Test Attribute::read(...,H5std_string& strg) with VL string */ // Read and verify the attribute string as an std::string. H5std_string read_str; - gr_attr.read(type, read_str); + gr_vlattr.read(vls_type, read_str); if (read_str != ATTRSTR_DATA) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_str=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_str.c_str()); - PASSED(); } // end try block diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp index 2f87feb..1d3cec2 100644 --- a/c++/test/tfilter.cpp +++ b/c++/test/tfilter.cpp @@ -60,7 +60,7 @@ static herr_t test_filter_internal(hid_t fid, const char *name, hid_t dcpl, static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); /* This message derives from H5Z */ -const H5Z_class_t H5Z_BOGUS[1] = {{ +const H5Z_class2_t H5Z_BOGUS[1] = {{ H5Z_CLASS_T_VERS, /* H5Z_class_t version */ H5Z_FILTER_BOGUS, /* Filter id number */ 1, 1, /* Encoding and decoding enabled */ |