/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/utils/range.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-21 22:39:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241221223917-jbt2ylyz9nxjss49
various changes
[utils/utils.vala]
* Removed uneeded int32_abs function

[utils/stack]
* more informative error when trying to pop an empty stack.

[utils/random.vala]
* added c_names to functions (probobly not needed).

[utils/pair.vala]
* Made compact
* made FreeFunc delegates unowned to fix error
* added constructor Pair.with_free_func ().

[utils/named_vector.vala]
* made class compact.

[utils/meson.build]
* Reordered files in list
* added logger.vala.

[utils/logger.vala]
* Added fast and easy logger class.

[utils/fast_number.vala]
* added a bunch of cname CCode attributes.

[general]
* Spelling in comments and functions.

[meson.build]
* Made dependancies easier to read
* added vala posix dependency

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
[CCode (cname = "V", cprefix = "v_")]
 
7
namespace Utils {
 
8
  [CCode (cname = "VRangeIterator", cprefix = "v_range_iterator_")]
 
9
  public class RangeIterator {
 
10
    private Range range;
 
11
    private int32 current;
 
12
    public RangeIterator (Range range) {
 
13
      this.range = range;
 
14
      this.current = this.range.start;
 
15
    }
 
16
     public int32 get () {
 
17
       return this.current;
 
18
     }
 
19
 
 
20
    public bool next () {
 
21
      if (!this.range.reverse) {
 
22
        if (this.current <= this.range.end) {
 
23
          this.current++;
 
24
          return true;
 
25
        }
 
26
      } else {
 
27
        if (this.current >= this.range.end){
 
28
          this.current--;
 
29
        }
 
30
      }
 
31
      return false;
 
32
    }
 
33
 
 
34
    public bool has_next () {
 
35
      return (this.current < this.range.end);
 
36
    }
 
37
  }
 
38
 
 
39
  [CCode (cname = "VRange", cprefix = "v_range_")]
 
40
  public class Range {
 
41
    public bool reverse {get; private set;}
 
42
    public int32 start {get; private set;}
 
43
    public int32 end {get; private set;}
 
44
 
 
45
    public Range (int32 start, int32 end) {
 
46
      if (start <= end) {
 
47
        this.reverse = false;
 
48
      } else {
 
49
        this.reverse = true;
 
50
      }
 
51
      this.start = start;
 
52
      this.end = end;
 
53
    }
 
54
 
 
55
    public Type element_type () {
 
56
      return typeof (int);
 
57
    }
 
58
     
 
59
    public RangeIterator iterator () {
 
60
      return new RangeIterator (this);
 
61
    }
 
62
  }
 
63
}