Skip to content

Commit

Permalink
lcio: make Float,Int,StrVec stringers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Apr 21, 2017
1 parent de1b57c commit f624bd1
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions lcio/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,37 @@ type FloatVec struct {
Elements [][]float32
}

func (vec FloatVec) String() string {
o := new(bytes.Buffer)
fmt.Fprintf(o, "%[1]s print out of LCFloatVec collection %[1]s\n\n", strings.Repeat("-", 15))
fmt.Fprintf(o, " flag: 0x%x\n%v", vec.Flags, vec.Params)
fmt.Fprintf(o, "\n")

const (
head = " [ id ] | val0, val1, ...\n"
tail = "------------|----------------\n"
)
fmt.Fprintf(o, head)
fmt.Fprintf(o, tail)
for _, slice := range vec.Elements {
fmt.Fprintf(o, " [%08d] |",
0, //id
)
for i, v := range slice {
if i > 0 {
fmt.Fprintf(o, ", ")
}
if i+1%10 == 0 {
fmt.Fprintf(o, "\n ")
}
fmt.Fprintf(o, "%8f", v)
}
fmt.Fprintf(o, "\n")
}
fmt.Fprintf(o, tail)
return string(o.Bytes())
}

func (*FloatVec) VersionSio() uint32 {
return Version
}
Expand Down Expand Up @@ -67,6 +98,37 @@ type IntVec struct {
Elements [][]int32
}

func (vec IntVec) String() string {
o := new(bytes.Buffer)
fmt.Fprintf(o, "%[1]s print out of LCIntVec collection %[1]s\n\n", strings.Repeat("-", 15))
fmt.Fprintf(o, " flag: 0x%x\n%v", vec.Flags, vec.Params)
fmt.Fprintf(o, "\n")

const (
head = " [ id ] | val0, val1, ...\n"
tail = "------------|----------------\n"
)
fmt.Fprintf(o, head)
fmt.Fprintf(o, tail)
for _, slice := range vec.Elements {
fmt.Fprintf(o, " [%08d] |",
0, //id
)
for i, v := range slice {
if i > 0 {
fmt.Fprintf(o, ", ")
}
if i+1%10 == 0 {
fmt.Fprintf(o, "\n ")
}
fmt.Fprintf(o, "%8d", v)
}
fmt.Fprintf(o, "\n")
}
fmt.Fprintf(o, tail)
return string(o.Bytes())
}

func (*IntVec) VersionSio() uint32 {
return Version
}
Expand Down Expand Up @@ -116,6 +178,37 @@ type StrVec struct {
Elements [][]string
}

func (vec StrVec) String() string {
o := new(bytes.Buffer)
fmt.Fprintf(o, "%[1]s print out of LCStrVec collection %[1]s\n\n", strings.Repeat("-", 15))
fmt.Fprintf(o, " flag: 0x%x\n%v", vec.Flags, vec.Params)
fmt.Fprintf(o, "\n")

const (
head = " [ id ] | val0, val1, ...\n"
tail = "------------|----------------\n"
)
fmt.Fprintf(o, head)
fmt.Fprintf(o, tail)
for _, slice := range vec.Elements {
fmt.Fprintf(o, " [%08d] |",
0, //id
)
for i, v := range slice {
if i > 0 {
fmt.Fprintf(o, ", ")
}
if i+1%10 == 0 {
fmt.Fprintf(o, "\n ")
}
fmt.Fprintf(o, "%s", v)
}
fmt.Fprintf(o, "\n")
}
fmt.Fprintf(o, tail)
return string(o.Bytes())
}

func (*StrVec) VersionSio() uint32 {
return Version
}
Expand Down

0 comments on commit f624bd1

Please sign in to comment.