[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [patch] koffice/libs/: port K3StaticDeleter to K_GLOBAL_STATIC
From:       Jaroslaw Staniek <js () iidea ! pl>
Date:       2008-08-26 22:56:48
Message-ID: 48B48A30.6020702 () iidea ! pl
[Download RAW message or body]

Hi,
Being bored with the warnings, I've finally ported K3StaticDeleters to 
K_GLOBAL_STATICs. Since K_GLOBAL_STATIC overloads 'operator type*', I've 
merged ctors with private ::init() method if there's any, to make the code 
even simpler.
All the statics like s_instance are no put within the private (but still 
static) usage of K_GLOBAL_STATIC within the blocks of instance() static 
methods. This is the way how K_GLOBAL_STATIC is used in kdelibs too (and, 
what's good, in our apps like KSpread).

OK?
-- 
regards / pozdrawiam, Jaroslaw Staniek
  Sponsored by OpenOffice Polska (http://www.openoffice.com.pl/en) to work on
  Kexi & KOffice (http://www.kexi.pl/en, http://www.koffice.org/kexi)
  KDE Libraries for MS Windows (http://windows.kde.org)

["kglobalstatic.patch" (text/plain)]

Index: libs/flake/KoShapeBorderRegistry.cpp
===================================================================
--- libs/flake/KoShapeBorderRegistry.cpp	(wersja 852932)
+++ libs/flake/KoShapeBorderRegistry.cpp	(kopia robocza)
@@ -19,14 +19,10 @@
 #include "KoShapeBorderRegistry.h"
 #include <KoPluginLoader.h>
 
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 KoShapeBorderRegistry::KoShapeBorderRegistry()
 {
-}
-
-void KoShapeBorderRegistry::init()
-{
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "FlakeBorderPlugins";
     config.blacklist = "FlakeBorderPluginsDisabled";
@@ -43,17 +39,10 @@
 {
 }
 
-KoShapeBorderRegistry *KoShapeBorderRegistry::m_singleton = 0;
-static K3StaticDeleter<KoShapeBorderRegistry> staticShapeRegistryDeleter;
-
 KoShapeBorderRegistry* KoShapeBorderRegistry::instance()
 {
-    if (KoShapeBorderRegistry::m_singleton == 0)
-    {
-        staticShapeRegistryDeleter.setObject(m_singleton, new \
                KoShapeBorderRegistry());
-        KoShapeBorderRegistry::m_singleton->init();
-    }
-    return KoShapeBorderRegistry::m_singleton;
+    K_GLOBAL_STATIC(KoShapeBorderRegistry, m_singleton)
+    return m_singleton;
 }
 
 #include "KoShapeBorderRegistry.moc"
Index: libs/flake/KoShapeRegistry.h
===================================================================
--- libs/flake/KoShapeRegistry.h	(wersja 852932)
+++ libs/flake/KoShapeRegistry.h	(kopia robocza)
@@ -66,13 +66,10 @@
     KoShapeRegistry();
     KoShapeRegistry(const KoShapeRegistry&);
     KoShapeRegistry operator=(const KoShapeRegistry&);
-    void init();
 
     KoShape * createShapeInternal( const KoXmlElement & fullElement, \
KoShapeLoadingContext & context, const KoXmlElement & element ) const;  
 private:
-    static KoShapeRegistry *s_singleton;
-
     class Private;
     Private * const d;
 
Index: libs/flake/KoToolRegistry.h
===================================================================
--- libs/flake/KoToolRegistry.h	(wersja 852932)
+++ libs/flake/KoToolRegistry.h	(kopia robocza)
@@ -51,9 +51,6 @@
     KoToolRegistry();
     KoToolRegistry(const KoToolRegistry&);
     KoToolRegistry operator=(const KoToolRegistry&);
-    void init();
-
-    static KoToolRegistry *s_instance;
 };
 
 #endif
Index: libs/flake/KoShapeRegistry.cpp
===================================================================
--- libs/flake/KoShapeRegistry.cpp	(wersja 852932)
+++ libs/flake/KoShapeRegistry.cpp	(kopia robocza)
@@ -38,7 +38,7 @@
 #include <QPainter>
 
 #include <kdebug.h>
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 class KoShapeRegistry::Private
 {
@@ -51,15 +51,6 @@
 KoShapeRegistry::KoShapeRegistry()
     : d(new Private())
 {
-}
-
-KoShapeRegistry::~KoShapeRegistry()
-{
-    delete d;
-}
-
-void KoShapeRegistry::init()
-{
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "FlakePlugins";
     config.blacklist = "FlakePluginsDisabled";
@@ -106,17 +97,15 @@
     }
 }
 
-KoShapeRegistry *KoShapeRegistry::s_singleton = 0;
-static K3StaticDeleter<KoShapeRegistry> staticShapeRegistryDeleter;
+KoShapeRegistry::~KoShapeRegistry()
+{
+    delete d;
+}
 
 KoShapeRegistry* KoShapeRegistry::instance()
 {
-    if (KoShapeRegistry::s_singleton == 0)
-    {
-        staticShapeRegistryDeleter.setObject(s_singleton, new KoShapeRegistry());
-        KoShapeRegistry::s_singleton->init();
-    }
-    return KoShapeRegistry::s_singleton;
+    K_GLOBAL_STATIC(KoShapeRegistry, s_singleton)
+    return s_singleton;
 }
 
 KoShape * KoShapeRegistry::createShapeFromOdf(const KoXmlElement & e, \
                KoShapeLoadingContext & context) const
Index: libs/flake/KoToolManager.cpp
===================================================================
--- libs/flake/KoToolManager.cpp	(wersja 852932)
+++ libs/flake/KoToolManager.cpp	(kopia robocza)
@@ -59,7 +59,7 @@
 #include <QTimer>
 #include <kactioncollection.h>
 #include <kdebug.h>
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 #include <kaction.h>
 #include <QStack>
 #include <QLabel>
@@ -757,14 +757,9 @@
     }
 }
 
-//static
-KoToolManager* KoToolManager::s_instance = 0;
-static K3StaticDeleter<KoToolManager> staticToolManagerDeleter;
-
 KoToolManager* KoToolManager::instance()
 {
-    if (s_instance == 0)
-        staticToolManagerDeleter.setObject(s_instance, new KoToolManager());
+    K_GLOBAL_STATIC(KoToolManager, s_instance)
     return s_instance;
 }
 
Index: libs/flake/KoShapeBorderRegistry.h
===================================================================
--- libs/flake/KoShapeBorderRegistry.h	(wersja 852932)
+++ libs/flake/KoShapeBorderRegistry.h	(kopia robocza)
@@ -44,10 +44,6 @@
     KoShapeBorderRegistry();
     KoShapeBorderRegistry(const KoShapeBorderRegistry&);
     KoShapeBorderRegistry operator=(const KoShapeBorderRegistry&);
-    void init();
-
-private:
-    static KoShapeBorderRegistry *m_singleton;
 };
 
 #endif
Index: libs/flake/KoToolManager.h
===================================================================
--- libs/flake/KoToolManager.h	(wersja 852932)
+++ libs/flake/KoToolManager.h	(kopia robocza)
@@ -264,8 +264,6 @@
 private:
     class Private;
     Private *const d;
-
-    static KoToolManager* s_instance;
 };
 
 #endif
Index: libs/flake/KoDeviceRegistry.cpp
===================================================================
--- libs/flake/KoDeviceRegistry.cpp	(wersja 852932)
+++ libs/flake/KoDeviceRegistry.cpp	(kopia robocza)
@@ -18,16 +18,12 @@
  */
 
 #include "KoDeviceRegistry.h"
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 #include <KoPluginLoader.h>
 
 KoDeviceRegistry::KoDeviceRegistry()
 {
-}
-
-void KoDeviceRegistry::init()
-{
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "DevicePlugins";
     config.blacklist = "DevicePluginsDisabled";
@@ -54,16 +50,11 @@
 }
 
 // static
-KoDeviceRegistry *KoDeviceRegistry::s_instance = 0;
-static K3StaticDeleter<KoDeviceRegistry> staticToolRegistryDeleter;
 
 KoDeviceRegistry* KoDeviceRegistry::instance()
 {
-    if (KoDeviceRegistry::s_instance == 0) {
-        staticToolRegistryDeleter.setObject(s_instance, new KoDeviceRegistry());
-        KoDeviceRegistry::s_instance->init();
-    }
-    return KoDeviceRegistry::s_instance;
+    K_GLOBAL_STATIC(KoDeviceRegistry, s_instance)
+    return s_instance;
 }
 
 #include "KoDeviceRegistry.moc"
Index: libs/flake/KoToolRegistry.cpp
===================================================================
--- libs/flake/KoToolRegistry.cpp	(wersja 852932)
+++ libs/flake/KoToolRegistry.cpp	(kopia robocza)
@@ -19,16 +19,12 @@
  */
 
 #include "KoToolRegistry.h"
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 #include <KoPluginLoader.h>
 
 KoToolRegistry::KoToolRegistry()
 {
-}
-
-void KoToolRegistry::init()
-{
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "FlakePlugins";
     config.blacklist = "FlakePluginsDisabled";
@@ -45,17 +41,10 @@
 {
 }
 
-// static
-KoToolRegistry *KoToolRegistry::s_instance = 0;
-static K3StaticDeleter<KoToolRegistry> staticToolRegistryDeleter;
-
 KoToolRegistry* KoToolRegistry::instance()
 {
-    if (KoToolRegistry::s_instance == 0) {
-        staticToolRegistryDeleter.setObject(s_instance, new KoToolRegistry());
-        KoToolRegistry::s_instance->init();
-    }
-    return KoToolRegistry::s_instance;
+    K_GLOBAL_STATIC(KoToolRegistry, s_instance)
+    return s_instance;
 }
 
 #include "KoToolRegistry.moc"
Index: libs/flake/KoDeviceRegistry.h
===================================================================
--- libs/flake/KoDeviceRegistry.h	(wersja 852932)
+++ libs/flake/KoDeviceRegistry.h	(kopia robocza)
@@ -49,9 +49,6 @@
     KoDeviceRegistry();
     KoDeviceRegistry(const KoDeviceRegistry&);
     KoDeviceRegistry operator=(const KoDeviceRegistry&);
-    void init();
-
-    static KoDeviceRegistry *s_instance;
 };
 
 #endif // KODEVICEREGISTRY_H
Index: libs/main/KoGlobal.h
===================================================================
--- libs/main/KoGlobal.h	(wersja 852932)
+++ libs/main/KoGlobal.h	(kopia robocza)
@@ -100,9 +100,6 @@
     int m_dpiY;
     // No BC problem here, constructor is private, feel free to add members
 
-    // Singleton pattern. Maybe this should even be refcounted, so
-    // that it gets cleaned up when closing all koffice parts in e.g. konqueror?
-    static KoGlobal* s_global;
     friend class this_is_a_singleton; // work around gcc warning
 };
 
