class GContainerBaseclass GPositionclass GPosition

Generic iterator class.

Public Methods

[more] GPosition()
Constructs a null GPosition object.
[more] GPosition(const GContainerBase &gc)
Constructs a GPosition object for a container.
[more] operator int()
Tests if a position is valid.
[more]int operator !()
Tests if a position is valid.
[more]GPosition& operator ++()
Moves to the next position.
[more]GPosition& operator --()
Moves to the previous position.


Documentation

Generic iterator class. This class represents a position in an arbitrary container It provides a generic way to iterate over the objects contained in a container. This is achieved with the following code:
    GArray<int>    a;
    GList<GString> l;
    for (GPosition pos=a.firstpos(); pos; ++pos) 
      l.append(a[pos]); 
    for (GPosition pos=l.lastpos(); pos; --pos)
      printf("%d\n", l[pos]);
    
A GPosition object remains meaningful as long as you do not modify the contents of the underlying container. You should not use a GPosition that was initialized before modifying the contents of container object. Undetermined results may occur (as they say...)
o GPosition()
Constructs a null GPosition object.

o GPosition(const GContainerBase &gc)
Constructs a GPosition object for a container. The constructed object denotes the first position in the container.
Parameters:
gc - reference to a GArray, GList or GMap.

o operator int()
Tests if a position is valid. Returns true if this denotes a valid position in a container.

oint operator !()
Tests if a position is valid. Returns true if this denotes an invalid position.

oGPosition& operator ++()
Moves to the next position. The GPosition object then points to the next position in the corresponding container object. It is marked as invalid if no such position exists.

oGPosition& operator --()
Moves to the previous position. The GPosition object then points to the previous position in the corresponding container object. It is marked as invalid if no such position exists.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java