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

pass ScAutoFormatData around with unique_ptr

Change-Id: Ia112f42560955029a4a337a080a3aa0659db06b8
Reviewed-on: https://gerrit.libreoffice.org/66419
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 99b20e58
......@@ -333,7 +333,7 @@ public:
iterator find(const ScAutoFormatData* pData);
iterator find(const OUString& rName);
bool insert(ScAutoFormatData* pNew);
iterator insert(std::unique_ptr<ScAutoFormatData> pNew);
void erase(const iterator& it);
size_t size() const;
......
......@@ -853,7 +853,7 @@ ScAutoFormat::ScAutoFormat() :
mbSaveLater(false)
{
// create default autoformat
ScAutoFormatData* pData = new ScAutoFormatData;
std::unique_ptr<ScAutoFormatData> pData(new ScAutoFormatData);
OUString aName(ScResId(STR_STYLENAME_STANDARD));
pData->SetName(aName);
......@@ -929,7 +929,7 @@ ScAutoFormat::ScAutoFormat() :
}
}
insert(pData);
insert(std::move(pData));
}
bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const
......@@ -985,10 +985,10 @@ ScAutoFormat::iterator ScAutoFormat::find(const OUString& rName)
return m_Data.find(rName);
}
bool ScAutoFormat::insert(ScAutoFormatData* pNew)
ScAutoFormat::iterator ScAutoFormat::insert(std::unique_ptr<ScAutoFormatData> pNew)
{
OUString aName = pNew->GetName();
return m_Data.insert(std::make_pair(aName, std::unique_ptr<ScAutoFormatData>(pNew))).second;
return m_Data.insert(std::make_pair(aName, std::move(pNew))).first;
}
void ScAutoFormat::erase(const iterator& it)
......@@ -1062,15 +1062,14 @@ void ScAutoFormat::Load()
{
m_aVersions.Load( rStream, nVal ); // item versions
ScAutoFormatData* pData;
sal_uInt16 nCnt = 0;
rStream.ReadUInt16( nCnt );
bRet = (rStream.GetError() == ERRCODE_NONE);
for (sal_uInt16 i=0; bRet && (i < nCnt); i++)
{
pData = new ScAutoFormatData();
std::unique_ptr<ScAutoFormatData> pData(new ScAutoFormatData());
bRet = pData->Load(rStream, m_aVersions);
insert(pData);
insert(std::move(pData));
}
}
}
......
......@@ -228,17 +228,16 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl, Button*, void)
if ( !aFormatName.isEmpty() && aFormatName != aStrStandard && pFormat->find(aFormatName) == pFormat->end() )
{
ScAutoFormatData* pNewData
= new ScAutoFormatData( *pSelFmtData );
std::unique_ptr<ScAutoFormatData> pNewData(
new ScAutoFormatData( *pSelFmtData ));
pNewData->SetName( aFormatName );
bFmtInserted = pFormat->insert(pNewData);
ScAutoFormat::iterator it = pFormat->insert(std::move(pNewData));
bFmtInserted = it != pFormat->end();
if ( bFmtInserted )
{
ScAutoFormat::const_iterator it = pFormat->find(pNewData);
ScAutoFormat::const_iterator itBeg = pFormat->begin();
size_t nPos = std::distance(itBeg, it);
size_t nPos = std::distance(pFormat->begin(), it);
m_pLbFormat->InsertEntry(aFormatName, nPos);
m_pLbFormat->SelectEntry( aFormatName );
m_pBtnAdd->Disable();
......@@ -252,9 +251,6 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, AddHdl, Button*, void)
SelFmtHdl( *m_pLbFormat.get() );
bOk = true;
}
else
delete pNewData;
}
if ( !bFmtInserted )
......@@ -344,8 +340,7 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl, Button*, void)
m_pLbFormat->RemoveEntry(nIndex );
const ScAutoFormatData* p = pFormat->findByIndex(nIndex);
ScAutoFormatData* pNewData
= new ScAutoFormatData(*p);
std::unique_ptr<ScAutoFormatData> pNewData(new ScAutoFormatData(*p));
it = pFormat->begin();
std::advance(it, nIndex);
......@@ -353,7 +348,7 @@ IMPL_LINK_NOARG(ScAutoFormatDlg, RenameHdl, Button*, void)
pNewData->SetName( aFormatName );
pFormat->insert(pNewData);
pFormat->insert(std::move(pNewData));
m_pLbFormat->SetUpdateMode(false);
m_pLbFormat->Clear();
......
......@@ -224,10 +224,10 @@ void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::
throw container::ElementExistException();
}
ScAutoFormatData* pNew = new ScAutoFormatData();
std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData());
pNew->SetName( aName );
if (pFormats->insert(pNew))
if (pFormats->insert(std::move(pNew)) != pFormats->end())
{
//! notify to other objects
pFormats->Save();
......@@ -493,13 +493,13 @@ void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
ScAutoFormatData *const pData = it->second.get();
OSL_ENSURE(pData,"AutoFormat data not available");
ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData(*pData));
pNew->SetName( aNewName );
pFormats->erase(it);
if (pFormats->insert(pNew))
it = pFormats->insert(std::move(pNew));
if (it != pFormats->end())
{
it = pFormats->find(pNew);
ScAutoFormat::iterator itBeg = pFormats->begin();
nFormatIndex = std::distance(itBeg, it);
......
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