summaryrefslogtreecommitdiffstats
path: root/src/UInt.vala
blob: 84e09aa99b907da82b19db6d2c00fbcfbe3bc631 (plain)
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
namespace Eva {
  public class UInt : Object, Term, Numeric {
    public ulong value {get; construct;}
    
    public int int_value {
      get {
        return (int)value;
      }
    }
    public uint uint_value {
      get {
        return (uint)value;
      }
    }
    public long long_value {
      get {
        return (long)value;
      }
    }
    public ulong ulong_value {
      get {
        return value;
      }
    }
    public double double_value {
      get {
        return value;
      }
    }
    
    public UInt(ulong v) {
      Object(value: v);
    }
    
    public string to_string() {
      return value.to_string();
    }
    
    protected bool do_match(Term o, Gee.Map<string, Term> vars, Gee.Map<string, string> aliases) {
      if(o is Var) {
        return o.do_match(this, vars, aliases);
      }
      
      if(o is Int) {
        return value == (o as Int).value;
      }
      else if(o is UInt) {
        return value == (o as UInt).value;
      }
      else {
        return false;
      }
    }

    
    public void encode(Erl.Buffer buffer) {
      buffer.encode_ulong(value);
    }
  }
}