Member Functions | |
container() findNext() insertAfterPoint() key() operator()() operator++() operator+=() remove() removeNext() reset() |
#include <rw/tpslist.h> RWTPtrSlist<T> list; RWTPtrSlistIterator<T> iterator(list);
If you do not have the Standard C++ Library, use the interface described here. Otherwise, use the interface to RWTPtrSlistIterator described in the Class Reference.
Iterator for class RWTPtrSlist<T>, allowing sequential access to all the elements of a singly-linked parameterized list. Elements are accessed in order, from first to last.
Like all Rogue Wave iterators, the "current item" is undefined immediately after construction -- you must define it by using operator() or some other (valid) operation.
If the slist is modified, the iterator is no longer valid. In addition, once the iterator has advanced beyond the end of the collection it is no longer valid--continuing to use it will bring undefined results.
None
#include<rw/tpslist.h> #include<iostream.h> #include<rw/cstring.h> int main(){ RWTPtrSlist<RWCString> a; RWTPtrSlistIterator<RWCString> itr(a); a.insert(new RWCString("John")); a.insert(new RWCString("Steve")); a.insert(new RWCString("Mark")); a.insert(new RWCString("Steve")); for(;itr();) cout << *itr.key() <<endl; return 0; } Program Output John Steve Mark Steve
RWTPtrSlistIterator<T>(RWTPtrSlist<T>& c);
Constructs an iterator to be used with the list c.
RWBoolean operator++();
Advances the iterator to the next item and returns TRUE. When the end of the collection is reached, returns FALSE and the position of the iterator will be undefined.
RWBoolean operator+=(size_t n);
Advances the iterator n positions and returns TRUE. When the end of the collection is reached, returns FALSE and the position of the iterator will be undefined.
T* operator()();
Advances the iterator to the next item and returns a pointer to it. When the end of the collection is reached, returns nil and the position of the iterator will be undefined.
RWTPtrSlist<T>* container() const;
Returns a pointer to the collection over which this iterator is iterating.
T* findNext(const T* a);
Advances the iterator to the first element that is equal to the object pointed to by a and returns a pointer to it. If no item is found, returns nil and the position of the iterator will be undefined. Equality is measured by the class-defined equality operator for type T.
T* findNext(RWBoolean (*testFun)(T*, void*), void*);
Advances the iterator to the first element for which the tester function pointed to by testFun returns TRUE and returns a pointer to it. If no item is found, returns nil and the position of the iterator will be undefined.
void insertAfterPoint(T* a);
Inserts the object pointed to by a into the iterator's associated collection in the position immediately after the iterator's current position which remains unchanged.
T* key() const;
Returns a pointer to the object at the iterator's current position. The results are undefined if the iterator is no longer valid.
T* remove();
Removes and returns the object at the iterator's current position from the iterator's associated collection. Afterwards, the iterator will be positioned at the element immediately before the removed element. Returns nil if unsuccessful in which case the position of the iterator is undefined. This function is relatively inefficient for a singly-linked list.
T* removeNext(const T* a);
Advances the iterator to the first element that is equal to the object pointed to by a, then removes and returns it. Afterwards, the iterator will be positioned at the element immediately before the removed element. Returns nil if unsuccessful in which case the position of the iterator is undefined. Equality is measured by the class-defined equality operator for type T.
T* removeNext(RWBoolean (*testFun)(T*, void*), void*);
Advances the iterator to the first element for which the tester function pointed to by testFun returns TRUE, then removes and returns it. Afterwards, the iterator will be positioned at the element immediately before the removed element. Returns nil if unsuccessful in which case the position of the iterator is undefined.
void reset();
Resets the iterator to the state it had immediately after construction.
void reset(RWTPtrSlist<T>& c);
Resets the iterator to iterate over the collection c.