aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-06 19:15:51 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-12-06 19:15:51 +0900
commit905263ceb5e2e13b862bec0a64f6d84eca3c2e9d (patch)
tree40ef6c56e1d72e215bf649928bfae9f82aa0b7a4
parentea2dcf5d6c9329a14b4e0039bd2dc45ac3fd89d8 (diff)
downloadlibquotient-905263ceb5e2e13b862bec0a64f6d84eca3c2e9d.tar.gz
libquotient-905263ceb5e2e13b862bec0a64f6d84eca3c2e9d.zip
GTAD pre-0.4, with local data types and parametrised arrays; make avoidCopy? actually work
Along with this: - avoid copying of QStrings (unneeded convenience in our case) - even less empty lines
-rw-r--r--jobs/gtad.yaml35
-rw-r--r--jobs/{{base}}.cpp.mustache72
-rw-r--r--jobs/{{base}}.h.mustache50
3 files changed, 105 insertions, 52 deletions
diff --git a/jobs/gtad.yaml b/jobs/gtad.yaml
index 4877aeb5..5f370ac5 100644
--- a/jobs/gtad.yaml
+++ b/jobs/gtad.yaml
@@ -1,8 +1,11 @@
preprocess:
"%CLIENT_RELEASE_LABEL%": r0
"%CLIENT_MAJOR_VERSION%": r0
- "unsigned:": "unsigned_:"
- "default:": "default_:"
+ # FIXME: the below only fixes C++ compilation but not actual work - the code
+ # will try to reach out for wrong values in JSON payloads
+ "signed:": "signedData:"
+ "unsigned:": "unsignedData:"
+ "default:": "isDefault:"
# Structure:
# swaggerType: <targetTypeSpec>
@@ -29,25 +32,37 @@ types:
string?: true
imports: <QtCore/QByteArray>
- binary: *QByteArray
- - date:
- type: QDate
- avoidCopy?: true
- imports: <QtCore/QDate>
+ - date: { type: QDate, "avoidCopy?": true, imports: <QtCore/QDate> }
- dateTime:
type: QDateTime
avoidCopy?: true
imports: <QtCore/QDateTime>
- - //: { type: QString, "string?": true, imports: <QtCore/QString> }
+ - //:
+ type: QString
+ string?: true
+ avoidCopy?: true
+ imports: <QtCore/QString>
file:
type: QByteArray
imports: <QtCore/QByteArray>
- "returnFile?": true
- object: { type: QJsonObject, "avoidCopy?": true, imports: <QtCore/QJsonObject> }
- array: { type: "QVector<{{1}}>", "avoidCopy?": true, imports: <QtCore/QVector> }
+ returnFile?: true
+ object:
+ type: QJsonObject
+ avoidCopy?: true
+ imports: <QtCore/QJsonObject>
+ array:
+ - /.+/:
+ type: "QVector<{{1}}>"
+ avoidCopy?: true
+ imports: <QtCore/QVector>
+ - //: { type: QJsonArray, "avoidCopy?": true, imports: <QtCore/QJsonArray> }
#operations:
env:
+ _typeRenderer: "{{#scope}}{{scopeCamelCase}}Job::{{/scope}}{{name}}"
+ maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}"
+ qualifiedMaybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}"
# preamble: preamble.mustache
copyrightName: Kitsune Ral
copyrightEmail: <kitsune-ral@users.sf.net>
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}}
diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache
index a751df9d..f7124f97 100644
--- a/jobs/{{base}}.h.mustache
+++ b/jobs/{{base}}.h.mustache
@@ -4,37 +4,51 @@
{{#operations}}#include "../basejob.h"
{{/operations}}
-{{#imports}}#include {{.}}
+{{#imports}}#include {{_}}
{{/imports}}
-{{#models}}#include "converters.h"
-{{/models}}
+{{#allModels}}#include "converters.h"
+{{/allModels}}
namespace QMatrixClient
{
{{#models}} // Data structures
-{{# model}}
- struct {{classname}}{{#parents?}} : {{#parents}}{{.}}{{#last?}}, {{/last?}}{{/parents}}{{/parents?}}
+{{# model}}{{#trivial?}}
+ using {{name}} = {{parent.name}};
+{{/ trivial?}}{{^trivial?}}
+ struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
{
- {{#vars}}{{datatype}} {{name}};
+ {{#vars}}{{dataType.name}} {{nameCamelCase}};
{{/vars}}
operator QJsonValue() const;
};
- template <> struct FromJson<{{classname}}>
+ template <> struct FromJson<{{name}}>
{
- {{classname}} operator()(QJsonValue jv);
+ {{name}} operator()(QJsonValue jv);
};
-{{/ model}}
-{{/models}}
-{{#operations}} // Operations
+{{/ trivial?}}{{/model}}
+{{/models}}{{#operations}} // Operations
{{# operation}}
class {{camelCaseOperationId}}Job : public BaseJob
{
- public:
- explicit {{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
-{{# responses}}{{#normalResponse?}}{{#properties?}}
+ public:{{# models}}
+ // Inner data structures
+{{# model}}{{#trivial?}}
+ using {{name}} = {{parent.name}};
+{{/ trivial?}}{{^trivial?}}
+ struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
+ {
+ {{#vars}}{{dataType.name}} {{nameCamelCase}};
+ {{/vars}}
+ operator QJsonValue() const;
+ };
+{{/ trivial?}}{{/model}}
+ // End of inner data structures
+{{/models}}
+ explicit {{camelCaseOperationId}}Job({{#allParams}}{{>maybeCrefType}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#@join}}, {{/@join}}{{/allParams}});{{!skip EOL
+}}{{# responses}}{{#normalResponse?}}{{#properties?}}
~{{camelCaseOperationId}}Job() override;
- {{#properties}}const {{dataType}}& {{paramName}}() const;
+ {{#properties}}{{>maybeCrefType}} {{paramName}}() const;
{{/properties}}
protected:
{{^returnFile}}Status parseJson(const QJsonDocument& data) override;{{/returnFile}}
@@ -42,6 +56,6 @@ namespace QMatrixClient
private:
class Private;
Private* d;{{/properties?}}{{/normalResponse?}}{{/responses}}
- };{{/operation}}
-{{/operations}}
-} // namespace QMatrixClient
+ };
+{{/operation}}{{/operations}}{{!skip EOL
+}}} // namespace QMatrixClient