diff options
Diffstat (limited to 'hl/c++')
-rw-r--r-- | hl/c++/src/H5PacketTable.cpp | 206 | ||||
-rw-r--r-- | hl/c++/src/H5PacketTable.h | 133 | ||||
-rw-r--r-- | hl/c++/test/ptableTest.cpp | 53 |
3 files changed, 161 insertions, 231 deletions
diff --git a/hl/c++/src/H5PacketTable.cpp b/hl/c++/src/H5PacketTable.cpp index 2a491de..50e11f6 100644 --- a/hl/c++/src/H5PacketTable.cpp +++ b/hl/c++/src/H5PacketTable.cpp @@ -39,6 +39,12 @@ table_id = H5PTopen( fileID, name); } + /* "Open" Constructor - will be deprecated because of char* name */ + PacketTable::PacketTable(hid_t fileID, char* name) + { + table_id = H5PTopen( fileID, name); + } + /* Destructor * Cleans up the packet table */ @@ -60,17 +66,14 @@ return false; } -#ifdef VLPT_REMOVED /* IsVariableLength - * Return 1 if this packet table is a Variable Length packet table, - * return 0 if it is Fixed Length. Returns -1 if the table is - * invalid (not open). + * Return 1 if this packet table uses variable-length datatype, + * and 0, otherwise. Returns -1 if the table is invalid (not open). */ int PacketTable::IsVariableLength() { return H5PTis_varlen(table_id); } -#endif /* VLPT_REMOVED */ /* ResetIndex * Sets the index to point to the first packet in the packet table @@ -113,39 +116,87 @@ { hsize_t npackets; - error = H5PTget_num_packets( table_id, (hsize_t *)&npackets); + error = H5PTget_num_packets(table_id, &npackets); return npackets; } + /* GetTableId + * Returns the identifier of the packet table + */ + hid_t PacketTable::GetTableId() + { + return table_id; + } + + /* GetDatatype + * Returns the datatype identifier used by the packet table, on success, + * or FAIL, on failure. + * Note: it is best to avoid using this identifier in applications, unless + * the desired functionality cannot be performed via the packet table ID. + */ + hid_t PacketTable::GetDatatype() + { + return H5PTget_type(table_id); + } + + /* GetDataset + * Returns the dataset identifier associated with the packet table, on + * success, or FAIL, on failure. + * Note: it is best to avoid using this identifier in applications, unless + * the desired functionality cannot be performed via the packet table ID. + */ + hid_t PacketTable::GetDataset() + { + return H5PTget_dataset(table_id); + } + + /* FreeBuff + * Frees the buffers created when variable-length packets are read. + * Takes the number of hvl_t structs to be freed and a pointer to their + * location in memory. + * Returns 0 on success, negative on error. + */ + int PacketTable::FreeBuff(size_t numStructs, hvl_t * buffer) + { + return H5PTfree_vlen_buff( table_id, numStructs, buffer); + } + + /********************************/ /* Fixed-Length Packet Table */ /********************************/ /* Constructor - * Creates a packet table in which to store fixed length packets. + * Creates a packet table to store either fixed- or variable-length packets. + * Takes the ID of the file the packet table will be created in, the ID of + * the property list to specify compression, the name of the packet table, + * the ID of the datatype, and the size of a memory chunk used in chunking. + */ + FL_PacketTable::FL_PacketTable(hid_t fileID, hid_t plist_id, const char* name, hid_t dtypeID, hsize_t chunkSize) + { + table_id = H5PTcreate(fileID, name, dtypeID, chunkSize, plist_id); + } + + /* Constructor + * Creates a packet table to store either fixed- or variable-length packets. * Takes the ID of the file the packet table will be created in, the name of * the packet table, the ID of the datatype of the set, and the size * of a memory chunk used in chunking. + * Note: this overload will be deprecated in favor of the constructor above. */ - FL_PacketTable::FL_PacketTable(hid_t fileID, const char* name, hid_t dtypeID, hsize_t chunkSize, int compression) + FL_PacketTable::FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, hsize_t chunkSize, int compression) { - table_id = H5PTcreate_fl ( fileID, name, dtypeID, chunkSize, compression); + table_id = H5PTcreate_fl(fileID, name, dtypeID, chunkSize, compression); } /* "Open" Constructor * Opens an existing fixed-length packet table. * Fails if the packet table specified is variable-length. */ - FL_PacketTable::FL_PacketTable(hid_t fileID, const char* name) : PacketTable(fileID, name) - { -#ifdef VLPT_REMOVED - if( H5PTis_varlen(table_id) != 0 ) // If this is not a fixed-length table - { - H5PTclose(table_id); - table_id = -1; - } -#endif /* VLPT_REMOVED */ - } + FL_PacketTable::FL_PacketTable(hid_t fileID, const char* name) : PacketTable(fileID, name) {} + + /* "Open" Constructor - will be deprecated because of char* name */ + FL_PacketTable::FL_PacketTable(hid_t fileID, char* name) : PacketTable(fileID, name) {} /* AppendPacket * Adds a single packet to the packet table. Takes a pointer @@ -215,119 +266,4 @@ return H5PTget_next(table_id, numPackets, data); } - -#ifdef VLPT_REMOVED - /********************************/ - /* Variable-Length Packet Table */ - /********************************/ - - /* Constructor - * Creates a packet table in which to store variable length packets. - * Takes the ID of the file the packet table will be created in, the name of - * the packet table, and the size of a memory chunk used in chunking. - */ - VL_PacketTable::VL_PacketTable(hid_t fileID, char* name, hsize_t chunkSize) - { - table_id = H5PTcreate_vl ( fileID, name, chunkSize); - } - - /* "Open" Constructor - * Opens an existing variable-length packet table. - * Fails if the packet table specified is fixed-length. - */ - VL_PacketTable::VL_PacketTable(hid_t fileID, char* name) : PacketTable(fileID, name) - { - if( H5PTis_varlen(table_id) != 1 ) // If this is not a variable-length table - { - H5PTclose(table_id); - table_id = -1; - } - } - - /* AppendPacket (variable-length) - * Adds a single variable-length packet to the packet table. - * Takes a pointer to the location of the data in memory and the length of the data - * in bytes. - * Returns 0 on success, negative on failure. - */ - int VL_PacketTable::AppendPacket(void * data, size_t length) - { - hvl_t packet; - - packet.len = length; - packet.p = data; - - return H5PTappend(table_id, 1, &packet); - } - - /* AppendPackets (multiple packets) - * Adds multiple variable-length packets to the packet table. Takes the - * number of - * packets to be added and a pointer to an array of hvl_t structs in memory. - * Returns 0 on success, negative on failure. - */ - int VL_PacketTable::AppendPackets(size_t numPackets, hvl_t * data) - { - return H5PTappend(table_id, numPackets, data); - } - - /* GetPacket (indexed) - * Gets a single variable-length packet from the packet table. Takes the - * index of the packet (with 0 being the first packet) and a pointer - * to a hvl_t struct in which to store the packet's size and location. - * Returns 0 on success, negative on failure. - */ - int VL_PacketTable::GetPacket(hsize_t index, hvl_t * data) - { - return H5PTread_packets(table_id, index, 1, data); - } - - /* GetPackets (multiple packets) - * Gets multiple variable-length packets at once, all packets between - * startIndex and endIndex inclusive. Takes a pointer to an array - * of hvl_t structs in memory in which to store pointers to the packets. - * Returns 0 on success, negative on failure. - */ - int VL_PacketTable::GetPackets(hsize_t startIndex, hsize_t endIndex, hvl_t * data) - { - // Make sure the range of indexes is valid - if (startIndex > endIndex) - return -1; - - return H5PTread_packets(table_id, startIndex, endIndex-startIndex+1, data); - } - - /* GetNextPacket (single packet) - * Gets the next packet in the packet table. Takes a pointer to - * an hvl_t struct where the packet should be stored. - * Returns 0 on success, negative on failure. Index - * is not advanced to the next packet on failure. - */ - int VL_PacketTable::GetNextPacket(hvl_t * data) - { - return H5PTget_next(table_id, 1, data); - } - - /* GetNextPackets (multiple packets) - * Gets the next numPackets packets in the packet table. Takes a - * pointer to an array of hvl_t structs where pointers to the packets - * should be stored. - * Returns 0 on success, negative on failure. Index - * is not advanced on failure. - */ - int VL_PacketTable::GetNextPackets(size_t numPackets, hvl_t * data) - { - return H5PTget_next(table_id, numPackets, data); - } - - /* FreeReadbuff - * Frees the buffers created when variable-length packets are read. - * Takes the number of hvl_t structs to be freed and a pointer to their - * location in memory. - * Returns 0 on success, negative on error. - */ - int VL_PacketTable::FreeReadbuff(size_t numStructs, hvl_t * buffer) - { - return H5PTfree_vlen_readbuff( table_id, numStructs, buffer); - } -#endif /* VLPT_REMOVED */ +/* Removed "ifdef VLPT_REMOVED" block. 03/08/2016, -BMR */ diff --git a/hl/c++/src/H5PacketTable.h b/hl/c++/src/H5PacketTable.h index c7c7fc0..bdd669d 100644 --- a/hl/c++/src/H5PacketTable.h +++ b/hl/c++/src/H5PacketTable.h @@ -44,10 +44,13 @@ public: */ PacketTable(hid_t fileID, const char* name); + /* "Open" Constructor - will be deprecated because of char* name */ + PacketTable(hid_t fileID, char* name); + /* Destructor * Cleans up the packet table */ - ~PacketTable(); + virtual ~PacketTable(); /* IsValid * Returns true if this packet table is valid, false otherwise. @@ -56,14 +59,12 @@ public: */ bool IsValid(); -#ifdef VLPT_REMOVED /* IsVariableLength - * Return 1 if this packet table is a Variable Length packet table, + * Return 1 if this packet table uses variable-length datatype, * return 0 if it is Fixed Length. Returns -1 if the table is * invalid (not open). */ int IsVariableLength(); -#endif /* VLPT_REMOVED */ /* ResetIndex * Sets the "current packet" index to point to the first packet in the @@ -96,6 +97,35 @@ public: return GetPacketCount(ignoreError); } + /* GetTableId + * Returns the identifier of the packet table. + */ + hid_t GetTableId(); + + /* GetDatatype + * Returns the datatype identifier used by the packet table, on success, + * or FAIL, on failure. + * Note: it is best to avoid using this identifier in applications, unless + * the desired functionality cannot be performed via the packet table ID. + */ + hid_t GetDatatype(); + + /* GetDataset + * Returns the dataset identifier associated with the packet table, on + * success, or FAIL, on failure. + * Note: it is best to avoid using this identifier in applications, unless + * the desired functionality cannot be performed via the packet table ID. + */ + hid_t GetDataset(); + + /* FreeBuff + * Frees the buffers created when variable-length packets are read. + * Takes the number of hvl_t structs to be freed and a pointer to their + * location in memory. + * Returns 0 on success, negative on error. + */ + int FreeBuff(size_t numStructs, hvl_t * buffer); + protected: hid_t table_id; }; @@ -104,13 +134,22 @@ class H5_HLCPPDLL FL_PacketTable : virtual public PacketTable { public: /* Constructor + * Creates a packet table to store either fixed- or variable-length packets. + * Takes the ID of the file the packet table will be created in, the ID of + * the property list to specify compression, the name of the packet table, + * the ID of the datatype, and the size of a memory chunk used in chunking. + */ + FL_PacketTable(hid_t fileID, hid_t plist_id, const char* name, hid_t dtypeID, hsize_t chunkSize); + + /* Constructor * Creates a packet table in which to store fixed length packets. * Takes the ID of the file the packet table will be created in, the name of * the packet table, the ID of the datatype of the set, the size * of a memory chunk used in chunking, and the desired compression level * (0-9, or -1 for no compression). + * Note: this overload will be deprecated in favor of the constructor above. */ - FL_PacketTable(hid_t fileID, const char* name, hid_t dtypeID, hsize_t chunkSize, int compression = -1); + FL_PacketTable(hid_t fileID, char* name, hid_t dtypeID, hsize_t chunkSize, int compression = -1); /* "Open" Constructor * Opens an existing fixed-length packet table. @@ -118,6 +157,14 @@ public: */ FL_PacketTable(hid_t fileID, const char* name); + /* "Open" Constructor - will be deprecated because of char* name */ + FL_PacketTable(hid_t fileID, char* name); + + /* Destructor + * Cleans up the packet table + */ + virtual ~FL_PacketTable() {}; + /* AppendPacket * Adds a single packet to the packet table. Takes a pointer * to the location of the data in memory. @@ -165,80 +212,6 @@ public: int GetNextPackets(size_t numPackets, void * data); }; -#ifdef VLPT_REMOVED -class H5_HLCPPDLL VL_PacketTable : virtual public PacketTable -{ -public: - /* Constructor - * Creates a packet table in which to store variable length packets. - * Takes the ID of the file the packet table will be created in, the name of - * the packet table, and the size of a memory chunk used in chunking. - */ - VL_PacketTable(hid_t fileID, char* name, hsize_t chunkSize); - - /* "Open" Constructor - * Opens an existing variable-length packet table. - * Fails if the packet table specified is fixed-length. - */ - VL_PacketTable(hid_t fileID, char* name); - - /* AppendPacket - * Adds a single packet of any length to the packet table. - * Takes a pointer to the location of the data in memory and the length of the data - * in bytes. - * Returns 0 on success, negative on failure. - */ - int AppendPacket(void * data, size_t length); - - /* AppendPackets (multiple packets) - * Adds multiple variable-length packets to the packet table. Takes the - * number of packets to be added and a pointer to an array of - * hvl_t structs in memory. - * Returns 0 on success, negative on failure. - */ - int AppendPackets(size_t numPackets, hvl_t * data); - - /* GetPacket (indexed) - * Gets a single variable-length packet from the packet table. Takes - * the index of the packet (with 0 being the first packet) and a pointer - * to a hvl_t struct in which to store the packet's size and location. - * Returns 0 on success, negative on failure. - */ - int GetPacket(hsize_t index, hvl_t * data); - - /* GetPackets (multiple packets) - * Gets multiple variable-length packets at once, all packets between - * startIndex and endIndex inclusive. Takes a pointer to an array - * of hvl_t structs in memory in which to store pointers to the packets. - * Returns 0 on success, negative on failure. - */ - int GetPackets(hsize_t startIndex, hsize_t endIndex, hvl_t * data); - - /* GetNextPacket (single packet) - * Gets the next packet in the packet table. Takes a pointer to - * an hvl_t struct where the packet should be stored. - * Returns 0 on success, negative on failure. Index - * is not advanced to the next packet on failure. - */ - int GetNextPacket(hvl_t * data); - - /* GetNextPackets (multiple packets) - * Gets the next numPackets packets in the packet table. Takes a - * pointer to an array of hvl_t structs where pointers to the packets - * should be stored. - * Returns 0 on success, negative on failure. Index - * is not advanced on failure. - */ - int GetNextPackets(size_t numPackets, hvl_t * data); - - /* FreeReadbuff - * Frees the buffers created when variable-length packets are read. - * Takes the number of hvl_t structs to be freed and a pointer to their - * location in memory. - * Returns 0 on success, negative on error. - */ - int FreeReadbuff(size_t numStructs, hvl_t * buffer); -}; -#endif /* VLPT_REMOVED */ +/* Removed "#ifdef VLPT_REMOVED" block. 03/08/2016, -BMR */ #endif /* H5PTWRAP_H */ diff --git a/hl/c++/test/ptableTest.cpp b/hl/c++/test/ptableTest.cpp index 929058d..ff99285 100644 --- a/hl/c++/test/ptableTest.cpp +++ b/hl/c++/test/ptableTest.cpp @@ -15,9 +15,11 @@ /* ptableTest.cpp */ +#include <iostream> #include "ptableTest.h" using namespace H5; +using namespace std; #define TEST_FILE "packettest.h5" @@ -74,7 +76,7 @@ int main(void) return -1; } - +const char* BASICTEST_PT("/basicTest"); int BasicTest() { herr_t err; @@ -82,9 +84,9 @@ int BasicTest() hsize_t count; int error; - TESTING("basic funtionality") + TESTING("basic functionality") - FL_PacketTable wrapper(fileID, "/basicTest", H5T_NATIVE_INT, 1); + FL_PacketTable wrapper(fileID, H5P_DEFAULT, BASICTEST_PT, H5T_NATIVE_INT, 1); if(! wrapper.IsValid()) goto out; @@ -131,6 +133,7 @@ out: return 1; } +const char* CMPDTEST_PT("/compoundTest"); int TestCompoundDatatype() { hid_t dtypeID; @@ -153,8 +156,8 @@ int TestCompoundDatatype() H5Tinsert(dtypeID, "charlie", HOFFSET( compoundType, c ), H5T_NATIVE_SHORT); H5Tinsert(dtypeID, "ebert", HOFFSET( compoundType, e ), H5T_NATIVE_INT); - /* Create packet table. Explicitly specify no compression */ - FL_PacketTable wrapper(fileID, "/compoundTest", dtypeID, 1, -1); + /* Create packet table using default property list. */ + FL_PacketTable wrapper(fileID, H5P_DEFAULT, CMPDTEST_PT, dtypeID, 1); if(! wrapper.IsValid()) goto out; @@ -198,6 +201,7 @@ out: return 1; } +const char* GETNEXT_PT("/TestGetNext"); int TestGetNext() { int error; @@ -208,7 +212,7 @@ int TestGetNext() TESTING("GetNextPacket") /* Create a dataset */ - FL_PacketTable wrapper(fileID, "/TestGetNext", H5T_NATIVE_INT, 500); + FL_PacketTable wrapper(fileID, H5P_DEFAULT, GETNEXT_PT, H5T_NATIVE_INT, 500); if(! wrapper.IsValid()) goto out; @@ -260,18 +264,27 @@ out: return 1; } +const char* COMPRESS_PT("/compressTest"); int TestCompress() { - - unsigned int flags = 0; + unsigned int flags = 0; unsigned int config = 0; size_t cd_nelemts = 0; TESTING("compression") #ifdef H5_HAVE_FILTER_DEFLATE try { + /* Prepare property list to set compression, randomly use deflate */ + DSetCreatPropList dscreatplist; + dscreatplist.setDeflate(6); + /* Create packet table with compression. */ - FL_PacketTable wrapper(fileID, "/compressTest", H5T_NATIVE_CHAR, 100, 8); + FL_PacketTable wrapper(fileID, dscreatplist.getId(), COMPRESS_PT, H5T_NATIVE_CHAR, 100); + + /* Close the property list */ + dscreatplist.close(); + + /* Verify that the deflate filter is set */ /* Create an HDF5 C++ file object */ H5File file; @@ -279,11 +292,14 @@ int TestCompress() /* Make sure that the deflate filter is set by opening the packet table * as a dataset and getting its creation property list */ - DataSet dsetID = file.openDataSet("/compressTest"); + DataSet dset = file.openDataSet(COMPRESS_PT); - DSetCreatPropList dcplID = dsetID.getCreatePlist(); + DSetCreatPropList dcpl = dset.getCreatePlist(); - dcplID.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 0, NULL, config); + char filter_name[8]; + dcpl.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 8, filter_name, config); + if (HDstrncmp(filter_name, "deflate", 7) != 0) + H5_FAILED() } catch (Exception e) { H5_FAILED(); return 1; @@ -296,6 +312,7 @@ int TestCompress() return 0; } +const char* PT_TESTGETPT = "/TestGetPacket"; int TestGetPacket() { int record; @@ -304,7 +321,7 @@ int TestGetPacket() TESTING("GetPacket") /* Create a dataset. Explicitly specify no compression */ - FL_PacketTable wrapper(fileID, "/TestGetPacket", H5T_NATIVE_INT, 1, -1); + FL_PacketTable wrapper(fileID, H5P_DEFAULT, PT_TESTGETPT, H5T_NATIVE_INT, 1); if(! wrapper.IsValid()) goto out; @@ -334,12 +351,14 @@ out: return 1; } +const char* PT_TESTERROR = "/TestErrors"; + int TestErrors() { TESTING("error conditions") /* Create a dataset */ - FL_PacketTable wrapper(fileID, "/TestErrors", H5T_NATIVE_INT, 1); + FL_PacketTable wrapper(fileID, H5P_DEFAULT, PT_TESTERROR, H5T_NATIVE_INT, 1); if(! wrapper.IsValid()) goto out; @@ -443,6 +462,8 @@ out: return 1; } +const char* PT_SYSTEMTST1 = "/SystemTest1"; +const char* PT_SYSTEMTST2 = "/SystemTest2"; int SystemTest() { TESTING("multiple datatypes") @@ -485,8 +506,8 @@ int SystemTest() ct2[0].g.e = 3000; /* Create the packet table datasets. Make one of them compressed. */ - FL_PacketTable wrapper1(fileID, "/SystemTest1", dtypeID1, 1); - FL_PacketTable wrapper2(fileID, "/SystemTest2", dtypeID2, 1, 5); + FL_PacketTable wrapper1(fileID, H5P_DEFAULT, PT_SYSTEMTST1, dtypeID1, 1); + FL_PacketTable wrapper2(fileID, H5P_DEFAULT, PT_SYSTEMTST2, dtypeID2, 1); if(! wrapper1.IsValid()) goto out; |