Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -848,10 +848,7 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
* a member called 'value' value = value will screw up the compiler
*/
const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
if (
(property.type instanceof UnionType && property.type.findMember("null") !== undefined) ||
(property.isOptional && property.type.kind !== "null" && property.type.kind !== "any")
) {
if (property.type instanceof UnionType && property.type.findMember("null") !== undefined) {
this.emitLine(rendered, " ", getterName, "() const { return ", name, "; }");
if (constraints?.has(jsonName)) {
this.emitLine(
Expand Down Expand Up @@ -1832,6 +1829,40 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
this.ensureBlankLine();
}
);

this.ensureBlankLine();

this.emitBlock(
[
"inline void ",
checkConst,
"(",
this._stringType.getConstType(),
" name, ",
this.withConst(classConstraint),
" & c, ",
"const ",
this._optionalType,
"<",
cppType,
"> & value)"
],
false,
() => {
this.emitBlock(
["if (value)"],
false,
() => {
this.emitLine(
checkConst,
"(name, c, *value);"
);
}
);
this.ensureBlankLine();
}
);

this.ensureBlankLine();
}

Expand Down Expand Up @@ -1921,7 +1952,12 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
}

const checkConst = this.lookupGlobalName(GlobalNames.CheckConstraint);
this.emitNumericCheckConstraints(checkConst, classConstraint, getterMinIntValue, getterMaxIntValue, "int64_t");
this.emitNumericCheckConstraints(
checkConst,
classConstraint,
getterMinIntValue,
getterMaxIntValue,
"int64_t");
this.emitNumericCheckConstraints(
checkConst,
classConstraint,
Expand Down Expand Up @@ -2040,6 +2076,39 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
this.ensureBlankLine();
}
);

this.ensureBlankLine();

this.emitBlock(
[
"inline void ",
checkConst,
"(",
this._stringType.getConstType(),
" name, ",
this.withConst(classConstraint),
" & c, ",
"const ",
this._optionalType,
"<",
this._stringType.getType(),
">& value)"
],
false,
() => {
this.emitBlock(
["if (value)"],
false,
() => {
this.emitLine(
checkConst,
"(name, c, *value);"
);
}
);
this.ensureBlankLine();
}
);
}

protected emitHelperFunctions(): void {
Expand Down