/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace Utils {

  public class RangeIterator {
    private Range range;
    private int32 current;
    public RangeIterator (Range range) {
      this.range = range;
      this.current = this.range.start;
    }
     public int32 get () {
       return this.current;
     }

    public bool next () {
      if (!this.range.reverse) {
        if (this.current <= this.range.end) {
          this.current++;
          return true;
        }
      } else {
        if (this.current >= this.range.end){
          this.current--;
        }
      }
      return false;
    }

    public bool has_next () {
      return (this.current < this.range.end);
    }
  }


  public class Range {
    public bool reverse {get; private set;}
    public int32 start {get; private set;}
    public int32 end {get; private set;}

    public Range (int32 start, int32 end) {
      if (start <= end) {
        this.reverse = false;
      } else {
        this.reverse = true;
      }
      this.start = start;
      this.end = end;
    }

    public Type element_type () {
      return typeof (int);
    }
     
    public RangeIterator iterator () {
      return new RangeIterator (this);
    }
  }
}