Kaydet (Commit) f4c387e9 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in ImplRepository

Change-Id: I664e16e4d61ed11df54bd161ad30c15fc41ce39b
Reviewed-on: https://gerrit.libreoffice.org/58648
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 04fe6b03
...@@ -63,7 +63,7 @@ namespace basic ...@@ -63,7 +63,7 @@ namespace basic
using ::com::sun::star::lang::XComponent; using ::com::sun::star::lang::XComponent;
using ::com::sun::star::document::XEmbeddedScripts; using ::com::sun::star::document::XEmbeddedScripts;
typedef std::map< Reference< XInterface >, BasicManager*, ::comphelper::OInterfaceCompare< XInterface > > BasicManagerStore; typedef std::map< Reference< XInterface >, std::unique_ptr<BasicManager>, ::comphelper::OInterfaceCompare< XInterface > > BasicManagerStore;
typedef std::vector< BasicManagerCreationListener* > CreationListeners; typedef std::vector< BasicManagerCreationListener* > CreationListeners;
...@@ -100,7 +100,7 @@ namespace basic ...@@ -100,7 +100,7 @@ namespace basic
@precond @precond
our mutex is locked our mutex is locked
*/ */
BasicManager*& std::unique_ptr<BasicManager>&
impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel ); impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel );
/** tests if there is a location set at which the BasicManager for the given model /** tests if there is a location set at which the BasicManager for the given model
...@@ -124,7 +124,7 @@ namespace basic ...@@ -124,7 +124,7 @@ namespace basic
the model whose BasicManager will be created. Must not be <NULL/>. the model whose BasicManager will be created. Must not be <NULL/>.
*/ */
bool impl_createManagerForModel( bool impl_createManagerForModel(
BasicManager*& _out_rpBasicManager, std::unique_ptr<BasicManager>& _out_rpBasicManager,
const Reference< XModel >& _rxDocumentModel ); const Reference< XModel >& _rxDocumentModel );
/** creates the application-wide BasicManager /** creates the application-wide BasicManager
...@@ -229,11 +229,11 @@ namespace basic ...@@ -229,11 +229,11 @@ namespace basic
thus a recursive call of this function will find and return it thus a recursive call of this function will find and return it
without creating another instance. without creating another instance.
*/ */
BasicManager*& pBasicManager = impl_getLocationForModel( _rxDocumentModel ); std::unique_ptr<BasicManager>& pBasicManager = impl_getLocationForModel( _rxDocumentModel );
if (pBasicManager != nullptr) if (pBasicManager != nullptr)
return pBasicManager; return pBasicManager.get();
if (impl_createManagerForModel(pBasicManager, _rxDocumentModel)) if (impl_createManagerForModel(pBasicManager, _rxDocumentModel))
return pBasicManager; return pBasicManager.get();
return nullptr; return nullptr;
} }
...@@ -364,12 +364,12 @@ namespace basic ...@@ -364,12 +364,12 @@ namespace basic
return pAppBasic; return pAppBasic;
} }
BasicManager*& ImplRepository::impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel ) std::unique_ptr<BasicManager>& ImplRepository::impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel )
{ {
Reference< XInterface > xNormalized( _rxDocumentModel, UNO_QUERY ); Reference< XInterface > xNormalized( _rxDocumentModel, UNO_QUERY );
DBG_ASSERT( _rxDocumentModel.is(), "ImplRepository::impl_getLocationForModel: invalid model!" ); DBG_ASSERT( _rxDocumentModel.is(), "ImplRepository::impl_getLocationForModel: invalid model!" );
BasicManager*& location = m_aStore[ xNormalized ]; std::unique_ptr<BasicManager>& location = m_aStore[ xNormalized ];
return location; return location;
} }
...@@ -406,7 +406,7 @@ namespace basic ...@@ -406,7 +406,7 @@ namespace basic
} }
} }
bool ImplRepository::impl_createManagerForModel( BasicManager*& _out_rpBasicManager, const Reference< XModel >& _rxDocumentModel ) bool ImplRepository::impl_createManagerForModel( std::unique_ptr<BasicManager>& _out_rpBasicManager, const Reference< XModel >& _rxDocumentModel )
{ {
StarBASIC* pAppBasic = impl_getDefaultAppBasicLibrary(); StarBASIC* pAppBasic = impl_getDefaultAppBasicLibrary();
...@@ -432,9 +432,9 @@ namespace basic ...@@ -432,9 +432,9 @@ namespace basic
// Storage and BaseURL are only needed by binary documents! // Storage and BaseURL are only needed by binary documents!
tools::SvRef<SotStorage> xDummyStor = new SotStorage( OUString() ); tools::SvRef<SotStorage> xDummyStor = new SotStorage( OUString() );
_out_rpBasicManager = new BasicManager( *xDummyStor, OUString() /* TODO/LATER: xStorage */, _out_rpBasicManager.reset(new BasicManager( *xDummyStor, OUString() /* TODO/LATER: xStorage */,
pAppBasic, pAppBasic,
&aAppBasicDir, true ); &aAppBasicDir, true ));
if ( !_out_rpBasicManager->GetErrors().empty() ) if ( !_out_rpBasicManager->GetErrors().empty() )
{ {
// handle errors // handle errors
...@@ -445,8 +445,7 @@ namespace basic ...@@ -445,8 +445,7 @@ namespace basic
if ( ErrorHandler::HandleError( rError.GetErrorId() ) == DialogMask::ButtonsCancel ) if ( ErrorHandler::HandleError( rError.GetErrorId() ) == DialogMask::ButtonsCancel )
{ {
// user wants to break loading of BASIC-manager // user wants to break loading of BASIC-manager
delete _out_rpBasicManager; _out_rpBasicManager.reset();
_out_rpBasicManager = nullptr;
xStorage.clear(); xStorage.clear();
break; break;
} }
...@@ -460,7 +459,7 @@ namespace basic ...@@ -460,7 +459,7 @@ namespace basic
// create new BASIC-manager // create new BASIC-manager
StarBASIC* pBasic = new StarBASIC( pAppBasic ); StarBASIC* pBasic = new StarBASIC( pAppBasic );
pBasic->SetFlag( SbxFlagBits::ExtSearch ); pBasic->SetFlag( SbxFlagBits::ExtSearch );
_out_rpBasicManager = new BasicManager( pBasic, nullptr, true ); _out_rpBasicManager.reset(new BasicManager( pBasic, nullptr, true ));
} }
// knit the containers with the BasicManager // knit the containers with the BasicManager
...@@ -543,14 +542,13 @@ namespace basic ...@@ -543,14 +542,13 @@ namespace basic
{ {
OSL_PRECOND( _pos != m_aStore.end(), "ImplRepository::impl_removeFromRepository: invalid position!" ); OSL_PRECOND( _pos != m_aStore.end(), "ImplRepository::impl_removeFromRepository: invalid position!" );
BasicManager* pManager = _pos->second; std::unique_ptr<BasicManager> pManager = std::move(_pos->second);
// *first* remove from map (else Notify won't work properly) // *first* remove from map (else Notify won't work properly)
m_aStore.erase( _pos ); m_aStore.erase( _pos );
// *then* delete the BasicManager // *then* delete the BasicManager
EndListening( *pManager ); EndListening( *pManager );
delete pManager;
} }
...@@ -590,7 +588,7 @@ namespace basic ...@@ -590,7 +588,7 @@ namespace basic
++loop ++loop
) )
{ {
if ( loop->second == pManager ) if ( loop->second.get() == pManager )
{ {
// a BasicManager which is still in our repository is being deleted. // a BasicManager which is still in our repository is being deleted.
// That's bad, since by definition, we *own* all instances in our // That's bad, since by definition, we *own* all instances in our
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment