forked from ctiom/kitchen
-
Notifications
You must be signed in to change notification settings - Fork 10
/
set.go
68 lines (58 loc) · 1.29 KB
/
set.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
package kitchen
import (
"sync"
)
// SetBase is a struct for supporting ISet, can treat as a sub menu.
type SetBase[D ICookware] struct {
cookbook[D, any, any]
_menu iMenu[D]
name string
parentSet []iSet[D]
self iSet[D]
path *string
}
func initSet[D ICookware](menu iMenu[D], group iSet[D], parent iSet[D], name string) {
group.init(menu, group, parent, name)
}
func (s *SetBase[D]) init(p iMenu[D], group, parent iSet[D], name string) {
s.cookbook.init()
s._menu = p
s.self = group
s.name = name
s.instance = group
s.concurrentLimit = new(int32)
s.running = new(int32)
s.spinLocker = &sync.Mutex{}
s.runningLock = &sync.Mutex{}
if parent != nil {
s.parentSet = parent.tree()
}
s.nodes = iterateStruct(group, p, group, p.cookware())
}
func (s *SetBase[D]) OverridePath(path string) *SetBase[D] {
s.path = &path
return s
}
func (s SetBase[D]) Menu() IMenu {
return s._menu
}
func (s SetBase[D]) menu() iMenu[D] {
return s._menu
}
func (s SetBase[D]) Name() string {
if s.path != nil {
return *s.path
}
return s.name
}
func (s SetBase[D]) tree() []iSet[D] {
return append([]iSet[D]{s.self}, s.parentSet...)
}
func (s SetBase[D]) Tree() []ISet {
nodes := s.tree()
res := make([]ISet, len(nodes))
for i, node := range nodes {
res[i] = node
}
return res
}