diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-06 20:47:56 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-07 19:44:33 +0200 |
commit | a0430b1fb722a77ad7cbd28f181727d46d92b3a2 (patch) | |
tree | ad2930c25107ec51c1134f2b68490a223d5debfc /gtad/operation.h.mustache | |
parent | 21c04d5b035cec0b6378e60acc93523f52c1c973 (diff) | |
download | libquotient-a0430b1fb722a77ad7cbd28f181727d46d92b3a2.tar.gz libquotient-a0430b1fb722a77ad7cbd28f181727d46d92b3a2.zip |
gtad/*: optimise and use latest GTAD features
- The generated code is updated to be compatible with the BaseJob
changes introduced in the previous commit. This includes greatly
reducing the number of header files that have to be explicitly
#included, as basejob.h now #includes converters.h. Also, thanks to
the changes in BaseJob, none of generated job classes needs
a pimpl Private class.
- gtad/template.*.mustache files are replaced with data.h.mustache for
data structures (entirely defined in header files from now on) and
operation.*.mustache for API operations (also massively moved to
header files, possibly also becoming header-only in the future).
- New variable-dropping and title-overring features in GTAD 0.7 allow
to use the upstream matrix-doc repo to generate the code.
- CMakeLists.txt makes use of file globbing with CONFIGURE_DEPENDS
where possible to alleviate build reconfiguration after a GTAD call.
Diffstat (limited to 'gtad/operation.h.mustache')
-rw-r--r-- | gtad/operation.h.mustache | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/gtad/operation.h.mustache b/gtad/operation.h.mustache new file mode 100644 index 00000000..34c8a361 --- /dev/null +++ b/gtad/operation.h.mustache @@ -0,0 +1,128 @@ +{{>preamble}} +#pragma once + +#include "jobs/basejob.h" +{{#imports}} +#include {{_}}{{/imports}} +{{#operations.producesNonJson?}} +#include <QtNetwork/QNetworkReply>{{/operations.producesNonJson?}} + +namespace Quotient { +{{#operations.operation}} + +/*!{{>docCommentSummary}}{{#description}} + * {{_}}{{/description}} + */ +class {{camelCaseOperationId}}Job : public BaseJob { +public: + {{#models}} + // Inner data structures + {{#model}} + + {{>docCommentShort}} + struct {{name}}{{#parents?}} : + {{!Quotient:: is a workaround for cases when the same name is used for + the outer and the inner structure (unfortunately very easy + to hit if you don't give a title to the structure that has + $ref and other properties)}} + {{#parents}}Quotient::{{name}}{{>cjoin}}{{/parents}}{{/parents?}} + { + {{#vars}} + {{>docCommentShort}} + {{>maybeOmittableType}} {{nameCamelCase}}; + {{/vars}} + {{#propertyMap}} + {{>docCommentShort}} + {{>maybeOmittableType}} {{nameCamelCase}}; + {{/propertyMap}} + }; + {{/model}} + + // Construction/destruction + + {{/models}} + {{#allParams?}} + /*!{{>docCommentSummary}} + {{#allParams}} + * + * \param {{nameCamelCase}}{{#description}} + * {{_}}{{/description}} + {{/allParams}} + */ + {{/allParams?}}{{^allParams?}} + {{#summary}} + /// {{summary}} + {{/summary}} + {{/allParams?}} + explicit {{camelCaseOperationId}}Job({{#allParams}}{{>joinedParamDecl}}{{/allParams}}); + {{^hasBody?}} + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for {{camelCaseOperationId}}Job + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl{{#allParams?}}, + {{#allParams}}{{>joinedParamDecl}}{{/allParams}}{{/allParams?}}); + {{/hasBody?}} + {{#responses}}{{#normalResponse?}}{{#allProperties?}} + + // Result properties + {{#headers}} + + {{>nonInlineResponseSignature}} + { + return reply()->rawHeader("{{baseName}}"); + } + {{/headers}}{{#inlineResponse}} + + {{>docCommentShort}} + {{dataType.name}} {{paramName}}(){{^moveOnly}}{{^producesNonJson?}} const{{/producesNonJson?}}{{/moveOnly}} + { + return {{#producesNonJson?}}reply(){{/producesNonJson?}} + {{^producesNonJson? + }}fromJson<{{dataType.name}}>(jsonData()){{/producesNonJson? + }}; + } + {{/inlineResponse}}{{#properties}} + + {{!there's nothing in #properties if the response is inline}} + {{>nonInlineResponseSignature}} + { + return {{>takeOrLoad}}FromJson<{{>maybeOmittableType}}>("{{baseName}}"_ls); + } + {{/properties}} + {{/allProperties?}}{{/normalResponse?}}{{/responses}} +}; + {{#models.model}} + +template <> struct JsonObjectConverter<{{qualifiedName}}> { + {{#in?}} + static void dumpTo(QJsonObject& jo, const {{qualifiedName}}& pod) + { {{#propertyMap}} + fillJson(jo, pod.{{nameCamelCase}}); + {{/propertyMap}}{{#parents}} + fillJson<{{name}}>(jo, pod); + {{/parents}}{{#vars}} + addParam<{{^required?}}IfNotEmpty{{/required?}}>(jo, + QStringLiteral("{{baseName}}"), pod.{{nameCamelCase}}); + {{/vars}} + } + {{/in?}} + {{#out?}} + static void fillFrom({{>maybeCrefJsonObject}} jo, {{qualifiedName}}& result) + { {{#parents}} + fillFromJson<{{name}}{{!of the parent!}}>(jo, result); + {{/parents}}{{#vars}} + fromJson(jo.{{>takeOrValue}}("{{baseName}}"_ls), + result.{{nameCamelCase}}); + {{/vars}}{{#propertyMap}} + fromJson(jo, result.{{nameCamelCase}}); + {{/propertyMap}} + } + {{/out?}} +}; + {{/models.model}} +{{/operations.operation}} + +} // namespace Quotient |