home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2004 August / GSSH0804.iso / Action / TumikiFighters / tf0_2.exe / tf / src / abagames / util / iterator.d < prev    next >
Text File  |  2004-04-03  |  693b  |  40 lines

  1. /*
  2.  * $Id: iterator.d,v 1.1.1.1 2004/04/03 10:36:32 kenta Exp $
  3.  *
  4.  * Copyright 2004 Kenta Cho. All rights reserved.
  5.  */
  6. module abagames.util.iterator;
  7.  
  8. /**
  9.  * Simple iterator for array.
  10.  */
  11. public template ArrayIterator(T) {
  12. public class ArrayIterator {
  13.  private:
  14.   T[] array;
  15.   int idx;
  16.  
  17.   public this(T[] a) {
  18.     array = a;
  19.     idx = 0;
  20.   }
  21.  
  22.   public bool hasNext() {
  23.     if (idx >= array.length)
  24.       return false;
  25.     else
  26.       return true;
  27.   }
  28.  
  29.   public T next() {
  30.     if (idx >= array.length)
  31.       throw new Error("No more items");
  32.     T result = array[idx];
  33.     idx++;
  34.     return result;
  35.   }
  36. }
  37. }
  38.  
  39. alias ArrayIterator!(char[]) StringIterator;
  40.