diff options
Diffstat (limited to 'hl/c++')
-rw-r--r-- | hl/c++/src/H5PacketTable.cpp | 15 | ||||
-rw-r--r-- | hl/c++/src/H5PacketTable.h | 6 | ||||
-rw-r--r-- | hl/c++/test/ptableTest.cpp | 16 |
3 files changed, 37 insertions, 0 deletions
diff --git a/hl/c++/src/H5PacketTable.cpp b/hl/c++/src/H5PacketTable.cpp index fabe490..6a16807 100644 --- a/hl/c++/src/H5PacketTable.cpp +++ b/hl/c++/src/H5PacketTable.cpp @@ -86,6 +86,21 @@ return H5PTset_index(table_id, index); } + /* SetIndex + * Sets the index to point to the packet specified by index. + * Returns 0 on success, negative on failure (if index is out of bounds) + */ + int PacketTable::GetIndex(int &error) + { + hsize_t index; + + error = H5PTget_index(table_id, &index); + if(error < 0) + return 0; + else + return index; + } + /* GetPacketCount * Returns the number of packets in the packet table. Error * is set to 0 on success. On failure, returns 0 and diff --git a/hl/c++/src/H5PacketTable.h b/hl/c++/src/H5PacketTable.h index 3ce24c4..3ba4e5e 100644 --- a/hl/c++/src/H5PacketTable.h +++ b/hl/c++/src/H5PacketTable.h @@ -74,6 +74,12 @@ public: */ int SetIndex(unsigned int index); + /* GetIndex + * Returns the position of the current packet. + * On failure, returns 0 and error is set to negative. + */ + int GetIndex(int& error); + /* GetPacketCount * Returns the number of packets in the packet table. Error * is set to 0 on success. On failure, returns 0 and diff --git a/hl/c++/test/ptableTest.cpp b/hl/c++/test/ptableTest.cpp index 9cae7f5..3b97d3e 100644 --- a/hl/c++/test/ptableTest.cpp +++ b/hl/c++/test/ptableTest.cpp @@ -210,7 +210,10 @@ int TestGetNext() goto out; } + /* Reset the index and check that it worked */ wrapper.ResetIndex(); + if(wrapper.GetIndex(error) != 0) goto out; + if(error < 0) goto out; /* Ensure that we can interate through the records and get the right ones */ for(i = 1; i < 6; i++) @@ -221,6 +224,8 @@ int TestGetNext() } wrapper.SetIndex(1); + if(wrapper.GetIndex(error) != 1) goto out; + if(error < 0) goto out; /* Ensure we can get multiple records with our index pointer */ wrapper.GetNextPackets(2, records); @@ -342,11 +347,15 @@ int TestErrors() error = wrapper.SetIndex(-1); if(error >= 0) goto out; + if(wrapper.GetIndex(error) != 0) goto out; + if(error < 0) goto out; error = wrapper.GetNextPacket(&record); if(error < 0) goto out; if(record != 1) goto out; + if(wrapper.GetIndex(error) != 1) goto out; + if(error < 0) goto out; error = wrapper.SetIndex(20); if(error >= 0) goto out; @@ -361,6 +370,8 @@ int TestErrors() goto out; if(record != 4) goto out; + if(wrapper.GetIndex(error) != 4) goto out; + if(error < 0) goto out; error = wrapper.GetNextPacket(&record); if(error >= 0) goto out; @@ -387,6 +398,7 @@ int SystemTest() hid_t dtypeID1, dtypeID2; unsigned int count; + int error; /* Creating two inter-related datatypes. Create two datasets and put * one datatype in each. */ @@ -452,6 +464,10 @@ int SystemTest() wrapper1.ResetIndex(); wrapper1.GetNextPacket(&ct1[1]); wrapper2.GetPacket(1, &ct2[2]); + if(wrapper1.GetIndex(error) != 1) goto out; + if(error < 0) goto out; + if(wrapper2.GetIndex(error) != 0) goto out; + if(error < 0) goto out; if(ct1[1].b != ct2[2].g.b) goto out; |