/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
1
using VQDR.Common;
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
    
11
    public Variable (int min = 0, int max = 0, int 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
    
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
24
    public long compare (Variable other) {
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
      
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
34
      // // this should be correct.
35
      // return (current_val.compare (other.current_val)) +
36
      //        (max_val.compare (other.max_val)) +
37
      //        (min_val.compare (other.min_val));
38
      // ------------------------------------------
39
      // if (this.current_val > other.current_val) {
40
      //   return -1;
41
      // } else if (this.current_val < other.current_val) {
42
      //   return 1;
43
      // } else {
44
      //   if (this.max_val > other.max_val) {
45
      //     return -1;
46
      //   } else if (this.max_val < other.max_val) {
47
      //     return 1;
48
      //   } else {
49
      //     if (this.min_val > other.min_val) {
50
      //       return -1;
51
      //     } else if (this.min_val < other.min_val) {
52
      //       return 1;
53
      //     } // End min_val comp.
54
      //   } // End max_val comp
55
      // } // End current_val Comp
56
      // return 0; // They are exacly the same.
1 by Gustav Hartvigsson
* Initial code - far from done
57
    }
58
    
59
    /**
60
     * Compares two Variables.
61
     * 
62
     * This is the same as @c compare. It is an alias to the same C function.
63
     */
64
    [CCode (cname = "vqdr_expression_variable_equals")]
65
    public static extern int static_compare (Variable a, Variable b);
66
    
67
    /**
68
     * Is this instance equal to the other?
69
     */
70
    public bool equals (Variable other) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
71
      return !(bool) this.compare (other);
1 by Gustav Hartvigsson
* Initial code - far from done
72
    }
73
    
74
    public bool equals_values (int min, int max, int current) {
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
75
      return (this.current_val.number == current) &&
76
             (this.max_val.number == max) &&
77
             (this.min_val.number == min);
1 by Gustav Hartvigsson
* Initial code - far from done
78
    }
79
    
80
    
81
    
82
    public string to_string () {
83
      StringBuilder s = new StringBuilder ();
84
      s.append("(Variable: ");
31 by Gustav Hartvigsson
Changed over the Variabel class to use FastNumers
85
      s.append_printf ("(max_val: %s, ", max_val.to_string (true));
86
      s.append_printf ("min_val: %s, ", max_val.to_string (true));
87
      s.append_printf ("current_val: %s)", current_val.to_string (true));
1 by Gustav Hartvigsson
* Initial code - far from done
88
      s.append(")");
89
      return s.str;
90
    }
91
  }
92
}