1package types
2
3import (
4 "strings"
5
6 "github.com/bnema/puregotk/internal/gir/util"
7)
8
9func ConvertInterface(currns string, ins string, inter Interface, implemented map[string]bool, kinds KindMap) InterfaceTemplate {
10 var methods []InterfaceFuncTemplate
11
12 for _, m := range inter.Methods {
13 name := util.SnakeToCamel(m.Name)
14 if implemented != nil {
15 v, ok := implemented[name]
16 if v && ok {
17 continue
18 }
19 }
20 var newns string
21 if ins != "" {
22 newns = ins + "."
23 }
24 methods = append(methods, InterfaceFuncTemplate{
25 Namespace: newns,
26 FullName: util.SnakeToCamel(m.CIdentifier),
27 FuncTemplate: FuncTemplate{
28 Doc: m.Doc.StringSafe(),
29 CName: m.CIdentifier,
30 Name: name,
31 Args: m.Parameters.Template(currns, ins, kinds, m.Throws, ArgsFromGoToC),
32 Ret: m.ReturnValue.Template(currns, ins, kinds, m.Throws),
33 },
34 })
35 }
36
37 properties := make([]PropertyTemplate, 0, len(inter.Properties))
38 for _, prop := range inter.Properties {
39 propTemp := prop.Template(currns, kinds)
40
41 // TODO: Implement non-primitive types, then remove this
42 if propTemp.GValueType != "" {
43 properties = append(properties, propTemp)
44 }
45 }
46
47 name := util.SnakeToCamel(inter.Name)
48 return InterfaceTemplate{
49 Name: name,
50 Doc: inter.Doc.StringSafe(),
51 Methods: methods,
52 Properties: properties,
53 TypeGetter: inter.GLibGetType,
54 }
55}
56
57func GetInterfaceFuncs(ns string, name string, implemented map[string]bool, kinds KindMap) InterfaceTemplate {
58 inter := kinds.MustInterface(ns, name)
59 parts := strings.Split(name, ".")
60 var ins string
61 if len(parts) > 1 {
62 ins = strings.ToLower(parts[0])
63 }
64 return ConvertInterface(ns, ins, inter, implemented, kinds)
65}