/
TC_cb_compare_bool.go
59 lines (51 loc) · 1.15 KB
/
TC_cb_compare_bool.go
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
package ThreadComputation
import (
)
func TCCompareBoolString(name string, x interface{}, y interface{}) interface{} {
cfun := GetStringConverter()
if cfun == nil {
return nil
}
res := cfun(y, Bool)
if res == nil {
return nil
}
cmpfun := GetCompareCallback(x, res)
if cmpfun == nil {
return nil
}
return cmpfun(name, x, res)
}
func TCCompareStringBool(name string, x interface{}, y interface{}) interface{} {
cfun := GetStringConverter()
if cfun == nil {
return nil
}
res := cfun(x, Bool)
if res == nil {
return nil
}
cmpfun := GetCompareCallback(res, y)
if cmpfun == nil {
return nil
}
return cmpfun(name, res, y)
}
func TCCompareBoolBool(name string, x interface{}, y interface{}) interface{} {
switch name {
case "=":
return x.(bool) == y.(bool)
case "!=":
return x.(bool) != y.(bool)
case "and":
return x.(bool) && y.(bool)
case "or":
return x.(bool) || y.(bool)
}
return nil
}
func init() {
RegisterCompareCallback(Bool, Bool, TCCompareBoolBool)
RegisterCompareCallback(Bool, String, TCCompareBoolString)
RegisterCompareCallback(String, Bool, TCCompareStringBool)
}