basic: replace boost::ptr_vector with std::vector<std::unqiue_ptr>

Change-Id: Ieba2fb34e0279871d36b4fe80d9de76e614b5cde
This commit is contained in:
Michael Stahl
2015-10-25 10:02:24 +01:00
parent c791bef561
commit 192ca71f07
2 changed files with 20 additions and 15 deletions

View File

@@ -23,21 +23,24 @@
#include <i18nlangtag/lang.h> #include <i18nlangtag/lang.h>
#include <basic/sbxdef.hxx> #include <basic/sbxdef.hxx>
#include <basic/basicdllapi.h> #include <basic/basicdllapi.h>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <memory>
#include <vector>
class SbxFactory; class SbxFactory;
class SbxVariable; class SbxVariable;
class SbxBasicFormater; class SbxBasicFormater;
typedef boost::ptr_vector<SbxFactory> SbxFacs; typedef std::vector<std::unique_ptr<SbxFactory>> SbxFactories;
// AppData structure for SBX: // AppData structure for SBX:
struct SbxAppData struct SbxAppData
: private ::boost::noncopyable : private ::boost::noncopyable
{ {
SbxError eSbxError; // Error code SbxError eSbxError; // Error code
SbxFacs aFacs; // Factories SbxFactories m_Factories;
SbxBasicFormater *pBasicFormater; // Pointer to Format()-Command helper class SbxBasicFormater *pBasicFormater; // Pointer to Format()-Command helper class
LanguageType eBasicFormaterLangType; LanguageType eBasicFormaterLangType;

View File

@@ -44,7 +44,7 @@ SbxAppData::~SbxAppData()
SolarMutexGuard g; SolarMutexGuard g;
delete pBasicFormater; delete pBasicFormater;
aFacs.clear(); m_Factories.clear();
} }
SbxBase::SbxBase() SbxBase::SbxBase()
@@ -124,25 +124,27 @@ void SbxBase::AddFactory( SbxFactory* pFac )
SbxAppData& r = GetSbxData_Impl(); SbxAppData& r = GetSbxData_Impl();
// From 1996-03-06: take the HandleLast-Flag into account // From 1996-03-06: take the HandleLast-Flag into account
sal_uInt16 nPos = r.aFacs.size(); // Insert position sal_uInt16 nPos = r.m_Factories.size(); // Insert position
if( !pFac->IsHandleLast() ) // Only if not self HandleLast if( !pFac->IsHandleLast() ) // Only if not self HandleLast
{ {
// Rank new factory in front of factories with HandleLast // Rank new factory in front of factories with HandleLast
while( nPos > 0 && while (nPos > 0 && r.m_Factories[ nPos-1 ]->IsHandleLast())
r.aFacs[ nPos-1 ].IsHandleLast() )
nPos--; nPos--;
} }
r.aFacs.insert( r.aFacs.begin() + nPos, pFac ); r.m_Factories.insert(r.m_Factories.begin() + nPos, std::unique_ptr<SbxFactory>(pFac));
} }
void SbxBase::RemoveFactory( SbxFactory* pFac ) void SbxBase::RemoveFactory( SbxFactory* pFac )
{ {
SbxAppData& r = GetSbxData_Impl(); SbxAppData& r = GetSbxData_Impl();
for(SbxFacs::iterator it = r.aFacs.begin(); it != r.aFacs.end(); ++it) for (auto it = r.m_Factories.begin(); it != r.m_Factories.end(); ++it)
{ {
if( &(*it) == pFac ) if ((*it).get() == pFac)
{ {
r.aFacs.release( it ).release(); break; std::unique_ptr<SbxFactory> tmp(std::move(*it));
r.m_Factories.erase( it );
tmp.release();
break;
} }
} }
} }
@@ -173,9 +175,9 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
// Unknown type: go over the factories! // Unknown type: go over the factories!
SbxAppData& r = GetSbxData_Impl(); SbxAppData& r = GetSbxData_Impl();
SbxBase* pNew = NULL; SbxBase* pNew = NULL;
for( SbxFactory& rFac : r.aFacs ) for (auto const& rpFac : r.m_Factories)
{ {
pNew = rFac.Create( nSbxId, nCreator ); pNew = rpFac->Create( nSbxId, nCreator );
if( pNew ) if( pNew )
break; break;
} }
@@ -187,9 +189,9 @@ SbxObject* SbxBase::CreateObject( const OUString& rClass )
{ {
SbxAppData& r = GetSbxData_Impl(); SbxAppData& r = GetSbxData_Impl();
SbxObject* pNew = NULL; SbxObject* pNew = NULL;
for( SbxFactory& rFac : r.aFacs ) for (auto const& rpFac : r.m_Factories)
{ {
pNew = rFac.CreateObject( rClass ); pNew = rpFac->CreateObject( rClass );
if( pNew ) if( pNew )
break; break;
} }