Index: libs/main/KoDockRegistry.h
===================================================================
--- libs/main/KoDockRegistry.h	(wersja 852932)
+++ libs/main/KoDockRegistry.h	(kopia robocza)
@@ -51,9 +51,6 @@
     KoDockRegistry();
     KoDockRegistry(const KoDockRegistry&);
     KoDockRegistry operator=(const KoDockRegistry&);
-    void init();
-
-    static KoDockRegistry *s_instance;
 };
 
 #endif
Index: libs/main/KoDockRegistry.cpp
===================================================================
--- libs/main/KoDockRegistry.cpp	(wersja 852932)
+++ libs/main/KoDockRegistry.cpp	(kopia robocza)
@@ -21,12 +21,9 @@
 
 #include "KoPluginLoader.h"
 
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
 KoDockRegistry::KoDockRegistry() {
-}
-
-void KoDockRegistry::init() {
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "DockerPlugins";
     config.blacklist = "DockerPluginsDisabled";
@@ -40,17 +37,10 @@
 {
 }
 
-// static
-KoDockRegistry *KoDockRegistry::s_instance = 0;
-static K3StaticDeleter<KoDockRegistry> staticToolRegistryDeleter;
-
 KoDockRegistry* KoDockRegistry::instance()
 {
-    if(KoDockRegistry::s_instance == 0) {
-        staticToolRegistryDeleter.setObject(s_instance, new KoDockRegistry());
-        KoDockRegistry::s_instance->init();
-    }
-    return KoDockRegistry::s_instance;
+    K_GLOBAL_STATIC(KoDockRegistry, s_instance)
+    return s_instance;
 }
 
 #include "KoDockRegistry.moc"
Index: libs/main/KoPluginLoader.cpp
===================================================================
--- libs/main/KoPluginLoader.cpp	(wersja 852932)
+++ libs/main/KoPluginLoader.cpp	(kopia robocza)
@@ -26,15 +26,13 @@
 #include <kdebug.h>
 #include <kservice.h>
 #include <kservicetypetrader.h>
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 #include <KConfig>
 #include <KConfigGroup>
 
 class KoPluginLoader::Private {
 public:
     QStringList loadedServiceTypes;
-
-    static KoPluginLoader *singleton;
 };
 
 KoPluginLoader::KoPluginLoader()
@@ -47,16 +45,10 @@
     delete d;
 }
 
