quicktype-core 23.0.3 → 23.0.5
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.
- package/dist/language/CPlusPlus.js +124 -28
- package/package.json +1 -1
|
@@ -765,7 +765,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
765
765
|
const [maybeNull, nonNulls] = (0, TypeUtils_1.removeNullFromUnion)(u, true);
|
|
766
766
|
(0, Support_2.assert)(nonNulls.size >= 2, "Variant not needed for less than two types.");
|
|
767
767
|
const indirection = maybeNull !== null;
|
|
768
|
-
const variant = this.cppTypeInOptional(nonNulls, {
|
|
768
|
+
const variant = this.cppTypeInOptional(nonNulls, {
|
|
769
|
+
needsForwardIndirection: !indirection,
|
|
770
|
+
needsOptionalIndirection: !indirection,
|
|
771
|
+
inJsonNamespace
|
|
772
|
+
}, true, false);
|
|
769
773
|
if (!indirection) {
|
|
770
774
|
return variant;
|
|
771
775
|
}
|
|
@@ -814,7 +818,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
814
818
|
}
|
|
815
819
|
}, arrayType => [
|
|
816
820
|
"std::vector<",
|
|
817
|
-
this.cppType(arrayType.items, {
|
|
821
|
+
this.cppType(arrayType.items, {
|
|
822
|
+
needsForwardIndirection: false,
|
|
823
|
+
needsOptionalIndirection: true,
|
|
824
|
+
inJsonNamespace
|
|
825
|
+
}, withIssues, forceNarrowString, false),
|
|
818
826
|
">"
|
|
819
827
|
], classType => this.variantIndirection(classType, ctx.needsForwardIndirection && this.isForwardDeclaredType(classType) && !isOptional, [this.ourQualifier(inJsonNamespace), this.nameForNamedType(classType)]), mapType => {
|
|
820
828
|
let keyType = this._stringType.getType();
|
|
@@ -825,14 +833,22 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
825
833
|
"std::map<",
|
|
826
834
|
keyType,
|
|
827
835
|
", ",
|
|
828
|
-
this.cppType(mapType.values, {
|
|
836
|
+
this.cppType(mapType.values, {
|
|
837
|
+
needsForwardIndirection: false,
|
|
838
|
+
needsOptionalIndirection: true,
|
|
839
|
+
inJsonNamespace
|
|
840
|
+
}, withIssues, forceNarrowString, false),
|
|
829
841
|
">"
|
|
830
842
|
];
|
|
831
843
|
}, enumType => [this.ourQualifier(inJsonNamespace), this.nameForNamedType(enumType)], unionType => {
|
|
832
844
|
const nullable = (0, TypeUtils_1.nullableFromUnion)(unionType);
|
|
833
845
|
if (nullable !== null) {
|
|
834
846
|
isOptional = true;
|
|
835
|
-
return this.cppType(nullable, {
|
|
847
|
+
return this.cppType(nullable, {
|
|
848
|
+
needsForwardIndirection: false,
|
|
849
|
+
needsOptionalIndirection: false,
|
|
850
|
+
inJsonNamespace
|
|
851
|
+
}, withIssues, forceNarrowString, false);
|
|
836
852
|
}
|
|
837
853
|
else {
|
|
838
854
|
return [this.ourQualifier(inJsonNamespace), this.nameForNamedType(unionType)];
|
|
@@ -920,7 +936,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
920
936
|
if (this._options.codeFormat) {
|
|
921
937
|
this.emitLine("private:");
|
|
922
938
|
this.forEachClassProperty(c, "none", (name, jsonName, property) => {
|
|
923
|
-
this.emitMember(this.cppType(property.type, {
|
|
939
|
+
this.emitMember(this.cppType(property.type, {
|
|
940
|
+
needsForwardIndirection: true,
|
|
941
|
+
needsOptionalIndirection: true,
|
|
942
|
+
inJsonNamespace: false
|
|
943
|
+
}, true, false, property.isOptional), name);
|
|
924
944
|
if (constraints !== undefined && constraints.has(jsonName)) {
|
|
925
945
|
/** FIXME!!! NameStyle will/can collide with other Names */
|
|
926
946
|
const cnst = this.lookupGlobalName(GlobalNames.ClassMemberConstraints);
|
|
@@ -933,11 +953,19 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
933
953
|
this.forEachClassProperty(c, "none", (name, jsonName, property) => {
|
|
934
954
|
this.emitDescription(this.descriptionForClassProperty(c, jsonName));
|
|
935
955
|
if (!this._options.codeFormat) {
|
|
936
|
-
this.emitMember(this.cppType(property.type, {
|
|
956
|
+
this.emitMember(this.cppType(property.type, {
|
|
957
|
+
needsForwardIndirection: true,
|
|
958
|
+
needsOptionalIndirection: true,
|
|
959
|
+
inJsonNamespace: false
|
|
960
|
+
}, true, false, property.isOptional), name);
|
|
937
961
|
}
|
|
938
962
|
else {
|
|
939
963
|
const [getterName, mutableGetterName, setterName] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
|
|
940
|
-
const rendered = this.cppType(property.type, {
|
|
964
|
+
const rendered = this.cppType(property.type, {
|
|
965
|
+
needsForwardIndirection: true,
|
|
966
|
+
needsOptionalIndirection: true,
|
|
967
|
+
inJsonNamespace: false
|
|
968
|
+
}, true, false, property.isOptional);
|
|
941
969
|
/**
|
|
942
970
|
* fix for optional type -> e.g. unique_ptrs can't be copied
|
|
943
971
|
* One might as why the "this->xxx = value". Simple if we have
|
|
@@ -1067,8 +1095,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1067
1095
|
className,
|
|
1068
1096
|
"& x)"
|
|
1069
1097
|
], false, () => {
|
|
1070
|
-
cppType = this.cppType(t, {
|
|
1071
|
-
|
|
1098
|
+
cppType = this.cppType(t, {
|
|
1099
|
+
needsForwardIndirection: true,
|
|
1100
|
+
needsOptionalIndirection: true,
|
|
1101
|
+
inJsonNamespace: true
|
|
1102
|
+
}, false, true, false);
|
|
1103
|
+
toType = this.cppType(t, {
|
|
1104
|
+
needsForwardIndirection: true,
|
|
1105
|
+
needsOptionalIndirection: true,
|
|
1106
|
+
inJsonNamespace: true
|
|
1107
|
+
}, false, false, false);
|
|
1072
1108
|
this.emitLine([
|
|
1073
1109
|
"x = ",
|
|
1074
1110
|
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
@@ -1087,8 +1123,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1087
1123
|
this.withConst([ourQualifier, className]),
|
|
1088
1124
|
" & x)"
|
|
1089
1125
|
], false, () => {
|
|
1090
|
-
cppType = this.cppType(t, {
|
|
1091
|
-
|
|
1126
|
+
cppType = this.cppType(t, {
|
|
1127
|
+
needsForwardIndirection: true,
|
|
1128
|
+
needsOptionalIndirection: true,
|
|
1129
|
+
inJsonNamespace: true
|
|
1130
|
+
}, false, false, false);
|
|
1131
|
+
toType = this.cppType(t, {
|
|
1132
|
+
needsForwardIndirection: true,
|
|
1133
|
+
needsOptionalIndirection: true,
|
|
1134
|
+
inJsonNamespace: true
|
|
1135
|
+
}, false, true, false);
|
|
1092
1136
|
this.emitLine([
|
|
1093
1137
|
"j = ",
|
|
1094
1138
|
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, "x"),
|
|
@@ -1157,8 +1201,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1157
1201
|
return;
|
|
1158
1202
|
}
|
|
1159
1203
|
}
|
|
1160
|
-
cppType = this.cppType(t, {
|
|
1161
|
-
|
|
1204
|
+
cppType = this.cppType(t, {
|
|
1205
|
+
needsForwardIndirection: true,
|
|
1206
|
+
needsOptionalIndirection: true,
|
|
1207
|
+
inJsonNamespace: false
|
|
1208
|
+
}, false, true, p.isOptional);
|
|
1209
|
+
toType = this.cppType(t, {
|
|
1210
|
+
needsForwardIndirection: true,
|
|
1211
|
+
needsOptionalIndirection: true,
|
|
1212
|
+
inJsonNamespace: false
|
|
1213
|
+
}, false, false, p.isOptional);
|
|
1162
1214
|
this.emitLine(assignment.wrap([], this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
1163
1215
|
"j.at(",
|
|
1164
1216
|
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([(0, Strings_1.stringEscape)(json)])),
|
|
@@ -1173,8 +1225,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1173
1225
|
this.emitLine("j = json::object();");
|
|
1174
1226
|
this.forEachClassProperty(c, "none", (name, json, p) => {
|
|
1175
1227
|
const t = p.type;
|
|
1176
|
-
cppType = this.cppType(t, {
|
|
1177
|
-
|
|
1228
|
+
cppType = this.cppType(t, {
|
|
1229
|
+
needsForwardIndirection: true,
|
|
1230
|
+
needsOptionalIndirection: true,
|
|
1231
|
+
inJsonNamespace: false
|
|
1232
|
+
}, false, false, p.isOptional);
|
|
1233
|
+
toType = this.cppType(t, {
|
|
1234
|
+
needsForwardIndirection: true,
|
|
1235
|
+
needsOptionalIndirection: true,
|
|
1236
|
+
inJsonNamespace: false
|
|
1237
|
+
}, false, true, p.isOptional);
|
|
1178
1238
|
const [getterName, ,] = (0, Support_1.defined)(this._gettersAndSettersForPropertyName.get(name));
|
|
1179
1239
|
let getter;
|
|
1180
1240
|
if (this._options.codeFormat) {
|
|
@@ -1232,7 +1292,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1232
1292
|
// but it's nontrivial to detect that (consider variant<string, variant<map<string, string>, int>> which
|
|
1233
1293
|
// does need an adl_serializer specialization) so we'll just specialize every time.
|
|
1234
1294
|
const nonNulls = (0, TypeUtils_1.removeNullFromUnion)(u, true)[1];
|
|
1235
|
-
const variantType = this.cppTypeInOptional(nonNulls, {
|
|
1295
|
+
const variantType = this.cppTypeInOptional(nonNulls, {
|
|
1296
|
+
needsForwardIndirection: false,
|
|
1297
|
+
needsOptionalIndirection: false,
|
|
1298
|
+
inJsonNamespace: true
|
|
1299
|
+
}, false, false);
|
|
1236
1300
|
this.emitLine("template <>");
|
|
1237
1301
|
this.emitBlock(["struct adl_serializer<", variantType, ">"], true, () => {
|
|
1238
1302
|
this.emitLine("static void from_json(", this.withConst("json"), " & j, ", variantType, " & x);");
|
|
@@ -1253,7 +1317,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1253
1317
|
["enum", "is_string"]
|
|
1254
1318
|
];
|
|
1255
1319
|
const nonNulls = (0, TypeUtils_1.removeNullFromUnion)(u, true)[1];
|
|
1256
|
-
const variantType = this.cppTypeInOptional(nonNulls, {
|
|
1320
|
+
const variantType = this.cppTypeInOptional(nonNulls, {
|
|
1321
|
+
needsForwardIndirection: false,
|
|
1322
|
+
needsOptionalIndirection: false,
|
|
1323
|
+
inJsonNamespace: true
|
|
1324
|
+
}, false, false);
|
|
1257
1325
|
this.emitBlock([
|
|
1258
1326
|
"inline void adl_serializer<",
|
|
1259
1327
|
variantType,
|
|
@@ -1270,8 +1338,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1270
1338
|
continue;
|
|
1271
1339
|
this.emitLine(onFirst ? "if" : "else if", " (j.", func, "())");
|
|
1272
1340
|
this.indent(() => {
|
|
1273
|
-
const cppType = this.cppType(typeForKind, {
|
|
1274
|
-
|
|
1341
|
+
const cppType = this.cppType(typeForKind, {
|
|
1342
|
+
needsForwardIndirection: true,
|
|
1343
|
+
needsOptionalIndirection: true,
|
|
1344
|
+
inJsonNamespace: true
|
|
1345
|
+
}, false, true, false);
|
|
1346
|
+
let toType = this.cppType(typeForKind, {
|
|
1347
|
+
needsForwardIndirection: true,
|
|
1348
|
+
needsOptionalIndirection: true,
|
|
1349
|
+
inJsonNamespace: true
|
|
1350
|
+
}, false, false, false);
|
|
1275
1351
|
this.emitLine("x = ", this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
1276
1352
|
"j.get<",
|
|
1277
1353
|
cppType,
|
|
@@ -1280,7 +1356,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1280
1356
|
});
|
|
1281
1357
|
onFirst = false;
|
|
1282
1358
|
}
|
|
1283
|
-
this.emitLine('else throw "Could not
|
|
1359
|
+
this.emitLine('else throw std::runtime_error("Could not deserialise!");');
|
|
1284
1360
|
});
|
|
1285
1361
|
this.ensureBlankLine();
|
|
1286
1362
|
this.emitBlock(["inline void adl_serializer<", variantType, ">::to_json(json & j, ", this.withConst(variantType), " & x)"], false, () => {
|
|
@@ -1308,7 +1384,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1308
1384
|
});
|
|
1309
1385
|
i++;
|
|
1310
1386
|
}
|
|
1311
|
-
this.emitLine('default: throw "Input JSON does not conform to schema";');
|
|
1387
|
+
this.emitLine('default: throw std::runtime_error("Input JSON does not conform to schema!");');
|
|
1312
1388
|
});
|
|
1313
1389
|
});
|
|
1314
1390
|
}
|
|
@@ -1350,7 +1426,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1350
1426
|
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, ";");
|
|
1351
1427
|
onFirst = false;
|
|
1352
1428
|
});
|
|
1353
|
-
this.emitLine('else throw "Input JSON does not conform to schema";');
|
|
1429
|
+
this.emitLine('else { throw std::runtime_error("Input JSON does not conform to schema!"); }');
|
|
1354
1430
|
}
|
|
1355
1431
|
});
|
|
1356
1432
|
this.ensureBlankLine();
|
|
@@ -1359,18 +1435,30 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1359
1435
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1360
1436
|
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;");
|
|
1361
1437
|
});
|
|
1362
|
-
this.emitLine('default: throw "This should not happen";');
|
|
1438
|
+
this.emitLine('default: throw std::runtime_error("This should not happen");');
|
|
1363
1439
|
});
|
|
1364
1440
|
});
|
|
1365
1441
|
}
|
|
1366
1442
|
emitTopLevelTypedef(t, name) {
|
|
1367
|
-
this.emitLine("using ", name, " = ", this.cppType(t, {
|
|
1443
|
+
this.emitLine("using ", name, " = ", this.cppType(t, {
|
|
1444
|
+
needsForwardIndirection: true,
|
|
1445
|
+
needsOptionalIndirection: true,
|
|
1446
|
+
inJsonNamespace: false
|
|
1447
|
+
}, true, false, false), ";");
|
|
1368
1448
|
}
|
|
1369
1449
|
emitAllUnionFunctions() {
|
|
1370
|
-
this.forEachUniqueUnion("leading-and-interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], {
|
|
1450
|
+
this.forEachUniqueUnion("leading-and-interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], {
|
|
1451
|
+
needsForwardIndirection: false,
|
|
1452
|
+
needsOptionalIndirection: false,
|
|
1453
|
+
inJsonNamespace: true
|
|
1454
|
+
}, false, false)), (u) => this.emitUnionFunctions(u));
|
|
1371
1455
|
}
|
|
1372
1456
|
emitAllUnionHeaders() {
|
|
1373
|
-
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], {
|
|
1457
|
+
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional((0, TypeUtils_1.removeNullFromUnion)(u, true)[1], {
|
|
1458
|
+
needsForwardIndirection: false,
|
|
1459
|
+
needsOptionalIndirection: false,
|
|
1460
|
+
inJsonNamespace: true
|
|
1461
|
+
}, false, false)), (u) => this.emitUnionHeaders(u));
|
|
1374
1462
|
}
|
|
1375
1463
|
emitOptionalHelpers() {
|
|
1376
1464
|
this.emitLine("#ifndef NLOHMANN_OPT_HELPER");
|
|
@@ -1952,8 +2040,16 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1952
2040
|
}
|
|
1953
2041
|
}
|
|
1954
2042
|
isConversionRequired(t) {
|
|
1955
|
-
let originalType = this.cppType(t, {
|
|
1956
|
-
|
|
2043
|
+
let originalType = this.cppType(t, {
|
|
2044
|
+
needsForwardIndirection: true,
|
|
2045
|
+
needsOptionalIndirection: true,
|
|
2046
|
+
inJsonNamespace: true
|
|
2047
|
+
}, false, false, false);
|
|
2048
|
+
let newType = this.cppType(t, {
|
|
2049
|
+
needsForwardIndirection: true,
|
|
2050
|
+
needsOptionalIndirection: true,
|
|
2051
|
+
inJsonNamespace: true
|
|
2052
|
+
}, false, true, false);
|
|
1957
2053
|
return originalType !== newType;
|
|
1958
2054
|
}
|
|
1959
2055
|
}
|