summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Laird <jlaird@hdfgroup.org>2006-08-14 16:18:28 (GMT)
committerJames Laird <jlaird@hdfgroup.org>2006-08-14 16:18:28 (GMT)
commit0f61afce1cc9286e0da761d60f0c0db51423db32 (patch)
tree04c46c8276655eefa07cf8bc674c31d5df86d104
parent89f36d62b776ef955eed82a109b83a187ef115bb (diff)
downloadhdf5-0f61afce1cc9286e0da761d60f0c0db51423db32.zip
hdf5-0f61afce1cc9286e0da761d60f0c0db51423db32.tar.gz
hdf5-0f61afce1cc9286e0da761d60f0c0db51423db32.tar.bz2
[svn-r12576] Added funtions to query the "current position" for Packet Tables in C and C++.
-rw-r--r--hl/c++/src/H5PacketTable.cpp15
-rw-r--r--hl/c++/src/H5PacketTable.h6
-rw-r--r--hl/c++/test/ptableTest.cpp16
-rw-r--r--hl/src/H5PT.c36
-rw-r--r--hl/src/H5PTpublic.h3
-rw-r--r--hl/test/test_packet.c12
6 files changed, 83 insertions, 5 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;
diff --git a/hl/src/H5PT.c b/hl/src/H5PT.c
index 94b8f08..da9bde6 100644
--- a/hl/src/H5PT.c
+++ b/hl/src/H5PT.c
@@ -35,6 +35,7 @@ static H5I_type_t H5PT_ptable_id_type = H5I_UNINIT;
herr_t H5PT_close( htbl_t* table );
herr_t H5PT_create_index(htbl_t *table_id);
herr_t H5PT_set_index(htbl_t *table_id, hsize_t pt_index);
+herr_t H5PT_get_index(htbl_t *table_id, hsize_t *pt_index);
/*-------------------------------------------------------------------------
*
@@ -528,9 +529,9 @@ out:
*/
/*-------------------------------------------------------------------------
- * Function: H5PT_create_index, H5PT_set_index
+ * Function: H5PT_create_index, H5PT_set_index, H5PT_get_index
*
- * Purpose: Resets and sets the current record index for a packet table
+ * Purpose: Resets, sets, and gets the current record index for a packet table
*
* Return: Success: 0, Failure: -1
*
@@ -569,10 +570,22 @@ herr_t H5PT_set_index(htbl_t *table, hsize_t index)
return -1;
}
+herr_t H5PT_get_index(htbl_t *table, hsize_t *index)
+{
+ /* Ensure index is valid */
+ if( table != NULL )
+ {
+ if(index)
+ *index = table->current_index;
+ return 0;
+ }
+ return -1;
+}
+
/*-------------------------------------------------------------------------
- * Function: H5PTcreate_index, H5PTset_index
+ * Function: H5PTcreate_index, H5PTset_index, H5PTget_index
*
- * Purpose: Resets and sets the current record index for a packet table
+ * Purpose: Resets, sets, and gets the current record index for a packet table
*
* Return: Success: 0, Failure: -1
*
@@ -608,6 +621,18 @@ herr_t H5PTset_index(hid_t table_id, hsize_t pt_index)
return H5PT_set_index(table, pt_index);
}
+
+herr_t H5PTget_index(hid_t table_id, hsize_t *pt_index)
+{
+ htbl_t * table;
+
+ /* find the table struct from its ID */
+ if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
+ return -1;
+
+ return H5PT_get_index(table, pt_index);
+}
+
/*-------------------------------------------------------------------------
*
* Inquiry functions
@@ -642,7 +667,8 @@ herr_t H5PTget_num_packets( hid_t table_id, hsize_t *nrecords)
if((table = (htbl_t *) H5Iobject_verify(table_id, H5PT_ptable_id_type)) == NULL)
goto out;
- *nrecords = table->size;
+ if(nrecords)
+ *nrecords = table->size;
return 0;
out:
diff --git a/hl/src/H5PTpublic.h b/hl/src/H5PTpublic.h
index d1d635b..43520d4 100644
--- a/hl/src/H5PTpublic.h
+++ b/hl/src/H5PTpublic.h
@@ -97,6 +97,9 @@ H5_HLDLL herr_t H5PTcreate_index( hid_t table_id );
H5_HLDLL herr_t H5PTset_index( hid_t table_id,
hsize_t pt_index );
+H5_HLDLL herr_t H5PTget_index( hid_t table_id,
+ hsize_t *pt_index );
+
/*-------------------------------------------------------------------------
*
* Memory Management functions
diff --git a/hl/test/test_packet.c b/hl/test/test_packet.c
index 7c7ab2c..375763b 100644
--- a/hl/test/test_packet.c
+++ b/hl/test/test_packet.c
@@ -789,6 +789,10 @@ static int test_error(hid_t fid)
goto out;
if(H5PTcreate_index(id) >= 0)
goto out;
+ if(H5PTset_index(id, 1) >= 0)
+ goto out;
+ if(H5PTget_index(id, NULL) >= 0)
+ goto out;
H5E_END_TRY
/* Open a high-level non-packet (H5TB) table and try to */
@@ -810,6 +814,10 @@ static int test_error(hid_t fid)
goto out;
if(H5PTcreate_index(id) >= 0)
goto out;
+ if(H5PTset_index(id, 1) >= 0)
+ goto out;
+ if(H5PTget_index(id, NULL) >= 0)
+ goto out;
H5E_END_TRY
id_open=0;
@@ -836,6 +844,10 @@ static int test_error(hid_t fid)
goto out;
if(H5PTcreate_index(id) >= 0)
goto out;
+ if(H5PTset_index(id, 1) >= 0)
+ goto out;
+ if(H5PTget_index(id, NULL) >= 0)
+ goto out;
H5E_END_TRY
PASSED();