diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-10 01:23:07 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-10 01:23:07 +0200 |
commit | f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a (patch) | |
tree | ded56a166ef4648061379bab6c65bc40e5d01f8d /src/Pid.vala | |
parent | 2fc49125e73554d68b4ee8874b9f84725b6f2157 (diff) | |
download | eva-f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a.tar eva-f87943409c8ae2e9f6ed81e7a1cfc5109c16f31a.zip |
Split Term code to individual class sources
Diffstat (limited to 'src/Pid.vala')
-rw-r--r-- | src/Pid.vala | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/Pid.vala b/src/Pid.vala new file mode 100644 index 0000000..3f71df7 --- /dev/null +++ b/src/Pid.vala @@ -0,0 +1,48 @@ +namespace Eva { + public class Pid : Object, Term { + public string node {get; construct;} + public uint num {get; construct;} + public uint serial {get; construct;} + public uint creation {get; construct;} + + public Pid(Erl.Pid pid) { + this.create(array_to_string(pid.node, Erl.MAXATOMLEN), pid.num, pid.serial, pid.creation); + } + + private Pid.create(string node0, uint num0, uint serial0, uint creation0) { + Object(node: node0, num: num0, serial: serial0, creation: creation0); + } + + public string to_string() { + return "<" + node + "." + num.to_string() + "." + serial.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 Pid)) + return false; + + Pid p = o as Pid; + + return (node == p.node && num == p.num && serial == p.serial && creation == p.creation); + } + + public void encode(Erl.Buffer buffer) { + Erl.Pid pid = Erl.Pid(); + char[]? nodedata = string_to_array(node); + assert(nodedata != null); + + Memory.copy(pid.node, nodedata, int.min(Erl.MAXATOMLEN, nodedata.length)); + pid.node[int.min(Erl.MAXATOMLEN, nodedata.length)] = 0; + + pid.num = num; + pid.serial = serial; + pid.creation = creation; + + buffer.encode_pid(pid); + } + } +} |