/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
64 by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming.
1
using Vee;
1 by Gustav Hartvigsson
* Initial code - far from done
2
namespace VQDR.Expression {
3
  /**
4
   * Represents a variable.
5
   */
6
  public struct Variable {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
7
    public FastNumber min_val;
8
    public FastNumber max_val;
9
    public FastNumber current_val;
1 by Gustav Hartvigsson
* Initial code - far from done
10
    
52.1.3 by Gustav Hartvigsson
int -> int32
11
    public Variable (int32 min = 0, int32 max = 0, uint32 current = 0) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
12
      this.max_val.number = max;
13
      this.min_val.number = min;
14
      this.current_val.number = current;
1 by Gustav Hartvigsson
* Initial code - far from done
15
    }
16
    
17
    [CCode (cname = "vqdr_expression_variable_copy")]
18
    public Variable.copy (Variable other) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
19
      this.max_val.copy (other.max_val);
20
      this.min_val.copy (other.min_val);
21
      this.current_val.copy (other.current_val);
1 by Gustav Hartvigsson
* Initial code - far from done
22
    }
23
    
52.1.1 by Gustav Hartvigsson
Use int64 instead of long.
24
    public int64 compare (Variable other) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
25
      if (! this.current_val.equals (other.current_val)) {
26
        return this.current_val.compare (other.current_val);
27
      } else if (! this.max_val.equals (other.max_val)) {
28
        return this.max_val.compare (other.max_val);
29
      } else if (! this.min_val.equals (other.min_val)) {
30
        return this.min_val.compare (other.min_val);
31
      }
32
      return 0;
1 by Gustav Hartvigsson
* Initial code - far from done
33
    }
34
    
35
    /**
36
     * Compares two Variables.
37
     * 
38
     * This is the same as @c compare. It is an alias to the same C function.
39
     */
40
    [CCode (cname = "vqdr_expression_variable_equals")]
52.1.3 by Gustav Hartvigsson
int -> int32
41
    public static extern int32 static_compare (Variable a, Variable b);
1 by Gustav Hartvigsson
* Initial code - far from done
42
    
43
    /**
44
     * Is this instance equal to the other?
45
     */
46
    public bool equals (Variable other) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
47
      return !(bool) this.compare (other);
1 by Gustav Hartvigsson
* Initial code - far from done
48
    }
49
    
52.1.3 by Gustav Hartvigsson
int -> int32
50
    public bool equals_values (int32 min, int32 max, int32 current) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
51
      return (this.current_val.number == current) &&
52
             (this.max_val.number == max) &&
53
             (this.min_val.number == min);
1 by Gustav Hartvigsson
* Initial code - far from done
54
    }
55
    
56
    
57
    
58
    public string to_string () {
59
      StringBuilder s = new StringBuilder ();
60
      s.append("(Variable: ");
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
61
      s.append_printf ("(max_val: %s, ", max_val.to_string (true));
62
      s.append_printf ("min_val: %s, ", max_val.to_string (true));
63
      s.append_printf ("current_val: %s)", current_val.to_string (true));
1 by Gustav Hartvigsson
* Initial code - far from done
64
      s.append(")");
65
      return s.str;
66
    }
67
  }
68
}