#ifndef __LISTITERATORS_H

#define __LISTITERATORS_H


#include "Lists.h"


template <class Items>
class ListIterators  {   
public:

  class EndOfListError{};

  ListIterators (const Lists<Items>&);
  virtual ~ListIterators();

  Items* currentItem() const;
  int isDone() const;

  void next();
  void reset();
  
protected:

  const Lists<Items>& theList;
  ListNodes<Items> *theIndex;
};


// ABSTRACT:

//

//   Class List Iterator provides forward iteration through lists.

//

// METHODS:

//

//   Self Explanatory.

//

// EXCEPTIONS:

//

//   next() throws EndOfListError on attempts to iterate past the end

//       of the list.

//

// EXAMPLES:

// 

//     foo foo1(34), foo2(88), foo3(12);

//     Lists<foo> list;

// 

//       list.append (foo1);

//       list.append (foo2);

//       list.append (foo3);

//   

//     ListIterators<foo> iterator(list);

// 

//      for (; !iterator.isDone(); iterator.next())

//          iterator.currentItem()->printValue();

// 

//      iterator.reset();

//      while (!iterator.isDone())

//      {

//        iterator.currentItem()->printValue();

//        iterator.next();

//      }

//

// LIMITATIONS:

//

//   None.

//

// NOTES:

//

//   None.

//



template <class Items>
ListIterators<Items>::ListIterators(const Lists<Items>& list) : theList (list)
{
  reset();
}

template <class Items> 
ListIterators<Items>::~ListIterators() 
{
}

template <class Items>
Items* ListIterators<Items>::currentItem() const
{
  return (&theIndex->item);
}

template <class Items>
int ListIterators<Items>::isDone() const
{
  return (theIndex == 0);
}

template <class Items>
void ListIterators<Items>::next()
{
  if (theIndex == 0)
    throw EndOfListError();
  else
    theIndex = theIndex->next;
}

template <class Items>
void ListIterators<Items>::reset()
{
  theIndex = theList.theList;
}


#endif



// Copyright (c) 1995-1996 D J Supel and ISX Corporation




syntax highlighted by Code2HTML, v. 0.9.1