/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
48 by Gustav Hartvigsson
Woops again.
1
namespace Utils {
2
3
  public class RangeIterator {
4
    private Range range;
5
    private int current;
6
    public RangeIterator (Range range) {
7
      this.range = range;
8
      this.current = this.range.start;
9
    }
10
     public int get () {
11
       return this.current;
12
     }
13
14
    public bool next () {
15
      if (!this.range.reverse) {
16
        if (this.current <= this.range.end) {
17
          this.current++;
18
          return true;
19
        }
20
      } else {
21
        if (this.current >= this.range.end){
22
          this.current--;
23
        }
24
      }
25
      return false;
26
    }
27
28
    public bool has_next () {
29
      return (this.current < this.range.end);
30
    }
31
  }
32
33
34
  public class Range {
35
    public bool reverse {get; private set;}
36
    public int start {get; private set;}
37
    public int end {get; private set;}
38
39
    public Range (int start, int end) {
40
      if (start <= end) {
41
        this.reverse = false;
42
      } else {
43
        this.reverse = true;
44
      }
45
      this.start = start;
46
      this.end = end;
47
    }
48
49
    public Type element_type () {
50
      return typeof (int);
51
    }
52
     
53
    public RangeIterator iterator () {
54
      return new RangeIterator (this);
55
    }
56
  }
57
}