summaryrefslogtreecommitdiffstats
path: root/scripts/templates/qclass.cpp
diff options
context:
space:
mode:
authorSandro S. Andrade <sandroandrade@kde.org>2013-09-02 22:02:41 -0300
committerSandro S. Andrade <sandroandrade@kde.org>2013-09-03 03:04:37 +0200
commita143fe8c5451493b128b4c6f0750f02b58af8666 (patch)
tree4b74787f6ece9256db04dc65002cae749f6936b3 /scripts/templates/qclass.cpp
parent2bfe659e4d30b449747585e18eeb84bfc5d73f43 (diff)
Add initial version of new UML metamodel implementation
Change-Id: Ic29a04dc49fac075d9c736237573b7f4e3da85ef Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts/templates/qclass.cpp')
-rw-r--r--scripts/templates/qclass.cpp361
1 files changed, 336 insertions, 25 deletions
diff --git a/scripts/templates/qclass.cpp b/scripts/templates/qclass.cpp
index 183c9e1f..cce4513c 100644
--- a/scripts/templates/qclass.cpp
+++ b/scripts/templates/qclass.cpp
@@ -40,43 +40,354 @@
**
****************************************************************************/
#include "q${namespace.lower}${className.lower}.h"
+[%- IF class.findvalue("@isAbstract") != "true" %]
-[% SET useNamespace = 'false' -%]
+#include "private/q${namespace.lower}${className.lower}object_p.h"
+[%- END -%]
+
+[%- superclasses = [] -%]
+[%- SET generalization = class.findnodes("generalization") -%]
+[%- FOREACH superclass IN generalization -%]
+[%- superclasses.push("${namespace}${superclass.findvalue('@general')}") -%]
+[%- END -%]
[%- forwards = [] -%]
-[%- visitedClasses = [] -%]
-[%- GENERATE_FWD_DECLARATIONS(class, visitedClasses, forwards, useNamespace) -%]
-[%- FOREACH forward = forwards.unique.sort -%]
-#include <Qt${namespace}/${forward}>
-[% IF loop.last %]
-[% END -%]
+[%- FOREACH forward = class.findnodes("ownedAttribute[@type] | ownedOperation/ownedParameter[@type]") -%]
+[%- SET forwardName = forward.findvalue('@type') -%]
+[%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$forwardName']").findvalue("@name") == "" -%]
+[%- IF forwardName != className && superclasses.grep("^${namespace}${forwardName}\$").size == 0 -%][%- forwards.push("${namespace}${forwardName}") -%][%- END -%]
+[%- END -%]
[%- END -%]
-QT_BEGIN_NAMESPACE
+[%- FOREACH forward = forwards.unique.sort -%]
+[%- IF loop.first %]
+[% END %]
+#include <Qt${namespace}/Q$${forward}>
+[%- END %]
/*!
- \class ${namespace}${className}
+ \class Q${namespace}${className}
\inmodule Qt${namespace}
\brief ${class.findvalue("ownedComment/body/text()")}
*/
+Q${namespace}${className}::Q${namespace}${className}([%- IF class.findvalue("@isAbstract") != "true" %]bool createQObject[% END %])
+[%- SET found = "false" -%]
+[%- FOREACH superclass IN generalization -%]
+[%- SET superclassName = superclass.findvalue('@general') -%]
+[%- IF xmi.findvalue("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${superclassName}\"]/@isAbstract") != "true" -%]
+ [%- IF found == "false" %] :
+[% SET found = "true" -%]
+ [%- ELSE %],
+[% END -%]
+ Q${namespace}${superclassName}(false)
+[%- END -%]
+[%- END -%]
+[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") -%]
+ [%- SET defaultType = attribute.findvalue("defaultValue/@xmi:type") -%]
+ [%- SET type = QT_TYPE(namespace, attribute) -%]
+ [%- IF defaultType == "uml:LiteralBoolean" || defaultType == "uml:InstanceValue" || defaultType == "uml:LiteralInteger" || defaultType == "uml:LiteralUnlimitedNatural" || type.match('\*$') -%]
+ [%- IF found == "false" %] :
+[% SET found = "true" -%]
+ [%- ELSE %],
+[% END -%]
+ [%- IF defaultType == "uml:LiteralBoolean" -%]
+ [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%]
+ [%- IF defaultValue != "" -%]
+ _[% QT_ATTRIBUTE(attribute) %](${defaultValue})
+ [%- ELSE -%]
+ _[% QT_ATTRIBUTE(attribute) %](false)
+ [%- END -%]
+ [%- ELSIF defaultType == "uml:InstanceValue" -%]
+ [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%]
+ _[% QT_ATTRIBUTE(attribute) %](Qt${namespace}::${defaultInstance.split("-").0}${defaultInstance.split("-").1.ucfirst})
+ [%- ELSIF defaultType == "uml:LiteralInteger" -%]
+ [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%]
+ [%- IF defaultValue != "" -%]
+ _[% QT_ATTRIBUTE(attribute) %](${defaultValue})
+ [%- ELSE -%]
+ _[% QT_ATTRIBUTE(attribute) %](0)
+ [%- END -%]
+ [%- ELSIF defaultType == "uml:LiteralUnlimitedNatural" -%]
+ [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%]
+ [%- IF defaultValue != "" -%]
+ _[% QT_ATTRIBUTE(attribute) %](${defaultValue})
+ [%- ELSE -%]
+ _[% QT_ATTRIBUTE(attribute) %](0)
+ [%- END -%]
+ [%- ELSIF type.match('\*$') -%]
+ _[% QT_ATTRIBUTE(attribute) %](0)
+ [%- END -%]
+ [%- END -%]
+[%- END %]
+{
+[%- IF class.findvalue("@isAbstract") != "true" %]
+ if (createQObject)
+ _qObject = new Q${namespace}${className}Object(this);
+[%- END %]
+}
+
+Q${namespace}${className}::~Q${namespace}${className}()
+{
+[%- IF class.findvalue("@isAbstract") != "true" %]
+ if (!deletingFromQObject) {
+ _qObject->setProperty("deletingFromModelingObject", true);
+ delete _qObject;
+ }
+[%- END %]
+}
+[%- FOREACH attribute = class.findnodes("ownedAttribute") %]
+[%- IF loop.first %]
+
+// OWNED ATTRIBUTES
+[%- END %]
+
+[%- SET qtAttribute = QT_ATTRIBUTE(attribute) -%]
+[%- SET qtType = QT_TYPE(namespace, attribute) -%]
+[%- SET readOnly = attribute.findvalue("@isReadOnly") -%]
+[%- SET derived = attribute.findvalue("@isDerived") -%]
+[%- SET derivedUnion = attribute.findvalue("@isDerivedUnion") -%]
+[%- SET association = attribute.findvalue("@association") -%]
+[%- SET documentation = attribute.findvalue("ownedComment/body/text()") -%]
+[%- IF documentation != "" %]
+/*!
+ ${documentation}
+ */
+[%- END %]
+[% IF qtType.match("QList|QSet") %]const [% END %]${qtType}
+Q${namespace}${className}::${qtAttribute}() const
+{
+ // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %]
+
+ [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]
+ qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])");
+
+ [%- IF qtType.match('\*$') %]
+ return 0;
+ [%- ELSE %]
+ return ${qtType.trim}();
+ [%- END %]
+ [%- ELSE %]
+ return _${qtAttribute};
+ [%- END %]
+}
+ [%- SET attributeName = attribute.findvalue("@name").ucfirst %]
+ [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]
-Q${namespace}${className}::Q${namespace}${className}(QObject *parent) :
- QObject(parent)
+void Q${namespace}${className}::add${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}${qtAttribute})
{
+ // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %]
+
+ [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]
+ qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])");
+ Q_UNUSED(${qtAttribute});
+
+ if (false /* <derivedexclusion-criteria> */) {
+ // <derived-code>
+ [%- ELSE %]
+ if (!_${qtAttribute}.contains(${qtAttribute})) {
+ _${qtAttribute}.[% IF qtType.match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute});
+ [%- IF qtType.match('\*') %]
+ if (${qtAttribute}->asQObject() && this->asQObject())
+ QObject::connect(${qtAttribute}->asQObject(), SIGNAL(destroyed(QObject*)), this->asQObject(), SLOT(remove${attributeName}(QObject *)));
+ [%- IF attribute.findvalue("@aggregation") == "composite" %]
+ ${qtAttribute}->asQObject()->setParent(this->asQObject());
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+ [%- found = "false" -%]
+ [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%]
+ [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%]
+ [%- IF subsettedProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+
+ // Adjust subsetted properties
+ [%- found = "true" -%]
+ [%- END -%]
+ [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %]
+ add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ [%- ELSE %]
+ set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+ [%- IF association != "" -%]
+ [%- found = "false" -%]
+ [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%]
+ [%- NEXT IF memberEnd.split('-').0 == className -%]
+ [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%]
+ [%- IF oppositeProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+
+ // Adjust opposite properties
+ [%- found = "true" -%]
+ [%- END %]
+ if (${qtAttribute}) {
+ [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %]
+ ${qtAttribute}->add${memberEnd.split('-').1.ucfirst}(this);
+ [%- ELSE %]
+ ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(this);
+ [%- END %]
+ }
+ [%- END %]
+ [%- END %]
+ [%- END %]
+ }
+}
+
+void Q${namespace}${className}::remove${attributeName}(${qtType.remove("QSet<").remove("QList<").replace(">", "").replace('\* $', '*')}${qtAttribute})
+{
+ // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %]
+
+ [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]
+ qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])");
+ Q_UNUSED(${qtAttribute});
+
+ if (false /* <derivedexclusion-criteria> */) {
+ // <derived-code>
+ [%- ELSE %]
+ if (_${qtAttribute}.contains(${qtAttribute})) {
+ _${qtAttribute}.[% IF qtType.match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute});
+ [%- IF attribute.findvalue("@aggregation") == "composite" %]
+ if (${qtAttribute}->asQObject())
+ ${qtAttribute}->asQObject()->setParent(0);
+ [%- END -%]
+ [%- END %]
+ [%- found = "false" -%]
+ [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%]
+ [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%]
+ [%- IF subsettedProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+
+ // Adjust subsetted properties
+ [%- found = "true" -%]
+ [%- END -%]
+ [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %]
+ remove${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ [%- ELSE %]
+ set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+ [%- IF association != "" -%]
+ [%- found = "false" -%]
+ [%- FOREACH memberEnd = xmi.findvalue("//packagedElement[@xmi:type=\"uml:Association\" and @name=\"${association}\"]/@memberEnd").split(' ') -%]
+ [%- NEXT IF memberEnd.split('-').0 == className -%]
+ [%- SET oppositeProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${memberEnd.split('-').0}\"]/ownedAttribute[@name=\"${memberEnd.split('-').1}\"]") -%]
+ [%- IF oppositeProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+
+ // Adjust opposite properties
+ [%- found = "true" -%]
+ [%- END %]
+ if (${qtAttribute}) {
+ [%- IF oppositeProperty.findvalue("upperValue/@value") == "*" %]
+ ${qtAttribute}->remove${memberEnd.split('-').1.ucfirst}(this);
+ [%- ELSE %]
+ ${qtAttribute}->set${memberEnd.split('-').1.ucfirst}(0);
+ [%- END %]
+ }
+ [%- END %]
+ [%- END %]
+ [%- END %]
+ }
+}
+ [%- ELSE %]
+
+void Q${namespace}${className}::set${attributeName.remove("^Is")}([% IF !qtType.match('\*$') %]${qtType.trim} [% ELSE %]${qtType}[% END %]${qtAttribute})
+{
+ // This is a [% IF readOnly == "" || readOnly == "false" %]read-write[% ELSE %]read-only[% END %][% IF derived == "true" %] derived[% END %][% IF derivedUnion == "true" %] union[% END %] [% IF association != "" %]association end[% ELSE %]property[% END %]
+
+ [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]
+ qWarning("${namespace}${className}::${qtAttribute}(): to be implemented (this is a derived [% IF association != "" %]association end[% ELSE %]property[% END %])");
+ Q_UNUSED(${qtAttribute});
+
+ if (false /* <derivedexclusion-criteria> */) {
+ [%- ELSE %]
+ if (_${qtAttribute} != ${qtAttribute}) {
+ [%- END %]
+ [%- found = "false" -%]
+ [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%]
+ [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%]
+ [%- IF subsettedProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+ // Adjust subsetted properties
+ [%- found = "true" -%]
+ [%- END -%]
+ [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %]
+ [% IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]// [% END %]remove${subsettedPropertyName.split('-').1.ucfirst}([%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]/* <derived-code> */[% ELSE %]_${qtAttribute}[% END %]);
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+[%- IF found == "true" %]
+[% END %]
+ [%- IF derived == "true" && (derivedUnion == "false" || derivedUnion == "") %]
+ // <derived-code>
+ [%- ELSE %]
+ _${qtAttribute} = ${qtAttribute};
+ [%- IF qtType.match('\*') %]
+ if (${qtAttribute}->asQObject() && this->asQObject())
+ QObject::connect(${qtAttribute}->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(set${attributeName}()));
+ [%- IF attribute.findvalue("@aggregation") == "composite" %]
+ ${qtAttribute}->asQObject()->setParent(this->asQObject());
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+ [%- found = "false" -%]
+ [%- FOREACH subsettedPropertyName = attribute.findvalue("@subsettedProperty").split(" ") -%]
+ [%- SET subsettedProperty = xmi.findnodes("//packagedElement[@xmi:type=\"uml:Class\" and @name=\"${subsettedPropertyName.split('-').0}\"]/ownedAttribute[@name=\"${subsettedPropertyName.split('-').1}\"]") -%]
+ [%- IF subsettedProperty.findvalue("@name") != "" -%]
+ [%- IF found == "false" %]
+
+ // Adjust subsetted properties
+ [%- found = "true" -%]
+ [%- END -%]
+ [%- IF subsettedProperty.findvalue("upperValue/@value") == "*" %]
+ if (${qtAttribute}) {
+ add${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ }
+ [%- ELSE %]
+ set${subsettedPropertyName.split('-').1.ucfirst}(${qtAttribute});
+ [%- END -%]
+ [%- END %]
+ [%- END %]
+ }
}
+ [%- END %]
+[%- END %]
+[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%]
+[%- IF loop.first %]
+
+// OPERATIONS
+[%- END %]
+[%- SET operationName = operation.findvalue("@name") -%]
-[%- SET originalClassName = class.findvalue("@name") -%]
-[%- visitedClasses = [] -%]
-[%- redefinedProperties = [] -%]
-[%- POPULATE_REDEFINED_PROPERTIES(class, visitedClasses, redefinedProperties) -%]
-[%- visitedClasses = [] %]
-[% GENERATE_CPP_ATTRIBUTES(originalClassName, class, visitedClasses, redefinedProperties) -%]
-[%- visitedClasses = [] -%]
-[%- redefinedOperations = [] -%]
-[%- POPULATE_REDEFINED_OPERATIONS(class, visitedClasses, redefinedOperations) -%]
-[%- visitedClasses = [] %]
-[%- GENERATE_CPP_OPERATIONS(originalClassName, class, visitedClasses, redefinedOperations) -%]
-[%- visitedClasses = [] %]
-[%- GENERATE_CPP_SLOTS(originalClassName, class, visitedClasses, redefinedProperties) -%]
-QT_END_NAMESPACE
+[%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %]
+
+[%- SET documentation = operation.findvalue("ownedComment/body/text()") -%]
+[%- IF documentation != "" %]
+/*!
+ ${documentation}
+ */
+[%- END %]
+${returnType}Q${namespace}${className}::${operationName}(
+ [%- SET parameters = operation.findnodes("ownedParameter[@direction!='return']") -%]
+ [%- FOREACH parameter = parameters -%]
+ [%- QT_TYPE(namespace, parameter) -%]
+${parameter.findvalue("@name")}
+ [%- IF !loop.last %], [% END -%]
+ [%- END -%]
+)[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]
+{
+ qWarning("${namespace}${className}::${operationName}(): to be implemented (operation)");
+
+ [%- FOREACH parameter = parameters %]
+ Q_UNUSED(${parameter.findvalue("@name")});
+ [%- END %]
+ [%- IF returnType.match('\*$') %]
+ return 0;
+ [%- ELSE %]
+ return ${returnType}();
+ [%- END %]
+}
+[%- END %]