diff options
Diffstat (limited to 'jobs')
-rw-r--r-- | jobs/generated/inviting.cpp | 5 | ||||
-rw-r--r-- | jobs/generated/inviting.h | 6 | ||||
-rw-r--r-- | jobs/generated/kicking.cpp | 5 | ||||
-rw-r--r-- | jobs/generated/kicking.h | 6 | ||||
-rw-r--r-- | jobs/{{base}}.cpp.mustache | 80 | ||||
-rw-r--r-- | jobs/{{base}}.h.mustache | 44 |
6 files changed, 78 insertions, 68 deletions
diff --git a/jobs/generated/inviting.cpp b/jobs/generated/inviting.cpp index 164a2b2b..95ba658d 100644 --- a/jobs/generated/inviting.cpp +++ b/jobs/generated/inviting.cpp @@ -5,8 +5,7 @@ #include "inviting.h" -#include "../converters.h" - +#include "jobs/converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; @@ -23,5 +22,3 @@ InviteUserJob::InviteUserJob(QString roomId, QString user_id) ) { } - - diff --git a/jobs/generated/inviting.h b/jobs/generated/inviting.h index 8cfc9118..ac0fd5fa 100644 --- a/jobs/generated/inviting.h +++ b/jobs/generated/inviting.h @@ -14,12 +14,12 @@ namespace QMatrixClient { // Operations - + class InviteUserJob : public BaseJob { public: - InviteUserJob(QString roomId, QString user_id); - + explicit InviteUserJob(QString roomId, QString user_id); + }; } // namespace QMatrixClient diff --git a/jobs/generated/kicking.cpp b/jobs/generated/kicking.cpp index 3e2ef5be..2e6797d6 100644 --- a/jobs/generated/kicking.cpp +++ b/jobs/generated/kicking.cpp @@ -5,8 +5,7 @@ #include "kicking.h" -#include "../converters.h" - +#include "jobs/converters.h" #include <QtCore/QStringBuilder> using namespace QMatrixClient; @@ -24,5 +23,3 @@ KickJob::KickJob(QString roomId, QString user_id, QString reason) ) { } - - diff --git a/jobs/generated/kicking.h b/jobs/generated/kicking.h index 6ef19fcd..658193d5 100644 --- a/jobs/generated/kicking.h +++ b/jobs/generated/kicking.h @@ -14,12 +14,12 @@ namespace QMatrixClient { // Operations - + class KickJob : public BaseJob { public: - KickJob(QString roomId, QString user_id, QString reason); - + explicit KickJob(QString roomId, QString user_id, QString reason = {}); + }; } // namespace QMatrixClient diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache index 0d01e6dd..beab77df 100644 --- a/jobs/{{base}}.cpp.mustache +++ b/jobs/{{base}}.cpp.mustache @@ -1,23 +1,40 @@ {{#@filePartial}}preamble{{/@filePartial}} #include "{{filenameBase}}.h" -{{#operations}} -#include "../converters.h" -#include <QtCore/QStringBuilder> +{{^models}}#include "jobs/converters.h"{{/models}} +{{#operations}}#include <QtCore/QStringBuilder>{{/operations}} using namespace QMatrixClient; -{{# returns?}} -class {{#@cap}}{{operationId}}{{/@cap}}Job::Private +{{#models}}{{#model}} +{{classname}}::operator QJsonValue() const +{ + QJsonObject o; + {{#vars}}o.insert("{{name}}", toJson({{name}})); + {{/vars}} + return o; +} + +{{classname}} FromJson<{{classname}}>::operator()(QJsonValue jv) +{ + QJsonObject o = jv.toObject(); + {{classname}} result; + {{#vars}}result.{{name}} = fromJson<{{datatype}}>(o.value("{{name}}")); + {{/vars}} + return result; +} +{{/model}}{{/models}}{{#operations}} +static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); +{{# operation}}{{#responses}}{{#normalResponse?}}{{#properties?}} +class {{camelCaseOperationId}}Job::Private { public: - {{#returns}}{{type}} {{name}};{{/returns}} + {{#properties}}{{dataType}} {{paramName}}; + {{/properties}} }; -{{/ returns?}} -static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); -{{# operation}} -{{#@cap}}{{operationId}}{{/@cap}}Job::{{#@cap}}{{operationId}}{{/@cap}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) - : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{#@cap}}{{operationId}}{{/@cap}}Job", +{{/ properties?}}{{/normalResponse?}}{{/responses}} +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", basePath{{#pathParts}} % {{part}}{{/pathParts}}, Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{ {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}}, @@ -27,37 +44,32 @@ static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); {{#bodyParams}}{ "{{baseName}}", toJson({{paramName}}) }{{#hasMore}}, {{/hasMore}}{{/bodyParams}} }{{/bodyParams?}}{{#skipAuth}}, false{{/skipAuth}} - ){{#returns?}}, d(new Private){{/returns?}} + ){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}} { } -{{/ operation}} -{{# returns?}} -{{className}}Job::~{{className}}Job() +{{# responses}}{{#normalResponse?}}{{#properties?}} +{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() { delete d; } -{{# returns}} -{{type}} {{className}}Job::{{name}}() const +{{# properties}} +{{dataType}} {{camelCaseOperationId}}Job::{{paramName}}() const { - return d->{{name}}; + return d->{{paramName}}; } -{{/ returns}} -{{# returnFile?}} -BaseJob::Status {{className}}Job::parseReply(QByteArray data) +{{/ properties}}{{#returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data) { - {{#returns}}{{name}}{{/returns}} = data; + {{#properties}}{{paramName}}{{/properties}} = data; return Success; -} -{{/ returnFile?}}{{^returnFile?}} -BaseJob::Status {{className}}Job::parseJson(const QJsonDocument& data) +}{{/ returnFile?}}{{^returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) { auto json = data.object(); - {{#returns}} - {{#required?}}if (!json.contains("{{name}}") - return { JsonParseError, "{{name}} not found in the response" };{{/required?}} - d->{{name}} = fromJson<{{type}}>(json.value("{{name}}")); - {{/returns}} + {{# properties}}{{#required?}}if (!json.contains("{{paramName}}")) + return { JsonParseError, + "The key '{{paramName}}' not found in the response" };{{/required?}} + d->{{paramName}} = fromJson<{{dataType}}>(json.value("{{paramName}}")); +{{/ properties}} return Success; -} -{{/ returnFile?}} -{{/ returns?}} -{{/operations}} +}{{/ returnFile?}} +{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} diff --git a/jobs/{{base}}.h.mustache b/jobs/{{base}}.h.mustache index e19cf03d..08372b77 100644 --- a/jobs/{{base}}.h.mustache +++ b/jobs/{{base}}.h.mustache @@ -2,42 +2,46 @@ #pragma once -{{#operations}}#include "../basejob.h"{{/operations}} -{{#imports}} -#include {{.}} +{{#operations}}#include "../basejob.h" +{{/operations}} +{{#imports}}#include {{.}} {{/imports}} -{{#models}}#include <QtCore/QJsonValue>{{/models}}{{! FIXME: This should probably go inside imports }} +{{#models}}#include "jobs/converters.h" +{{/models}} namespace QMatrixClient { {{#models}} // Data structures - {{#model}} +{{# model}} struct {{classname}} { - {{#vars}} - {{datatype}} {{name}}; + {{#vars}}{{datatype}} {{name}}; {{/vars}} - operator QJsonValue() const { return {}; } - };{{/model}} + operator QJsonValue() const; + }; + + template <> struct FromJson<{{classname}}> + { + {{classname}} operator()(QJsonValue jv); + }; +{{/ model}} {{/models}} {{#operations}} // Operations - {{#operation}} - class {{#@cap}}{{operationId}}{{/@cap}}Job : public BaseJob +{{# operation}} + class {{camelCaseOperationId}}Job : public BaseJob { public: - {{#@cap}}{{operationId}}{{/@cap}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - {{#returns?}} - virtual {{className}}Job(); - - {{#returns}}{{type}} {{name}}() const;{{/returns}} + explicit {{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{^required?}} = {{defaultValue}}{{^defaultValue}}{}{{/defaultValue}}{{/required?}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); +{{# responses}}{{#normalResponse?}}{{#properties?}} + virtual ~{{camelCaseOperationId}}Job(); + {{#properties}}{{dataType}} {{paramName}}() const; + {{/properties}} protected: + {{^returnFile}}Status parseJson(const QJsonDocument& data) override;{{/returnFile}} {{#returnFile?}}Status parseReply(QByteArray data) override;{{/returnFile?}} - {{^returnFile}}Status parseJson(const JsonDocument& data) override;{{/returnFile}} - private: class Private; - Private* d; - {{/returns?}} + Private* d;{{/properties?}}{{/normalResponse?}}{{/responses}} };{{/operation}} {{/operations}} } // namespace QMatrixClient |