-
Notifications
You must be signed in to change notification settings - Fork 9
/
geommethods.go.tmpl
145 lines (125 loc) · 4.38 KB
/
geommethods.go.tmpl
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This file is automatically generated. DO NOT EDIT.
package geos
// #include "go-geos.h"
import "C"
import "unsafe"
{{- range . }}
{{- $geosFunction := printf "GEOS%s_r" .name }}
{{- if .geosFunction }}
{{- if eq .geosFunction $geosFunction }}
{{- with printf "%s: do not set default .geosFunction" .name }}
{{- fatal . }}
{{- end }}
{{- end }}
{{- $geosFunction = .geosFunction }}
{{- end }}
{{- if not .comment }}
{{ with printf "%s: comment not set" .name }}
{{- fatal . }}
{{- end }}
{{- end }}
{{- if eq .type "unary" }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}({{ range $index, $arg := .extraArgs }}{{ if $index }}, {{ end }}{{ $arg.name }} {{ $arg.type }}{{ end }}) *Geom {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
return g.context.new{{ if not .nil }}NonNil{{ end }}Geom(C.{{ $geosFunction }}(g.context.handle, g.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }}), nil)
}
{{- else if eq .type "binary" }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}(other *Geom{{ range .extraArgs }}, {{ .name }} {{ .type }}{{ end }}) *Geom {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
if other.context != g.context {
other.context.Lock()
defer other.context.Unlock()
}
return g.context.newGeom(C.{{ $geosFunction }}(g.context.handle, g.geom, other.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }}), nil)
}
{{- else if eq .type "unaryPredicate" }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}() bool {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
switch C.{{ $geosFunction }}(g.context.handle, g.geom) {
case 0:
return false
case 1:
return true
default:
panic(g.context.err)
}
}
{{- else if eq .type "binaryPredicate" }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}(other *Geom{{ range .extraArgs }}, {{ .name }} {{ .type }}{{ end }}) bool {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
if other.context != g.context {
other.context.Lock()
defer other.context.Unlock()
}
switch C.{{ $geosFunction }}(g.context.handle, g.geom, other.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }}) {
case 0:
return false
case 1:
return true
default:
panic(g.context.err)
}
}
{{- else if eq .type "float64Property" }}
{{- $varName := .name | firstRuneToLower }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}() float64 {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
var {{ $varName }} float64
if C.{{ $geosFunction }}(g.context.handle, g.geom, (*C.double)(&{{ $varName }})) == 0 {
panic(g.context.err)
}
return {{ $varName }}
}
{{- else if eq .type "float64BinaryProperty" }}
{{- $varName := .name | firstRuneToLower }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}(other *Geom{{ range .extraArgs }}, {{ .name }} {{ .type }}{{ end }}) float64 {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
if other.context != g.context {
other.context.Lock()
defer other.context.Unlock()
}
{{- if .valueReturned }}
return float64(C.{{ $geosFunction }}(g.context.handle, g.geom, other.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }}))
{{- else }}
var {{ $varName }} float64
if C.{{ $geosFunction }}(g.context.handle, g.geom, other.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }}, (*C.double)(&{{ $varName }})) == 0 {
panic(g.context.err)
}
return {{ $varName }}
{{- end }}
}
{{- else if eq .type "stringBinaryProperty" }}
{{- $varName := .name | firstRuneToLower }}
{{ if .comment }}// {{ .name }} {{ .comment }}.{{ end }}
func (g *Geom) {{ .name }}(other *Geom{{ range .extraArgs }}, {{ .name }} {{ .type }}{{ end }}) string {
g.mustNotBeDestroyed()
g.context.Lock()
defer g.context.Unlock()
if other.context != g.context {
other.context.Lock()
defer other.context.Unlock()
}
{{ $varName }}CStr := C.{{ $geosFunction }}(g.context.handle, g.geom, other.geom{{ range .extraArgs }}, {{ .type | cType }}({{ .name }}){{ end }})
defer C.GEOSFree_r(g.context.handle, unsafe.Pointer({{ $varName }}CStr))
return C.GoString({{ $varName }}CStr)
}
{{- end }}
{{- end }}