tdf#89329: use unique_ptr for pImpl in sbxvar

Change-Id: I74734c34e72ba5d508830dbcff88f0d3b93a0766
Reviewed-on: https://gerrit.libreoffice.org/25742
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Xisco Fauli
2016-06-01 00:55:54 +02:00
committed by Noel Grandin
parent 4b917b2cfc
commit 0216b8dc61
2 changed files with 14 additions and 21 deletions

View File

@@ -62,7 +62,6 @@ class SbxVariableImpl
SbxVariable::SbxVariable() : SbxValue() SbxVariable::SbxVariable() : SbxValue()
{ {
mpSbxVariableImpl = nullptr;
pCst = nullptr; pCst = nullptr;
pParent = nullptr; pParent = nullptr;
nUserData = 0; nUserData = 0;
@@ -75,14 +74,13 @@ SbxVariable::SbxVariable( const SbxVariable& r )
mpPar( r.mpPar ), mpPar( r.mpPar ),
pInfo( r.pInfo ) pInfo( r.pInfo )
{ {
mpSbxVariableImpl = nullptr; if( r.mpImpl != nullptr )
if( r.mpSbxVariableImpl != nullptr )
{ {
mpSbxVariableImpl = new SbxVariableImpl( *r.mpSbxVariableImpl ); mpImpl.reset( new SbxVariableImpl( *r.mpImpl ) );
#if HAVE_FEATURE_SCRIPTING #if HAVE_FEATURE_SCRIPTING
if( mpSbxVariableImpl->m_xComListener.is() ) if( mpImpl->m_xComListener.is() )
{ {
registerComListenerVariableForBasic( this, mpSbxVariableImpl->m_pComListenerParentBasic ); registerComListenerVariableForBasic( this, mpImpl->m_pComListenerParentBasic );
} }
#endif #endif
} }
@@ -104,7 +102,6 @@ SbxVariable::SbxVariable( const SbxVariable& r )
SbxVariable::SbxVariable( SbxDataType t, void* p ) : SbxValue( t, p ) SbxVariable::SbxVariable( SbxDataType t, void* p ) : SbxValue( t, p )
{ {
mpSbxVariableImpl = nullptr;
pCst = nullptr; pCst = nullptr;
pParent = nullptr; pParent = nullptr;
nUserData = 0; nUserData = 0;
@@ -119,7 +116,6 @@ SbxVariable::~SbxVariable()
removeDimAsNewRecoverItem( this ); removeDimAsNewRecoverItem( this );
} }
#endif #endif
delete mpSbxVariableImpl;
delete pCst; delete pCst;
} }
@@ -349,21 +345,17 @@ sal_uInt16 SbxVariable::MakeHashCode( const OUString& rName )
SbxVariable& SbxVariable::operator=( const SbxVariable& r ) SbxVariable& SbxVariable::operator=( const SbxVariable& r )
{ {
SbxValue::operator=( r ); SbxValue::operator=( r );
delete mpSbxVariableImpl; mpImpl.reset();
if( r.mpSbxVariableImpl != nullptr ) if( r.mpImpl != nullptr )
{ {
mpSbxVariableImpl = new SbxVariableImpl( *r.mpSbxVariableImpl ); mpImpl.reset( new SbxVariableImpl( *r.mpImpl ) );
#if HAVE_FEATURE_SCRIPTING #if HAVE_FEATURE_SCRIPTING
if( mpSbxVariableImpl->m_xComListener.is() ) if( mpImpl->m_xComListener.is() )
{ {
registerComListenerVariableForBasic( this, mpSbxVariableImpl->m_pComListenerParentBasic ); registerComListenerVariableForBasic( this, mpImpl->m_pComListenerParentBasic );
} }
#endif #endif
} }
else
{
mpSbxVariableImpl = nullptr;
}
return *this; return *this;
} }
@@ -431,11 +423,11 @@ void SbxVariable::SetParent( SbxObject* p )
SbxVariableImpl* SbxVariable::getImpl() SbxVariableImpl* SbxVariable::getImpl()
{ {
if( mpSbxVariableImpl == nullptr ) if(!mpImpl)
{ {
mpSbxVariableImpl = new SbxVariableImpl(); mpImpl.reset(new SbxVariableImpl);
} }
return mpSbxVariableImpl; return mpImpl.get();
} }
const OUString& SbxVariable::GetDeclareClassName() const OUString& SbxVariable::GetDeclareClassName()

View File

@@ -24,6 +24,7 @@
#include <com/sun/star/bridge/oleautomation/Decimal.hpp> #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
#include <basic/sbxcore.hxx> #include <basic/sbxcore.hxx>
#include <basic/basicdllapi.h> #include <basic/basicdllapi.h>
#include <memory>
class SbxDecimal; class SbxDecimal;
@@ -227,7 +228,7 @@ class BASIC_DLLPUBLIC SbxVariable : public SbxValue
{ {
friend class SbMethod; friend class SbMethod;
SbxVariableImpl* mpSbxVariableImpl; // Impl data std::unique_ptr<SbxVariableImpl> mpImpl; // Impl data
SfxBroadcaster* pCst; // Broadcaster, if needed SfxBroadcaster* pCst; // Broadcaster, if needed
OUString maName; // Name, if available OUString maName; // Name, if available
SbxArrayRef mpPar; // Parameter-Array, if set SbxArrayRef mpPar; // Parameter-Array, if set