aboutsummaryrefslogtreecommitdiff
path: root/jobs/{{base}}.cpp.mustache
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-08-20 18:56:58 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-09-01 19:50:39 +0900
commitc28211698b8f9b82cafc0f9d9457e40c6c17632a (patch)
tree85e8d0b17476cc70b09156d5e034f4322c7b057f /jobs/{{base}}.cpp.mustache
parent45c138903c20d32a8a69b5637a72898bc690f1f1 (diff)
downloadlibquotient-c28211698b8f9b82cafc0f9d9457e40c6c17632a.tar.gz
libquotient-c28211698b8f9b82cafc0f9d9457e40c6c17632a.zip
Added files to (eventually) generate *Job classes automatically
KitsuneRal/api-generator project is a place where all the heavy lifting will (eventually) be implemented. This commit marks a point when the generated files at least compile (whether they work is not tested yet). Return values are so far entirely ignored.
Diffstat (limited to 'jobs/{{base}}.cpp.mustache')
-rw-r--r--jobs/{{base}}.cpp.mustache75
1 files changed, 75 insertions, 0 deletions
diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache
new file mode 100644
index 00000000..05c865b3
--- /dev/null
+++ b/jobs/{{base}}.cpp.mustache
@@ -0,0 +1,75 @@
+{{#@filePartial}}preamble{{/@filePartial}}
+
+#include "{{filenameBase}}.h"
+
+{{#operations}}
+#include "../converters.h"
+
+#include <QtCore/QStringBuilder>
+
+using namespace QMatrixClient;
+
+ {{#returns?}}
+class {{#@cap}}{{operationId}}{{/@cap}}Job::Private
+{
+ public:
+ {{#returns}}
+ {{type}} {{name}};
+ {{/returns}}
+};
+ {{/returns?}}
+
+ {{#operation}}
+{{#@cap}}{{operationId}}{{/@cap}}Job::{{#@cap}}{{operationId}}{{/@cap}}Job(const ConnectionData* connection{{#allParams}}, {{!}}
+ {{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}
+ {{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}
+ {{/allParams}})
+ : BaseJob(connection, HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{#@cap}}{{operationId}}{{/@cap}}Job"
+ , {{#pathParts}}{{part}}{{#hasMore}} % {{/hasMore}}{{/pathParts}}
+ , Query { {{#queryParams}}
+ { "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}}, {{/hasMore}}
+ {{/queryParams}} }
+ , Data { {{#bodyParams}}
+ { "{{baseName}}", toJson({{paramName}}) }{{#hasMore}}, {{/hasMore}}
+ {{/bodyParams}} }
+ {{#skipAuth}}, false{{/skipAuth}}
+ ){{#returns?}}, d(new Private){{/returns?}}
+{ }
+ {{/operation}}
+
+ {{#returns?}}
+{{className}}Job::~{{className}}Job()
+{
+ delete d;
+}
+
+ {{#returns}}
+{{type}} {{className}}Job::{{name}}() const
+{
+ return d->{{name}};
+}
+ {{/returns}}
+
+ {{#returnFile?}}
+BaseJob::Status {{className}}Job::parseReply(QByteArray data)
+{
+ {{#returns}}{{name}}{{/returns}} = data;
+ return Success;
+}
+ {{/returnFile?}}
+ {{^returnFile?}}
+BaseJob::Status {{className}}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}}
+ return Success;
+}
+ {{/returnFile?}}
+ {{/returns?}}
+{{/operations}}