diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-08-22 22:09:42 -0300 |
---|---|---|
committer | Sandro S. Andrade <sandroandrade@kde.org> | 2013-08-23 03:14:27 +0200 |
commit | cac2d532793a8ea2c871fdfca0c122fa4e605d1f (patch) | |
tree | bd76c6555f7f8de8630acf78e39aa45eca3f487c /scripts | |
parent | 2d02ef07339a9e004af82c7775acc40d506a954e (diff) |
Add improved generation of model classes
- No more xmi2qt.xq, classes are generated directly from normative
xmi
- Still takes long time to generate because of multiple passes in
input xmi model
Change-Id: I561f452ac89007400c93dfc48b5dcfe23593de3c
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/templates/class.cpp | 80 | ||||
-rw-r--r-- | scripts/templates/class.h | 70 | ||||
-rw-r--r-- | scripts/templates/class_p.h | 7 | ||||
-rw-r--r-- | scripts/templates/common.tmpl | 45 | ||||
-rw-r--r-- | scripts/templates/global.h | 4 | ||||
-rw-r--r-- | scripts/templates/module.pri | 7 | ||||
-rw-r--r-- | scripts/templates/module.pro | 2 | ||||
-rw-r--r-- | scripts/templates/modulenamespace.cpp | 60 | ||||
-rw-r--r-- | scripts/templates/modulenamespace.h | 80 | ||||
-rwxr-xr-x | scripts/xmi2qt.pl | 32 |
10 files changed, 318 insertions, 69 deletions
diff --git a/scripts/templates/class.cpp b/scripts/templates/class.cpp index 352fc45f..8f8d4930 100644 --- a/scripts/templates/class.cpp +++ b/scripts/templates/class.cpp @@ -1,21 +1,4 @@ -[% USE xmi = XML.XPath("$xmi") -%] -[% SET class = xmi.findnodes("//packagedElement[@xmi:type='uml:Class' and @name='$className']") -%] -[% SET uml2qt = { - "Boolean" = "bool", - "Integer" = "int", - "String" = "QString", - "Real" = "double" - }; --%] -[%- MACRO QT_TYPE(namespace, attribute) BLOCK -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]QList<[% END -%] - [%- IF attribute.findvalue("@type") != "" -%] -Q${namespace}${attribute.findvalue("@type")} * - [%- ELSE -%] -${uml2qt.item(attribute.findnodes("type").findvalue("@href").split("#").last)} - [%- END -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]> [% END -%] -[%- END -%] +[%- PROCESS common.tmpl -%] /**************************************************************************** ** ** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> @@ -57,9 +40,16 @@ ${uml2qt.item(attribute.findnodes("type").findvalue("@href").split("#").last)} ** ****************************************************************************/ #include "q${namespace.lower}${className.lower}.h" +[%- superclasses = [] -%] +[%- FOREACH superclass = class.findnodes("generalization") -%] +[%- superclasses.push("Q${namespace}${superclass.findvalue('@general')}") -%] +[%- END -%] [%- forwards = [] -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type]") -%] -[%- IF forward.findvalue('@type') != className -%][%- forwards.push("Q${namespace}${forward.findvalue('@type')}") -%][%- 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("^Q${namespace}${forwardName}$").size == 0 -%][%- forwards.push("Q${namespace}${forwardName}") -%][%- END -%] +[%- END -%] [%- END -%] [%- FOREACH forward = forwards.unique.sort -%] [%- IF loop.first %] @@ -69,6 +59,14 @@ ${uml2qt.item(attribute.findnodes("type").findvalue("@href").split("#").last)} QT_BEGIN_NAMESPACE +/*! + \class Q${namespace}${className} + + \inmodule Qt${namespace} + + \brief ${class.findvalue("ownedComment/body/text()")} + */ + Q${namespace}${className}::Q${namespace}${className}() { } @@ -78,43 +76,69 @@ Q${namespace}${className}::Q${namespace}${className}() // Owned attributes [%- END %] +/*! + ${attribute.findvalue("ownedComment/body/text()")} + */ [% QT_TYPE(namespace, attribute) -%] -Q${namespace}${className}::${attribute.findvalue("@name")}() const +Q${namespace}${className}::[% QT_ATTRIBUTE(attribute) %]() const { + [%- SET qtType = QT_TYPE(namespace, attribute).trim -%] + [%- IF qtType.match('\*$') %] + return 0; + [%- ELSE %] + return [% QT_TYPE(namespace, attribute).trim -%](); + [%- END %] } + [%- SET attributeName = attribute.findvalue("@name").ucfirst %] [%- IF attribute.findvalue("@isReadOnly") != "true" -%] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] -void Q${namespace}${className}::add${attribute.findvalue("@name").ucfirst}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}) +void Q${namespace}${className}::add${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]) { + Q_UNUSED([% QT_ATTRIBUTE(attribute) %]); } -void Q${namespace}${className}::remove${attribute.findvalue("@name").ucfirst}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}) +void Q${namespace}${className}::remove${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]) { + Q_UNUSED([% QT_ATTRIBUTE(attribute) %]); } [%- ELSE %] -void Q${namespace}${className}::set${attribute.findvalue("@name").ucfirst.remove("^Is")}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}) +void Q${namespace}${className}::set${attributeName.remove("^Is")}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]) { + Q_UNUSED([% QT_ATTRIBUTE(attribute) %]); } [%- END %] [%- END %] [%- END %] -[%- FOREACH operation = class.findnodes("ownedOperation") %] +[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] [%- IF loop.first %] // Operations [%- END %] +[%- SET operationName = operation.findvalue("@name") -%] -[% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] -Q${namespace}${className}::${operation.findvalue("@name")}( - [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] +[%- SET returnType = QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) %] +/*! + ${operation.findvalue("ownedComment/body/text()")} + */ +${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 %] { + [%- FOREACH parameter = parameters %] + Q_UNUSED(${parameter.findvalue("@name")}); + [%- END %] + [%- IF returnType.match('\*$') %] + return 0; + [%- ELSE %] + return ${returnType}(); + [%- END %] } [%- END %] diff --git a/scripts/templates/class.h b/scripts/templates/class.h index 2cdb5ab6..02becbaa 100644 --- a/scripts/templates/class.h +++ b/scripts/templates/class.h @@ -1,21 +1,4 @@ -[% USE xmi = XML.XPath("$xmi") -%] -[% SET class = xmi.findnodes("//packagedElement[@xmi:type='uml:Class' and @name='$className']") -%] -[% SET uml2qt = { - "Boolean" = "bool", - "Integer" = "int", - "String" = "QString", - "Real" = "double" - }; --%] -[%- MACRO QT_TYPE(namespace, attribute) BLOCK -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]QList<[% END -%] - [%- IF attribute.findvalue("@type") != "" -%] -Q${namespace}${attribute.findvalue("@type")} * - [%- ELSE -%] -${uml2qt.item(attribute.findnodes("type").findvalue("@href").split("#").last)} - [%- END -%] - [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %]> [% END -%] -[%- END -%] +[%- PROCESS common.tmpl -%] /**************************************************************************** ** ** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> @@ -60,21 +43,36 @@ ${uml2qt.item(attribute.findnodes("type").findvalue("@href").split("#").last)} #define Q${namespace.upper}${className.upper}_H #include <Qt${namespace}/Qt${namespace}Global> -[% FOREACH superclass = class.findnodes("generalization") %] -#include <Qt${namespace}/Q${namespace}${superclass.findvalue("@general")}> +[%- superclasses = [] -%] +[%- SET generalization = class.findnodes("generalization") -%] +[% FOREACH superclass IN generalization -%] +[%- IF loop.first %] +[% END -%] +[% SET superclassName = superclass.findvalue("@general") %] +#include <Qt${namespace}/Q${namespace}${superclassName}> +[%- superclasses.push("Q${namespace}${superclassName}") -%] [%- IF loop.last %] [% END -%] [%- END -%] +[%- SET useNamespace = 'false' -%] +[%- forwards = [] -%] +[%- 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") != "" -%] + [%- SET useNamespace = 'true' -%] +[%- ELSE -%] +[%- IF forwardName != className && superclasses.grep("^Q${namespace}${forwardName}$").size == 0 -%][%- forwards.push("Q${namespace}${forwardName}") -%][%- END -%] +[%- END -%] +[%- END -%] +[%- IF useNamespace == 'true' -%] +#include <Qt${namespace}/Qt${namespace}Namespace> +[% END %] QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(Qt${namespace}) -[%- forwards = [] -%] -[%- FOREACH forward = class.findnodes("ownedAttribute[@type]") -%] -[%- IF forward.findvalue('@type') != className -%][%- forwards.push("Q${namespace}${forward.findvalue('@type')}") -%][%- END -%] -[%- END -%] [%- FOREACH forward = forwards.unique.sort -%] [%- IF loop.first %] [% END %] @@ -84,7 +82,7 @@ class ${forward}; [%- END -%] class Q_${namespace.upper}_EXPORT Q${namespace}${className} -[%- FOREACH superclass = class.findnodes("generalization") -%] +[%- FOREACH superclass IN generalization -%] [%- IF loop.first %] :[% END -%] public Q${namespace}${superclass.findvalue("@general")} [%- IF !loop.last %],[% END -%] @@ -92,29 +90,33 @@ class Q_${namespace.upper}_EXPORT Q${namespace}${className} { public: [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% END %]Q${namespace}${className}(); - -[%- FOREACH attribute = class.findnodes("ownedAttribute") %] +[%- FOREACH attribute = class.findnodes("ownedAttribute") -%] [%- IF loop.first %] + // Owned attributes [%- END %] [% QT_TYPE(namespace, attribute) -%] -${attribute.findvalue("@name")}() const; + [%- QT_ATTRIBUTE(attribute) -%]() const; + [%- SET attributeName = attribute.findvalue("@name").ucfirst -%] [%- IF attribute.findvalue("@isReadOnly") != "true" -%] [%- IF attribute.findnodes("upperValue").findvalue("@value") == "*" %] - void add${attribute.findvalue("@name").ucfirst}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}); - void remove${attribute.findvalue("@name").ucfirst}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}); + void add${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]); + void remove${attributeName}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]); [%- ELSE %] - void set${attribute.findvalue("@name").ucfirst.remove("^Is")}([% QT_TYPE(namespace, attribute) %]${attribute.findvalue("@name")}); + void set${attributeName.remove("^Is")}([% QT_TYPE(namespace, attribute) %][% QT_ATTRIBUTE(attribute) %]); [%- END %] [%- END %] -[%- END %] -[%- FOREACH operation = class.findnodes("ownedOperation") %] + [%- IF loop.last %] + [%- END %] +[%- END -%] +[%- FOREACH operation = class.findnodes("ownedOperation[@name != ../ownedAttribute[@isDerived='true']/@name]") -%] [%- IF loop.first %] // Operations [%- END %] +[% SET operationName = operation.findvalue("@name") -%] [% QT_TYPE(namespace, operation.findnodes("ownedParameter[@direction='return']")) -%] -${operation.findvalue("@name")}( +${operationName}( [%- FOREACH parameter = operation.findnodes("ownedParameter[@direction!='return']") -%] [%- QT_TYPE(namespace, parameter) -%] ${parameter.findvalue("@name")} diff --git a/scripts/templates/class_p.h b/scripts/templates/class_p.h index 02577037..cda0a862 100644 --- a/scripts/templates/class_p.h +++ b/scripts/templates/class_p.h @@ -1,5 +1,4 @@ -[% USE xmi = XML.XPath("$xmi") -%] -[% SET class = xmi.findnodes("//packagedElement[@xmi:type='uml:Class' and @name='$className']") -%] +[%- PROCESS common.tmpl -%] /**************************************************************************** ** ** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> @@ -58,6 +57,10 @@ class Q_${namespace.upper}_EXPORT Q${namespace}${className}Private [%- IF !loop.last %],[% END -%] [%- END %] { +public: +[%- FOREACH attribute = class.findnodes("ownedAttribute") %] + [% QT_TYPE(namespace, attribute) -%][%- QT_ATTRIBUTE(attribute) %]; +[%- END %] }; QT_END_NAMESPACE diff --git a/scripts/templates/common.tmpl b/scripts/templates/common.tmpl new file mode 100644 index 00000000..d173d2a7 --- /dev/null +++ b/scripts/templates/common.tmpl @@ -0,0 +1,45 @@ +[% USE xmi = XML.XPath("$xmi") -%] +[% SET class = xmi.findnodes("//packagedElement[@xmi:type='uml:Class' and @name='$className']") -%] +[% SET uml2qt_type = { + "Boolean" = "bool", + "Integer" = "int", + "UnlimitedNatural" = "int", + "String" = "QString", + "Real" = "double" + }; +-%] +[%- MACRO QT_TYPE(namespace, attribute) BLOCK -%] + [%- SET multiplicity = attribute.findnodes("upperValue").findvalue("@value") -%] + [%- SET isUnique = attribute.findvalue("@isUnique") -%] + [%- SET isOrdered = attribute.findvalue("@isOrdered") -%] + [%- IF multiplicity == "*" %][% IF (isUnique == "true" || isUnique == "") && (isOrdered == "false" || isOrdered == "") %]QSet[% ELSE %]QList[% END %]<[% END -%] + [%- attributeType = attribute.findvalue("@type") -%] + [%- IF attributeType != "" -%] + [%- IF xmi.findnodes("//packagedElement[@xmi:type='uml:Enumeration' and @name='$attributeType']").findvalue("@name") != "" -%] +Qt${namespace}::${attributeType} + [%- ELSE -%] +Q${namespace}${attributeType} * + [%- END -%] + [%- ELSE -%] +${uml2qt_type.item(attribute.findnodes("type").findvalue("@href").split("#").last)}[%- IF multiplicity != "*" %] [% END -%] + [%- END -%] + [%- IF multiplicity == "*" %]> [% END -%] +[%- END -%] +[% SET uml2qt_attribute = { + "namespace" = "namespace_", + "interface" = "interface_", + "class" = "class_", + "default" = "default_", + "template" = "template_", + "slot" = "slot_", + "delete" = "delete_" + }; +-%] +[%- MACRO QT_ATTRIBUTE(attribute) BLOCK -%] +[%- SET attributeName = attribute.findvalue("@name") -%] +[%- IF uml2qt_attribute.item(attributeName) != "" -%] +${uml2qt_attribute.item(attributeName)} +[%- ELSE -%] +${attributeName} +[%- END -%] +[%- END -%] diff --git a/scripts/templates/global.h b/scripts/templates/global.h index a46f1972..32285441 100644 --- a/scripts/templates/global.h +++ b/scripts/templates/global.h @@ -43,6 +43,10 @@ #include <QtCore/QtGlobal> +#include <QtCore/QList> +#include <QtCore/QSet> +#include <QtCore/QString> + QT_BEGIN_NAMESPACE #ifndef QT_STATIC diff --git a/scripts/templates/module.pri b/scripts/templates/module.pri index 28d2f890..50405690 100644 --- a/scripts/templates/module.pri +++ b/scripts/templates/module.pri @@ -1,5 +1,7 @@ [% USE xmi = XML.XPath("$xmi") -%] -PUBLIC_HEADERS += +PUBLIC_HEADERS += \ + qt${namespace.lower}global.h \ + qt${namespace.lower}namespace.h [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] \ q${namespace.lower}${class.findvalue('@name').lower}.h @@ -11,7 +13,8 @@ PRIVATE_HEADERS += q${namespace.lower}${class.findvalue('@name').lower}_p.h [%- END %] -SOURCES += +SOURCES += \ + qt${namespace.lower}namespace.cpp [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] \ q${namespace.lower}${class.findvalue('@name').lower}.cpp diff --git a/scripts/templates/module.pro b/scripts/templates/module.pro index a9138c21..4b39de97 100644 --- a/scripts/templates/module.pro +++ b/scripts/templates/module.pro @@ -1,7 +1,7 @@ load(qt_build_config) TARGET = Qt${namespace} -QT = modeling core-private +QT = core QMAKE_DOCS = [%- GET '$$PWD' -%]/doc/qt${namespace.lower}.qdocconf diff --git a/scripts/templates/modulenamespace.cpp b/scripts/templates/modulenamespace.cpp new file mode 100644 index 00000000..3cb601e5 --- /dev/null +++ b/scripts/templates/modulenamespace.cpp @@ -0,0 +1,60 @@ +[%- PROCESS common.tmpl -%] +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt${namespace} module of the Qt Toolkit. +** +** \$QT_BEGIN_LICENSE:LGPL\$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** \$QT_END_LICENSE\$ +** +****************************************************************************/ +#include "qt${namespace.lower}namespace.h" + +QT_BEGIN_NAMESPACE + +[%- SET enumerations = xmi.findnodes("//uml:Package/packagedElement[@xmi:type=\"uml:Enumeration\"]") -%] +[% FOREACH enumeration IN enumerations %] +[%- SET enumerationName = enumeration.findvalue("@name") %] +/*! + \enum Qt${namespace}::${enumerationName} + + ${enumeration.findvalue("ownedComment/body/text()")} + + [%- FOREACH literal IN enumeration.findnodes("ownedLiteral") %] + \value ${enumerationName.remove("Kind$")}${literal.findvalue("@name").ucfirst} ${literal.findvalue("ownedComment/body/text()")} +[% END -%] + */ +[% END -%] +QT_END_NAMESPACE + diff --git a/scripts/templates/modulenamespace.h b/scripts/templates/modulenamespace.h new file mode 100644 index 00000000..2d931fb6 --- /dev/null +++ b/scripts/templates/modulenamespace.h @@ -0,0 +1,80 @@ +[%- PROCESS common.tmpl -%] +/**************************************************************************** +** +** Copyright (C) 2013 Sandro S. Andrade <sandroandrade@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt${namespace} module of the Qt Toolkit. +** +** \$QT_BEGIN_LICENSE:LGPL\$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** \$QT_END_LICENSE\$ +** +****************************************************************************/ +#ifndef QT${namespace.upper}NAMESPACE_H +#define QT${namespace.upper}NAMESPACE_H + +#include <Qt${namespace}/Qt${namespace}Global> + +#include <QtCore/QObject> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Qt${namespace}) + +class Q_${namespace.upper}_EXPORT Qt${namespace} : public QObject +{ + Q_OBJECT + +[%- SET enumerations = xmi.findnodes("//uml:Package/packagedElement[@xmi:type=\"uml:Enumeration\"]") -%] +[% FOREACH enumeration IN enumerations -%] + Q_ENUMS(${enumeration.findvalue("@name")}) +[% END %] +public: +[%- FOREACH enumeration IN enumerations %] + [%- SET enumerationName = enumeration.findvalue("@name") %] + enum ${enumerationName} + { + [%- FOREACH literal IN enumeration.findnodes("ownedLiteral") %] + ${enumerationName.remove("Kind$")}${literal.findvalue("@name").ucfirst}[%- IF loop.first -%] = 0[%- END -%][%- IF !loop.last -%],[%- END -%] + [%- END %] + }; +[%- END %] +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QT${namespace.upper}NAMESPACE_H + diff --git a/scripts/xmi2qt.pl b/scripts/xmi2qt.pl index eea5f150..4a648b32 100755 --- a/scripts/xmi2qt.pl +++ b/scripts/xmi2qt.pl @@ -49,7 +49,7 @@ use XML::XPath; use Template; my %options=(); -getopt("oi",\%options); +getopt("oip",\%options); my $tt = Template->new(INTERPOLATE => 1, INCLUDE_PATH => 'templates/'); @@ -66,6 +66,20 @@ if ($tt->process('global.h', { }) ne 1) { print $tt->error(); } close STDOUT; +open STDOUT, '>', $options{o}."/".$namespace."/qt".lc($namespace)."namespace.h"; +if ($tt->process('modulenamespace.h', { + xmi => $options{i}, + namespace => $namespace, +}) ne 1) { print $tt->error(); } +close STDOUT; + +open STDOUT, '>', $options{o}."/".$namespace."/qt".lc($namespace)."namespace.cpp"; +if ($tt->process('modulenamespace.cpp', { + xmi => $options{i}, + namespace => $namespace, +}) ne 1) { print $tt->error(); } +close STDOUT; + open STDOUT, '>', $options{o}."/".$namespace."/".lc($namespace).".pri"; if ($tt->process('module.pri', { xmi => $options{i}, @@ -80,8 +94,22 @@ if ($tt->process('module.pro', { close STDOUT; my $classset = $xmi->find('//packagedElement[@xmi:type=\'uml:Class\']'); +my $count = 0; +my @pids; foreach my $class ($classset->get_nodelist) { my $className = $class->findvalue('@name'); - system("./generate-class.pl -i " . $options{i} . " -o " . $options{o} . " -c " . $className); + die "could not fork" unless defined(my $pid = fork); + unless ($pid) { #child execs + exec "./generate-class.pl", "-i", $options{i}, "-o", $options{o}, "-c", $className; + die "exec of generate-class.pl failed"; + } + push @pids, $pid; + $count = $count + 1; + if ($count % $options{p} == 0) { + for my $pid (@pids) { + waitpid $pid, 0; + } + @pids=(); + } } |