quicktype 18.0.5 → 19.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +1 -1
  2. package/dist/{cli/CompressedJSONFromStream.d.ts → CompressedJSONFromStream.d.ts} +1 -1
  3. package/dist/{cli/CompressedJSONFromStream.js → CompressedJSONFromStream.js} +2 -2
  4. package/dist/{cli/GraphQLIntrospection.d.ts → GraphQLIntrospection.d.ts} +0 -0
  5. package/dist/{cli/GraphQLIntrospection.js → GraphQLIntrospection.js} +1 -1
  6. package/dist/{cli/TypeSource.d.ts → TypeSource.d.ts} +2 -2
  7. package/dist/{cli/TypeSource.js → TypeSource.js} +0 -0
  8. package/dist/{cli/URLGrammar.d.ts → URLGrammar.d.ts} +0 -0
  9. package/dist/{cli/URLGrammar.js → URLGrammar.js} +1 -1
  10. package/dist/{cli/index.d.ts → index.d.ts} +1 -1
  11. package/dist/{cli/index.js → index.js} +4 -5
  12. package/package.json +61 -77
  13. package/dist/quicktype-core/Annotation.d.ts +0 -8
  14. package/dist/quicktype-core/Annotation.js +0 -16
  15. package/dist/quicktype-core/ConvenienceRenderer.d.ts +0 -138
  16. package/dist/quicktype-core/ConvenienceRenderer.js +0 -668
  17. package/dist/quicktype-core/DateTime.d.ts +0 -10
  18. package/dist/quicktype-core/DateTime.js +0 -57
  19. package/dist/quicktype-core/DeclarationIR.d.ts +0 -14
  20. package/dist/quicktype-core/DeclarationIR.js +0 -167
  21. package/dist/quicktype-core/EncodedMarkovChain.d.ts +0 -1
  22. package/dist/quicktype-core/EncodedMarkovChain.js +0 -4
  23. package/dist/quicktype-core/GatherNames.d.ts +0 -2
  24. package/dist/quicktype-core/GatherNames.js +0 -333
  25. package/dist/quicktype-core/Graph.d.ts +0 -12
  26. package/dist/quicktype-core/Graph.js +0 -220
  27. package/dist/quicktype-core/GraphRewriting.d.ts +0 -87
  28. package/dist/quicktype-core/GraphRewriting.js +0 -421
  29. package/dist/quicktype-core/MakeTransformations.d.ts +0 -4
  30. package/dist/quicktype-core/MakeTransformations.js +0 -193
  31. package/dist/quicktype-core/MarkovChain.d.ts +0 -15
  32. package/dist/quicktype-core/MarkovChain.js +0 -154
  33. package/dist/quicktype-core/Messages.d.ts +0 -294
  34. package/dist/quicktype-core/Messages.js +0 -105
  35. package/dist/quicktype-core/Naming.d.ts +0 -64
  36. package/dist/quicktype-core/Naming.js +0 -356
  37. package/dist/quicktype-core/Renderer.d.ts +0 -50
  38. package/dist/quicktype-core/Renderer.js +0 -274
  39. package/dist/quicktype-core/RendererOptions.d.ts +0 -71
  40. package/dist/quicktype-core/RendererOptions.js +0 -141
  41. package/dist/quicktype-core/Run.d.ts +0 -174
  42. package/dist/quicktype-core/Run.js +0 -393
  43. package/dist/quicktype-core/Source.d.ts +0 -65
  44. package/dist/quicktype-core/Source.js +0 -204
  45. package/dist/quicktype-core/TargetLanguage.d.ts +0 -34
  46. package/dist/quicktype-core/TargetLanguage.js +0 -66
  47. package/dist/quicktype-core/Transformers.d.ts +0 -209
  48. package/dist/quicktype-core/Transformers.js +0 -836
  49. package/dist/quicktype-core/Type.d.ts +0 -206
  50. package/dist/quicktype-core/Type.js +0 -716
  51. package/dist/quicktype-core/TypeBuilder.d.ts +0 -61
  52. package/dist/quicktype-core/TypeBuilder.js +0 -324
  53. package/dist/quicktype-core/TypeGraph.d.ts +0 -75
  54. package/dist/quicktype-core/TypeGraph.js +0 -420
  55. package/dist/quicktype-core/TypeUtils.d.ts +0 -33
  56. package/dist/quicktype-core/TypeUtils.js +0 -230
  57. package/dist/quicktype-core/UnifyClasses.d.ts +0 -16
  58. package/dist/quicktype-core/UnifyClasses.js +0 -159
  59. package/dist/quicktype-core/UnionBuilder.d.ts +0 -49
  60. package/dist/quicktype-core/UnionBuilder.js +0 -282
  61. package/dist/quicktype-core/attributes/AccessorNames.d.ts +0 -18
  62. package/dist/quicktype-core/attributes/AccessorNames.js +0 -182
  63. package/dist/quicktype-core/attributes/Constraints.d.ts +0 -38
  64. package/dist/quicktype-core/attributes/Constraints.js +0 -172
  65. package/dist/quicktype-core/attributes/Description.d.ts +0 -9
  66. package/dist/quicktype-core/attributes/Description.js +0 -97
  67. package/dist/quicktype-core/attributes/EnumValues.d.ts +0 -8
  68. package/dist/quicktype-core/attributes/EnumValues.js +0 -31
  69. package/dist/quicktype-core/attributes/StringTypes.d.ts +0 -28
  70. package/dist/quicktype-core/attributes/StringTypes.js +0 -189
  71. package/dist/quicktype-core/attributes/TypeAttributes.d.ts +0 -34
  72. package/dist/quicktype-core/attributes/TypeAttributes.js +0 -119
  73. package/dist/quicktype-core/attributes/TypeNames.d.ts +0 -46
  74. package/dist/quicktype-core/attributes/TypeNames.js +0 -274
  75. package/dist/quicktype-core/attributes/URIAttributes.d.ts +0 -8
  76. package/dist/quicktype-core/attributes/URIAttributes.js +0 -85
  77. package/dist/quicktype-core/index.d.ts +0 -48
  78. package/dist/quicktype-core/index.js +0 -180
  79. package/dist/quicktype-core/input/CompressedJSON.d.ts +0 -69
  80. package/dist/quicktype-core/input/CompressedJSON.js +0 -276
  81. package/dist/quicktype-core/input/FetchingJSONSchemaStore.d.ts +0 -6
  82. package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +0 -18
  83. package/dist/quicktype-core/input/Inference.d.ts +0 -22
  84. package/dist/quicktype-core/input/Inference.js +0 -240
  85. package/dist/quicktype-core/input/Inputs.d.ts +0 -48
  86. package/dist/quicktype-core/input/Inputs.js +0 -145
  87. package/dist/quicktype-core/input/JSONSchemaInput.d.ts +0 -91
  88. package/dist/quicktype-core/input/JSONSchemaInput.js +0 -1041
  89. package/dist/quicktype-core/input/JSONSchemaStore.d.ts +0 -8
  90. package/dist/quicktype-core/input/JSONSchemaStore.js +0 -36
  91. package/dist/quicktype-core/input/PostmanCollection.d.ts +0 -5
  92. package/dist/quicktype-core/input/PostmanCollection.js +0 -60
  93. package/dist/quicktype-core/input/io/NodeIO.d.ts +0 -3
  94. package/dist/quicktype-core/input/io/NodeIO.js +0 -87
  95. package/dist/quicktype-core/input/io/get-stream/buffer-stream.d.ts +0 -2
  96. package/dist/quicktype-core/input/io/get-stream/buffer-stream.js +0 -45
  97. package/dist/quicktype-core/input/io/get-stream/index.d.ts +0 -9
  98. package/dist/quicktype-core/input/io/get-stream/index.js +0 -52
  99. package/dist/quicktype-core/language/All.d.ts +0 -3
  100. package/dist/quicktype-core/language/All.js +0 -57
  101. package/dist/quicktype-core/language/CPlusPlus.d.ts +0 -241
  102. package/dist/quicktype-core/language/CPlusPlus.js +0 -1847
  103. package/dist/quicktype-core/language/CSharp.d.ts +0 -201
  104. package/dist/quicktype-core/language/CSharp.js +0 -1850
  105. package/dist/quicktype-core/language/Crystal.d.ts +0 -37
  106. package/dist/quicktype-core/language/Crystal.js +0 -337
  107. package/dist/quicktype-core/language/Dart.d.ts +0 -66
  108. package/dist/quicktype-core/language/Dart.js +0 -576
  109. package/dist/quicktype-core/language/Elm.d.ts +0 -58
  110. package/dist/quicktype-core/language/Elm.js +0 -522
  111. package/dist/quicktype-core/language/Golang.d.ts +0 -51
  112. package/dist/quicktype-core/language/Golang.js +0 -460
  113. package/dist/quicktype-core/language/Haskell.d.ts +0 -56
  114. package/dist/quicktype-core/language/Haskell.js +0 -411
  115. package/dist/quicktype-core/language/JSONSchema.d.ts +0 -31
  116. package/dist/quicktype-core/language/JSONSchema.js +0 -169
  117. package/dist/quicktype-core/language/Java.d.ts +0 -125
  118. package/dist/quicktype-core/language/Java.js +0 -1081
  119. package/dist/quicktype-core/language/JavaScript.d.ts +0 -68
  120. package/dist/quicktype-core/language/JavaScript.js +0 -435
  121. package/dist/quicktype-core/language/JavaScriptPropTypes.d.ts +0 -40
  122. package/dist/quicktype-core/language/JavaScriptPropTypes.js +0 -213
  123. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.d.ts +0 -2
  124. package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +0 -134
  125. package/dist/quicktype-core/language/Kotlin.d.ts +0 -109
  126. package/dist/quicktype-core/language/Kotlin.js +0 -832
  127. package/dist/quicktype-core/language/Objective-C.d.ts +0 -79
  128. package/dist/quicktype-core/language/Objective-C.js +0 -777
  129. package/dist/quicktype-core/language/Php.d.ts +0 -80
  130. package/dist/quicktype-core/language/Php.js +0 -702
  131. package/dist/quicktype-core/language/Pike.d.ts +0 -37
  132. package/dist/quicktype-core/language/Pike.js +0 -276
  133. package/dist/quicktype-core/language/Python.d.ts +0 -107
  134. package/dist/quicktype-core/language/Python.js +0 -969
  135. package/dist/quicktype-core/language/Rust.d.ts +0 -56
  136. package/dist/quicktype-core/language/Rust.js +0 -309
  137. package/dist/quicktype-core/language/Swift.d.ts +0 -96
  138. package/dist/quicktype-core/language/Swift.js +0 -1211
  139. package/dist/quicktype-core/language/TypeScriptFlow.d.ts +0 -77
  140. package/dist/quicktype-core/language/TypeScriptFlow.js +0 -286
  141. package/dist/quicktype-core/language/ruby/index.d.ts +0 -52
  142. package/dist/quicktype-core/language/ruby/index.js +0 -557
  143. package/dist/quicktype-core/language/ruby/keywords.d.ts +0 -3
  144. package/dist/quicktype-core/language/ruby/keywords.js +0 -358
  145. package/dist/quicktype-core/rewrites/CombineClasses.d.ts +0 -3
  146. package/dist/quicktype-core/rewrites/CombineClasses.js +0 -125
  147. package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +0 -4
  148. package/dist/quicktype-core/rewrites/ExpandStrings.js +0 -143
  149. package/dist/quicktype-core/rewrites/FlattenStrings.d.ts +0 -3
  150. package/dist/quicktype-core/rewrites/FlattenStrings.js +0 -45
  151. package/dist/quicktype-core/rewrites/FlattenUnions.d.ts +0 -3
  152. package/dist/quicktype-core/rewrites/FlattenUnions.js +0 -47
  153. package/dist/quicktype-core/rewrites/InferMaps.d.ts +0 -3
  154. package/dist/quicktype-core/rewrites/InferMaps.js +0 -117
  155. package/dist/quicktype-core/rewrites/ReplaceObjectType.d.ts +0 -3
  156. package/dist/quicktype-core/rewrites/ReplaceObjectType.js +0 -60
  157. package/dist/quicktype-core/rewrites/ResolveIntersections.d.ts +0 -3
  158. package/dist/quicktype-core/rewrites/ResolveIntersections.js +0 -244
  159. package/dist/quicktype-core/support/Acronyms.d.ts +0 -10
  160. package/dist/quicktype-core/support/Acronyms.js +0 -1128
  161. package/dist/quicktype-core/support/Chance.d.ts +0 -38
  162. package/dist/quicktype-core/support/Chance.js +0 -2146
  163. package/dist/quicktype-core/support/Converters.d.ts +0 -6
  164. package/dist/quicktype-core/support/Converters.js +0 -16
  165. package/dist/quicktype-core/support/Strings.d.ts +0 -44
  166. package/dist/quicktype-core/support/Strings.js +0 -525
  167. package/dist/quicktype-core/support/Support.d.ts +0 -29
  168. package/dist/quicktype-core/support/Support.js +0 -162
  169. package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +0 -645
  170. package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -39
  171. package/dist/quicktype-graphql-input/index.d.ts +0 -17
  172. package/dist/quicktype-graphql-input/index.js +0 -407
  173. package/dist/quicktype-typescript-input/index.d.ts +0 -2
  174. package/dist/quicktype-typescript-input/index.js +0 -98
