aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-03 20:14:19 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-05-03 21:22:37 +0900
commit37700bbf2df8b96c82a193c25764d9020b1140e9 (patch)
tree640701e5485dd83d43324d03d0f66f9c68e71242 /lib
parent1e42eca5c3d864750609eacd4996794c901c6c37 (diff)
downloadlibquotient-37700bbf2df8b96c82a193c25764d9020b1140e9.tar.gz
libquotient-37700bbf2df8b96c82a193c25764d9020b1140e9.zip
GTAD: Use QMatrixClient::Event-derived classes in generated jobs + Mustache cleanup
This should make generated jobs buildable across the whole CS API (sync.yaml is disabled as the manual implementation is still considerably better).
Diffstat (limited to 'lib')
-rw-r--r--lib/jobs/gtad.yaml40
-rw-r--r--lib/jobs/{{base}}.cpp.mustache41
-rw-r--r--lib/jobs/{{base}}.h.mustache32
3 files changed, 66 insertions, 47 deletions
diff --git a/lib/jobs/gtad.yaml b/lib/jobs/gtad.yaml
index 052d8301..4ef55bce 100644
--- a/lib/jobs/gtad.yaml
+++ b/lib/jobs/gtad.yaml
@@ -6,7 +6,8 @@ analyzer:
signed: signedData
unsigned: unsignedData
default: isDefault
- origin_server_ts: originServerTimestamp
+ origin_server_ts: originServerTimestamp # Instead of originServerTs
+ start: begin # Because start() is a method in BaseJob
types:
# Structure:
@@ -51,18 +52,42 @@ analyzer:
avoidCopy?: true
file: *ByteStream
object:
- - definitions/event.yaml:
+ - /.+m\.room\.member/: # A stub for EventsBatch<RoomMemberEvent>
+ type: none
+ - /.+state_event.yaml/:
+ type: StateEventPtr
+ noCopy?: true
+ imports: '"events/event.h"'
+ - /.*room_event.yaml/:
+ type: RoomEventPtr
+ noCopy?: true
+ imports: '"events/event.h"'
+ - /.*event.yaml/:
type: EventPtr
+ noCopy?: true
imports: '"events/event.h"'
- //:
type: QJsonObject
avoidCopy?: true
imports: <QtCore/QJsonObject>
array:
- - Notification:
+ - /^Notification|Result$/:
type: "std::vector<{{1}}>"
- avoidCopy?: true
- imports: <vector>
+ noCopy?: true
+ imports: '"events/event.h"'
+ - /.+m\.room\.member/:
+ type: "EventsArray<RoomMemberEvent>"
+ noCopy?: true
+ imports: '"events/roommemberevent.h"'
+ - /.+state_event.yaml/:
+ type: StateEvents
+ noCopy?: true
+ - /.+room_event.yaml/:
+ type: RoomEvents
+ noCopy?: true
+ - /.+event.yaml/:
+ type: Events
+ noCopy?: true
- /.+/:
type: "QVector<{{1}}>"
avoidCopy?: true
@@ -78,8 +103,9 @@ mustache:
definitions:
_scopeRenderer: "{{scopeCamelCase}}Job::"
_literalQuote: '"'
- maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}"
- qualifiedMaybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}"
+ maybeCrefType: "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.name}}{{#avoidCopy?}}&{{/avoidCopy?}}{{#noCopy?}}&&{{/noCopy?}}"
+ qualifiedMaybeCrefType:
+ "{{#avoidCopy?}}const {{/avoidCopy?}}{{dataType.qualifiedName}}{{#avoidCopy?}}&{{/avoidCopy?}}{{#noCopy?}}&&{{/noCopy?}}"
initializeDefaultValue: "{{#defaultValue}}{{>initializer}}{{/defaultValue}}{{^defaultValue}}{}{{/defaultValue}}"
joinedParamDecl: '{{>maybeCrefType}} {{paramName}}{{^required?}} = {{>initializeDefaultValue}}{{/required?}}{{#@join}}, {{/@join}}'
joinedParamDef: '{{>maybeCrefType}} {{paramName}}{{#@join}}, {{/@join}}'
diff --git a/lib/jobs/{{base}}.cpp.mustache b/lib/jobs/{{base}}.cpp.mustache
index 1ca23799..d3726f1e 100644
--- a/lib/jobs/{{base}}.cpp.mustache
+++ b/lib/jobs/{{base}}.cpp.mustache
@@ -7,18 +7,15 @@
{{/producesNonJson?}}#include <QtCore/QStringBuilder>
{{/operations}}
using namespace QMatrixClient;
-{{#models.model}}{{^trivial?}}
-namespace QMatrixClient
+{{#models.model}}{{#in?}}
+QJsonObject QMatrixClient::toJson(const {{qualifiedName}}& pod)
{
- QJsonObject toJson(const {{qualifiedName}}& pod)
- {
- QJsonObject o;
- {{#vars}}o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}}));
- {{/vars}}
- return o;
- }
+ QJsonObject o;
+{{#vars}} o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}}));
+{{/vars}}
+ return o;
}
-
+{{/in?}}{{#out?}}
{{qualifiedName}} FromJson<{{qualifiedName}}>::operator()(const QJsonValue& jv)
{
const auto& o = jv.toObject();
@@ -28,33 +25,35 @@ namespace QMatrixClient
{{/vars}}
return result;
}
-{{/trivial?}}{{/models.model}}{{#operations}}
+{{/out?}}{{/models.model}}{{#operations}}
static const auto basePath = QStringLiteral("{{basePathWithoutHost}}");
-{{# operation}}{{#models.model}}{{^trivial?}}
+{{# operation}}{{#models}}
namespace QMatrixClient
{
+ // Converters
+{{#model}}{{#in?}}
QJsonObject toJson(const {{qualifiedName}}& pod)
{
QJsonObject o;
- {{#vars}}o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}}));
- {{/vars}}
+{{#vars}} o.insert("{{baseName}}", toJson(pod.{{nameCamelCase}}));
+{{/vars}}
return o;
}
-
+{{/in?}}{{#out?}}
template <> struct FromJson<{{qualifiedName}}>
{
{{qualifiedName}} operator()(const QJsonValue& jv)
{
const auto& o = jv.toObject();
{{qualifiedName}} result;
- {{#vars}}result.{{nameCamelCase}} =
+{{#vars}} result.{{nameCamelCase}} =
fromJson<{{dataType.qualifiedName}}>(o.value("{{baseName}}"));
- {{/vars}}
+{{/vars}}
return result;
}
};
-} // namespace QMatrixClient
-{{/ trivial?}}{{/models.model}}{{#responses}}{{#normalResponse?}}{{#allProperties?}}
+{{/out?}}{{/model}}} // namespace QMatrixClient
+{{/ models}}{{#responses}}{{#normalResponse?}}{{#allProperties?}}
class {{camelCaseOperationId}}Job::Private
{
public:{{#allProperties}}
@@ -99,9 +98,9 @@ QUrl {{camelCaseOperationId}}Job::makeRequestUrl(QUrl baseUrl{{#allParams?}}, {{
{{# responses}}{{#normalResponse?}}{{#allProperties?}}
{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() = default;
{{# allProperties}}
-{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}() const
+{{>qualifiedMaybeCrefType}} {{camelCaseOperationId}}Job::{{paramName}}(){{^noCopy?}} const{{/noCopy?}}
{
- return d->{{paramName}};
+ return {{#noCopy?}}std::move({{/noCopy?}}d->{{paramName}}{{#noCopy?}}){{/noCopy?}};
}
{{/ allProperties}}{{#producesNonJson?}}
BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QNetworkReply* reply)
diff --git a/lib/jobs/{{base}}.h.mustache b/lib/jobs/{{base}}.h.mustache
index f49945d4..ff9a7e7a 100644
--- a/lib/jobs/{{base}}.h.mustache
+++ b/lib/jobs/{{base}}.h.mustache
@@ -10,39 +10,33 @@
namespace QMatrixClient
{
{{#models}} // Data structures
-{{# model}}{{#trivial?}}
- using {{name}} = {{parent.name}};
-{{/ trivial?}}{{^trivial?}}
+{{# model}}
struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
{
- {{#vars}}{{dataType.name}} {{nameCamelCase}};
- {{/vars}}{{!
-}} };
-
+{{#vars}} {{dataType.name}} {{nameCamelCase}};
+{{/vars}} };
+{{#in?}}
QJsonObject toJson(const {{name}}& pod);
-
+{{/in?}}{{#out?}}
template <> struct FromJson<{{name}}>
{
{{name}} operator()(const QJsonValue& jv);
};
-{{/ trivial?}}{{/model}}
+{{/ out?}}{{/model}}
{{/models}}{{#operations}} // Operations
{{# operation}}
class {{camelCaseOperationId}}Job : public BaseJob
{
- public:{{# models}}
+ public:{{#models}}
// Inner data structures
-{{# model}}{{#trivial?}}
- using {{name}} = {{parent.name}};
-{{/ trivial?}}{{^trivial?}}
+{{# model}}
struct {{name}}{{#parents?}} : {{#parents}}{{name}}{{#@join}}, {{/@join}}{{/parents}}{{/parents?}}
{
- {{#vars}}{{dataType.name}} {{nameCamelCase}};
- {{/vars}}
- };
-{{/ trivial?}}{{/model}}
+{{#vars}} {{dataType.name}} {{nameCamelCase}};
+{{/vars}} };
+{{/ model}}
// End of inner data structures
-{{/models}}{{^bodyParams}}
+{{/ models}}{{^bodyParams}}
/** Construct a URL out of baseUrl and usual parameters passed to
* {{camelCaseOperationId}}Job. This function can be used when
* a URL for {{camelCaseOperationId}}Job is necessary but the job
@@ -54,7 +48,7 @@ namespace QMatrixClient
}}{{# responses}}{{#normalResponse?}}{{#allProperties?}}
~{{camelCaseOperationId}}Job() override;
{{#allProperties}}
- {{>maybeCrefType}} {{paramName}}() const;{{/allProperties}}
+ {{>maybeCrefType}} {{paramName}}(){{^noCopy?}} const{{/noCopy?}};{{/allProperties}}
protected:
Status {{#producesNonJson?}}parseReply(QNetworkReply* reply){{/producesNonJson?}}{{^producesNonJson?}}parseJson(const QJsonDocument& data){{/producesNonJson?}} override;