/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvee/range.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-22 00:30:29 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241222003029-k74ogrm32zobz325
[General] Split libvee into it's own library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contects of this file is in the Public Domain.
 
3
 *
 
4
 * Created by Gustav Hartivgsson.
 
5
 */
 
6
 
 
7
namespace Vee {
 
8
  public class RangeIterator {
 
9
    private Range range;
 
10
    private int32 current;
 
11
    public RangeIterator (Range range) {
 
12
      this.range = range;
 
13
      this.current = this.range.start;
 
14
    }
 
15
     public int32 get () {
 
16
       return this.current;
 
17
     }
 
18
 
 
19
    public bool next () {
 
20
      if (!this.range.reverse) {
 
21
        if (this.current <= this.range.end) {
 
22
          this.current++;
 
23
          return true;
 
24
        }
 
25
      } else {
 
26
        if (this.current >= this.range.end){
 
27
          this.current--;
 
28
        }
 
29
      }
 
30
      return false;
 
31
    }
 
32
 
 
33
    public bool has_next () {
 
34
      return (this.current < this.range.end);
 
35
    }
 
36
  }
 
37
 
 
38
  public class Range {
 
39
    public bool reverse {get; private set;}
 
40
    public int32 start {get; private set;}
 
41
    public int32 end {get; private set;}
 
42
 
 
43
    public Range (int32 start, int32 end) {
 
44
      if (start <= end) {
 
45
        this.reverse = false;
 
46
      } else {
 
47
        this.reverse = true;
 
48
      }
 
49
      this.start = start;
 
50
      this.end = end;
 
51
    }
 
52
 
 
53
    public Type element_type () {
 
54
      return typeof (int);
 
55
    }
 
56
     
 
57
    public RangeIterator iterator () {
 
58
      return new RangeIterator (this);
 
59
    }
 
60
  }
 
61
}