can use a reference for singleton

This commit is contained in:
Caolán McNamara 2012-02-11 21:25:24 +00:00
parent 56122bdf25
commit 761f502083
3 changed files with 28 additions and 17 deletions

View file

@ -35,9 +35,8 @@ namespace utl {
class SbGlobal
{
static utl::TransliterationWrapper* pTransliteration;
public:
static utl::TransliterationWrapper* GetTransliteration();
static utl::TransliterationWrapper& GetTransliteration();
};
#endif

View file

@ -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 )

View file

@ -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: */