From 761f502083652f0e45de9c38f56cf4867a8197e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Sat, 11 Feb 2012 21:25:24 +0000 Subject: [PATCH] can use a reference for singleton --- basic/inc/basic/global.hxx | 3 +-- basic/source/basmgr/basmgr.cxx | 6 +++--- basic/source/classes/global.cxx | 36 ++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/basic/inc/basic/global.hxx b/basic/inc/basic/global.hxx index 75c5d625a99e..fd79dc942342 100644 --- a/basic/inc/basic/global.hxx +++ b/basic/inc/basic/global.hxx @@ -35,9 +35,8 @@ namespace utl { class SbGlobal { - static utl::TransliterationWrapper* pTransliteration; public: - static utl::TransliterationWrapper* GetTransliteration(); + static utl::TransliterationWrapper& GetTransliteration(); }; #endif diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx index 83000b820d74..2395296b3e92 100644 --- a/basic/source/basmgr/basmgr.cxx +++ b/basic/source/basmgr/basmgr.cxx @@ -1737,11 +1737,11 @@ namespace String sModule = sMacro.GetToken( 0, '.', nLast ); sMacro.Erase( 0, nLast ); - utl::TransliterationWrapper* pTransliteration = SbGlobal::GetTransliteration(); + utl::TransliterationWrapper& rTransliteration = SbGlobal::GetTransliteration(); sal_uInt16 nLibCount = i_manager->GetLibCount(); for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib ) { - if ( pTransliteration->isEqual( i_manager->GetLibName( nLib ), sLibName ) ) + if ( rTransliteration.isEqual( i_manager->GetLibName( nLib ), sLibName ) ) { StarBASIC* pLib = i_manager->GetLib( nLib ); if( !pLib ) @@ -1756,7 +1756,7 @@ namespace for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod ) { SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod ); - if ( pMod && pTransliteration->isEqual( pMod->GetName(), sModule ) ) + if ( pMod && rTransliteration.isEqual( pMod->GetName(), sModule ) ) { SbMethod* pMethod = (SbMethod*)pMod->Find( sMacro, SbxCLASS_METHOD ); if( pMethod ) diff --git a/basic/source/classes/global.cxx b/basic/source/classes/global.cxx index 023ed85a32c1..324a18a12aa7 100644 --- a/basic/source/classes/global.cxx +++ b/basic/source/classes/global.cxx @@ -27,24 +27,36 @@ */ #include "basic/global.hxx" -#include #include #include +#include +#include #include -utl::TransliterationWrapper* SbGlobal::pTransliteration = NULL; - -utl::TransliterationWrapper* SbGlobal::GetTransliteration() +namespace { - if(!pTransliteration) + class lclTransliterationWrapper { - const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguage(); - pTransliteration = new ::utl::TransliterationWrapper( - comphelper::getProcessServiceFactory(), - com::sun::star::i18n::TransliterationModules_IGNORE_CASE ); - pTransliteration->loadModuleIfNeeded( eOfficeLanguage ); - } - return pTransliteration; + private: + utl::TransliterationWrapper m_aTransliteration; + public: + lclTransliterationWrapper() + : m_aTransliteration( + comphelper::getProcessServiceFactory(), + com::sun::star::i18n::TransliterationModules_IGNORE_CASE ) + { + const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguage(); + m_aTransliteration.loadModuleIfNeeded( eOfficeLanguage ); + } + utl::TransliterationWrapper& getTransliteration() { return m_aTransliteration; } + }; + + class theTransliterationWrapper : public rtl::Static {}; +} + +utl::TransliterationWrapper& SbGlobal::GetTransliteration() +{ + return theTransliterationWrapper::get().getTransliteration(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */