first commit
This commit is contained in:
60
internal/codegen/templates/class.tmpl
Normal file
60
internal/codegen/templates/class.tmpl
Normal file
@ -0,0 +1,60 @@
|
||||
{{if not .IsAbstract}}
|
||||
const Signature{{.Name}} string = "{{.Signature}}"
|
||||
|
||||
type {{.Name}} struct {
|
||||
ole.IUnknown
|
||||
}
|
||||
|
||||
{{if .HasEmptyConstructor}}
|
||||
func New{{.Name}}() (*{{.Name}}, error) {
|
||||
inspectable, err := ole.RoActivateInstance("{{.FullyQualifiedName}}")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return (*{{.Name}})(unsafe.Pointer(inspectable)), nil
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{$owner := .Name}}
|
||||
{{range .ImplInterfaces}}
|
||||
{{range .Funcs}}
|
||||
{{if not .Implement}}{{continue}}{{end}}
|
||||
func (impl *{{$owner}}) {{funcName .}} (
|
||||
{{- range .InParams -}}
|
||||
{{/*do not include out parameters, they are used as return values*/ -}}
|
||||
{{ if .IsOut }}{{continue}}{{ end -}}
|
||||
{{.GoVarName}} {{template "variabletype.tmpl" . }},
|
||||
{{- end -}}
|
||||
)
|
||||
|
||||
{{- /* return params */ -}}
|
||||
|
||||
( {{range .InParams -}}
|
||||
{{ if not .IsOut }}{{continue}}{{ end -}}
|
||||
{{template "variabletype.tmpl" . }},{{end -}}
|
||||
{{range .ReturnParams}}{{template "variabletype.tmpl" . }},{{end}} error )
|
||||
|
||||
{{- /* method body */ -}}
|
||||
|
||||
{
|
||||
itf := impl.MustQueryInterface(ole.NewGUID({{if .InheritedFrom.Namespace}}{{.InheritedFrom.Namespace}}.{{end}}GUID{{.InheritedFrom.Name}}))
|
||||
defer itf.Release()
|
||||
v := (*{{if .InheritedFrom.Namespace}}{{.InheritedFrom.Namespace}}.{{end}}{{.InheritedFrom.Name}})(unsafe.Pointer(itf))
|
||||
return v.{{funcName . -}}
|
||||
(
|
||||
{{- range .InParams -}}
|
||||
{{if .IsOut -}}
|
||||
{{continue -}}
|
||||
{{end -}}
|
||||
{{.GoVarName -}}
|
||||
,
|
||||
{{- end -}}
|
||||
)
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{range .ExclusiveInterfaces}}
|
||||
{{ template "interface.tmpl" .}}
|
||||
{{end}}
|
Reference in New Issue
Block a user