summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-02-11 21:25:24 +0000
committerCaolán McNamara <caolanm@redhat.com>2012-02-13 11:02:46 +0000
commit761f502083652f0e45de9c38f56cf4867a8197e9 (patch)
tree95508ea2c3c1aa67e2a01bb172fbde073a8c73f9 /basic
parent56122bdf25c64ef8ebdab0c7d83eb8bd94e3aa41 (diff)
can use a reference for singleton
Diffstat (limited to 'basic')
-rw-r--r--basic/inc/basic/global.hxx3
-rw-r--r--basic/source/basmgr/basmgr.cxx6
-rw-r--r--basic/source/classes/global.cxx36
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 <unotools/transliterationwrapper.hxx>
#include <comphelper/processfactory.hxx>
#include <i18npool/lang.h>
+#include <rtl/instance.hxx>
+#include <unotools/transliterationwrapper.hxx>
#include <vcl/svapp.hxx>
-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<lclTransliterationWrapper, theTransliterationWrapper> {};
+}
+
+utl::TransliterationWrapper& SbGlobal::GetTransliteration()
+{
+ return theTransliterationWrapper::get().getTransliteration();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */