-
Notifications
You must be signed in to change notification settings - Fork 2
/
bindings_gen.go
54 lines (45 loc) · 1.26 KB
/
bindings_gen.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
//go:build ignore
// +build ignore
package main
import (
"os"
"strings"
"text/template"
"unicode"
)
type Instance struct {
Functions map[string]string
}
func ConvertName(name string) string {
convertedName := ""
for _, word := range strings.Split(name, "_") {
r := []rune(word)
convertedName += string(append([]rune{unicode.ToUpper(r[0])}, r[1:]...))
}
return convertedName
}
func writeTemplate(instance *Instance, templatePath, outputPath string) {
tl, err := template.ParseFiles(templatePath)
if err != nil {
panic(err)
}
out, err := os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
panic(err)
}
if err = tl.Execute(out, *instance); err != nil {
panic(err)
}
}
func main() {
fn := []string{"route", "locate", "optimized_route", "matrix", "isochrone", "trace_route", "trace_attributes", "height", "transit_available", "expansion", "centroid", "status"}
instance := Instance{
Functions: map[string]string{},
}
for _, v := range fn {
instance.Functions[v] = ConvertName(v)
}
writeTemplate(&instance, "templates/valhalla_go.templ.cpp", "bindings/valhalla_go.cpp")
writeTemplate(&instance, "templates/valhalla_go.templ.h", "bindings/valhalla_go.h")
writeTemplate(&instance, "templates/valhalla.templ.go", "valhalla.go")
}