1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-24 18:15:16 +00:00
harbour-sailfin/core/codegen/object_header.hbs
Chris Josten 90db983c30 Replace not-fully-initializing DTO constructors
There were some constructors in the DTOs which allowed construction of
DTO which weren't fully initialized. These constructors have been made
private, as they are still used in the 'fromJson' methods. Additionally,
a constructor with all required parameters to fully initialize the
class has been added.

Additionally, the Loader class has been modified, since it no longer can
assume it is able to default construct the parameter type. The parameter
is now stored as an optional.

Closes #15
2021-09-25 17:07:12 +02:00

100 lines
1.8 KiB
Handlebars

{{#each userImports as |userClass|}}
{{#if userClass != className}}
class {{className}};
{{/if}}
{{/each}}
class {{className}} {
public:
{{#if hasRequiredProperties}}
{{className}}(
{{#each properties as |p|}}
{{#if p.isNotNullable}}
{{p.typeNameWithQualifiers}} {{p.name}}{{#if p.isLastNonNullable}}{{else}},{{/if}}
{{/if}}
{{/each}}
);
{{else}}
{{className}}();
{{/if}}
{{className}}(const {{className}} &other);
/**
* Replaces the data being hold by this class with that of the other.
*/
void replaceData({{className}} &other);
static {{className}} fromJson(QJsonObject source);
void setFromJson(QJsonObject source);
QJsonObject toJson() const;
// Properties
{{#each properties as |p|}}
{{#if p.description.length > 0}}
/**
* @brief {{p.description}}
*/
{{/if}}
{{p.typeNameWithQualifiers}} {{p.name}}() const;
{{#if p.description.length > 0}}
/**
* @brief {{p.description}}
*/
{{/if}}
void set{{p.writeName}}({{p.typeNameWithQualifiers}} new{{p.writeName}});
{{#if p.isNullable}}
bool {{p.name}}Null() const;
void set{{p.writeName}}Null();
{{/if}}
{{/each}}
protected:
{{#each properties as |p|}}
{{#if p.defaultInitializer.length > 0}}
{{p.typeNameWithQualifiers}} {{p.memberName}} = {{p.defaultInitializer}};
{{else}}
{{p.typeNameWithQualifiers}} {{p.memberName}};
{{/if}}
{{/each}}
{{#if hasRequiredProperties}}
private:
// Private constructor which generates an invalid object, for use withing {{className}}::fromJson();
{{className}}();
{{/if}}
};
} // NS DTO
namespace Support {
using {{className}} = Jellyfin::DTO::{{className}};
template <>
{{className}} fromJsonValue(const QJsonValue &source, convertType<{{className}}>);
template<>
QJsonValue toJsonValue(const {{className}} &source, convertType<{{className}}>);