Skip to content

Commit

Permalink
refactor(cpp): support for extern types
Browse files Browse the repository at this point in the history
  • Loading branch information
w4bremer committed Jul 9, 2024
1 parent 6d5f1a5 commit fa03ada
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
10 changes: 7 additions & 3 deletions pkg/gen/filters/filtercpp/cpp_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ func ToDefaultString(prefix string, schema *model.Schema) (string, error) {
text = "false"
case model.TypeExtern:
xe := parseCppExtern(schema)
if xe.NameSpace != "" {
prefix = fmt.Sprintf("%s::", xe.NameSpace)
if xe.Default != "" {
text = xe.Default
} else {
if xe.NameSpace != "" {
prefix = fmt.Sprintf("%s::", xe.NameSpace)
}
text = fmt.Sprintf("%s%s()", prefix, xe.Name)
}
text = fmt.Sprintf("%s%s()", prefix, xe.Name)
case model.TypeEnum:
e := schema.LookupEnum(schema.Import, schema.Type)
NameSpace := ""
Expand Down
7 changes: 7 additions & 0 deletions pkg/gen/filters/filtercpp/cpp_type_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func ToTypeRefString(prefix string, schema *model.Schema) (string, error) {
case "bool":
text = "bool"
default:
if schema.GetExtern() != nil {
xe := parseCppExtern(schema)
if xe.NameSpace != "" {
prefix = fmt.Sprintf("%s::", xe.NameSpace)
}
text = fmt.Sprintf("const %s%s&", prefix, xe.Name)
}
if schema.Import != "" {
prefix = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
Expand Down
30 changes: 21 additions & 9 deletions pkg/gen/filters/filtercpp/extern.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import (
)

type CppExtern struct {
NameSpace string
Include string
Name string
Library string
NameSpace string
Include string
Name string
Default string
Component string
Package string
ConanPackage string
ConanVersion string
}

func parseCppExtern(schema *model.Schema) CppExtern {
Expand All @@ -19,15 +23,23 @@ func parseCppExtern(schema *model.Schema) CppExtern {
func cppExtern(xe *model.Extern) CppExtern {
ns := xe.Meta.GetString("cpp.namespace")
inc := xe.Meta.GetString("cpp.include")
lib := xe.Meta.GetString("cpp.library")
name := xe.Meta.GetString("cpp.name")
dft := xe.Meta.GetString("cpp.default")
cmakePackage := xe.Meta.GetString("cpp.package")
cmakeComponent := xe.Meta.GetString("cpp.component")
conanPackage := xe.Meta.GetString("cpp.conanpackage")
conanVersion := xe.Meta.GetString("cpp.conanversion")
if name == "" {
name = xe.Name
}
return CppExtern{
NameSpace: ns,
Include: inc,
Name: name,
Library: lib,
NameSpace: ns,
Include: inc,
Name: name,
Default: dft,
Package: cmakePackage,
Component: cmakeComponent,
ConanPackage: conanPackage,
ConanVersion: conanVersion,
}
}

0 comments on commit fa03ada

Please sign in to comment.