Abstract bidirectional iterator for an xmap<Key,Payload>
$interface+ IBiDirIterator
{
void Close();
const void* GetElement();
void Next();
void Prev();
};
void Close()
An iterator must always be closed when it is no longer required
const void* GetElement()
Returns the address of the current element pointed to by this iterator, or else returns nullptr if the iterator is positioned one before the first or one after the last element.
void Next()
Step the iterator forwards.
void Prev()
Step the iterator backwards.
The following shows an example of forwards iteration through all the (Key,Payload) elements of a given IXMap 'xm'.
void f(ptr<IXMap> xm)
{
ptr<IBiDirIterator> i = xm->GetIterator();
ssize_t payloadOffset = xm->GetPayloadOffset();
while(const void* key = i->GetElement())
{
const void* payload = (const octet_t*)key + payloadOffset;
// process (key,payload) pair
i->Next();
}
i->Close(); // iterator must be closed when no longer required
}