RWTPtrSetIterator(3C++) RWTPtrSetIterator(3C++)
Name
RWTPtrSetIterator<T,C> - Rogue Wave library class
Synopsis
#include<rw/tpset.h>
RWTPtrSet<T,C> set;
RWTPtrSetIterator<T,C> itr(set);
Standard C++ Library Dependent!RWTPtrSetIterator requires the Standard C++ Library.
DescriptionRWTPtrSetIterator is supplied with Tools 7 to provide an iterator
interface to the new Standard Library based collections that has backward
compatibility with the container iterators provided in Tools 6. The order
of iteration over an RWTPtrSet is dependent on the comparator object
supplied as applied to the values stored in the container. The current
item referenced by this iterator is undefined after construction or after
a call to reset(). The iterator becomes valid after being advanced with
either a preincrement or operator(). For both operator++ and operator(),
iterating past the last element will return a value equivalent to boolean
false. Continued increments will return a value equivalent to false
until reset() is called.
Persistence
None
Examples
#include<rw/tpset.h>
#include<iostream.h>
#include<rw/cstring.h>
int main(){
RWTPtrSet<RWCString,less<RWCString> > a;
RWTPtrSetIterator<RWCString,less<RWCString> > itr(a);
a.insert(new RWCString("John"));
Page 1
RWTPtrSetIterator(3C++) RWTPtrSetIterator(3C++)
a.insert(new RWCString("Steve"));
a.insert(new RWCString("Mark"));
//Rejected, duplicate insertions not allowed
a.insert(new RWCString("Steve"));
for(;itr();)
cout << *itr.key() <<endl;
return 0;
}
Program Output
John
Mark
Public Constructors
Steve
RWTPtrSetIterator<T,C>(const RWTPtrSet<T,C>& s);
Creates an iterator for the set s. The iterator begins in an undefined
state and must be advanced before the first element will be accessible
Public Member Operators
T*
operator()();
Advances self to the next element, dereferences the resulting iterator
and returns its value. If the iterator has advanced past the last item
in the container, the element returned will be a nil pointer equivalent
to boolean false.
Page 2
RWTPtrSetIterator(3C++) RWTPtrSetIterator(3C++)
RWBoolean
operator++();
Advances self to the next element. If the iterator has been reset or
just created self will now reference the first element. If, before
iteration, self referenced the last association in the set, self will now
reference an undefined value and a value equivalent to false will be
returned. Otherwise, a value equivalent to true is returned. Note: no
post-increment operator is provided.
Public Member Functions
RWTPtrSet<T,C>*
container() const;
Returns a pointer to the collection being iterated over.
T*
key() const;
Returns the stored value pointed to by self. Undefined if self is not
referencing a value within the set.
void
reset();
void
reset(RWTPtrSet<T,C>& h);
Resets the iterator so that after being advanced it will point to the
first element of the collection. Using reset() with no argument will
reset the iterator on the current container. Supplying a RWTPtrSet to
reset() will reset the iterator on the new container.
Page 3