summaryrefslogtreecommitdiffstats
path: root/tools/repc/repcodegenerator.cpp
diff options
context:
space:
mode:
authorBrett Stottlemyer <bstottle@ford.com>2017-05-15 23:01:01 -0400
committerBrett Stottlemyer <bstottle@ford.com>2017-05-16 13:27:39 +0000
commiteb1854b58d802a46405f68cef61a5b4450d01f4b (patch)
tree088d24bbcc33eb02b828088c9d50e91f711cd039 /tools/repc/repcodegenerator.cpp
parente8885167458935b760eca751c5cc70509bad5292 (diff)
Provide static method for registering metatypes
This provides an entry point (before a type is instantiated) to register the needed types (for instance, enums used by a type). It also makes it easier to guard against attempting to register a replica's types multiple times. Change-Id: Ic01c70586eab618afeb90c98df042b1ae7a9eed9 Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tools/repc/repcodegenerator.cpp')
-rw-r--r--tools/repc/repcodegenerator.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/tools/repc/repcodegenerator.cpp b/tools/repc/repcodegenerator.cpp
index 969eff6..73bc532 100644
--- a/tools/repc/repcodegenerator.cpp
+++ b/tools/repc/repcodegenerator.cpp
@@ -574,6 +574,17 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass
if (mode == REPLICA) {
out << " " << className << "() : QRemoteObjectReplica() { initialize(); }" << endl;
+ out << " static void registerMetatypes()" << endl;
+ out << " {" << endl;
+ out << " static bool initialized = false;" << endl;
+ out << " if (initialized)" << endl;
+ out << " return;" << endl;
+ out << " initialized = true;" << endl;
+
+ if (!metaTypeRegistrationCode.isEmpty())
+ out << metaTypeRegistrationCode << endl;
+
+ out << " }" << endl;
out << "" << endl;
out << "private:" << endl;
@@ -582,23 +593,10 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass
out << " { initializeNode(node, name); }" << endl;
out << "" << endl;
- out << " void initialize()" << endl;
- } else {
- out << " explicit " << className << "(QObject *parent = nullptr) : QObject(parent)" << endl;
-
- if (mode == SIMPLE_SOURCE) {
- Q_FOREACH (const ASTProperty &property, astClass.properties) {
- out << " , _" << property.name << "(" << property.defaultValue << ")" << endl;
- }
- }
- }
-
- out << " {" << endl;
-
- if (!metaTypeRegistrationCode.isEmpty())
- out << metaTypeRegistrationCode << endl;
- if (mode == REPLICA) {
+ out << " void initialize()" << endl;
+ out << " {" << endl;
+ out << " " << className << "::registerMetatypes();" << endl;
out << " QVariantList properties;" << endl;
out << " properties.reserve(" << astClass.properties.size() << ");" << endl;
Q_FOREACH (const ASTProperty &property, astClass.properties) {
@@ -617,9 +615,21 @@ void RepCodeGenerator::generateClass(Mode mode, QTextStream &out, const ASTClass
out << " }" << endl;
}
out << " setProperties(properties);" << endl;
- }
+ out << " }" << endl;
+ } else {
+ out << " explicit " << className << "(QObject *parent = nullptr) : QObject(parent)" << endl;
+
+ if (mode == SIMPLE_SOURCE) {
+ Q_FOREACH (const ASTProperty &property, astClass.properties) {
+ out << " , _" << property.name << "(" << property.defaultValue << ")" << endl;
+ }
+ }
- out << " }" << endl;
+ out << " {" << endl;
+ if (!metaTypeRegistrationCode.isEmpty())
+ out << metaTypeRegistrationCode << endl;
+ out << " }" << endl;
+ }
out << "" << endl;
out << "public:" << endl;