-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtomb.go
87 lines (69 loc) · 1.38 KB
/
tomb.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package gone
import (
"reflect"
)
func NewTomb(goner Goner) Tomb {
return &tomb{
goner: goner,
defaultTypes: make(map[reflect.Type]void),
order: Order3,
}
}
type void struct{}
var voidValue void
type tomb struct {
id GonerId
goner Goner
reviveFlag bool
defaultTypes map[reflect.Type]void
order Order
}
func (t *tomb) SetId(id GonerId) Tomb {
t.id = id
return t
}
func (t *tomb) GetId() GonerId {
return t.id
}
func (t *tomb) GetGoner() Goner {
return t.goner
}
func (t *tomb) GonerIsRevive(flags ...bool) bool {
if len(flags) > 0 {
t.reviveFlag = flags[0]
}
return t.reviveFlag
}
type Tombs []Tomb
func (tombs Tombs) Len() int {
return len(tombs)
}
func (tombs Tombs) Less(i, j int) bool {
return tombs[i].GetOrder() < tombs[j].GetOrder()
}
func (tombs Tombs) Swap(i, j int) {
tombs[i], tombs[j] = tombs[j], tombs[i]
}
func (tombs Tombs) GetTomByType(t reflect.Type) (filterTombs []Tomb) {
for _, tomb := range tombs {
if IsCompatible(t, tomb.GetGoner()) {
filterTombs = append(filterTombs, tomb)
}
}
return
}
func (t *tomb) IsDefault(T reflect.Type) bool {
_, existed := t.defaultTypes[T]
return existed
}
func (t *tomb) SetDefault(T reflect.Type) Tomb {
t.defaultTypes[T] = voidValue
return t
}
func (t *tomb) GetOrder() Order {
return t.order
}
func (t *tomb) SetOrder(order Order) Tomb {
t.order = order
return t
}