-KoPluginLoader *KoPluginLoader::Private::singleton = 0;
-static K3StaticDeleter<KoPluginLoader> pluginLoaderStatic;
-
 KoPluginLoader* KoPluginLoader::instance()
 {
-    if(KoPluginLoader::Private::singleton == 0)
-    {
-        pluginLoaderStatic.setObject(Private::singleton, new KoPluginLoader());
-    }
-    return KoPluginLoader::Private::singleton;
+    K_GLOBAL_STATIC(KoPluginLoader, singleton)
+    return singleton;
 }
 
 void KoPluginLoader::load(const QString & serviceType, const QString & \
                versionString, const PluginsConfig &config) {
Index: libs/main/KoGlobal.cpp
===================================================================
--- libs/main/KoGlobal.cpp	(wersja 852932)
+++ libs/main/KoGlobal.cpp	(kopia robocza)
@@ -36,17 +36,12 @@
 #include <klocale.h>
 #include <kconfig.h>
 #include <kstandarddirs.h>
-#include <k3staticdeleter.h>
 #include <kimageio.h>
 
 
-KoGlobal* KoGlobal::s_global = 0L;
-static K3StaticDeleter<KoGlobal> sdg;
-
 KoGlobal* KoGlobal::self()
 {
-    if ( !s_global )
-        sdg.setObject( s_global, new KoGlobal );
+    K_GLOBAL_STATIC(KoGlobal, s_global)
     return s_global;
 }
 
Index: libs/kotext/KoTextEditingRegistry.h
===================================================================
--- libs/kotext/KoTextEditingRegistry.h	(wersja 852932)
+++ libs/kotext/KoTextEditingRegistry.h	(kopia robocza)
@@ -45,11 +45,7 @@
     static KoTextEditingRegistry * instance();
 
 private:
-    KoTextEditingRegistry() {}
-    void init();
-
-private:
-    static KoTextEditingRegistry *s_instance;
+    KoTextEditingRegistry();
 };
 
 #endif
