forked from pSpaces/goSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations.go
68 lines (54 loc) · 1.54 KB
/
transformations.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
60
61
62
63
64
65
66
67
68
package policy
// Transformations defines a structure for a collection of transformations to be applied.
type Transformations struct {
Tmpl Transformation
Mtch Transformation
Rslt Transformation
}
// NewTransformations creates a collection of transformations to be applied.
// NewTransformations returns a pointer to a collection if exactly 3 types of transformations are specified, otherwise nil is returned.
func NewTransformations(tr ...*Transformation) (trs *Transformations) {
if len(tr) != 3 {
trs = nil
} else {
trc := make([]Transformation, len(tr))
// Make a copy of the transformations.
for i := range tr {
if tr[i] != nil {
trans := tr[i]
function := trans.Function()
params := trans.Parameters()
ntr := NewTransformation(function, params...)
trc[i] = ntr
} else {
trc[i] = Transformation{}
}
}
trs = &Transformations{Tmpl: trc[0], Mtch: trc[1], Rslt: trc[2]}
}
return trs
}
// Template returns a transformation that can be applied to template entities.
func (trs *Transformations) Template() (trans *Transformation) {
trans = nil
if trs != nil {
trans = &trs.Tmpl
}
return trans
}
// Match returns an transformation that can be applied to matched entities.
func (trs *Transformations) Match() (match *Transformation) {
match = nil
if trs != nil {
match = &trs.Mtch
}
return match
}
// Result returns an transformation that can be applied to result entities.
func (trs *Transformations) Result() (rslt *Transformation) {
rslt = nil
if trs != nil {
rslt = &trs.Rslt
}
return rslt
}