diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-09-19 00:50:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-09-19 09:59:25 +0100 |
commit | 4eca665bd1f1dfe884729cc2ef073c1b07a6112e (patch) | |
tree | 47cc68690034ebc25d9d1ea4d6cdbb078ff8af4b /basic/source/sbx | |
parent | 2b7fdc51dc418ac4d9719ece12d383a6661df1cd (diff) |
ditch SHL_SBX and don't leak
Diffstat (limited to 'basic/source/sbx')
-rw-r--r-- | basic/source/sbx/sbxbase.cxx | 55 | ||||
-rw-r--r-- | basic/source/sbx/sbxscan.cxx | 22 |
2 files changed, 38 insertions, 39 deletions
diff --git a/basic/source/sbx/sbxbase.cxx b/basic/source/sbx/sbxbase.cxx index 0e116c9a9b5b..79c593e1c48e 100644 --- a/basic/source/sbx/sbxbase.cxx +++ b/basic/source/sbx/sbxbase.cxx @@ -37,6 +37,7 @@ #include <basic/sbxfac.hxx> #include <basic/sbxbase.hxx> +#include <rtl/instance.hxx> #include <rtl/strbuf.hxx> // AppData-Structure for SBX: @@ -46,16 +47,14 @@ SV_IMPL_PTRARR(SbxFacs,SbxFactory*); TYPEINIT0(SbxBase) -// Request SBX-Data or if necessary create them -// we just create the area and waive the release! +namespace +{ + class theSbxAppData : public rtl::Static<SbxAppData, theSbxAppData> {}; +} -SbxAppData* GetSbxData_Impl() +SbxAppData& GetSbxData_Impl() { - SbxAppData** ppData = (SbxAppData**) ::GetAppData( SHL_SBX ); - SbxAppData* p = *ppData; - if( !p ) - p = *ppData = new SbxAppData; - return p; + return theSbxAppData::get(); } SbxAppData::~SbxAppData() @@ -130,51 +129,51 @@ void SbxBase::SetModified( sal_Bool b ) SbxError SbxBase::GetError() { - return GetSbxData_Impl()->eSbxError; + return GetSbxData_Impl().eSbxError; } void SbxBase::SetError( SbxError e ) { - SbxAppData* p = GetSbxData_Impl(); - if( e && p->eSbxError == SbxERR_OK ) - p->eSbxError = e; + SbxAppData& r = GetSbxData_Impl(); + if( e && r.eSbxError == SbxERR_OK ) + r.eSbxError = e; } sal_Bool SbxBase::IsError() { - return sal_Bool( GetSbxData_Impl()->eSbxError != SbxERR_OK ); + return sal_Bool( GetSbxData_Impl().eSbxError != SbxERR_OK ); } void SbxBase::ResetError() { - GetSbxData_Impl()->eSbxError = SbxERR_OK; + GetSbxData_Impl().eSbxError = SbxERR_OK; } void SbxBase::AddFactory( SbxFactory* pFac ) { - SbxAppData* p = GetSbxData_Impl(); + SbxAppData& r = GetSbxData_Impl(); const SbxFactory* pTemp = pFac; // From 1996-03-06: take the HandleLast-Flag into account - sal_uInt16 nPos = p->aFacs.Count(); // Insert position + sal_uInt16 nPos = r.aFacs.Count(); // Insert position if( !pFac->IsHandleLast() ) // Only if not self HandleLast { // Rank new factory in front of factories with HandleLast while( nPos > 0 && - (static_cast<SbxFactory*>(p->aFacs.GetObject( nPos-1 )))->IsHandleLast() ) + (static_cast<SbxFactory*>(r.aFacs.GetObject( nPos-1 )))->IsHandleLast() ) nPos--; } - p->aFacs.Insert( pTemp, nPos ); + r.aFacs.Insert( pTemp, nPos ); } void SbxBase::RemoveFactory( SbxFactory* pFac ) { - SbxAppData* p = GetSbxData_Impl(); - for( sal_uInt16 i = 0; i < p->aFacs.Count(); i++ ) + SbxAppData& r = GetSbxData_Impl(); + for( sal_uInt16 i = 0; i < r.aFacs.Count(); i++ ) { - if( p->aFacs.GetObject( i ) == pFac ) + if( r.aFacs.GetObject( i ) == pFac ) { - p->aFacs.Remove( i, 1 ); break; + r.aFacs.Remove( i, 1 ); break; } } } @@ -204,11 +203,11 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) case SBXID_PROPERTY: return new SbxProperty( aEmptyStr, SbxEMPTY ); } // Unknown type: go over the factories! - SbxAppData* p = GetSbxData_Impl(); + SbxAppData& r = GetSbxData_Impl(); SbxBase* pNew = NULL; - for( sal_uInt16 i = 0; i < p->aFacs.Count(); i++ ) + for( sal_uInt16 i = 0; i < r.aFacs.Count(); i++ ) { - SbxFactory* pFac = p->aFacs.GetObject( i ); + SbxFactory* pFac = r.aFacs.GetObject( i ); pNew = pFac->Create( nSbxId, nCreator ); if( pNew ) break; @@ -227,11 +226,11 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator ) SbxObject* SbxBase::CreateObject( const XubString& rClass ) { - SbxAppData* p = GetSbxData_Impl(); + SbxAppData& r = GetSbxData_Impl(); SbxObject* pNew = NULL; - for( sal_uInt16 i = 0; i < p->aFacs.Count(); i++ ) + for( sal_uInt16 i = 0; i < r.aFacs.Count(); i++ ) { - pNew = p->aFacs.GetObject( i )->CreateObject( rClass ); + pNew = r.aFacs.GetObject( i )->CreateObject( rClass ); if( pNew ) break; } diff --git a/basic/source/sbx/sbxscan.cxx b/basic/source/sbx/sbxscan.cxx index 57cc69d5e5d6..0a127f49360f 100644 --- a/basic/source/sbx/sbxscan.cxx +++ b/basic/source/sbx/sbxscan.cxx @@ -850,21 +850,21 @@ void SbxValue::Format( XubString& rRes, const XubString* pFmt ) const cvt2: if( pFmt ) { - SbxAppData* pData = GetSbxData_Impl(); + SbxAppData& rAppData = GetSbxData_Impl(); LanguageType eLangType = GetpApp()->GetSettings().GetLanguage(); - if( pData->pBasicFormater ) + if( rAppData.pBasicFormater ) { - if( pData->eBasicFormaterLangType != eLangType ) + if( rAppData.eBasicFormaterLangType != eLangType ) { - delete pData->pBasicFormater; - pData->pBasicFormater = NULL; + delete rAppData.pBasicFormater; + rAppData.pBasicFormater = NULL; } } - pData->eBasicFormaterLangType = eLangType; + rAppData.eBasicFormaterLangType = eLangType; - if( !pData->pBasicFormater ) + if( !rAppData.pBasicFormater ) { SvtSysLocale aSysLocale; const LocaleDataWrapper& rData = aSysLocale.GetLocaleData(); @@ -890,7 +890,7 @@ void SbxValue::Format( XubString& rRes, const XubString* pFmt ) const String aCurrencyFormatStrg = String( SbxValueFormatResId( STR_BASICKEY_FORMAT_CURRENCY) ); - pData->pBasicFormater + rAppData.pBasicFormater = new SbxBasicFormater( cComma,c1000,aOnStrg,aOffStrg, aYesStrg,aNoStrg,aTrueStrg,aFalseStrg, aCurrencyStrg,aCurrencyFormatStrg ); @@ -904,14 +904,14 @@ void SbxValue::Format( XubString& rRes, const XubString* pFmt ) const // here are problems with ;;;Null because this method is only // called, if SbxValue is a number!!! - // in addition pData->pBasicFormater->BasicFormatNull( *pFmt ); could be called! + // in addition rAppData.pBasicFormater->BasicFormatNull( *pFmt ); could be called! if( eType != SbxNULL ) { - rRes = pData->pBasicFormater->BasicFormat( d ,*pFmt ); + rRes = rAppData.pBasicFormater->BasicFormat( d ,*pFmt ); } else { - rRes = pData->pBasicFormater->BasicFormatNull( *pFmt ); + rRes = rAppData.pBasicFormater->BasicFormatNull( *pFmt ); } } |