File: convert.go

package info (click to toggle)
golang-github-kshedden-dstream 0.0~git20190512.c4c4106-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 596 kB
  • sloc: makefile: 30
file content (46 lines) | stat: -rw-r--r-- 736 bytes parent folder | download
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
package dstream

import "fmt"

type convert struct {
	xform

	// The name of the variable to be converted
	vname string

	// The position of the variable to be converted
	vpos int

	// The new type of the variable
	dtype Dtype
}

// Convert returns a Dstream in which the named variable is converted
// to the given type.
func Convert(da Dstream, vname string, dtype Dtype) Dstream {

	vpos := -1
	for k, na := range da.Names() {
		if na == vname {
			vpos = k
			break
		}
	}
	if vpos == -1 {
		msg := fmt.Sprintf("Convert: no variable '%s'\n", vname)
		panic(msg)
	}

	c := &convert{
		xform: xform{
			source: da,
		},
		vname: vname,
		dtype: dtype,
		vpos:  vpos,
	}

	c.bdata = make([]interface{}, c.source.NumVar())

	return c
}