Kaydet (Commit) 01648a39 authored tarafından Michael Stahl's avatar Michael Stahl

sw: replace boost::ptr_vector with std::vector<std::unique_ptr>

Change-Id: I880526fdcce3be0f9e9149695812e048d95004e6
üst 54045cc8
...@@ -310,9 +310,9 @@ public: ...@@ -310,9 +310,9 @@ public:
size_t size() const; size_t size() const;
SwTableAutoFormat const& operator[](size_t i) const; SwTableAutoFormat const& operator[](size_t i) const;
SwTableAutoFormat & operator[](size_t i); SwTableAutoFormat & operator[](size_t i);
void InsertAutoFormat(size_t i, SwTableAutoFormat * pFormat); void InsertAutoFormat(size_t i, std::unique_ptr<SwTableAutoFormat> pFormat);
void EraseAutoFormat(size_t i); void EraseAutoFormat(size_t i);
SwTableAutoFormat* ReleaseAutoFormat(size_t i); std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(size_t i);
bool Load(); bool Load();
bool Save() const; bool Save() const;
......
...@@ -41,9 +41,11 @@ ...@@ -41,9 +41,11 @@
#include <fmtornt.hxx> #include <fmtornt.hxx>
#include <editsh.hxx> #include <editsh.hxx>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <memory>
#include <vector>
/* /*
* XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
* be synchronized with Calc's ScAutoFormat sc/source/core/tool/autoform.cxx * be synchronized with Calc's ScAutoFormat sc/source/core/tool/autoform.cxx
...@@ -1006,7 +1008,7 @@ bool SwTableAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const ...@@ -1006,7 +1008,7 @@ bool SwTableAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
struct SwTableAutoFormatTable::Impl struct SwTableAutoFormatTable::Impl
{ {
boost::ptr_vector<SwTableAutoFormat> m_AutoFormats; std::vector<std::unique_ptr<SwTableAutoFormat>> m_AutoFormats;
}; };
size_t SwTableAutoFormatTable::size() const size_t SwTableAutoFormatTable::size() const
...@@ -1016,17 +1018,17 @@ size_t SwTableAutoFormatTable::size() const ...@@ -1016,17 +1018,17 @@ size_t SwTableAutoFormatTable::size() const
SwTableAutoFormat const& SwTableAutoFormatTable::operator[](size_t const i) const SwTableAutoFormat const& SwTableAutoFormatTable::operator[](size_t const i) const
{ {
return m_pImpl->m_AutoFormats[i]; return *m_pImpl->m_AutoFormats[i];
} }
SwTableAutoFormat & SwTableAutoFormatTable::operator[](size_t const i) SwTableAutoFormat & SwTableAutoFormatTable::operator[](size_t const i)
{ {
return m_pImpl->m_AutoFormats[i]; return *m_pImpl->m_AutoFormats[i];
} }
void void
SwTableAutoFormatTable::InsertAutoFormat(size_t const i, SwTableAutoFormat *const pFormat) SwTableAutoFormatTable::InsertAutoFormat(size_t const i, std::unique_ptr<SwTableAutoFormat> pFormat)
{ {
m_pImpl->m_AutoFormats.insert(m_pImpl->m_AutoFormats.begin() + i, pFormat); m_pImpl->m_AutoFormats.insert(m_pImpl->m_AutoFormats.begin() + i, std::move(pFormat));
} }
void SwTableAutoFormatTable::EraseAutoFormat(size_t const i) void SwTableAutoFormatTable::EraseAutoFormat(size_t const i)
...@@ -1034,9 +1036,12 @@ void SwTableAutoFormatTable::EraseAutoFormat(size_t const i) ...@@ -1034,9 +1036,12 @@ void SwTableAutoFormatTable::EraseAutoFormat(size_t const i)
m_pImpl->m_AutoFormats.erase(m_pImpl->m_AutoFormats.begin() + i); m_pImpl->m_AutoFormats.erase(m_pImpl->m_AutoFormats.begin() + i);
} }
SwTableAutoFormat* SwTableAutoFormatTable::ReleaseAutoFormat(size_t const i) std::unique_ptr<SwTableAutoFormat> SwTableAutoFormatTable::ReleaseAutoFormat(size_t const i)
{ {
return m_pImpl->m_AutoFormats.release(m_pImpl->m_AutoFormats.begin() + i).release(); auto const iter(m_pImpl->m_AutoFormats.begin() + i);
std::unique_ptr<SwTableAutoFormat> pRet(std::move(*iter));
m_pImpl->m_AutoFormats.erase(iter);
return pRet;
} }
SwTableAutoFormatTable::~SwTableAutoFormatTable() SwTableAutoFormatTable::~SwTableAutoFormatTable()
...@@ -1047,8 +1052,8 @@ SwTableAutoFormatTable::SwTableAutoFormatTable() ...@@ -1047,8 +1052,8 @@ SwTableAutoFormatTable::SwTableAutoFormatTable()
: m_pImpl(new Impl) : m_pImpl(new Impl)
{ {
OUString sNm; OUString sNm;
SwTableAutoFormat* pNew = new SwTableAutoFormat( std::unique_ptr<SwTableAutoFormat> pNew(new SwTableAutoFormat(
SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm ) ); SwStyleNameMapper::GetUIName(RES_POOLCOLL_STANDARD, sNm)));
SwBoxAutoFormat aNew; SwBoxAutoFormat aNew;
...@@ -1098,7 +1103,7 @@ SwTableAutoFormatTable::SwTableAutoFormatTable() ...@@ -1098,7 +1103,7 @@ SwTableAutoFormatTable::SwTableAutoFormatTable()
const_cast<SwBoxAutoFormat&>(pNew->GetBoxFormat( i )).SetBox( aBox ); const_cast<SwBoxAutoFormat&>(pNew->GetBoxFormat( i )).SetBox( aBox );
} }
m_pImpl->m_AutoFormats.push_back(pNew); m_pImpl->m_AutoFormats.push_back(std::move(pNew));
} }
bool SwTableAutoFormatTable::Load() bool SwTableAutoFormatTable::Load()
...@@ -1163,7 +1168,6 @@ bool SwTableAutoFormatTable::Load( SvStream& rStream ) ...@@ -1163,7 +1168,6 @@ bool SwTableAutoFormatTable::Load( SvStream& rStream )
{ {
aVersions.Load( rStream, nVal ); // Item versions aVersions.Load( rStream, nVal ); // Item versions
SwTableAutoFormat* pNew;
sal_uInt16 nCount = 0; sal_uInt16 nCount = 0;
rStream.ReadUInt16( nCount ); rStream.ReadUInt16( nCount );
...@@ -1180,15 +1184,15 @@ bool SwTableAutoFormatTable::Load( SvStream& rStream ) ...@@ -1180,15 +1184,15 @@ bool SwTableAutoFormatTable::Load( SvStream& rStream )
} }
for (sal_uInt16 i = 0; i < nCount; ++i) for (sal_uInt16 i = 0; i < nCount; ++i)
{ {
pNew = new SwTableAutoFormat( OUString() ); std::unique_ptr<SwTableAutoFormat> pNew(
new SwTableAutoFormat( OUString() ));
bRet = pNew->Load( rStream, aVersions ); bRet = pNew->Load( rStream, aVersions );
if( bRet ) if( bRet )
{ {
m_pImpl->m_AutoFormats.push_back(pNew); m_pImpl->m_AutoFormats.push_back(std::move(pNew));
} }
else else
{ {
delete pNew;
break; break;
} }
} }
...@@ -1221,7 +1225,7 @@ bool SwTableAutoFormatTable::Save( SvStream& rStream ) const ...@@ -1221,7 +1225,7 @@ bool SwTableAutoFormatTable::Save( SvStream& rStream ) const
return false; return false;
// Write this version number for all attributes // Write this version number for all attributes
m_pImpl->m_AutoFormats[0].GetBoxFormat(0).SaveVersionNo( m_pImpl->m_AutoFormats[0]->GetBoxFormat(0).SaveVersionNo(
rStream, AUTOFORMAT_FILE_VERSION); rStream, AUTOFORMAT_FILE_VERSION);
rStream.WriteUInt16( m_pImpl->m_AutoFormats.size() - 1 ); rStream.WriteUInt16( m_pImpl->m_AutoFormats.size() - 1 );
...@@ -1229,7 +1233,7 @@ bool SwTableAutoFormatTable::Save( SvStream& rStream ) const ...@@ -1229,7 +1233,7 @@ bool SwTableAutoFormatTable::Save( SvStream& rStream ) const
for (sal_uInt16 i = 1; bRet && i < m_pImpl->m_AutoFormats.size(); ++i) for (sal_uInt16 i = 1; bRet && i < m_pImpl->m_AutoFormats.size(); ++i)
{ {
SwTableAutoFormat const& rFormat = m_pImpl->m_AutoFormats[i]; SwTableAutoFormat const& rFormat = *m_pImpl->m_AutoFormats[i];
bRet = rFormat.Save(rStream, AUTOFORMAT_FILE_VERSION); bRet = rFormat.Save(rStream, AUTOFORMAT_FILE_VERSION);
} }
} }
......
...@@ -328,8 +328,8 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, AddHdl, Button*, void) ...@@ -328,8 +328,8 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, AddHdl, Button*, void)
if( n >= pTableTable->size() ) if( n >= pTableTable->size() )
{ {
// Format with the name does not already exist, so take up. // Format with the name does not already exist, so take up.
SwTableAutoFormat* pNewData = new std::unique_ptr<SwTableAutoFormat> pNewData(
SwTableAutoFormat( aFormatName ); new SwTableAutoFormat(aFormatName));
pShell->GetTableAutoFormat( *pNewData ); pShell->GetTableAutoFormat( *pNewData );
// Insert sorted!! // Insert sorted!!
...@@ -337,7 +337,7 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, AddHdl, Button*, void) ...@@ -337,7 +337,7 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, AddHdl, Button*, void)
if( (*pTableTable)[ n ].GetName() > aFormatName ) if( (*pTableTable)[ n ].GetName() > aFormatName )
break; break;
pTableTable->InsertAutoFormat(n, pNewData); pTableTable->InsertAutoFormat(n, std::move(pNewData));
m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n ); m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n );
m_pLbFormat->SelectEntryPos( nDfltStylePos + n ); m_pLbFormat->SelectEntryPos( nDfltStylePos + n );
bFormatInserted = true; bFormatInserted = true;
...@@ -423,7 +423,8 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, RenameHdl, Button*, void) ...@@ -423,7 +423,8 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, RenameHdl, Button*, void)
{ {
// no format with this name exists, so rename it // no format with this name exists, so rename it
m_pLbFormat->RemoveEntry( nDfltStylePos + nIndex ); m_pLbFormat->RemoveEntry( nDfltStylePos + nIndex );
SwTableAutoFormat* p = pTableTable->ReleaseAutoFormat( nIndex ); std::unique_ptr<SwTableAutoFormat> p(
pTableTable->ReleaseAutoFormat(nIndex));
p->SetName( aFormatName ); p->SetName( aFormatName );
...@@ -434,7 +435,7 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, RenameHdl, Button*, void) ...@@ -434,7 +435,7 @@ IMPL_LINK_NOARG_TYPED(SwAutoFormatDlg, RenameHdl, Button*, void)
break; break;
} }
pTableTable->InsertAutoFormat( n, p ); pTableTable->InsertAutoFormat( n, std::move(p) );
m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n ); m_pLbFormat->InsertEntry( aFormatName, nDfltStylePos + n );
m_pLbFormat->SelectEntryPos( nDfltStylePos + n ); m_pLbFormat->SelectEntryPos( nDfltStylePos + n );
......
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