aboutsummaryrefslogtreecommitdiff
path: root/jobs/{{base}}.cpp.mustache
diff options
context:
space:
mode:
Diffstat (limited to 'jobs/{{base}}.cpp.mustache')
-rw-r--r--jobs/{{base}}.cpp.mustache72
1 files changed, 48 insertions, 24 deletions
diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache
index 31b867fa..84bb2bea 100644
--- a/jobs/{{base}}.cpp.mustache
+++ b/jobs/{{base}}.cpp.mustache
@@ -2,43 +2,68 @@
#include "{{filenameBase}}.h"
-{{^models}}#include "converters.h"{{/models}}
-{{#operations}}#include <QtCore/QStringBuilder>{{/operations}}
-
+#include "converters.h"
+{{#operations}}
+#include <QtCore/QStringBuilder>
+{{/operations}}
using namespace QMatrixClient;
-{{#models}}{{#model}}
-{{classname}}::operator QJsonValue() const
+{{#models.model}}{{^trivial?}}
+{{qualifiedName}}::operator QJsonValue() const
{
QJsonObject o;
- {{#vars}}o.insert("{{name}}", toJson({{name}}));
+ {{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
{{/vars}}
return o;
}
-{{classname}} FromJson<{{classname}}>::operator()(QJsonValue jv)
+{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(QJsonValue jv)
{
QJsonObject o = jv.toObject();
- {{classname}} result;
- {{#vars}}result.{{name}} = fromJson<{{datatype}}>(o.value("{{name}}"));
+ {{qualifiedName}} result;
+ {{#vars}}result.{{nameCamelCase}} =
+ fromJson<{{dataType.name}}>(o.value("{{baseName}}"));
{{/vars}}
return result;
}
-{{/model}}{{/models}}{{#operations}}
+{{/trivial?}}{{/models.model}}{{#operations}}
static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
-{{# operation}}{{#responses}}{{#normalResponse?}}{{#properties?}}
+{{# operation}}{{#models.model}}{{^trivial?}}
+{{qualifiedName}}::operator QJsonValue() const
+{
+ QJsonObject o;
+ {{#vars}}o.insert("{{baseName}}", toJson({{nameCamelCase}}));
+ {{/vars}}
+ return o;
+}
+namespace QMatrixClient
+{
+ template <> struct FromJson<{{qualifiedName}}>
+ {
+ {{qualifiedName}} operator()(QJsonValue jv)
+ {
+ QJsonObject o = jv.toObject();
+ {{qualifiedName}} result;
+ {{#vars}}result.{{nameCamelCase}} =
+ fromJson<{{dataType.qualifiedName}}>(o.value("{{baseName}}"));
+ {{/vars}}
+ return result;
+ }
+ };
+}
+{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#properties?}}
class {{camelCaseOperationId}}Job::Private
{
public:
- {{#properties}}{{dataType}} {{paramName}};
- {{/properties}}
+ {{#properties}}{{dataType.name}} {{paramName}};{{#@join}}{{!EOL except the last line}}
+ {{/@join}}{{/properties}}
};
{{/ properties?}}{{/normalResponse?}}{{/responses}}
-{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
+{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}{{/allParams}})
: BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job",
- basePath{{#pathParts}} % {{.}}{{/pathParts}},
+ basePath{{#pathParts}} % {{_}}{{/pathParts}},
Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{
- {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}},
- {{/hasMore}}{{/queryParams}}
+ {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#@join}},
+ {{/@join}}{{/queryParams}}
}{{/queryParams?}}{{#skipAuth}}, Data { }, false{{/skipAuth}}
){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}}
{{#bodyParams?}}{
@@ -53,24 +78,23 @@ class {{camelCaseOperationId}}Job::Private
delete d;
}
{{# properties}}
-const {{dataType}}& {{camelCaseOperationId}}Job::{{paramName}}() const
+{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const
{
return d->{{paramName}};
}
{{/ properties}}{{#returnFile?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data)
{
- {{#properties}}{{paramName}}{{/properties}} = data;
+ {{properties.nameCamelCase}} = data;
return Success;
}{{/ returnFile?}}{{^returnFile?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data)
{
auto json = data.object();
- {{# properties}}{{#required?}}if (!json.contains("{{paramName}}"))
+ {{# properties}}{{#required?}}if (!json.contains("{{baseName}}"))
return { JsonParseError,
- "The key '{{paramName}}' not found in the response" };{{/required?}}
- d->{{paramName}} = fromJson<{{dataType}}>(json.value("{{baseName}}"));
-{{/ properties}}
- return Success;
+ "The key '{{baseName}}' not found in the response" };
+ {{/required?}}d->{{paramName}} = fromJson<{{dataType.name}}>(json.value("{{baseName}}"));
+ {{/ properties}}return Success;
}{{/ returnFile?}}
{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}