From 5392c0a8ce5545783c86d830e8c321d487538613 Mon Sep 17 00:00:00 2001 From: "Sandro S. Andrade" Date: Sun, 25 Aug 2013 21:01:35 -0300 Subject: Add dpointer-free UML metamodel implementation - UML metamodel isn't likely to have changes, therefore we can get rid of d-pointer and private classes Change-Id: Id61fd25b965da5ed920e863d047e40ec293c106a Reviewed-by: Sandro S. Andrade --- scripts/templates/class.cpp | 69 +++++++++++++---------------------- scripts/templates/class.h | 8 +++-- scripts/templates/class_p.h | 86 -------------------------------------------- scripts/templates/module.pri | 8 +---- scripts/templates/module.pro | 2 -- 5 files changed, 32 insertions(+), 141 deletions(-) delete mode 100644 scripts/templates/class_p.h (limited to 'scripts/templates') diff --git a/scripts/templates/class.cpp b/scripts/templates/class.cpp index 622ba55f..c5a0229c 100644 --- a/scripts/templates/class.cpp +++ b/scripts/templates/class.cpp @@ -40,7 +40,6 @@ ** ****************************************************************************/ #include "q${namespace.lower}${className.lower}.h" -#include "q${namespace.lower}${className.lower}_p.h" [%- superclasses = [] -%] [%- SET generalization = class.findnodes("generalization") -%] [%- FOREACH superclass IN generalization -%] @@ -61,7 +60,15 @@ QT_BEGIN_NAMESPACE -Q${namespace}${className}Private::Q${namespace}${className}Private() +/*! + \class Q${namespace}${className} + + \inmodule Qt${namespace} + + \brief ${class.findvalue("ownedComment/body/text()")} + */ + +Q${namespace}${className}::Q${namespace}${className}() [%- SET found = "false" -%] [%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") -%] [%- SET defaultType = attribute.findvalue("defaultValue/@xmi:type") -%] @@ -71,59 +78,37 @@ Q${namespace}${className}Private::Q${namespace}${className}Private() [% SET found = "true" -%] [%- ELSE %], [% END -%] - [%- END -%] [%- IF defaultType == "uml:LiteralBoolean" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" -%] - [% QT_ATTRIBUTE(attribute) %](${defaultValue}) + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) [%- ELSE -%] - [% QT_ATTRIBUTE(attribute) %](false) + _[% QT_ATTRIBUTE(attribute) %](false) [%- END -%] [%- ELSIF defaultType == "uml:InstanceValue" -%] [%- SET defaultInstance = attribute.findvalue("defaultValue/@instance") -%] - [% QT_ATTRIBUTE(attribute) %](Qt${namespace}::${defaultInstance.split("-").0.remove("Kind$").remove("Sort$")}${defaultInstance.split("-").1.ucfirst}) + _[% QT_ATTRIBUTE(attribute) %](Qt${namespace}::${defaultInstance.split("-").0.remove("Kind$").remove("Sort$")}${defaultInstance.split("-").1.ucfirst}) [%- ELSIF defaultType == "uml:LiteralInteger" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" -%] - [% QT_ATTRIBUTE(attribute) %](${defaultValue}) + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) [%- ELSE -%] - [% QT_ATTRIBUTE(attribute) %](0) + _[% QT_ATTRIBUTE(attribute) %](0) [%- END -%] [%- ELSIF defaultType == "uml:LiteralUnlimitedNatural" -%] [%- SET defaultValue = attribute.findvalue("defaultValue/@value") -%] [%- IF defaultValue != "" -%] - [% QT_ATTRIBUTE(attribute) %](${defaultValue}) + _[% QT_ATTRIBUTE(attribute) %](${defaultValue}) [%- ELSE -%] - [% QT_ATTRIBUTE(attribute) %](0) + _[% QT_ATTRIBUTE(attribute) %](0) [%- END -%] [%- ELSIF type.match('\*$') -%] - [% QT_ATTRIBUTE(attribute) %](0) + _[% QT_ATTRIBUTE(attribute) %](0) + [%- END -%] [%- END -%] [%- END %] { } - -/*! - \class Q${namespace}${className} - - \inmodule Qt${namespace} - - \brief ${class.findvalue("ownedComment/body/text()")} - */ - -Q${namespace}${className}::Q${namespace}${className}(bool create_d_ptr) : -[%- FOREACH superclass IN generalization %] - Q${namespace}${superclass.findvalue("@general")}(false) -[%- IF !loop.last %], -[%- END -%] -[%- END -%] -[%- IF superclasses.size == 0 %] - QModelingObject(false) -[%- END %] -{ - if (create_d_ptr) - set_d_ptr(new Q${namespace}${className}Private); -} [%- FOREACH attribute = class.findnodes("ownedAttribute") %] [%- IF loop.first %] @@ -155,8 +140,7 @@ Q${namespace}${className}::${qtAttribute}() const return ${QT_TYPE(namespace, attribute).trim}(); [%- END %] [%- ELSE %] - QM_D(const Q${namespace}${className}); - return d->${qtAttribute}; + return _${qtAttribute}; [%- END %] } [%- SET attributeName = attribute.findvalue("@name").ucfirst %] @@ -175,9 +159,8 @@ void Q${namespace}${className}::add${attributeName}(${QT_TYPE(namespace, attribu // } [%- ELSE %] - QM_D(Q${namespace}${className}); - if (!d->${qtAttribute}.contains(${qtAttribute})) { - d->${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute}); + if (!_${qtAttribute}.contains(${qtAttribute})) { + _${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]append[% ELSE %]insert[% END %](${qtAttribute}); } [%- END %] } @@ -194,9 +177,8 @@ void Q${namespace}${className}::remove${attributeName}(${QT_TYPE(namespace, attr // } [%- ELSE %] - QM_D(Q${namespace}${className}); - if (d->${qtAttribute}.contains(${qtAttribute})) { - d->${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute}); + if (_${qtAttribute}.contains(${qtAttribute})) { + _${qtAttribute}.[% IF QT_TYPE(namespace, attribute).match("QList") %]removeAll[% ELSE %]remove[% END %](${qtAttribute}); } [%- END %] } @@ -214,9 +196,8 @@ void Q${namespace}${className}::set${attributeName.remove("^Is")}(${QT_TYPE(name // } [%- ELSE %] - QM_D(Q${namespace}${className}); - if (d->${qtAttribute} != ${qtAttribute}) { - d->${qtAttribute} = ${qtAttribute}; + if (_${qtAttribute} != ${qtAttribute}) { + _${qtAttribute} = ${qtAttribute}; } [%- END %] } diff --git a/scripts/templates/class.h b/scripts/templates/class.h index 23242b12..a7312309 100644 --- a/scripts/templates/class.h +++ b/scripts/templates/class.h @@ -80,7 +80,6 @@ class ${forward}; [% END %] [%- END -%] -class Q${namespace}${className}Private; class Q_${namespace.upper}_EXPORT Q${namespace}${className} : [%- FOREACH superclass IN generalization -%] public Q${namespace}${superclass.findvalue("@general")} @@ -91,7 +90,7 @@ public QModelingObject [%- END %] { public: - [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% END %]Q${namespace}${className}(bool create_d_ptr = true); + [% IF class.findvalue("@isAbstract") == "true" %]Q_DECL_HIDDEN [% END %]Q${namespace}${className}(); [%- FOREACH attribute = class.findnodes("ownedAttribute") -%] [%- IF loop.first %] @@ -126,6 +125,11 @@ ${parameter.findvalue("@name")} [%- END -%] )[% IF operation.findvalue("@isQuery") == "true" %] const[% END %]; [%- END %] + +protected: +[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") %] + [% QT_TYPE(namespace, attribute) -%]_[%- QT_ATTRIBUTE(attribute) %]; +[%- END %] }; QT_END_NAMESPACE diff --git a/scripts/templates/class_p.h b/scripts/templates/class_p.h deleted file mode 100644 index 31e6eb30..00000000 --- a/scripts/templates/class_p.h +++ /dev/null @@ -1,86 +0,0 @@ -[%- PROCESS common.tmpl -%] -/**************************************************************************** -** -** Copyright (C) 2013 Sandro S. Andrade -** 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 Q${namespace.upper}${className.upper}_P_H -#define Q${namespace.upper}${className.upper}_P_H - -#include "Qt${namespace}/Q${namespace}${className}" - -[%- SET generalization = class.findnodes('generalization') -%] -[% superclasses = [] -%] -[%- FOREACH superclass IN generalization %] -#include "private/q${namespace.lower}${superclass.findvalue('@general').lower}_p.h" -[%- superclasses.push("Q${namespace}${superclassName}") -%] -[%- IF loop.last %] -[% END -%] -[%- END %] -[%- IF superclasses.size == 0 %] -#include "private/qmodelingobject_p.h" -[% END %] -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Qt${namespace}) - -class Q_${namespace.upper}_EXPORT Q${namespace}${className}Private : -[%- FOREACH superclass IN generalization -%] -public Q${namespace}${superclass.findvalue('@general')}Private -[%- IF !loop.last %], [% END -%] -[%- END %] -[%- IF superclasses.size == 0 -%] -public QModelingObjectPrivate -[%- END %] -{ -public: - Q${namespace}${className}Private(); - -[%- FOREACH attribute = class.findnodes("ownedAttribute[(@isDerived=\"false\" or not(@isDerived)) or (@isDerivedUnion and @isDerivedUnion=\"true\")]") %] - [% QT_TYPE(namespace, attribute) -%][%- QT_ATTRIBUTE(attribute) %]; -[%- END %] -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // Q${namespace.upper}${className.upper}_P_H - diff --git a/scripts/templates/module.pri b/scripts/templates/module.pri index 0dd4307a..4c1784a3 100644 --- a/scripts/templates/module.pri +++ b/scripts/templates/module.pri @@ -1,5 +1,5 @@ [% USE xmi = XML.XPath("$xmi") -%] -PUBLIC_HEADERS += \ +HEADERS += \ qt${namespace.lower}global.h \ qt${namespace.lower}namespace.h [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] @@ -7,12 +7,6 @@ PUBLIC_HEADERS += \ q${namespace.lower}${class.findvalue('@name').lower}.h [%- END %] -PRIVATE_HEADERS += -[%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] - \ - q${namespace.lower}${class.findvalue('@name').lower}_p.h -[%- END %] - SOURCES += \ qt${namespace.lower}namespace.cpp [%- FOREACH class = xmi.findnodes('//packagedElement[@xmi:type=\'uml:Class\']') -%] diff --git a/scripts/templates/module.pro b/scripts/templates/module.pro index b2f2eea0..b88feb62 100644 --- a/scripts/templates/module.pro +++ b/scripts/templates/module.pro @@ -8,5 +8,3 @@ QMAKE_DOCS = [%- GET '$$PWD' -%]/doc/qt${namespace.lower}.qdocconf load(qt_module) include(${namespace.lower}.pri) - -HEADERS += [%- GET '$$PUBLIC_HEADERS' -%] [% GET '$$PRIVATE_HEADERS' -%] -- cgit v1.2.3