@@ -59,16 +59,18 @@ def safename(name: str) -> str:
59
59
classname = re .sub ("[^a-zA-Z0-9]" , "_" , name )
60
60
return replaceKeywords (classname )
61
61
62
+
62
63
def safenamespacename (name : str ) -> str :
63
64
"""Create a C++ safe name for namespaces"""
64
- name = re .sub ("^[a-zA-Z0-9]+://" , "" , name ) # remove protocol
65
- name = re .sub ("//+" , "" , name ) # remove duplicate slashes
66
- name = re .sub ("/$" , "" , name ) # remove trailing slashes
65
+ name = re .sub ("^[a-zA-Z0-9]+://" , "" , name ) # remove protocol
66
+ name = re .sub ("//+" , "" , name ) # remove duplicate slashes
67
+ name = re .sub ("/$" , "" , name ) # remove trailing slashes
67
68
name = re .sub ("[^a-zA-Z0-9/]" , "_" , name )
68
69
name = re .sub ("[/]" , "::" , name )
69
70
70
71
return name
71
72
73
+
72
74
# TODO: this should be somehow not really exists
73
75
def safename2 (name : dict [str , str ]) -> str :
74
76
"""Create a namespaced safename."""
@@ -122,7 +124,9 @@ def writeFwdDeclaration(self, target: IO[str], fullInd: str, ind: str) -> None:
122
124
"""Write forward declaration."""
123
125
target .write (f"{ fullInd } namespace { self .namespace } {{ struct { self .classname } ; }}\n " )
124
126
125
- def writeDefinition (self , target : IO [Any ], fullInd : str , ind : str , common_namespace : str ) -> None :
127
+ def writeDefinition (
128
+ self , target : IO [Any ], fullInd : str , ind : str , common_namespace : str
129
+ ) -> None :
126
130
"""Write definition of the class."""
127
131
target .write (f"{ fullInd } namespace { self .namespace } {{\n " )
128
132
target .write (f"{ fullInd } struct { self .classname } " )
@@ -151,7 +155,9 @@ def writeDefinition(self, target: IO[Any], fullInd: str, ind: str, common_namesp
151
155
target .write (f"{ fullInd } }};\n " )
152
156
target .write (f"{ fullInd } }}\n \n " )
153
157
154
- def writeImplDefinition (self , target : IO [str ], fullInd : str , ind : str , common_namespace : str ) -> None :
158
+ def writeImplDefinition (
159
+ self , target : IO [str ], fullInd : str , ind : str , common_namespace : str
160
+ ) -> None :
155
161
"""Write definition with implementation."""
156
162
extends = list (map (safename2 , self .extends ))
157
163
@@ -300,7 +306,9 @@ def writeDefinition(self, target: IO[str], ind: str, common_namespace: str) -> N
300
306
target .write ("};\n " )
301
307
target .write ("}\n \n " )
302
308
303
- def writeImplDefinition (self , target : IO [str ], fullInd : str , ind : str , common_namespace : str ) -> None :
309
+ def writeImplDefinition (
310
+ self , target : IO [str ], fullInd : str , ind : str , common_namespace : str
311
+ ) -> None :
304
312
"""Write definition with implementation."""
305
313
# Write toYaml function
306
314
functionname = f"{ self .namespace } ::{ self .classname } ::toYaml"
@@ -356,7 +364,9 @@ def writeDefinition(self, target: IO[str], ind: str, common_namespace: str) -> N
356
364
target .write ("};\n " )
357
365
target .write ("}\n \n " )
358
366
359
- def writeImplDefinition (self , target : IO [str ], fullInd : str , ind : str , common_namespace : str ) -> None :
367
+ def writeImplDefinition (
368
+ self , target : IO [str ], fullInd : str , ind : str , common_namespace : str
369
+ ) -> None :
360
370
"""Write definition with implementation."""
361
371
# Write constructor
362
372
functionname = f"{ self .namespace } ::{ self .classname } ::{ self .classname } "
@@ -695,7 +705,14 @@ def convertTypeToCpp(self, type_declaration: Union[list[Any], dict[str, Any], st
695
705
def epilogue (self , root_loader : Optional [TypeDef ]) -> None :
696
706
# find common namespace
697
707
698
- common_namespace = os .path .commonprefix (list (map (lambda x : x .namespace , list (self .classDefinitions .values ()) + list (self .enumDefinitions .values ()))))
708
+ common_namespace = os .path .commonprefix (
709
+ list (
710
+ map (
711
+ lambda x : x .namespace ,
712
+ list (self .classDefinitions .values ()) + list (self .enumDefinitions .values ()),
713
+ )
714
+ )
715
+ )
699
716
common_namespace = re .sub ("(::)+$" , "" , common_namespace )
700
717
701
718
"""Generate final part of our cpp file."""
@@ -738,7 +755,8 @@ def epilogue(self, root_loader: Optional[TypeDef]) -> None:
738
755
)
739
756
740
757
self .target .write (f"namespace { common_namespace } {{\n " )
741
- self .target .write ("""
758
+ self .target .write (
759
+ """
742
760
struct store_config {
743
761
bool simplifyTypes = true;
744
762
bool transformListsToMaps = true;
@@ -1145,12 +1163,15 @@ class heap_object {
1145
1163
1146
1164
# write implementations
1147
1165
for key in self .classDefinitions :
1148
- self .classDefinitions [key ].writeImplDefinition (self .target , "" , " " , common_namespace )
1166
+ self .classDefinitions [key ].writeImplDefinition (
1167
+ self .target , "" , " " , common_namespace
1168
+ )
1149
1169
for key in self .mapDefinitions :
1150
1170
self .mapDefinitions [key ].writeImplDefinition (self .target , "" , " " , common_namespace )
1151
1171
for key in self .unionDefinitions :
1152
- self .unionDefinitions [key ].writeImplDefinition (self .target , "" , " " , common_namespace )
1153
-
1172
+ self .unionDefinitions [key ].writeImplDefinition (
1173
+ self .target , "" , " " , common_namespace
1174
+ )
1154
1175
1155
1176
self .target .write (f"namespace { common_namespace } {{\n " )
1156
1177
self .target .write (
0 commit comments