@@ -1,1847 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CPlusPlusRenderer = exports.MemberNames = exports.GlobalNames = exports.IncludeKind = exports.CPlusPlusTargetLanguage = exports.cPlusPlusOptions = void 0;
4
- const collection_utils_1 = require("collection-utils");
5
- const TargetLanguage_1 = require("../TargetLanguage");
6
- const Type_1 = require("../Type");
7
- const TypeUtils_1 = require("../TypeUtils");
8
- const Naming_1 = require("../Naming");
9
- const Source_1 = require("../Source");
10
- const Annotation_1 = require("../Annotation");
11
- const Strings_1 = require("../support/Strings");
12
- const Support_1 = require("../support/Support");
13
- const ConvenienceRenderer_1 = require("../ConvenienceRenderer");
14
- const RendererOptions_1 = require("../RendererOptions");
15
- const Support_2 = require("../support/Support");
16
- const AccessorNames_1 = require("../attributes/AccessorNames");
17
- const EnumValues_1 = require("../attributes/EnumValues");
18
- const Constraints_1 = require("../attributes/Constraints");
19
- const pascalValue = ["pascal-case", "pascal"];
20
- const underscoreValue = ["underscore-case", "underscore"];
21
- const camelValue = ["camel-case", "camel"];
22
- const upperUnderscoreValue = ["upper-underscore-case", "upper-underscore"];
23
- const pascalUpperAcronymsValue = ["pascal-case-upper-acronyms", "pascal-upper-acronyms"];
24
- const camelUpperAcronymsValue = ["camel-case-upper-acronyms", "camel-upper-acronyms"];
25
- exports.cPlusPlusOptions = {
26
- typeSourceStyle: new RendererOptions_1.EnumOption("source-style", "Source code generation type, whether to generate single or multiple source files", [
27
- ["single-source", true],
28
- ["multi-source", false]
29
- ], "single-source", "secondary"),
30
- includeLocation: new RendererOptions_1.EnumOption("include-location", "Whether json.hpp is to be located globally or locally", [
31
- ["local-include", true],
32
- ["global-include", false]
33
- ], "local-include", "secondary"),
34
- codeFormat: new RendererOptions_1.EnumOption("code-format", "Generate classes with getters/setters, instead of structs", [
35
- ["with-struct", false],
36
- ["with-getter-setter", true]
37
- ], "with-getter-setter"),
38
- wstring: new RendererOptions_1.EnumOption("wstring", "Store strings using Utf-16 std::wstring, rather than Utf-8 std::string", [
39
- ["use-string", false],
40
- ["use-wstring", true]
41
- ], "use-string"),
42
- westConst: new RendererOptions_1.EnumOption("const-style", "Put const to the left/west (const T) or right/east (T const)", [
43
- ["west-const", true],
44
- ["east-const", false]
45
- ], "west-const"),
46
- justTypes: new RendererOptions_1.BooleanOption("just-types", "Plain types only", false),
47
- namespace: new RendererOptions_1.StringOption("namespace", "Name of the generated namespace(s)", "NAME", "quicktype"),
48
- enumType: new RendererOptions_1.StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"),
49
- typeNamingStyle: new RendererOptions_1.EnumOption("type-style", "Naming style for types", [
50
- pascalValue,
51
- underscoreValue,
52
- camelValue,
53
- upperUnderscoreValue,
54
- pascalUpperAcronymsValue,
55
- camelUpperAcronymsValue
56
- ]),
57
- memberNamingStyle: new RendererOptions_1.EnumOption("member-style", "Naming style for members", [
58
- underscoreValue,
59
- pascalValue,
60
- camelValue,
61
- upperUnderscoreValue,
62
- pascalUpperAcronymsValue,
63
- camelUpperAcronymsValue
64
- ]),
65
- enumeratorNamingStyle: new RendererOptions_1.EnumOption("enumerator-style", "Naming style for enumerators", [
66
- upperUnderscoreValue,
67
- underscoreValue,
68
- pascalValue,
69
- camelValue,
70
- pascalUpperAcronymsValue,
71
- camelUpperAcronymsValue
72
- ]),
73
- boost: new RendererOptions_1.BooleanOption("boost", "Require a dependency on boost. Without boost, C++17 is required", true),
74
- hideNullOptional: new RendererOptions_1.BooleanOption("hide-null-optional", "Hide null value for optional field", false)
75
- };
76
- class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
77
- constructor(displayName = "C++", names = ["c++", "cpp", "cplusplus"], extension = "cpp") {
78
- super(displayName, names, extension);
79
- }
80
- getOptions() {
81
- return [
82
- exports.cPlusPlusOptions.justTypes,
83
- exports.cPlusPlusOptions.namespace,
84
- exports.cPlusPlusOptions.codeFormat,
85
- exports.cPlusPlusOptions.wstring,
86
- exports.cPlusPlusOptions.westConst,
87
- exports.cPlusPlusOptions.typeSourceStyle,
88
- exports.cPlusPlusOptions.includeLocation,
89
- exports.cPlusPlusOptions.typeNamingStyle,
90
- exports.cPlusPlusOptions.memberNamingStyle,
91
- exports.cPlusPlusOptions.enumeratorNamingStyle,
92
- exports.cPlusPlusOptions.enumType,
93
- exports.cPlusPlusOptions.boost,
94
- exports.cPlusPlusOptions.hideNullOptional
95
- ];
96
- }
97
- get supportsUnionsWithBothNumberTypes() {
98
- return true;
99
- }
100
- get supportsOptionalClassProperties() {
101
- return true;
102
- }
103
- makeRenderer(renderContext, untypedOptionValues) {
104
- return new CPlusPlusRenderer(this, renderContext, (0, RendererOptions_1.getOptionValues)(exports.cPlusPlusOptions, untypedOptionValues));
105
- }
106
- }
107
- exports.CPlusPlusTargetLanguage = CPlusPlusTargetLanguage;
108
- function constraintsForType(t) {
109
- const minMax = (0, Constraints_1.minMaxValueForType)(t);
110
- const minMaxLength = (0, Constraints_1.minMaxLengthForType)(t);
111
- const pattern = (0, Constraints_1.patternForType)(t);
112
- if (minMax === undefined && minMaxLength === undefined && pattern === undefined)
113
- return undefined;
114
- return { minMax, minMaxLength, pattern };
115
- }
116
- const legalizeName = (0, Strings_1.legalizeCharacters)(cp => (0, Strings_1.isAscii)(cp) && (0, Strings_1.isLetterOrUnderscoreOrDigit)(cp));
117
- const keywords = [
118
- "alignas",
119
- "alignof",
120
- "and",
121
- "and_eq",
122
- "asm",
123
- "atomic_cancel",
124
- "atomic_commit",
125
- "atomic_noexcept",
126
- "auto",
127
- "bitand",
128
- "bitor",
129
- "bool",
130
- "break",
131
- "case",
132
- "catch",
133
- "char",
134
- "char16_t",
135
- "char32_t",
136
- "class",
137
- "compl",
138
- "concept",
139
- "const",
140
- "constexpr",
141
- "const_cast",
142
- "continue",
143
- "co_await",
144
- "co_return",
145
- "co_yield",
146
- "decltype",
147
- "default",
148
- "delete",
149
- "do",
150
- "double",
151
- "dynamic_cast",
152
- "else",
153
- "enum",
154
- "explicit",
155
- "export",
156
- "extern",
157
- "false",
158
- "float",
159
- "for",
160
- "friend",
161
- "goto",
162
- "if",
163
- "import",
164
- "inline",
165
- "int",
166
- "long",
167
- "module",
168
- "mutable",
169
- "namespace",
170
- "new",
171
- "noexcept",
172
- "not",
173
- "not_eq",
174
- "nullptr",
175
- "operator",
176
- "or",
177
- "or_eq",
178
- "private",
179
- "protected",
180
- "public",
181
- "register",
182
- "reinterpret_cast",
183
- "requires",
184
- "return",
185
- "short",
186
- "signed",
187
- "sizeof",
188
- "static",
189
- "static_assert",
190
- "static_cast",
191
- "struct",
192
- "switch",
193
- "synchronized",
194
- "template",
195
- "this",
196
- "thread_local",
197
- "throw",
198
- "true",
199
- "try",
200
- "typedef",
201
- "typeid",
202
- "typename",
203
- "union",
204
- "unsigned",
205
- "using",
206
- "virtual",
207
- "void",
208
- "volatile",
209
- "wchar_t",
210
- "while",
211
- "xor",
212
- "xor_eq",
213
- "override",
214
- "final",
215
- "transaction_safe",
216
- "transaction_safe_dynamic",
217
- "NULL"
218
- ];
219
- /**
220
- * We can't use boost/std optional. They MUST have the declaration of
221
- * the given structure available, meaning we can't forward declare anything.
222
- * Which is bad as we have circles in Json schema, which require at least
223
- * forward declarability.
224
- * The next question, why isn't unique_ptr is enough here?
225
- * That problem relates to getter/setter. If using getter/setters we
226
- * can't/mustn't return a unique_ptr out of the class -> as that is the
227
- * sole reason why we have declared that as unique_ptr, so that only
228
- * the class owns it. We COULD return unique_ptr references, which practically
229
- * kills the uniqueness of the smart pointer -> hence we use shared_ptrs.
230
- */
231
- const optionalType = "std::shared_ptr";
232
- /**
233
- * To be able to support circles in multiple files -
234
- * e.g. class#A using class#B using class#A (obviously not directly,
235
- * but in vector or in variant) we can forward declare them;
236
- */
237
- var IncludeKind;
238
- (function (IncludeKind) {
239
- IncludeKind[IncludeKind["ForwardDeclare"] = 0] = "ForwardDeclare";
240
- IncludeKind[IncludeKind["Include"] = 1] = "Include";
241
- })(IncludeKind = exports.IncludeKind || (exports.IncludeKind = {}));
242
- var GlobalNames;
243
- (function (GlobalNames) {
244
- GlobalNames[GlobalNames["ClassMemberConstraints"] = 0] = "ClassMemberConstraints";
245
- GlobalNames[GlobalNames["ClassMemberConstraintException"] = 1] = "ClassMemberConstraintException";
246
- GlobalNames[GlobalNames["ValueTooLowException"] = 2] = "ValueTooLowException";
247
- GlobalNames[GlobalNames["ValueTooHighException"] = 3] = "ValueTooHighException";
248
- GlobalNames[GlobalNames["ValueTooShortException"] = 4] = "ValueTooShortException";
249
- GlobalNames[GlobalNames["ValueTooLongException"] = 5] = "ValueTooLongException";
250
- GlobalNames[GlobalNames["InvalidPatternException"] = 6] = "InvalidPatternException";
251
- GlobalNames[GlobalNames["CheckConstraint"] = 7] = "CheckConstraint";
252
- })(GlobalNames = exports.GlobalNames || (exports.GlobalNames = {}));
253
- var MemberNames;
254
- (function (MemberNames) {
255
- MemberNames[MemberNames["MinValue"] = 0] = "MinValue";
256
- MemberNames[MemberNames["GetMinValue"] = 1] = "GetMinValue";
257
- MemberNames[MemberNames["SetMinValue"] = 2] = "SetMinValue";
258
- MemberNames[MemberNames["MaxValue"] = 3] = "MaxValue";
259
- MemberNames[MemberNames["GetMaxValue"] = 4] = "GetMaxValue";
260
- MemberNames[MemberNames["SetMaxValue"] = 5] = "SetMaxValue";
261
- MemberNames[MemberNames["MinLength"] = 6] = "MinLength";
262
- MemberNames[MemberNames["GetMinLength"] = 7] = "GetMinLength";
263
- MemberNames[MemberNames["SetMinLength"] = 8] = "SetMinLength";
264
- MemberNames[MemberNames["MaxLength"] = 9] = "MaxLength";
265
- MemberNames[MemberNames["GetMaxLength"] = 10] = "GetMaxLength";
266
- MemberNames[MemberNames["SetMaxLength"] = 11] = "SetMaxLength";
267
- MemberNames[MemberNames["Pattern"] = 12] = "Pattern";
268
- MemberNames[MemberNames["GetPattern"] = 13] = "GetPattern";
269
- MemberNames[MemberNames["SetPattern"] = 14] = "SetPattern";
270
- })(MemberNames = exports.MemberNames || (exports.MemberNames = {}));
271
- function addQualifier(qualifier, qualified) {
272
- if (qualified.length === 0) {
273
- return [];
274
- }
275
- return [qualifier, qualified];
276
- }
277
- class WrappingCode {
278
- _start;
279
- _end;
280
- constructor(start, end) {
281
- this._start = start;
282
- this._end = end;
283
- }
284
- wrap(qualifier, inner) {
285
- return [addQualifier(qualifier, this._start), inner, this._end];
286
- }
287
- }
288
- class BaseString {
289
- _stringType;
290
- _constStringType;
291
- _smatch;
292
- _regex;
293
- _stringLiteralPrefix;
294
- _toString;
295
- _encodingClass;
296
- _encodingFunction;
297
- constructor(stringType, constStringType, smatch, regex, stringLiteralPrefix, toString, encodingClass, encodingFunction) {
298
- (this._stringType = stringType),
299
- (this._constStringType = constStringType),
300
- (this._smatch = smatch),
301
- (this._regex = regex),
302
- (this._stringLiteralPrefix = stringLiteralPrefix),
303
- (this._toString = toString),
304
- (this._encodingClass = encodingClass),
305
- (this._encodingFunction = encodingFunction);
306
- }
307
- getType() {
308
- return this._stringType;
309
- }
310
- getConstType() {
311
- return this._constStringType;
312
- }
313
- getSMatch() {
314
- return this._smatch;
315
- }
316
- getRegex() {
317
- return this._regex;
318
- }
319
- createStringLiteral(inner) {
320
- return [this._stringLiteralPrefix, '"', inner, '"'];
321
- }
322
- wrapToString(inner) {
323
- return this._toString.wrap([], inner);
324
- }
325
- }
326
- class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
327
- _options;
328
- /**
329
- * For forward declaration practically
330
- */
331
- _enumType;
332
- _generatedFiles;
333
- _currentFilename;
334
- _allTypeNames;
335
- _gettersAndSettersForPropertyName = new Map();
336
- _namespaceNames;
337
- _memberNameStyle;
338
- _namedTypeNameStyle;
339
- _generatedGlobalNames;
340
- _generatedMemberNames;
341
- _forbiddenGlobalNames;
342
- _memberNamingFunction;
343
- _stringType;
344
- _optionalType;
345
- _nulloptType;
346
- _variantType;
347
- _variantIndexMethodName;
348
- typeNamingStyle;
349
- enumeratorNamingStyle;
350
- constructor(targetLanguage, renderContext, _options) {
351
- super(targetLanguage, renderContext);
352
- this._options = _options;
353
- this._enumType = _options.enumType;
354
- this._namespaceNames = _options.namespace.split("::");
355
- this.typeNamingStyle = _options.typeNamingStyle;
356
- this._namedTypeNameStyle = (0, Strings_1.makeNameStyle)(this.typeNamingStyle, legalizeName);
357
- this.enumeratorNamingStyle = _options.enumeratorNamingStyle;
358
- this._memberNameStyle = (0, Strings_1.makeNameStyle)(_options.memberNamingStyle, legalizeName);
359
- this._memberNamingFunction = (0, Naming_1.funPrefixNamer)("members", this._memberNameStyle);
360
- this._gettersAndSettersForPropertyName = new Map();
361
- this._allTypeNames = new Set();
362
- this._generatedFiles = new Set();
363
- this._generatedGlobalNames = new Map();
364
- this._generatedMemberNames = new Map();
365
- this._forbiddenGlobalNames = [];
366
- if (_options.wstring) {
367
- this._stringType = this.WideString;
368
- }
369
- else {
370
- this._stringType = this.NarrowString;
371
- }
372
- if (_options.boost) {
373
- this._optionalType = "boost::optional";
374
- this._nulloptType = "boost::none";
375
- this._variantType = "boost::variant";
376
- this._variantIndexMethodName = "which";
377
- }
378
- else {
379
- this._optionalType = "std::optional";
380
- this._nulloptType = "std::nullopt";
381
- this._variantType = "std::variant";
382
- this._variantIndexMethodName = "index";
383
- }
384
- this.setupGlobalNames();
385
- }
386
- getConstraintMembers() {
387
- return [
388
- {
389
- name: MemberNames.MinValue,
390
- getter: MemberNames.GetMinValue,
391
- setter: MemberNames.SetMinValue,
392
- cppType: "int64_t"
393
- },
394
- {
395
- name: MemberNames.MaxValue,
396
- getter: MemberNames.GetMaxValue,
397
- setter: MemberNames.SetMaxValue,
398
- cppType: "int64_t"
399
- },
400
- {
401
- name: MemberNames.MinLength,
402
- getter: MemberNames.GetMinLength,
403
- setter: MemberNames.SetMinLength,
404
- cppType: "size_t"
405
- },
406
- {
407
- name: MemberNames.MaxLength,
408
- getter: MemberNames.GetMaxLength,
409
- setter: MemberNames.SetMaxLength,
410
- cppType: "size_t"
411
- },
412
- {
413
- name: MemberNames.Pattern,
414
- getter: MemberNames.GetPattern,
415
- setter: MemberNames.SetPattern,
416
- cppType: this._stringType.getType(),
417
- cppConstType: this._stringType.getConstType()
418
- }
419
- ];
420
- }
421
- lookupGlobalName(type) {
422
- return (0, Support_1.defined)(this._generatedGlobalNames.get(type));
423
- }
424
- lookupMemberName(type) {
425
- return (0, Support_1.defined)(this._generatedMemberNames.get(type));
426
- }
427
- addGlobalName(type) {
428
- const genName = this._namedTypeNameStyle(GlobalNames[type]);
429
- this._generatedGlobalNames.set(type, genName);
430
- this._forbiddenGlobalNames.push(genName);
431
- }
432
- addMemberName(type) {
433
- this._generatedMemberNames.set(type, this._memberNameStyle(MemberNames[type]));
434
- }
435
- setupGlobalNames() {
436
- for (const v of (0, Support_1.numberEnumValues)(GlobalNames)) {
437
- this.addGlobalName(v);
438
- }
439
- for (const v of (0, Support_1.numberEnumValues)(MemberNames)) {
440
- this.addMemberName(v);
441
- }
442
- }
443
- forbiddenNamesForGlobalNamespace() {
444
- return [...keywords, ...this._forbiddenGlobalNames];
445
- }
446
- forbiddenForObjectProperties(_c, _className) {
447
- return { names: [], includeGlobalForbidden: true };
448
- }
449
- forbiddenForEnumCases(_e, _enumName) {
450
- return { names: [], includeGlobalForbidden: true };
451
- }
452
- makeNamedTypeNamer() {
453
- return (0, Naming_1.funPrefixNamer)("types", this._namedTypeNameStyle);
454
- }
455
- namerForObjectProperty() {
456
- return this._memberNamingFunction;
457
- }
458
- makeUnionMemberNamer() {
459
- return null;
460
- }
461
- makeEnumCaseNamer() {
462
- return (0, Naming_1.funPrefixNamer)("enumerators", (0, Strings_1.makeNameStyle)(this.enumeratorNamingStyle, legalizeName));
463
- }
464
- makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
465
- const getterName = new Naming_1.DependencyName(this._memberNamingFunction, name.order, lookup => `get_${lookup(name)}`);
466
- const mutableGetterName = new Naming_1.DependencyName(this._memberNamingFunction, name.order, lookup => `getMutable_${lookup(name)}`);
467
- const setterName = new Naming_1.DependencyName(this._memberNamingFunction, name.order, lookup => `set_${lookup(name)}`);
468
- return [getterName, mutableGetterName, setterName];
469
- }
470
- makePropertyDependencyNames(c, className, p, jsonName, name) {
471
- const getterAndSetterNames = this.makeNamesForPropertyGetterAndSetter(c, className, p, jsonName, name);
472
- this._gettersAndSettersForPropertyName.set(name, getterAndSetterNames);
473
- return getterAndSetterNames;
474
- }
475
- withConst(s) {
476
- if (this._options.westConst) {
477
- return ["const ", s];
478
- }
479
- else {
480
- return [s, " const"];
481
- }
482
- }
483
- emitInclude(global, name) {
484
- this.emitLine("#include ", global ? "<" : '"', name, global ? ">" : '"');
485
- }
486
- startFile(basename, includeHelper = true) {
487
- (0, Support_2.assert)(this._currentFilename === undefined, "Previous file wasn't finished");
488
- if (basename !== undefined) {
489
- this._currentFilename = this.sourcelikeToString(basename);
490
- }
491
- if (this.leadingComments !== undefined) {
492
- this.emitCommentLines(this.leadingComments);
493
- }
494
- else if (!this._options.justTypes) {
495
- this.emitCommentLines([" To parse this JSON data, first install", ""]);
496
- if (this._options.boost) {
497
- this.emitCommentLines([" Boost http://www.boost.org"]);
498
- }
499
- this.emitCommentLines([
500
- " json.hpp https://github.com/nlohmann/json",
501
- "",
502
- " Then include this file, and then do",
503
- ""
504
- ]);
505
- if (this._options.typeSourceStyle) {
506
- this.forEachTopLevel("none", (_, topLevelName) => {
507
- this.emitLine("// ", topLevelName, " data = nlohmann::json::parse(jsonString);");
508
- });
509
- }
510
- else {
511
- this.emitLine("// ", basename, " data = nlohmann::json::parse(jsonString);");
512
- }
513
- if (this._options.wstring) {
514
- this.emitLine("//");
515
- this.emitLine("// You can get std::wstring data back out using");
516
- this.emitLine("//");
517
- this.forEachTopLevel("none", (_, topLevelName) => {
518
- this.emitLine("// std::wcout << ", "wdump((nlohmann::json) ", topLevelName, ");");
519
- });
520
- }
521
- }
522
- this.ensureBlankLine();
523
- this.emitLine("#pragma once");
524
- this.ensureBlankLine();
525
- if (this.haveNamedUnions) {
526
- if (this._options.boost) {
527
- this.emitInclude(true, "boost/variant.hpp");
528
- }
529
- else {
530
- this.emitInclude(true, "variant");
531
- }
532
- }
533
- if (!this._options.justTypes) {
534
- if (!this._options.includeLocation) {
535
- this.emitInclude(true, "nlohmann/json.hpp");
536
- }
537
- else {
538
- this.emitInclude(false, "json.hpp");
539
- }
540
- if (includeHelper && !this._options.typeSourceStyle) {
541
- this.emitInclude(false, "helper.hpp");
542
- }
543
- }
544
- this.ensureBlankLine();
545
- }
546
- finishFile() {
547
- super.finishFile((0, Support_1.defined)(this._currentFilename));
548
- this._currentFilename = undefined;
549
- }
550
- get needsTypeDeclarationBeforeUse() {
551
- return true;
552
- }
553
- canBeForwardDeclared(t) {
554
- const kind = t.kind;
555
- return kind === "class";
556
- }
557
- emitDescriptionBlock(lines) {
558
- this.emitCommentLines(lines, " * ", "/**", " */");
559
- }
560
- emitBlock(line, withSemicolon, f, withIndent = true) {
561
- this.emitLine(line, " {");
562
- this.preventBlankLine();
563
- if (withIndent) {
564
- this.indent(f);
565
- }
566
- else {
567
- f();
568
- }
569
- this.preventBlankLine();
570
- if (withSemicolon) {
571
- this.emitLine("};");
572
- }
573
- else {
574
- this.emitLine("}");
575
- }
576
- }
577
- emitNamespaces(namespaceNames, f) {
578
- const namesArray = (0, collection_utils_1.toReadonlyArray)(namespaceNames);
579
- const first = namesArray[0];
580
- if (first === undefined) {
581
- f();
582
- }
583
- else {
584
- this.emitBlock(["namespace ", first], false, () => this.emitNamespaces(namesArray.slice(1), f), namesArray.length === 1);
585
- }
586
- }
587
- cppTypeInOptional(nonNulls, ctx, withIssues, forceNarrowString) {
588
- if (nonNulls.size === 1) {
589
- return this.cppType((0, Support_1.defined)((0, collection_utils_1.iterableFirst)(nonNulls)), ctx, withIssues, forceNarrowString, false);
590
- }
591
- const typeList = [];
592
- for (const t of nonNulls) {
593
- if (typeList.length !== 0) {
594
- typeList.push(", ");
595
- }
596
- typeList.push(this.cppType(t, {
597
- needsForwardIndirection: true,
598
- needsOptionalIndirection: false,
599
- inJsonNamespace: ctx.inJsonNamespace
600
- }, withIssues, false, false));
601
- }
602
- return [this._variantType, "<", typeList, ">"];
603
- }
604
- variantType(u, inJsonNamespace) {
605
- const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, true);
606
- (0, Support_2.assert)(nonNulls.size >= 2, "Variant not needed for less than two types.");
607
- const indirection = maybeNull !== null;
608
- const variant = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: !indirection, needsOptionalIndirection: !indirection, inJsonNamespace }, true, false);
609
- if (!indirection) {
610
- return variant;
611
- }
612
- return [optionalType, "<", variant, ">"];
613
- }
614
- ourQualifier(inJsonNamespace) {
615
- return inJsonNamespace ? [(0, collection_utils_1.arrayIntercalate)("::", this._namespaceNames), "::"] : [];
616
- }
617
- jsonQualifier(inJsonNamespace) {
618
- return inJsonNamespace ? [] : "nlohmann::";
619
- }
620
- variantIndirection(needIndirection, typeSrc) {
621
- if (!needIndirection)
622
- return typeSrc;
623
- return [optionalType, "<", typeSrc, ">"];
624
- }
625
- cppType(t, ctx, withIssues, forceNarrowString, isOptional) {
626
- const inJsonNamespace = ctx.inJsonNamespace;
627
- if (isOptional && t instanceof Type_1.UnionType) {
628
- // avoid have optionalType<optionalType<Type>>
629
- for (const tChild of t.getChildren()) {
630
- if (tChild.isNullable) {
631
- isOptional = false;
632
- break;
633
- }
634
- }
635
- }
636
- let typeSource = (0, TypeUtils_1.matchType)(t, _anyType => {
637
- isOptional = false;
638
- return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.anyTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
639
- }, _nullType => {
640
- isOptional = false;
641
- return (0, Source_1.maybeAnnotated)(withIssues, Annotation_1.nullTypeIssueAnnotation, [this.jsonQualifier(inJsonNamespace), "json"]);
642
- }, _boolType => "bool", _integerType => "int64_t", _doubleType => "double", _stringType => {
643
- if (forceNarrowString) {
644
- return "std::string";
645
- }
646
- else {
647
- return this._stringType.getType();
648
- }
649
- }, arrayType => [
650
- "std::vector<",
651
- this.cppType(arrayType.items, { needsForwardIndirection: false, needsOptionalIndirection: true, inJsonNamespace }, withIssues, forceNarrowString, false),
652
- ">"
653
- ], classType => this.variantIndirection(ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [this.ourQualifier(inJsonNamespace), this.nameForNamedType(classType)]), mapType => {
654
- let keyType = this._stringType.getType();
655
- if (forceNarrowString) {
656
- keyType = "std::string";
657
- }
658
- return [
659
- "std::map<",
660
- keyType,
661
- ", ",
662
- this.cppType(mapType.values, { needsForwardIndirection: false, needsOptionalIndirection: true, inJsonNamespace }, withIssues, forceNarrowString, false),
663
- ">"
664
- ];
665
- }, enumType => [this.ourQualifier(inJsonNamespace), this.nameForNamedType(enumType)], unionType => {
666
- const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
667
- if (nullable === null)
668
- return [this.ourQualifier(inJsonNamespace), this.nameForNamedType(unionType)];
669
- isOptional = true;
670
- return this.cppType(nullable, { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace }, withIssues, forceNarrowString, false);
671
- });
672
- if (!isOptional)
673
- return typeSource;
674
- return [optionalType, "<", typeSource, ">"];
675
- }
676
- /**
677
- * similar to cppType, it practically gathers all the generated types within
678
- * 't'. It also records, whether a given sub-type is part of a variant or not.
679
- */
680
- generatedTypes(isClassMember, theType) {
681
- const result = [];
682
- const recur = (forceInclude, isVariant, l, t) => {
683
- if (t instanceof Type_1.ArrayType) {
684
- recur(forceInclude, isVariant, l + 1, t.items);
685
- }
686
- else if (t instanceof Type_1.ClassType) {
687
- result.push({
688
- name: this.nameForNamedType(t),
689
- type: t,
690
- level: l,
691
- variant: isVariant,
692
- forceInclude: forceInclude
693
- });
694
- }
695
- else if (t instanceof Type_1.MapType) {
696
- recur(forceInclude, isVariant, l + 1, t.values);
697
- }
698
- else if (t instanceof Type_1.EnumType) {
699
- result.push({
700
- name: this.nameForNamedType(t),
701
- type: t,
702
- level: l,
703
- variant: isVariant,
704
- forceInclude: false
705
- });
706
- }
707
- else if (t instanceof Type_1.UnionType) {
708
- /**
709
- * If we have a union as a class member and we see it as a "named union",
710
- * we can safely include it as-is.
711
- * HOWEVER if we define a union on its own, we must recurse into the
712
- * typedefinition and include all subtypes.
713
- */
714
- if (this.unionNeedsName(t) && isClassMember) {
715
- /**
716
- * This is NOT ENOUGH.
717
- * We have a variant member in a class, e.g. defined with a boost::variant.
718
- * The compiler can only compile the class if IT KNOWS THE SIZES
719
- * OF ALL MEMBERS OF THE VARIANT.
720
- * So it means that you must include ALL SUBTYPES (practically classes only)
721
- * AS WELL
722
- */
723
- forceInclude = true;
724
- result.push({
725
- name: this.nameForNamedType(t),
726
- type: t,
727
- level: l,
728
- variant: true,
729
- forceInclude: forceInclude
730
- });
731
- /** intentional "fall-through", add all subtypes as well - but forced include */
732
- }
733
- const [hasNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(t);
734
- isVariant = hasNull !== null;
735
- /** we need to collect all the subtypes of the union */
736
- for (const tt of nonNulls) {
737
- recur(forceInclude, isVariant, l + 1, tt);
738
- }
739
- }
740
- };
741
- recur(false, false, 0, theType);
742
- return result;
743
- }
744
- constraintMember(jsonName) {
745
- return this._memberNameStyle(jsonName + "Constraint");
746
- }
747
- emitMember(cppType, name) {
748
- this.emitLine(cppType, " ", name, ";");
749
- }
750
- emitClassMembers(c, constraints) {
751
- if (this._options.codeFormat) {
752
- this.emitLine("private:");
753
- this.forEachClassProperty(c, "none", (name, jsonName, property) => {
754
- this.emitMember(this.cppType(property.type, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, property.isOptional), name);
755
- if (constraints !== undefined && constraints.has(jsonName)) {
756
- /** FIXME!!! NameStyle will/can collide with other Names */
757
- const cnst = this.lookupGlobalName(GlobalNames.ClassMemberConstraints);
758
- this.emitMember(cnst, this.constraintMember(jsonName));
759
- }
760
- });
761
- this.ensureBlankLine();
762
- this.emitLine("public:");
763
- }
764
- this.forEachClassProperty(c, "none", (name, jsonName, property) => {
765
- this.emitDescription(this.descriptionForClassProperty(c, jsonName));
766
- if (!this._options.codeFormat) {
767
- this.emitMember(this.cppType(property.type, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, property.isOptional), name);
768
- }
769
- else {
770
- const [getterName, mutableGetterName, setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
771
- const rendered = this.cppType(property.type, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, property.isOptional);
772
- /**
773
- * fix for optional type -> e.g. unique_ptrs can't be copied
774
- * One might as why the "this->xxx = value". Simple if we have
775
- * a member called 'value' value = value will screw up the compiler
776
- */
777
- const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
778
- if ((property.type instanceof Type_1.UnionType && property.type.findMember("null") !== undefined) ||
779
- (property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")) {
780
- this.emitLine(rendered, " ", getterName, "() const { return ", name, "; }");
781
- if (constraints !== undefined && constraints.has(jsonName)) {
782
- this.emitLine("void ", setterName, "(", rendered, " value) { if (value) ", checkConst, "(", this._stringType.createStringLiteral([name]), ", ", this.constraintMember(jsonName), ", *value); this->", name, " = value; }");
783
- }
784
- else {
785
- this.emitLine("void ", setterName, "(", rendered, " value) { this->", name, " = value; }");
786
- }
787
- }
788
- else {
789
- this.emitLine(this.withConst(rendered), " & ", getterName, "() const { return ", name, "; }");
790
- this.emitLine(rendered, " & ", mutableGetterName, "() { return ", name, "; }");
791
- if (constraints !== undefined && constraints.has(jsonName)) {
792
- this.emitLine("void ", setterName, "(", this.withConst(rendered), " & value) { ", checkConst, "(", this._stringType.createStringLiteral([name]), ", ", this.constraintMember(jsonName), ", value); this->", name, " = value; }");
793
- }
794
- else {
795
- this.emitLine("void ", setterName, "(", this.withConst(rendered), " & value) { this->", name, " = value; }");
796
- }
797
- }
798
- this.ensureBlankLine();
799
- }
800
- });
801
- }
802
- generateClassConstraints(c) {
803
- let res = new Map();
804
- this.forEachClassProperty(c, "none", (_name, jsonName, property) => {
805
- const constraints = constraintsForType(property.type);
806
- if (constraints === undefined)
807
- return;
808
- const { minMax, minMaxLength, pattern } = constraints;
809
- res.set(jsonName, [
810
- this.constraintMember(jsonName),
811
- "(",
812
- minMax !== undefined && minMax[0] !== undefined ? String(minMax[0]) : this._nulloptType,
813
- ", ",
814
- minMax !== undefined && minMax[1] !== undefined ? String(minMax[1]) : this._nulloptType,
815
- ", ",
816
- minMaxLength !== undefined && minMaxLength[0] !== undefined
817
- ? String(minMaxLength[0])
818
- : this._nulloptType,
819
- ", ",
820
- minMaxLength !== undefined && minMaxLength[1] !== undefined
821
- ? String(minMaxLength[1])
822
- : this._nulloptType,
823
- ", ",
824
- pattern === undefined
825
- ? this._nulloptType
826
- : [
827
- this._stringType.getType(),
828
- "(",
829
- this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(pattern)]),
830
- ")"
831
- ],
832
- ")"
833
- ]);
834
- });
835
- return res.size === 0 ? undefined : res;
836
- }
837
- emitClass(c, className) {
838
- this.emitDescription(this.descriptionForType(c));
839
- this.emitBlock([this._options.codeFormat ? "class " : "struct ", className], true, () => {
840
- const constraints = this.generateClassConstraints(c);
841
- if (this._options.codeFormat) {
842
- this.emitLine("public:");
843
- if (constraints === undefined) {
844
- this.emitLine(className, "() = default;");
845
- }
846
- else {
847
- this.emitLine(className, "() :");
848
- let numEmits = 0;
849
- constraints.forEach((initializer, _propName) => {
850
- numEmits++;
851
- this.indent(() => {
852
- if (numEmits === constraints.size) {
853
- this.emitLine(initializer);
854
- }
855
- else {
856
- this.emitLine(initializer, ",");
857
- }
858
- });
859
- });
860
- this.emitLine("{}");
861
- }
862
- this.emitLine("virtual ~", className, "() = default;");
863
- this.ensureBlankLine();
864
- }
865
- this.emitClassMembers(c, constraints);
866
- });
867
- }
868
- emitTopLevelHeaders(t, className) {
869
- // Forward declarations for std::map<std::wstring, Key> (need to convert UTF16 <-> UTF8)
870
- if (t instanceof Type_1.MapType && this._stringType !== this.NarrowString) {
871
- const ourQualifier = this.ourQualifier(true);
872
- this.emitLine("template <>");
873
- this.emitBlock(["struct adl_serializer<", ourQualifier, className, ">"], true, () => {
874
- this.emitLine("static void from_json(", this.withConst("json"), " & j, ", ourQualifier, className, " & x);");
875
- this.emitLine("static void to_json(json & j, ", this.withConst([ourQualifier, className]), " & x);");
876
- });
877
- }
878
- }
879
- emitClassHeaders(className) {
880
- const ourQualifier = this.ourQualifier(false);
881
- this.emitLine("void from_json(", this.withConst("json"), " & j, ", ourQualifier, className, " & x);");
882
- this.emitLine("void to_json(json & j, ", this.withConst([ourQualifier, className]), " & x);");
883
- }
884
- emitTopLevelFunction(t, className) {
885
- // Function definitions for std::map<std::wstring, Key> (need to convert UTF16 <-> UTF8)
886
- if (t instanceof Type_1.MapType && this._stringType !== this.NarrowString) {
887
- const ourQualifier = this.ourQualifier(true);
888
- let cppType;
889
- let toType;
890
- this.emitBlock(["inline void adl_serializer<", ourQualifier, className, ">::from_json(", this.withConst("json"), " & j, ", ourQualifier, className, "& x)"], false, () => {
891
- cppType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, false);
892
- toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
893
- this.emitLine([
894
- "x = ",
895
- this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
896
- "j.get<",
897
- cppType,
898
- ">()"
899
- ]),
900
- ";"
901
- ]);
902
- });
903
- this.emitBlock(["inline void adl_serializer<", ourQualifier, className, ">::to_json(json & j, ", this.withConst([ourQualifier, className]), " & x)"], false, () => {
904
- cppType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
905
- toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, false);
906
- this.emitLine([
907
- "j = ",
908
- this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, "x"),
909
- ";"
910
- ]);
911
- });
912
- }
913
- }
914
- emitClassFunctions(c, className) {
915
- const ourQualifier = this.ourQualifier(false);
916
- let cppType;
917
- let toType;
918
- this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, className, "& x)"], false, () => {
919
- this.forEachClassProperty(c, "none", (name, json, p) => {
920
- const [, , setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
921
- const t = p.type;
922
- let assignment;
923
- if (this._options.codeFormat) {
924
- assignment = new WrappingCode(["x.", setterName, "("], [")"]);
925
- }
926
- else {
927
- assignment = new WrappingCode(["x.", name, " = "], []);
928
- }
929
- if (t.kind === "null" || t.kind === "any") {
930
- this.emitLine(assignment.wrap([], [
931
- ourQualifier,
932
- "get_untyped(j, ",
933
- this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])]),
934
- ")"
935
- ]), ";");
936
- return;
937
- }
938
- if (p.isOptional || t instanceof Type_1.UnionType) {
939
- const [nullOrOptional, typeSet] = (function () {
940
- if (t instanceof Type_1.UnionType) {
941
- const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(t, true);
942
- return [maybeNull !== null || p.isOptional, nonNulls];
943
- }
944
- else {
945
- let set = new Set();
946
- set.add(t);
947
- return [true, set];
948
- }
949
- })();
950
- if (nullOrOptional) {
951
- cppType = this.cppTypeInOptional(typeSet, {
952
- needsForwardIndirection: false,
953
- needsOptionalIndirection: false,
954
- inJsonNamespace: false
955
- }, false, true);
956
- toType = this.cppTypeInOptional(typeSet, {
957
- needsForwardIndirection: false,
958
- needsOptionalIndirection: false,
959
- inJsonNamespace: false
960
- }, false, false);
961
- this.emitLine(assignment.wrap([], [
962
- this._stringType.wrapEncodingChange([ourQualifier], [optionalType, "<", cppType, ">"], [optionalType, "<", toType, ">"], [
963
- ourQualifier,
964
- "get_optional<",
965
- cppType,
966
- ">(j, ",
967
- this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])]),
968
- ")"
969
- ])
970
- ]), ";");
971
- return;
972
- }
973
- }
974
- cppType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, false, true, p.isOptional);
975
- toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, false, false, p.isOptional);
976
- this.emitLine(assignment.wrap([], this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
977
- "j.at(",
978
- this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])),
979
- ").get<",
980
- cppType,
981
- ">()"
982
- ])), ";");
983
- });
984
- });
985
- this.ensureBlankLine();
986
- this.emitBlock(["inline void to_json(json & j, ", this.withConst([ourQualifier, className]), " & x)"], false, () => {
987
- this.emitLine("j = json::object();");
988
- this.forEachClassProperty(c, "none", (name, json, p) => {
989
- const t = p.type;
990
- cppType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, false, false, p.isOptional);
991
- toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, false, true, p.isOptional);
992
- const [getterName, ,] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
993
- let getter;
994
- if (this._options.codeFormat) {
995
- getter = [getterName, "()"];
996
- }
997
- else {
998
- getter = [name];
999
- }
1000
- let assignment = [
1001
- "j[",
1002
- this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])),
1003
- "] = ",
1004
- this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
1005
- ";"
1006
- ];
1007
- if (p.isOptional && this._options.hideNullOptional) {
1008
- this.emitBlock([
1009
- "if (",
1010
- this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
1011
- ")"
1012
- ], false, () => {
1013
- this.emitLine(assignment);
1014
- });
1015
- }
1016
- else {
1017
- this.emitLine(assignment);
1018
- }
1019
- });
1020
- });
1021
- }
1022
- emitEnum(e, enumName) {
1023
- const caseNames = [];
1024
- const enumValues = (0, EnumValues_1.enumCaseValues)(e, this.targetLanguage.name);
1025
- this.forEachEnumCase(e, "none", (name, jsonName) => {
1026
- if (caseNames.length > 0)
1027
- caseNames.push(", ");
1028
- caseNames.push(name);
1029
- if (enumValues !== undefined) {
1030
- const [enumValue] = (0, AccessorNames_1.getAccessorName)(enumValues, jsonName);
1031
- if (enumValue !== undefined) {
1032
- caseNames.push(" = ", enumValue.toString());
1033
- }
1034
- }
1035
- });
1036
- this.emitDescription(this.descriptionForType(e));
1037
- this.emitLine("enum class ", enumName, " : ", this._enumType, " { ", caseNames, " };");
1038
- }
1039
- emitUnionTypedefs(u, unionName) {
1040
- this.emitLine("using ", unionName, " = ", this.variantType(u, false), ";");
1041
- }
1042
- emitUnionHeaders(u) {
1043
- // Forward declarations for boost::variant<Ts...>. If none of the Ts were defined by us (e.g. if we have
1044
- // boost::variant<int32_t, std::string>) then we need to specialize nlohmann::adl_serializer for our
1045
- // variant type. If at least one of the Ts is our type then we could get away with regular adl definitions,
1046
- // but it's nontrivial to detect that (consider variant<string, variant<map<string, string>, int>> which
1047
- // does need an adl_serializer specialization) so we'll just specialize every time.
1048
- const nonNulls = (0, TypeUtils_1.removeNullFromUnion)(u, true)[1];
1049
- const variantType = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false);
1050
- this.emitLine("template <>");
1051
- this.emitBlock(["struct adl_serializer<", variantType, ">"], true, () => {
1052
- this.emitLine("static void from_json(", this.withConst("json"), " & j, ", variantType, " & x);");
1053
- this.emitLine("static void to_json(json & j, ", this.withConst(variantType), " & x);");
1054
- });
1055
- }
1056
- emitUnionFunctions(u) {
1057
- // Function definitions for boost::variant<Ts...>.
1058
- const ourQualifier = this.ourQualifier(true);
1059
- const functionForKind = [
1060
- ["bool", "is_boolean"],
1061
- ["integer", "is_number_integer"],
1062
- ["double", "is_number"],
1063
- ["string", "is_string"],
1064
- ["class", "is_object"],
1065
- ["map", "is_object"],
1066
- ["array", "is_array"],
1067
- ["enum", "is_string"]
1068
- ];
1069
- const nonNulls = (0, TypeUtils_1.removeNullFromUnion)(u, true)[1];
1070
- const variantType = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false);
1071
- this.emitBlock(["inline void adl_serializer<", variantType, ">::from_json(", this.withConst("json"), " & j, ", variantType, " & x)"], false, () => {
1072
- let onFirst = true;
1073
- for (const [kind, func] of functionForKind) {
1074
- const typeForKind = (0, collection_utils_1.iterableFind)(nonNulls, t => t.kind === kind);
1075
- if (typeForKind === undefined)
1076
- continue;
1077
- this.emitLine(onFirst ? "if" : "else if", " (j.", func, "())");
1078
- this.indent(() => {
1079
- const cppType = this.cppType(typeForKind, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, false);
1080
- let toType = this.cppType(typeForKind, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
1081
- this.emitLine("x = ", this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
1082
- "j.get<",
1083
- cppType,
1084
- ">()"
1085
- ]), ";");
1086
- });
1087
- onFirst = false;
1088
- }
1089
- this.emitLine('else throw "Could not deserialize";');
1090
- });
1091
- this.ensureBlankLine();
1092
- this.emitBlock(["inline void adl_serializer<", variantType, ">::to_json(json & j, ", this.withConst(variantType), " & x)"], false, () => {
1093
- this.emitBlock(["switch (x.", this._variantIndexMethodName, "())"], false, () => {
1094
- let i = 0;
1095
- for (const t of nonNulls) {
1096
- this.emitLine("case ", i.toString(), ":");
1097
- this.indent(() => {
1098
- const cppType = this.cppType(t, {
1099
- needsForwardIndirection: true,
1100
- needsOptionalIndirection: true,
1101
- inJsonNamespace: true
1102
- }, false, false, false);
1103
- const toType = this.cppType(t, {
1104
- needsForwardIndirection: true,
1105
- needsOptionalIndirection: true,
1106
- inJsonNamespace: true
1107
- }, false, true, false);
1108
- this.emitLine("j = ", this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
1109
- this._options.boost ? "boost::get<" : "std::get<",
1110
- cppType,
1111
- ">(x)"
1112
- ]), ";");
1113
- this.emitLine("break;");
1114
- });
1115
- i++;
1116
- }
1117
- this.emitLine('default: throw "Input JSON does not conform to schema";');
1118
- });
1119
- });
1120
- }
1121
- emitEnumHeaders(enumName) {
1122
- const ourQualifier = this.ourQualifier(false);
1123
- this.emitLine("void from_json(", this.withConst("json"), " & j, ", ourQualifier, enumName, " & x);");
1124
- this.emitLine("void to_json(json & j, ", this.withConst([ourQualifier, enumName]), " & x);");
1125
- }
1126
- isLargeEnum(e) {
1127
- // This is just an estimation. Someone might want to do some
1128
- // benchmarks to find the optimum value here
1129
- return e.cases.size > 15;
1130
- }
1131
- emitEnumFunctions(e, enumName) {
1132
- const ourQualifier = this.ourQualifier(false);
1133
- this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, enumName, " & x)"], false, () => {
1134
- if (this.isLargeEnum(e)) {
1135
- this.emitBlock([
1136
- "static std::unordered_map<",
1137
- this._stringType.getType(),
1138
- ", ",
1139
- ourQualifier,
1140
- enumName,
1141
- "> enumValues"
1142
- ], true, () => {
1143
- this.forEachEnumCase(e, "none", (name, jsonName) => {
1144
- this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), ", ", ourQualifier, enumName, "::", name, "},");
1145
- });
1146
- });
1147
- this.emitLine(`auto iter = enumValues.find(j.get<${this._stringType.getType()}>());`);
1148
- this.emitBlock("if (iter != enumValues.end())", false, () => {
1149
- this.emitLine("x = iter->second;");
1150
- });
1151
- }
1152
- else {
1153
- let onFirst = true;
1154
- this.forEachEnumCase(e, "none", (name, jsonName) => {
1155
- const maybeElse = onFirst ? "" : "else ";
1156
- this.emitLine(maybeElse, "if (j == ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), ") x = ", ourQualifier, enumName, "::", name, ";");
1157
- onFirst = false;
1158
- });
1159
- this.emitLine('else throw "Input JSON does not conform to schema";');
1160
- }
1161
- });
1162
- this.ensureBlankLine();
1163
- this.emitBlock(["inline void to_json(json & j, ", this.withConst([ourQualifier, enumName]), " & x)"], false, () => {
1164
- this.emitBlock("switch (x)", false, () => {
1165
- this.forEachEnumCase(e, "none", (name, jsonName) => {
1166
- this.emitLine("case ", ourQualifier, enumName, "::", name, ": j = ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(jsonName)])]), "; break;");
1167
- });
1168
- this.emitLine('default: throw "This should not happen";');
1169
- });
1170
- });
1171
- }
1172
- emitTopLevelTypedef(t, name) {
1173
- this.emitLine("using ", name, " = ", this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, false), ";");
1174
- }
1175
- emitAllUnionFunctions() {
1176
- this.forEachUniqueUnion("leading-and-interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false)), (u) => this.emitUnionFunctions(u));
1177
- }
1178
- emitAllUnionHeaders() {
1179
- this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false)), (u) => this.emitUnionHeaders(u));
1180
- }
1181
- emitOptionalHelpers() {
1182
- this.emitLine("#ifndef NLOHMANN_OPT_HELPER");
1183
- this.emitLine("#define NLOHMANN_OPT_HELPER");
1184
- this.emitNamespaces(["nlohmann"], () => {
1185
- this.emitLine("template <typename T>");
1186
- this.emitBlock(["struct adl_serializer<", optionalType, "<T>>"], true, () => {
1187
- this.emitBlock(["static void to_json(json & j, ", this.withConst([optionalType, "<T>"]), " & opt)"], false, () => {
1188
- this.emitLine("if (!opt) j = nullptr; else j = *opt;");
1189
- });
1190
- this.ensureBlankLine();
1191
- this.emitBlock(["static ", optionalType, "<T> from_json(", this.withConst("json"), " & j)"], false, () => {
1192
- this.emitLine(`if (j.is_null()) return std::unique_ptr<T>(); else return std::unique_ptr<T>(new T(j.get<T>()));`);
1193
- });
1194
- });
1195
- });
1196
- this.emitLine("#endif");
1197
- }
1198
- emitDeclaration(decl) {
1199
- if (decl.kind === "forward") {
1200
- if (this._options.codeFormat) {
1201
- this.emitLine("class ", this.nameForNamedType(decl.type), ";");
1202
- }
1203
- else {
1204
- this.emitLine("struct ", this.nameForNamedType(decl.type), ";");
1205
- }
1206
- }
1207
- else if (decl.kind === "define") {
1208
- const t = decl.type;
1209
- const name = this.nameForNamedType(t);
1210
- if (t instanceof Type_1.ClassType) {
1211
- this.emitClass(t, name);
1212
- }
1213
- else if (t instanceof Type_1.EnumType) {
1214
- this.emitEnum(t, name);
1215
- }
1216
- else if (t instanceof Type_1.UnionType) {
1217
- this.emitUnionTypedefs(t, name);
1218
- }
1219
- else {
1220
- return (0, Support_1.panic)(`Cannot declare type ${t.kind}`);
1221
- }
1222
- }
1223
- else {
1224
- return (0, Support_1.assertNever)(decl.kind);
1225
- }
1226
- }
1227
- emitGetterSetter(t, getterName, setterName, memberName) {
1228
- this.emitLine("void ", setterName, "(", t, " ", memberName, ") { this->", memberName, " = ", memberName, "; }");
1229
- this.emitLine("auto ", getterName, "() const { return ", memberName, "; }");
1230
- }
1231
- emitConstraintClasses() {
1232
- const ourQualifier = this.ourQualifier(false);
1233
- const getterMinValue = this.lookupMemberName(MemberNames.GetMinValue);
1234
- const getterMaxValue = this.lookupMemberName(MemberNames.GetMaxValue);
1235
- const getterMinLength = this.lookupMemberName(MemberNames.GetMinLength);
1236
- const getterMaxLength = this.lookupMemberName(MemberNames.GetMaxLength);
1237
- const getterPattern = this.lookupMemberName(MemberNames.GetPattern);
1238
- const classConstraint = this.lookupGlobalName(GlobalNames.ClassMemberConstraints);
1239
- this.emitBlock(["class ", classConstraint], true, () => {
1240
- this.emitLine("private:");
1241
- let constraintMembers = this.getConstraintMembers();
1242
- for (const member of constraintMembers) {
1243
- this.emitMember([this._optionalType, "<", member.cppType, ">"], this.lookupMemberName(member.name));
1244
- }
1245
- this.ensureBlankLine();
1246
- this.emitLine("public:");
1247
- this.emitLine(classConstraint, "(");
1248
- this.indent(() => {
1249
- this.iterableForEach(constraintMembers, ({ name, cppType }, pos) => {
1250
- const comma = pos === "first" || pos === "middle" ? "," : [];
1251
- this.emitLine(this._optionalType, "<", cppType, "> ", this.lookupMemberName(name), comma);
1252
- });
1253
- });
1254
- const args = constraintMembers.map(({ name }) => {
1255
- const member = this.lookupMemberName(name);
1256
- return [member, "(", member, ")"];
1257
- });
1258
- this.emitLine(") : ", (0, collection_utils_1.arrayIntercalate)([", "], args), " {}");
1259
- this.emitLine(classConstraint, "() = default;");
1260
- this.emitLine("virtual ~", classConstraint, "() = default;");
1261
- for (const member of constraintMembers) {
1262
- this.ensureBlankLine();
1263
- this.emitGetterSetter((0, collection_utils_1.withDefault)(member.cppConstType, member.cppType), this.lookupMemberName(member.getter), this.lookupMemberName(member.setter), this.lookupMemberName(member.name));
1264
- }
1265
- });
1266
- this.ensureBlankLine();
1267
- const classConstEx = this.lookupGlobalName(GlobalNames.ClassMemberConstraintException);
1268
- this.emitBlock(["class ", classConstEx, " : public std::runtime_error"], true, () => {
1269
- this.emitLine("public:");
1270
- this.emitLine(classConstEx, "(", this._stringType.getConstType(), " msg) : std::runtime_error(", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), ["msg"]), ") {}");
1271
- });
1272
- this.ensureBlankLine();
1273
- const exceptions = [
1274
- GlobalNames.ValueTooLowException,
1275
- GlobalNames.ValueTooHighException,
1276
- GlobalNames.ValueTooShortException,
1277
- GlobalNames.ValueTooLongException,
1278
- GlobalNames.InvalidPatternException
1279
- ];
1280
- for (const ex of exceptions) {
1281
- const name = this.lookupGlobalName(ex);
1282
- this.emitBlock(["class ", name, " : public ", classConstEx], true, () => {
1283
- this.emitLine("public:");
1284
- this.emitLine(name, "(", this._stringType.getConstType(), " msg) : ", classConstEx, "(msg) {}");
1285
- });
1286
- this.ensureBlankLine();
1287
- }
1288
- const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
1289
- this.emitBlock([
1290
- "inline void ",
1291
- checkConst,
1292
- "(",
1293
- this._stringType.getConstType(),
1294
- " name, ",
1295
- this.withConst(classConstraint),
1296
- " & c, int64_t value)"
1297
- ], false, () => {
1298
- this.emitBlock(["if (c.", getterMinValue, "() != ", this._nulloptType, " && value < *c.", getterMinValue, "())"], false, () => {
1299
- this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLowException), " (", this._stringType.createStringLiteral(["Value too low for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinValue, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1300
- });
1301
- this.ensureBlankLine();
1302
- this.emitBlock(["if (c.", getterMaxValue, "() != ", this._nulloptType, " && value > *c.", getterMaxValue, "())"], false, () => {
1303
- this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooHighException), " (", this._stringType.createStringLiteral(["Value too high for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value"]), " + ", this._stringType.createStringLiteral([">"]), " + ", this._stringType.wrapToString(["*c.", getterMaxValue, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1304
- });
1305
- this.ensureBlankLine();
1306
- });
1307
- this.ensureBlankLine();
1308
- this.emitBlock([
1309
- "inline void ",
1310
- checkConst,
1311
- "(",
1312
- this._stringType.getConstType(),
1313
- " name, ",
1314
- this.withConst(classConstraint),
1315
- " & c, ",
1316
- this._stringType.getConstType(),
1317
- " value)"
1318
- ], false, () => {
1319
- this.emitBlock([
1320
- "if (c.",
1321
- getterMinLength,
1322
- "() != ",
1323
- this._nulloptType,
1324
- " && value.length() < *c.",
1325
- getterMinLength,
1326
- "())"
1327
- ], false, () => {
1328
- this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooShortException), " (", this._stringType.createStringLiteral(["Value too short for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral(["<"]), " + ", this._stringType.wrapToString(["*c.", getterMinLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1329
- });
1330
- this.ensureBlankLine();
1331
- this.emitBlock([
1332
- "if (c.",
1333
- getterMaxLength,
1334
- "() != ",
1335
- this._nulloptType,
1336
- " && value.length() > *c.",
1337
- getterMaxLength,
1338
- "())"
1339
- ], false, () => {
1340
- this.emitLine("throw ", this.lookupGlobalName(GlobalNames.ValueTooLongException), " (", this._stringType.createStringLiteral(["Value too long for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + ", this._stringType.wrapToString(["value.length()"]), " + ", this._stringType.createStringLiteral([">"]), " + ", this._stringType.wrapToString(["*c.", getterMaxLength, "()"]), " + ", this._stringType.createStringLiteral([")"]), ");");
1341
- });
1342
- this.ensureBlankLine();
1343
- this.emitBlock(["if (c.", getterPattern, "() != ", this._nulloptType, ")"], false, () => {
1344
- this.emitLine(this._stringType.getSMatch(), " result;");
1345
- this.emitLine("std::regex_search(value, result, ", this._stringType.getRegex(), "( *c.", getterPattern, "() ));");
1346
- this.emitBlock(["if (result.empty())"], false, () => {
1347
- this.emitLine("throw ", this.lookupGlobalName(GlobalNames.InvalidPatternException), " (", this._stringType.createStringLiteral(["Value doesn't match pattern for "]), " + name + ", this._stringType.createStringLiteral([" ("]), " + value +", this._stringType.createStringLiteral([" != "]), " + *c.", getterPattern, "() + ", this._stringType.createStringLiteral([")"]), ");");
1348
- });
1349
- });
1350
- this.ensureBlankLine();
1351
- });
1352
- }
1353
- emitHelperFunctions() {
1354
- this._stringType.emitHelperFunctions();
1355
- if (this._options.codeFormat &&
1356
- (0, collection_utils_1.iterableSome)(this.typeGraph.allTypesUnordered(), t => constraintsForType(t) !== undefined)) {
1357
- this.emitConstraintClasses();
1358
- this.ensureBlankLine();
1359
- }
1360
- this.ensureBlankLine();
1361
- let untypedMacroName = "NLOHMANN_UNTYPED_";
1362
- let optionalMacroName = "NLOHMANN_OPTIONAL_";
1363
- this._namespaceNames.forEach(value => {
1364
- // We can't use upper name, because namespaces are case sensitive
1365
- untypedMacroName += value;
1366
- untypedMacroName += "_";
1367
- optionalMacroName += value;
1368
- optionalMacroName += "_";
1369
- });
1370
- untypedMacroName += "HELPER";
1371
- untypedMacroName += "HELPER";
1372
- this.emitLine("#ifndef " + untypedMacroName);
1373
- this.emitLine("#define " + untypedMacroName);
1374
- this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, ", this.withConst("char"), " * property)"], false, () => {
1375
- this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
1376
- this.emitLine("return j.at(property).get<json>();");
1377
- });
1378
- this.emitLine("return json();");
1379
- });
1380
- this.ensureBlankLine();
1381
- this.emitBlock(["inline json get_untyped(", this.withConst("json"), " & j, std::string property)"], false, () => {
1382
- this.emitLine("return get_untyped(j, property.data());");
1383
- });
1384
- this.emitLine("#endif");
1385
- this.ensureBlankLine();
1386
- if (this.haveUnions || this.haveOptionalProperties) {
1387
- this.ensureBlankLine();
1388
- this.emitLine("#ifndef " + optionalMacroName);
1389
- this.emitLine("#define " + optionalMacroName);
1390
- this.emitLine("template <typename T>");
1391
- this.emitBlock([
1392
- "inline ",
1393
- optionalType,
1394
- "<T> get_optional(",
1395
- this.withConst("json"),
1396
- " & j, ",
1397
- this.withConst("char"),
1398
- " * property)"
1399
- ], false, () => {
1400
- this.emitBlock(["if (j.find(property) != j.end())"], false, () => {
1401
- this.emitLine("return j.at(property).get<", optionalType, "<T>>();");
1402
- });
1403
- this.emitLine("return ", optionalType, "<T>();");
1404
- });
1405
- this.ensureBlankLine();
1406
- this.emitLine("template <typename T>");
1407
- this.emitBlock(["inline ", optionalType, "<T> get_optional(", this.withConst("json"), " & j, std::string property)"], false, () => {
1408
- this.emitLine("return get_optional<T>(j, property.data());");
1409
- });
1410
- this.emitLine("#endif");
1411
- this.ensureBlankLine();
1412
- }
1413
- }
1414
- emitExtraIncludes() {
1415
- this.ensureBlankLine();
1416
- if (this._options.codeFormat) {
1417
- if (this._options.boost) {
1418
- this.emitInclude(true, `boost/optional.hpp`);
1419
- }
1420
- else {
1421
- this.emitInclude(true, `optional`);
1422
- }
1423
- this.emitInclude(true, `stdexcept`);
1424
- this.emitInclude(true, `regex`);
1425
- }
1426
- if (this._options.wstring) {
1427
- this.emitInclude(true, `codecvt`);
1428
- this.emitInclude(true, `locale`);
1429
- }
1430
- // Include unordered_map if contains large enums
1431
- if (Array.from(this.enums).some(enumType => this.isLargeEnum(enumType))) {
1432
- this.emitInclude(true, `unordered_map`);
1433
- }
1434
- this.ensureBlankLine();
1435
- }
1436
- emitHelper() {
1437
- this.startFile("helper.hpp", false);
1438
- this.emitExtraIncludes();
1439
- this.emitInclude(true, `sstream`);
1440
- this.ensureBlankLine();
1441
- this.emitNamespaces(this._namespaceNames, () => {
1442
- this.emitLine("using nlohmann::json;");
1443
- this.ensureBlankLine();
1444
- this.emitHelperFunctions();
1445
- });
1446
- if (this.haveUnions || this.haveOptionalProperties) {
1447
- this.ensureBlankLine();
1448
- this.emitOptionalHelpers();
1449
- }
1450
- this.finishFile();
1451
- }
1452
- emitTypes() {
1453
- if (!this._options.justTypes) {
1454
- this.emitLine("using nlohmann::json;");
1455
- this.ensureBlankLine();
1456
- this.emitHelperFunctions();
1457
- }
1458
- this.forEachDeclaration("interposing", decl => this.emitDeclaration(decl));
1459
- if (this._options.justTypes)
1460
- return;
1461
- this.forEachTopLevel("leading", (t, name) => this.emitTopLevelTypedef(t, name), t => this.namedTypeToNameForTopLevel(t) === undefined);
1462
- }
1463
- gatherUserNamespaceForwardDecls() {
1464
- return this.gatherSource(() => {
1465
- this.forEachObject("leading-and-interposing", (_, className) => this.emitClassHeaders(className));
1466
- this.forEachEnum("leading-and-interposing", (_, enumName) => this.emitEnumHeaders(enumName));
1467
- });
1468
- }
1469
- gatherNlohmannNamespaceForwardDecls() {
1470
- return this.gatherSource(() => {
1471
- this.forEachTopLevel("leading-and-interposing", (t, className) => this.emitTopLevelHeaders(t, className));
1472
- this.ensureBlankLine();
1473
- this.emitAllUnionHeaders();
1474
- });
1475
- }
1476
- emitUserNamespaceImpls() {
1477
- this.forEachObject("leading-and-interposing", (c, className) => this.emitClassFunctions(c, className));
1478
- this.forEachEnum("leading-and-interposing", (e, enumName) => this.emitEnumFunctions(e, enumName));
1479
- }
1480
- emitNlohmannNamespaceImpls() {
1481
- this.forEachTopLevel("leading-and-interposing", (t, name) => this.emitTopLevelFunction(t, name), t => this.namedTypeToNameForTopLevel(t) === undefined);
1482
- this.ensureBlankLine();
1483
- this.emitAllUnionFunctions();
1484
- }
1485
- emitGenerators() {
1486
- if (this._options.justTypes) {
1487
- let didEmit = false;
1488
- const gathered = this.gatherSource(() => this.emitNamespaces(this._namespaceNames, () => {
1489
- didEmit = this.forEachTopLevel("none", (t, name) => this.emitTopLevelTypedef(t, name), t => this.namedTypeToNameForTopLevel(t) === undefined);
1490
- }));
1491
- if (didEmit) {
1492
- this.emitGatheredSource(gathered);
1493
- this.ensureBlankLine();
1494
- }
1495
- }
1496
- else {
1497
- let userNamespaceForwardDecls = this.gatherUserNamespaceForwardDecls();
1498
- let nlohmannNamespaceForwardDecls = this.gatherNlohmannNamespaceForwardDecls();
1499
- if (userNamespaceForwardDecls.length == 0 && nlohmannNamespaceForwardDecls.length > 0) {
1500
- this.emitNamespaces(["nlohmann"], () => {
1501
- this.emitGatheredSource(nlohmannNamespaceForwardDecls);
1502
- this.emitNlohmannNamespaceImpls();
1503
- });
1504
- }
1505
- else if (userNamespaceForwardDecls.length > 0 && nlohmannNamespaceForwardDecls.length == 0) {
1506
- this.emitNamespaces(this._namespaceNames, () => {
1507
- this.emitGatheredSource(userNamespaceForwardDecls);
1508
- this.emitUserNamespaceImpls();
1509
- });
1510
- }
1511
- else if (userNamespaceForwardDecls.length > 0 && nlohmannNamespaceForwardDecls.length > 0) {
1512
- this.emitNamespaces(this._namespaceNames, () => {
1513
- this.emitGatheredSource(userNamespaceForwardDecls);
1514
- });
1515
- this.emitNamespaces(["nlohmann"], () => {
1516
- this.emitGatheredSource(nlohmannNamespaceForwardDecls);
1517
- });
1518
- this.emitNamespaces(this._namespaceNames, () => {
1519
- this.emitUserNamespaceImpls();
1520
- });
1521
- this.emitNamespaces(["nlohmann"], () => {
1522
- this.emitNlohmannNamespaceImpls();
1523
- });
1524
- }
1525
- }
1526
- }
1527
- emitSingleSourceStructure(proposedFilename) {
1528
- this.startFile(proposedFilename);
1529
- this._generatedFiles.add(proposedFilename);
1530
- this.emitExtraIncludes();
1531
- if (this._options.justTypes) {
1532
- this.emitTypes();
1533
- }
1534
- else {
1535
- if (!this._options.justTypes && this.haveNamedTypes && (this.haveUnions || this.haveOptionalProperties)) {
1536
- this.emitOptionalHelpers();
1537
- this.ensureBlankLine();
1538
- }
1539
- this.emitNamespaces(this._namespaceNames, () => this.emitTypes());
1540
- }
1541
- this.ensureBlankLine();
1542
- this.emitGenerators();
1543
- this.finishFile();
1544
- }
1545
- updateIncludes(isClassMember, includes, propertyType, _defName) {
1546
- const propTypes = this.generatedTypes(isClassMember, propertyType);
1547
- for (const t of propTypes) {
1548
- const typeName = this.sourcelikeToString(t.name);
1549
- let propRecord = { kind: undefined, typeKind: undefined };
1550
- if (t.type instanceof Type_1.ClassType) {
1551
- /**
1552
- * Ok. We can NOT forward declare direct class members, e.g. a class type is included
1553
- * at level#0. HOWEVER if it is not a direct class member (e.g. std::shared_ptr<Class>),
1554
- * - level > 0 - then we can SURELY forward declare it.
1555
- */
1556
- propRecord.typeKind = "class";
1557
- propRecord.kind = t.level === 0 ? IncludeKind.Include : IncludeKind.ForwardDeclare;
1558
- if (t.forceInclude) {
1559
- propRecord.kind = IncludeKind.Include;
1560
- }
1561
- }
1562
- else if (t.type instanceof Type_1.EnumType) {
1563
- propRecord.typeKind = "enum";
1564
- propRecord.kind = IncludeKind.ForwardDeclare;
1565
- }
1566
- else if (t.type instanceof Type_1.UnionType) {
1567
- propRecord.typeKind = "union";
1568
- /** Recurse into the union */
1569
- const [maybeNull] = (0, TypeUtils_1.removeNullFromUnion)(t.type, true);
1570
- if (maybeNull !== undefined) {
1571
- /** Houston this is a variant, include it */
1572
- propRecord.kind = IncludeKind.Include;
1573
- }
1574
- else {
1575
- if (t.forceInclude) {
1576
- propRecord.kind = IncludeKind.Include;
1577
- }
1578
- else {
1579
- propRecord.kind = IncludeKind.ForwardDeclare;
1580
- }
1581
- }
1582
- }
1583
- if (includes.has(typeName)) {
1584
- const incKind = includes.get(typeName);
1585
- /**
1586
- * If we already include the type as typed include,
1587
- * do not write it over with forward declare
1588
- */
1589
- if (incKind !== undefined && incKind.kind === IncludeKind.ForwardDeclare) {
1590
- includes.set(typeName, propRecord);
1591
- }
1592
- }
1593
- else {
1594
- includes.set(typeName, propRecord);
1595
- }
1596
- }
1597
- }
1598
- emitIncludes(c, defName) {
1599
- /**
1600
- * Need to generate "includes", in terms 'c' has members, which
1601
- * are defined by others
1602
- */
1603
- let includes = new Map();
1604
- if (c instanceof Type_1.UnionType) {
1605
- this.updateIncludes(false, includes, c, defName);
1606
- }
1607
- else if (c instanceof Type_1.ClassType) {
1608
- this.forEachClassProperty(c, "none", (_name, _jsonName, property) => {
1609
- this.updateIncludes(true, includes, property.type, defName);
1610
- });
1611
- }
1612
- if (includes.size !== 0) {
1613
- let numForwards = 0;
1614
- let numIncludes = 0;
1615
- includes.forEach((rec, name) => {
1616
- /** Don't bother including the one we are defining */
1617
- if (name === defName) {
1618
- return;
1619
- }
1620
- if (rec.kind !== IncludeKind.ForwardDeclare) {
1621
- this.emitInclude(false, [name, ".hpp"]);
1622
- numIncludes++;
1623
- }
1624
- else {
1625
- numForwards++;
1626
- }
1627
- });
1628
- if (numIncludes > 0) {
1629
- this.ensureBlankLine();
1630
- }
1631
- if (numForwards > 0) {
1632
- this.emitNamespaces(this._namespaceNames, () => {
1633
- includes.forEach((rec, name) => {
1634
- /** Don't bother including the one we are defining */
1635
- if (name === defName) {
1636
- return;
1637
- }
1638
- if (rec.kind !== IncludeKind.ForwardDeclare) {
1639
- return;
1640
- }
1641
- if (rec.typeKind === "class" || rec.typeKind === "union") {
1642
- if (this._options.codeFormat) {
1643
- this.emitLine("class ", name, ";");
1644
- }
1645
- else {
1646
- this.emitLine("struct ", name, ";");
1647
- }
1648
- }
1649
- else if (rec.typeKind === "enum") {
1650
- this.emitLine("enum class ", name, " : ", this._enumType, ";");
1651
- }
1652
- else {
1653
- (0, Support_1.panic)(`Invalid type "${rec.typeKind}" to forward declare`);
1654
- }
1655
- });
1656
- });
1657
- }
1658
- this.ensureBlankLine();
1659
- }
1660
- }
1661
- emitDefinition(d, defName) {
1662
- const name = this.sourcelikeToString(defName) + ".hpp";
1663
- this.startFile(name, true);
1664
- this._generatedFiles.add(name);
1665
- this.emitIncludes(d, this.sourcelikeToString(defName));
1666
- this.emitNamespaces(this._namespaceNames, () => {
1667
- this.emitDescription(this.descriptionForType(d));
1668
- this.ensureBlankLine();
1669
- this.emitLine("using nlohmann::json;");
1670
- this.ensureBlankLine();
1671
- if (d instanceof Type_1.ClassType) {
1672
- this.emitClass(d, defName);
1673
- }
1674
- else if (d instanceof Type_1.EnumType) {
1675
- this.emitEnum(d, defName);
1676
- }
1677
- else if (d instanceof Type_1.UnionType) {
1678
- this.emitUnionTypedefs(d, defName);
1679
- }
1680
- });
1681
- this.finishFile();
1682
- }
1683
- emitMultiSourceStructure(proposedFilename) {
1684
- if (!this._options.justTypes && this.haveNamedTypes) {
1685
- this.emitHelper();
1686
- this.startFile("Generators.hpp", true);
1687
- this._allTypeNames.forEach(t => {
1688
- this.emitInclude(false, [t, ".hpp"]);
1689
- });
1690
- this.ensureBlankLine();
1691
- this.emitGenerators();
1692
- this.finishFile();
1693
- }
1694
- this.forEachNamedType("leading-and-interposing", (c, n) => {
1695
- this.emitDefinition(c, n);
1696
- }, (e, n) => {
1697
- this.emitDefinition(e, n);
1698
- }, (u, n) => {
1699
- this.emitDefinition(u, n);
1700
- });
1701
- /**
1702
- * If for some reason we have not generated anything,
1703
- * it means that a unnamed type has been generated - or nothing.
1704
- */
1705
- if (!this._generatedFiles.has(proposedFilename)) {
1706
- if (!this.haveNamedTypes) {
1707
- this.emitHelper();
1708
- }
1709
- this.startFile(proposedFilename);
1710
- this._generatedFiles.forEach(f => {
1711
- this.emitInclude(false, f);
1712
- });
1713
- this.emitNamespaces(this._namespaceNames, () => {
1714
- this.forEachTopLevel("leading", (t, name) => this.emitTopLevelTypedef(t, name), t => this.namedTypeToNameForTopLevel(t) === undefined);
1715
- });
1716
- this.finishFile();
1717
- }
1718
- }
1719
- emitSourceStructure(proposedFilename) {
1720
- this._generatedFiles.clear();
1721
- /** Gather all the unique/custom types used by the schema */
1722
- this._allTypeNames.clear();
1723
- this.forEachDeclaration("none", decl => {
1724
- const definedTypes = (0, TypeUtils_1.directlyReachableTypes)(decl.type, t => {
1725
- if ((0, TypeUtils_1.isNamedType)(t) && (t instanceof Type_1.ClassType || t instanceof Type_1.EnumType || t instanceof Type_1.UnionType)) {
1726
- return new Set([
1727
- this.sourcelikeToString(this.cppType(t, {
1728
- needsForwardIndirection: false,
1729
- needsOptionalIndirection: false,
1730
- inJsonNamespace: false
1731
- }, true, false, false))
1732
- ]);
1733
- }
1734
- return null;
1735
- });
1736
- this._allTypeNames = (0, collection_utils_1.setUnion)(definedTypes, this._allTypeNames);
1737
- });
1738
- if (this._options.typeSourceStyle) {
1739
- this.emitSingleSourceStructure(proposedFilename);
1740
- }
1741
- else {
1742
- this.emitMultiSourceStructure(proposedFilename);
1743
- }
1744
- }
1745
- isConversionRequired(t) {
1746
- let originalType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, false);
1747
- let newType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, false);
1748
- return originalType !== newType;
1749
- }
1750
- NarrowString = new (class extends BaseString {
1751
- constructor() {
1752
- super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
1753
- }
1754
- wrapEncodingChange(_qualifier, _fromType, _toType, inner) {
1755
- return inner;
1756
- }
1757
- emitHelperFunctions() {
1758
- return;
1759
- }
1760
- })();
1761
- WideString = new (class extends BaseString {
1762
- superThis;
1763
- constructor(superThis) {
1764
- super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
1765
- this.superThis = superThis;
1766
- }
1767
- wrapEncodingChange(qualifier, fromType, toType, inner) {
1768
- if (this.superThis.sourcelikeToString(fromType) === this.superThis.sourcelikeToString(toType)) {
1769
- return inner;
1770
- }
1771
- return [
1772
- addQualifier(qualifier, [this._encodingClass]),
1773
- "<",
1774
- fromType,
1775
- ", ",
1776
- toType,
1777
- ">::",
1778
- this._encodingFunction,
1779
- "(",
1780
- inner,
1781
- ")"
1782
- ];
1783
- }
1784
- emitHelperFunctions() {
1785
- this.superThis.emitLine("template<typename T>");
1786
- this.superThis.emitLine("struct tag {};");
1787
- this.superThis.ensureBlankLine();
1788
- this.superThis.emitLine("template<typename fromType, typename toType>");
1789
- this.superThis.emitBlock(["class Utf16_Utf8"], true, () => {
1790
- this.superThis.emitLine("private:");
1791
- this.superThis.emitLine("template<typename TF, typename TT>");
1792
- this.superThis.emitBlock(["static toType convert(tag<std::shared_ptr<TF> >, tag<std::shared_ptr<TT> >, fromType ptr)"], false, () => {
1793
- this.superThis.emitLine("if (ptr == nullptr) return std::unique_ptr<TT>(); else return std::unique_ptr<TT>(new TT(Utf16_Utf8<TF,TT>::convert(*ptr)));");
1794
- });
1795
- this.superThis.ensureBlankLine();
1796
- this.superThis.emitLine("template<typename TF, typename TT>");
1797
- this.superThis.emitBlock(["static toType convert(tag<std::vector<TF> >, tag<std::vector<TT> >, fromType v)"], false, () => {
1798
- this.superThis.emitLine("auto it = v.begin();");
1799
- this.superThis.emitLine("auto newVector = std::vector<TT>();");
1800
- this.superThis.emitBlock(["while (it != v.end())"], false, () => {
1801
- this.superThis.emitLine("newVector.push_back(Utf16_Utf8<TF,TT>::convert(*it));");
1802
- this.superThis.emitLine("it++;");
1803
- });
1804
- this.superThis.emitLine("return newVector;");
1805
- });
1806
- this.superThis.ensureBlankLine();
1807
- this.superThis.emitLine("template<typename KF, typename VF, typename KT, typename VT>");
1808
- this.superThis.emitBlock(["static toType convert(tag<std::map<KF,VF> >, tag<std::map<KT,VT> >, fromType m)"], false, () => {
1809
- this.superThis.emitLine("auto it = m.begin();");
1810
- this.superThis.emitLine("auto newMap = std::map<KT, VT>();");
1811
- this.superThis.emitBlock(["while (it != m.end())"], false, () => {
1812
- this.superThis.emitLine("newMap.insert(std::pair<KT, VT>(Utf16_Utf8<KF, KT>::convert(it->first), Utf16_Utf8<VF, VT>::convert(it->second)));");
1813
- this.superThis.emitLine("it++;");
1814
- });
1815
- this.superThis.emitLine("return newMap;");
1816
- });
1817
- this.superThis.ensureBlankLine();
1818
- this.superThis.emitLine("template<typename TF, typename TT>");
1819
- this.superThis.emitBlock(["static fromType convert(tag<TF>, tag<TT>, fromType from)"], false, () => {
1820
- this.superThis.emitLine("return from;");
1821
- });
1822
- this.superThis.ensureBlankLine();
1823
- this.superThis.emitBlock(["static std::wstring convert(tag<std::string>, tag<std::wstring>, std::string str)"], false, () => {
1824
- this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.from_bytes(str.data());");
1825
- });
1826
- this.superThis.ensureBlankLine();
1827
- this.superThis.emitBlock(["static std::string convert(tag<std::wstring>, tag<std::string>, std::wstring str)"], false, () => {
1828
- this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.to_bytes(str.data());");
1829
- });
1830
- this.superThis.ensureBlankLine();
1831
- this.superThis.emitLine("public:");
1832
- this.superThis.emitBlock(["static toType convert(fromType in)"], false, () => {
1833
- this.superThis.emitLine("return convert(tag<fromType>(), tag<toType>(), in);");
1834
- });
1835
- });
1836
- this.superThis.ensureBlankLine();
1837
- this.superThis.emitLine("template<typename T>");
1838
- this.superThis.emitBlock(["std::wstring wdump(const T& j)"], false, () => {
1839
- this.superThis.emitLine("std::ostringstream s;");
1840
- this.superThis.emitLine("s << j;");
1841
- this.superThis.emitLine("return ", this.superThis.ourQualifier(false), "Utf16_Utf8<std::string, std::wstring>::convert(s.str()); ");
1842
- });
1843
- this.superThis.ensureBlankLine();
1844
- }
1845
- })(this);
1846
- }
1847
- exports.CPlusPlusRenderer = CPlusPlusRenderer;