10
type float32SliceValue struct {
15
func newFloat32SliceValue(val []float32, p *[]float32) *float32SliceValue {
16
isv := new(float32SliceValue)
22
func (s *float32SliceValue) Set(val string) error {
23
ss := strings.Split(val, ",")
24
out := make([]float32, len(ss))
25
for i, d := range ss {
28
temp64, err = strconv.ParseFloat(d, 32)
32
out[i] = float32(temp64)
38
*s.value = append(*s.value, out...)
44
func (s *float32SliceValue) Type() string {
48
func (s *float32SliceValue) String() string {
49
out := make([]string, len(*s.value))
50
for i, d := range *s.value {
51
out[i] = fmt.Sprintf("%f", d)
53
return "[" + strings.Join(out, ",") + "]"
56
func (s *float32SliceValue) fromString(val string) (float32, error) {
57
t64, err := strconv.ParseFloat(val, 32)
61
return float32(t64), nil
64
func (s *float32SliceValue) toString(val float32) string {
65
return fmt.Sprintf("%f", val)
68
func (s *float32SliceValue) Append(val string) error {
69
i, err := s.fromString(val)
73
*s.value = append(*s.value, i)
77
func (s *float32SliceValue) Replace(val []string) error {
78
out := make([]float32, len(val))
79
for i, d := range val {
81
out[i], err = s.fromString(d)
90
func (s *float32SliceValue) GetSlice() []string {
91
out := make([]string, len(*s.value))
92
for i, d := range *s.value {
93
out[i] = s.toString(d)
98
func float32SliceConv(val string) (interface{}, error) {
99
val = strings.Trim(val, "[]")
102
return []float32{}, nil
104
ss := strings.Split(val, ",")
105
out := make([]float32, len(ss))
106
for i, d := range ss {
109
temp64, err = strconv.ParseFloat(d, 32)
113
out[i] = float32(temp64)
120
func (f *FlagSet) GetFloat32Slice(name string) ([]float32, error) {
121
val, err := f.getFlagType(name, "float32Slice", float32SliceConv)
123
return []float32{}, err
125
return val.([]float32), nil
130
func (f *FlagSet) Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
131
f.VarP(newFloat32SliceValue(value, p), name, "", usage)
135
func (f *FlagSet) Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
136
f.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
141
func Float32SliceVar(p *[]float32, name string, value []float32, usage string) {
142
CommandLine.VarP(newFloat32SliceValue(value, p), name, "", usage)
146
func Float32SliceVarP(p *[]float32, name, shorthand string, value []float32, usage string) {
147
CommandLine.VarP(newFloat32SliceValue(value, p), name, shorthand, usage)
152
func (f *FlagSet) Float32Slice(name string, value []float32, usage string) *[]float32 {
154
f.Float32SliceVarP(&p, name, "", value, usage)
159
func (f *FlagSet) Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 {
161
f.Float32SliceVarP(&p, name, shorthand, value, usage)
167
func Float32Slice(name string, value []float32, usage string) *[]float32 {
168
return CommandLine.Float32SliceP(name, "", value, usage)
172
func Float32SliceP(name, shorthand string, value []float32, usage string) *[]float32 {
173
return CommandLine.Float32SliceP(name, shorthand, value, usage)