[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdecore/kconfig_compiler
From: Matthias Kretz <kretz () kde ! org>
Date: 2007-05-21 13:05:49
Message-ID: 1179752749.874643.2684.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 666981 by mkretz:
use K_GLOBAL_STATIC instead of KStaticDeleter
M +22 -16 kconfig_compiler.cpp
--- trunk/KDE/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp #666980:666981
@@ -1583,7 +1583,7 @@
if ( cfgFileNameArg )
h << "const QString& arg";
h << ");" << endl;
- h << " static " << className << " *mSelf;" << endl << endl;
+ h << " friend class " << className << "Helper;" << endl << endl;
}
if ( hasSignals ) {
@@ -1719,32 +1719,38 @@
// Singleton implementation
if ( singleton ) {
- cpp << className << " *" << className << "::mSelf = 0;" << endl;
- cpp << "static KStaticDeleter<" << className << "> static" << className << \
"Deleter;" << endl << endl; + cpp << "class " << className << "Helper" << endl;
+ cpp << '{' << endl;
+ cpp << " public:" << endl;
+ cpp << " " << className << "Helper() : q(0) {}" << endl;
+ cpp << " ~" << className << "Helper() { delete q; }" << endl;
+ cpp << " " << className << " *q;" << endl;
+ cpp << "};" << endl;
+ cpp << "K_GLOBAL_STATIC(" << className << "Helper, s_global" << className << ")" \
<< endl;
cpp << className << " *" << className << "::self()" << endl;
cpp << "{" << endl;
if ( cfgFileNameArg ) {
- cpp << " if (!mSelf)" << endl;
+ cpp << " if (!s_global" << className << "->q)" << endl;
cpp << " kFatal() << \"you need to call " << className << "::instance \
before using\" << endl;" << endl; } else {
- cpp << " if ( !mSelf ) {" << endl;
- cpp << " static" << className << "Deleter.setObject( mSelf, new " << \
className << "() );" << endl;
- cpp << " mSelf->readConfig();" << endl;
- cpp << " }" << endl << endl;
+ cpp << " if (!s_global" << className << "->q) {" << endl;
+ cpp << " new " << className << ';' << endl;
+ cpp << " s_global" << className << "->q->readConfig();" << endl;
+ cpp << " }" << endl << endl;
}
- cpp << " return mSelf;" << endl;
+ cpp << " return s_global" << className << "->q;" << endl;
cpp << "}" << endl << endl;
if ( cfgFileNameArg ) {
cpp << "void " << className << "::instance(const QString& cfgfilename)" << \
endl; cpp << "{" << endl;
- cpp << " if (mSelf) {" << endl;
+ cpp << " if (s_global" << className << "->q) {" << endl;
cpp << " kDebug() << \"" << className << "::instance called after the \
first use - ignoring\" << endl;" << endl; cpp << " return;" << endl;
cpp << " }" << endl;
- cpp << " static" << className << "Deleter.setObject( mSelf, new " << \
className << "(cfgfilename) );" << endl;
- cpp << " mSelf->readConfig();" << endl;
+ cpp << " new " << className << "(cfgfilename);" << endl;
+ cpp << " s_global" << className << "->q->readConfig();" << endl;
cpp << "}" << endl << endl;
}
}
@@ -1790,8 +1796,10 @@
cpp << " d = new " + className + "Private;" << endl;
// Needed in case the singleton class is used as baseclass for
// another singleton.
- if ( singleton )
- cpp << " mSelf = this;" << endl;
+ if (singleton) {
+ cpp << " Q_ASSERT(!s_global" << className << "->q);" << endl;
+ cpp << " s_global" << className << "->q = this;" << endl;
+ }
group.clear();
@@ -1953,8 +1961,6 @@
if ( singleton ) {
if ( dpointer )
cpp << " delete d;" << endl;
- cpp << " if ( mSelf == this )" << endl;
- cpp << " static" << className << "Deleter.setObject( mSelf, 0, false );" << \
endl; }
cpp << "}" << endl << endl;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic