/
TC_cb_generator_list.go
59 lines (52 loc) · 1.21 KB
/
TC_cb_generator_list.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 (
log "github.com/sirupsen/logrus"
)
func tcGetNFromList(res *TCIterator, i int64) interface{} {
if i < 0 || i >= int64(res.Gen.(*TCList).Len()) {
res.Last = nil
return nil
}
log.Debugf("list-iterator: getting value at %v", i)
e := res.Gen.(*TCList).Q.At(int(i))
if e == nil {
res.Last = nil
return nil
}
res.Last = e
return e
}
func ListGenerator(v interface{}) *TCIterator {
switch e := v.(type) {
case *TCList:
log.Debug("iterator: create iterator for List")
res := new(TCIterator)
res.Type = List
res.Gen = e
res.Last = nil
res.Set("current", int64(0))
return res
}
return nil
}
func ListNext(res *TCIterator) interface{} {
i := res.Get("current").(int64)
log.Debugf("%v(s) element from list", i)
out := tcGetNFromList(res, i)
i = i + 1
res.Set("current", i)
return out
}
func ListPrev(res *TCIterator) interface{} {
i := res.Get("current").(int64)
log.Debugf("%v(s) element from list", i)
out := tcGetNFromList(res, i)
i = i - 1
res.Set("current", i)
return out
}
func init() {
RegisterGenCallback(List, ListGenerator)
RegisterNextCallback(List, ListNext)
RegisterPrevCallback(List, ListPrev)
}