-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod.cpp
104 lines (82 loc) · 4.03 KB
/
method.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "method.h"
#include "shared.h"
void writeMethodHeader(QTextStream& header, SCHEMA& schema, QString prefix, CONSTRUCTOR m, bool forward)
{
if (forward) {
header << "template <READ_METHOD R, WRITE_METHOD W> ";
header << "void read" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant &i, void* callback = 0);" << endl;
header << "template <READ_METHOD R, WRITE_METHOD W> ";
header << "void write" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant i, void* callback = 0);" << endl;
return;
}
header << "template <READ_METHOD R, WRITE_METHOD W> ";
header << "void read" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant &i, void* callback)" << endl;
header << "{" << endl;
header << " QVariant conId;" << endl;
header << " readInt32(stream, conId, callback);" << endl;
header << " switch (conId.toInt()) {" << endl;
header << " case " << QString::number(m.id) << ":" << endl;
PARAM returnParam = {"i", m.type};
header << " ";
readParam(header, m.params, returnParam, prefix, false, "i");
header << " break;" << endl;
header << " }" << endl;
header << "}" << endl;
header << endl;
header << "template <READ_METHOD R, WRITE_METHOD W> ";
header << "void write" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant i, void* callback)" << endl;
header << "{" << endl;
header << " TelegramObject obj = i.toMap();" << endl;
header << " switch (obj[\"_\"].toInt()) {" << endl;
header << " case " << QString::number(m.id) << ":" << endl;
PARAM id = {"_", "int"};
header << " ";
writeParam(header, m.params, id, prefix);
for (qint32 j = 0; j < m.params.size(); ++j) {
if (m.params[j].type.split("?").last().toLower() != "true") header << " ";
writeParam(header, m.params, m.params[j], prefix);
}
header << " break;" << endl;
header << " }" << endl;
header << "}" << endl;
header << endl;
}
void writeMethod(QTextStream& header, QTextStream& source, SCHEMA& schema, QString prefix, CONSTRUCTOR m, bool forward)
{
if (m.type == "X") {
writeMethodHeader(header, schema, prefix, m, forward);
return;
}
if (forward) return;
header << "void read" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant &i, void* callback = 0);" << endl;
header << "void write" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant i, void* callback = 0);" << endl;
source << "void read" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant &i, void* callback)" << endl;
source << "{" << endl;
source << " QVariant conId;" << endl;
source << " readInt32(stream, conId, callback);" << endl;
source << " switch (conId.toInt()) {" << endl;
source << " case " << QString::number(m.id) << ":" << endl;
PARAM returnParam = {"i", m.type};
source << " ";
readParam(source, m.params, returnParam, prefix, false, "i");
source << " break;" << endl;
source << " }" << endl;
source << "}" << endl;
source << endl;
source << "void write" << prepareName(prefix + "Method", m.predicate) << "(TelegramStream &stream, QVariant i, void* callback)" << endl;
source << "{" << endl;
source << " TelegramObject obj = i.toMap();" << endl;
source << " switch (obj[\"_\"].toInt()) {" << endl;
source << " case " << QString::number(m.id) << ":" << endl;
PARAM id = {"_", "int"};
source << " ";
writeParam(source, m.params, id, prefix);
for (qint32 j = 0; j < m.params.size(); ++j) {
if (m.params[j].type.split("?").last().toLower() != "true") source << " ";
writeParam(source, m.params, m.params[j], prefix);
}
source << " break;" << endl;
source << " }" << endl;
source << "}" << endl;
source << endl;
}