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
58
59
60
61
62
63
|
/*
* The contects of this file is in the Public Domain.
*
* Created by Gustav Hartivgsson.
*/
[CCode (cname = "V", cprefix = "v_")]
namespace Utils {
[CCode (cname = "VRangeIterator", cprefix = "v_range_iterator_")]
public class RangeIterator {
private Range range;
private int current;
public RangeIterator (Range range) {
this.range = range;
this.current = this.range.start;
}
public int 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);
}
}
[CCode (cname = "VRange", cprefix = "v_range_")]
public class Range {
public bool reverse {get; private set;}
public int start {get; private set;}
public int end {get; private set;}
public Range (int start, int 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);
}
}
}
|