-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrow.go
More file actions
47 lines (39 loc) · 762 Bytes
/
row.go
File metadata and controls
47 lines (39 loc) · 762 Bytes
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
package data
import (
"fmt"
"reflect"
"strings"
)
type Row struct {
Factory RowFactory
Data []Cell
}
func (r *Row) Recycle() {
r.Factory.Recycle(r)
}
func (r *Row) Width() int {
return r.Factory.Width()
}
func (r *Row) Index(name string) (int, bool) {
return r.Factory.Index(name)
}
func (r *Row) At(i int) Cell {
if i >= 0 && i < len(r.Data) {
return r.Data[i]
}
return Cell{}
}
func (r *Row) Col(n string) Cell {
if i, ok := r.Index(n); ok {
return r.Data[i]
}
return Cell{}
}
func (r Row) String() string {
var ss []string
for i := 0; i < len(r.Data); i++ {
n := r.Factory.Name(i)
ss = append(ss, fmt.Sprintf("%s: %v(%v)", n, reflect.TypeOf(r.Data[i].Val), r.Data[i].Val))
}
return "Row{" + strings.Join(ss, ", ") + "}"
}