1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-05-17 11:32:42 +00:00
harbour-sailfin/core/codegen/object_implementation.hbs
Chris Josten b9b08ab384 Make model code compileable
This disables some application level logic, but I'm going to rewrite
that using Lager anyway.
2021-03-20 16:29:31 +01:00

63 lines
1.5 KiB
Handlebars

{{className}}::{{className}}() {}
{{className}} {{className}}::fromJson(QJsonObject source) {
{{className}} instance;
instance.setFromJson(source);
return instance;
}
void {{className}}::setFromJson(QJsonObject source) {
{{#each properties as |property|}}
{{property.memberName}} = {{supportNamespace}}::fromJsonValue<{{property.typeNameWithQualifiers}}>(source["{{property.originalName}}"]);
{{/each}}
}
QJsonObject {{className}}::toJson() {
QJsonObject result;
{{#each properties as |property|}}
result["{{property.originalName}}"] = {{supportNamespace}}::toJsonValue<{{property.typeNameWithQualifiers}}>({{property.memberName}});
{{/each}}
return result;
}
{{#each properties as |property|}}
{{property.typeNameWithQualifiers}} {{className}}::{{property.name}}() const { return {{property.memberName}}; }
void {{className}}::set{{property.writeName}}({{property.typeNameWithQualifiers}} new{{property.writeName}}) {
{{property.memberName}} = new{{property.writeName}};
}
{{#if property.isNullable}}
bool {{className}}::is{{property.writeName}}Null() const {
return {{property.nullableCheck}};
}
void {{className}}::setNull() {
{{property.nullableSetter}};
}
{{/each}}
} // NS DTO
namespace Support {
using {{className}} = Jellyfin::DTO::{{className}};
template <>
{{className}} fromJsonValue<{{className}}>(const QJsonValue &source) {
if (!source.isObject()) throw new ParseException("Expected JSON Object");
return {{className}}::fromJson(source.toObject());
}