Jive reference manual
List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions
jem::util::Enumerator Class Referenceabstract

Iterates over a set of objects. More...

Inheritance diagram for jem::util::Enumerator:
Inheritance graph

Public Member Functions

virtual ClassgetClass () const
 Returns the Class instance representing the runtime class of this object. More...
 
virtual bool atEnd () const =0
 Checks whether this enumerator points to an end object. More...
 
virtual void toNext ()=0
 Advances this enumerator to the next object. More...
 
virtual Ref< Objectget () const =0
 Returns the current object. More...
 
- Public Member Functions inherited from jem::Object
virtual String toString () const
 Returns a short textual description of this object. More...
 
virtual long hashValue () const
 Returns a hash value for this object. More...
 
virtual bool equals (const Ref< Object > &obj) const
 Tests whether two objects are equal. More...
 
Ref< Objectclone () const
 Returns a copy of this object. More...
 

Static Public Member Functions

static ClassmakeClass ()
 
static ClassgetType ()
 
- Static Public Member Functions inherited from jem::Object
static ClassgetType ()
 Returns the Class instance representing the Object class. More...
 

Protected Member Functions

virtual ~Enumerator ()
 
- Protected Member Functions inherited from jem::Collectable
 Collectable ()
 Creates an empty Collectable. More...
 
 ~Collectable ()
 Frees resources. More...
 

Detailed Description

#include <jem/util/Enumerator.h>

The abstract class Enumerator can be used to iterate over a collection of objects. An Enumerator can be viewed as a type of forward iterator with virtual member functions.

An Enumerator either points to an object in a collection, or to a special end object that is located one position past the last object in the collection. The member function atEnd() can be used to check whether an enumerator points to a regular object or to an end object. Note that end objects can not be accessed; they are conceptual objects that are not physically stored in memory.

The following code fragment demonstrates how the Enumerator class is typically used.

void print ( io::Writer& out, Enumerable& collection )
{
Ref<Enumerator> e = collection.getEnumerator ();
for ( ; ! e->atEnd(); e->toNext() )
{
out << e->get()->toString();
}
}
See also
Enumerable

Constructor & Destructor Documentation

virtual jem::util::Enumerator::~Enumerator ( )
protectedvirtual

Member Function Documentation

static Class* jem::util::Enumerator::makeClass ( )
static
static Class* jem::util::Enumerator::getType ( )
static
virtual Class* jem::util::Enumerator::getClass ( ) const
virtual

Returns a pointer to the Class instance representing the runtime class of this object. If T denotes the runtime class of this object, then this function is equivalent with T::getType(). The pointer is valid during the entire lifetime of the program.

Returns
A pointer to the Class instance representing the runtime class of this object.

Reimplemented from jem::Object.

Reimplemented in jem::util::DictionaryEnumerator.

virtual bool jem::util::Enumerator::atEnd ( ) const
pure virtual

Checks whether this enumerator points to an end object that marks the end of an object collection.

Returns
true if this enumerator points to an end object, or false otherwise.
virtual void jem::util::Enumerator::toNext ( )
pure virtual

Advances this enumerator to the next object in the collection, or to the end object if there is no next object. This function may not be called if this enumerator already points to the end object.

Precondition
this->atEnd() == false

Implemented in jem::util::SequenceEnumerator.

virtual Ref<Object> jem::util::Enumerator::get ( ) const
pure virtual

Returns a reference to the object that this enumerator is currently pointing to. This function may not be called if this enumerator is pointing to an end object.

Precondition
this->atEnd() == false
Returns
A reference to the current object.

Implemented in jem::util::DictionaryEnumerator, and jem::util::MapEnumerator.