Index: libs/kotext/KoInlineObjectRegistry.h
===================================================================
--- libs/kotext/KoInlineObjectRegistry.h	(wersja 852932)
+++ libs/kotext/KoInlineObjectRegistry.h	(kopia robocza)
@@ -40,7 +40,7 @@
 {
     Q_OBJECT
 public:
-    ~KoInlineObjectRegistry() {}
+    ~KoInlineObjectRegistry();
 
     /**
      * Return an instance of the KoInlineObjectRegistry
@@ -62,8 +62,7 @@
     QList<QAction*> createInsertVariableActions(KoCanvasBase *host) const;
 
 private:
-    KoInlineObjectRegistry() {}
-    void init();
+    KoInlineObjectRegistry();
 
 private:
     static KoInlineObjectRegistry *s_instance;
Index: libs/kotext/KoTextEditingRegistry.cpp
===================================================================
--- libs/kotext/KoTextEditingRegistry.cpp	(wersja 852932)
+++ libs/kotext/KoTextEditingRegistry.cpp	(kopia robocza)
@@ -21,9 +21,9 @@
 
 #include <KoPluginLoader.h>
 
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
-void KoTextEditingRegistry::init() {
+KoTextEditingRegistry::KoTextEditingRegistry() {
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "TextEditingPlugins";
     config.blacklist = "TextEditingPluginsDisabled";
@@ -32,15 +32,9 @@
                                       QString::fromLatin1("[X-KoText-MinVersion] <= \
0"), config);  }
 
-KoTextEditingRegistry *KoTextEditingRegistry::s_instance = 0;
-static K3StaticDeleter<KoTextEditingRegistry> staticShapeRegistryDeleter;
-
 KoTextEditingRegistry* KoTextEditingRegistry::instance() {
-    if(KoTextEditingRegistry::s_instance == 0) {
-        staticShapeRegistryDeleter.setObject(s_instance, new \
                KoTextEditingRegistry());
-        KoTextEditingRegistry::s_instance->init();
-    }
-    return KoTextEditingRegistry::s_instance;
+    K_GLOBAL_STATIC(KoTextEditingRegistry, s_instance)
+    return s_instance;
 }
 
 #include "KoTextEditingRegistry.moc"
Index: libs/kotext/kohyphen/kohyphen.cpp
===================================================================
--- libs/kotext/kohyphen/kohyphen.cpp	(wersja 852932)
+++ libs/kotext/kohyphen/kohyphen.cpp	(kopia robocza)
@@ -29,19 +29,14 @@
 #include <klocale.h>
 #include <kglobal.h>
 #include <kstandarddirs.h>
-#include <k3staticdeleter.h>
 #include <kdebug.h>
 
 
 //#define DEBUG_HYPHENATOR 1
 
-KoHyphenator* KoHyphenator::s_self;
-static K3StaticDeleter<KoHyphenator> kohyphensd;
-
 KoHyphenator* KoHyphenator::self()
 {
-    if ( !s_self )
-        kohyphensd.setObject( s_self, new KoHyphenator );
+    K_GLOBAL_STATIC(KoHyphenator, s_self)
     return s_self;
 }
 
Index: libs/kotext/kohyphen/kohyphen.h
===================================================================
--- libs/kotext/kohyphen/kohyphen.h	(wersja 852932)
+++ libs/kotext/kohyphen/kohyphen.h	(kopia robocza)
@@ -124,8 +124,6 @@
         };
         typedef QMap<QString, EncodingStruct> EncodingMap;
         mutable EncodingMap encodings; // key is the language code
-
-        static KoHyphenator* s_self;
 };
 
 #endif
Index: libs/kotext/KoInlineObjectRegistry.cpp
===================================================================
--- libs/kotext/KoInlineObjectRegistry.cpp	(wersja 852932)
+++ libs/kotext/KoInlineObjectRegistry.cpp	(kopia robocza)
@@ -25,9 +25,9 @@
 #include <KoPluginLoader.h>
 
 #include <kdebug.h>
-#include <k3staticdeleter.h>
+#include <kglobal.h>
 
-void KoInlineObjectRegistry::init() {
+KoInlineObjectRegistry::KoInlineObjectRegistry() {
     KoPluginLoader::PluginsConfig config;
     config.whiteList = "TextInlinePlugins";
     config.blacklist = "TextInlinePluginsDisabled";
@@ -36,15 +36,12 @@
                                       QString::fromLatin1("[X-KoText-MinVersion] <= \
0"), config);  }
 
-KoInlineObjectRegistry *KoInlineObjectRegistry::s_instance = 0;
-static K3StaticDeleter<KoInlineObjectRegistry> staticInlineObjectRegistryDeleter;
+KoInlineObjectRegistry::~KoInlineObjectRegistry() {
+}
 
 KoInlineObjectRegistry* KoInlineObjectRegistry::instance() {
-    if(KoInlineObjectRegistry::s_instance == 0) {
-        staticInlineObjectRegistryDeleter.setObject(s_instance, new \
                KoInlineObjectRegistry());
-        KoInlineObjectRegistry::s_instance->init();
-    }
-    return KoInlineObjectRegistry::s_instance;
+    K_GLOBAL_STATIC(KoInlineObjectRegistry, s_instance)
+    return s_instance;
 }
 
 QList<QAction*> KoInlineObjectRegistry::createInsertVariableActions(KoCanvasBase \
*host) const {



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic