|
Sybase dbQueue Reference Guide
|
Lists
The dbQueue objects library includes a simple read-only list class called DbqEnumerator that is used for storing lists of entities. DbqEnumerator instances store items in first-in, first-out (FIFO) order. The items in the list are of the type DbqListObject; applications must cast them properly to the actual object type in order to invoke methods.
There are two ways to process a list returned from a library call:
- Use the Fetch() method to get items from the head of the list. The DbqEnumerator keeps track of the items in the list and forwards the next item when requested. The following code sample illustrates this approach.
DbqEnumerator* dblist;
DbqAppDb* appdb;
if (dom->ListAllAppDbs(&dblist) != DBQ_SUCCEED)
exit(1);
// Extract items--note the cast to DbqAppDb*.
while ((appdb = (DbqAppDb*) dblist->Fetch()) != DBQ_NULL)
printf("%s\n", appdb->GetDbAlias());// Release list.
dblist->Delete();
- Use GetElement() and an index number to read an element that is within the list. The following code sample replaces the "while loop" in the previous code sample with an iterative "for loop" with GetElement().
for (i = 1; i <= dblist->Size(); i++)
{ const DbqAppDb* appdb = (DbqAppDb*)
dblist->GetElement(i);
printf("%s\n", appdb->GetDbAlias());}
Applications should never delete any single item returned in a DbqEnumerator instance. Instead, delete the entire list by calling Delete() on DbqEnumerator to delete itself and all instances it contains.