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

simplify call sites of SfxItemPool::Put

use template to make return type match input type, so we don't need to
cast at the call sites

Change-Id: I1e65f362c67f74c9a230cdbc1db12545b28eb499
Reviewed-on: https://gerrit.libreoffice.org/71216
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 90e3b47b
......@@ -146,10 +146,10 @@ public:
virtual SfxItemPool* Clone() const;
const OUString& GetName() const;
const SfxPoolItem& Put( std::unique_ptr<SfxPoolItem> xItem, sal_uInt16 nWhich = 0 )
{ return PutImpl( *xItem.release(), nWhich, /*bPassingOwnership*/true); }
const SfxPoolItem& Put( const SfxPoolItem& rItem, sal_uInt16 nWhich = 0 )
{ return PutImpl( rItem, nWhich, /*bPassingOwnership*/false); }
template<class T> const T& Put( std::unique_ptr<T> xItem, sal_uInt16 nWhich = 0 )
{ return static_cast<const T&>(PutImpl( *xItem.release(), nWhich, /*bPassingOwnership*/true)); }
template<class T> const T& Put( const T& rItem, sal_uInt16 nWhich = 0 )
{ return static_cast<const T&>(PutImpl( rItem, nWhich, /*bPassingOwnership*/false)); }
void Remove( const SfxPoolItem& );
const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
......
......@@ -60,7 +60,7 @@ ScAttrArray::ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc, ScAttr
{
mvData[nIdx].nEndRow = pDefaultColAttrArray->mvData[nIdx].nEndRow;
ScPatternAttr aNewPattern( *(pDefaultColAttrArray->mvData[nIdx].pPattern) );
mvData[nIdx].pPattern = static_cast<const ScPatternAttr*>( &pDocument->GetPool()->Put( aNewPattern ) );
mvData[nIdx].pPattern = &pDocument->GetPool()->Put( aNewPattern );
bool bNumFormatChanged = false;
if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
mvData[nIdx].pPattern->GetItemSet(), pDocument->GetDefPattern()->GetItemSet() ) )
......@@ -145,7 +145,7 @@ void ScAttrArray::Reset( const ScPatternAttr* pPattern )
pDocument->SetStreamValid(nTab, false);
mvData.resize(1);
const ScPatternAttr* pNewPattern = static_cast<const ScPatternAttr*>( &pDocPool->Put(*pPattern) );
const ScPatternAttr* pNewPattern = &pDocPool->Put(*pPattern);
mvData[0].nEndRow = MAXROW;
mvData[0].pPattern = pNewPattern;
}
......@@ -455,9 +455,9 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd
if (bPutToPool)
{
if (bPassingOwnership)
pPattern = static_cast<const ScPatternAttr*>(&pDocument->GetPool()->Put(std::unique_ptr<ScPatternAttr>(const_cast<ScPatternAttr*>(pPattern))));
pPattern = &pDocument->GetPool()->Put(std::unique_ptr<ScPatternAttr>(const_cast<ScPatternAttr*>(pPattern)));
else
pPattern = static_cast<const ScPatternAttr*>(&pDocument->GetPool()->Put(*pPattern));
pPattern = &pDocument->GetPool()->Put(*pPattern);
}
if ((nStartRow == 0) && (nEndRow == MAXROW))
Reset(pPattern);
......@@ -684,8 +684,7 @@ void ScAttrArray::ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleS
}
pDocument->GetPool()->Remove(*mvData[nPos].pPattern);
mvData[nPos].pPattern = static_cast<const ScPatternAttr*>(
&pDocument->GetPool()->Put(*pNewPattern));
mvData[nPos].pPattern = &pDocument->GetPool()->Put(*pNewPattern);
if (Concat(nPos))
Search(nStart, nPos);
else
......@@ -825,8 +824,8 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow,
{
// remove from pool ?
pDocument->GetPool()->Remove(*mvData[nPos].pPattern);
mvData[nPos].pPattern = static_cast<const ScPatternAttr*>(
&pDocument->GetPool()->Put(std::move(pNewPattern)) );
mvData[nPos].pPattern =
&pDocument->GetPool()->Put(std::move(pNewPattern));
if (Concat(nPos))
Search(nStart, nPos);
......@@ -1830,8 +1829,7 @@ void ScAttrArray::FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBo
Find( ScResId(STR_STYLENAME_STANDARD),
SfxStyleFamily::Para,
SfxStyleSearchBits::Auto | SfxStyleSearchBits::ScStandard ) ) );
mvData[nPos].pPattern = static_cast<const ScPatternAttr*>(
&pDocument->GetPool()->Put(*pNewPattern));
mvData[nPos].pPattern = &pDocument->GetPool()->Put(*pNewPattern);
pNewPattern.reset();
if (Concat(nPos))
......@@ -2439,14 +2437,14 @@ void ScAttrArray::CopyArea(
pTmpPattern->GetItemSet().ClearItem( ATTR_MERGE_FLAG );
if (bSamePool)
pNewPattern = static_cast<const ScPatternAttr*>( &pDestDocPool->Put(*pTmpPattern) );
pNewPattern = &pDestDocPool->Put(*pTmpPattern);
else
pNewPattern = pTmpPattern->PutInPool( rAttrArray.pDocument, pDocument );
}
else
{
if (bSamePool)
pNewPattern = static_cast<const ScPatternAttr*>( &pDestDocPool->Put(*pOldPattern) );
pNewPattern = &pDestDocPool->Put(*pOldPattern);
else
pNewPattern = pOldPattern->PutInPool( rAttrArray.pDocument, pDocument );
}
......@@ -2487,8 +2485,7 @@ void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttr
{
const ScPatternAttr* pNewPattern;
if (bSamePool)
pNewPattern = static_cast<const ScPatternAttr*>(
&pDestDocPool->Put(*pDocument->GetDefPattern()));
pNewPattern = &pDestDocPool->Put(*pDocument->GetDefPattern());
else
pNewPattern = pDocument->GetDefPattern()->PutInPool( rAttrArray.pDocument, pDocument );
......@@ -2505,7 +2502,7 @@ void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, long nDy, ScAttr
const ScPatternAttr* pNewPattern;
if (bSamePool)
pNewPattern = static_cast<const ScPatternAttr*>( &pDestDocPool->Put(*pOldPattern) );
pNewPattern = &pDestDocPool->Put(*pOldPattern);
else
pNewPattern = pOldPattern->PutInPool( rAttrArray.pDocument, pDocument );
......
......@@ -715,7 +715,7 @@ void ScColumn::ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr )
const ScPatternAttr* pOldPattern = pAttrArray->GetPattern( nRow );
std::unique_ptr<ScPatternAttr> pTemp(new ScPatternAttr(*pOldPattern));
pTemp->GetItemSet().Put(rAttr);
const ScPatternAttr* pNewPattern = static_cast<const ScPatternAttr*>( &pDocPool->Put( *pTemp ) );
const ScPatternAttr* pNewPattern = &pDocPool->Put( *pTemp );
if ( pNewPattern != pOldPattern )
pAttrArray->SetPattern( nRow, pNewPattern );
......
......@@ -1106,8 +1106,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD
}
}
ScPatternAttr* pPatternAttr =
const_cast<ScPatternAttr*>( static_cast<const ScPatternAttr*>( &pDestDoc->GetPool()->Put(*pDestPattern) ) );
ScPatternAttr* pPatternAttr = const_cast<ScPatternAttr*>( &pDestDoc->GetPool()->Put(*pDestPattern) );
return pPatternAttr;
}
......
......@@ -1394,7 +1394,7 @@ void XclImpXF::ApplyPatternToAttrVector(
ScAttrEntry aEntry;
aEntry.nEndRow = nRow2;
aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat));
aEntry.pPattern = &rDoc.GetPool()->Put(rPat);
rAttrs.push_back(aEntry);
}
}
......
......@@ -2079,7 +2079,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
// Fill this gap with the default pattern.
ScAttrEntry aEntry;
aEntry.nEndRow = nRow1 - 1;
aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(*rAttrs.mpDefPattern));
aEntry.pPattern = &rDoc.GetPool()->Put(*rAttrs.mpDefPattern);
rAttrs.maAttrs.push_back(aEntry);
// Check if the default pattern is 'General'.
......@@ -2089,7 +2089,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal
ScAttrEntry aEntry;
aEntry.nEndRow = nRow2;
aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat));
aEntry.pPattern = &rDoc.GetPool()->Put(rPat);
rAttrs.maAttrs.push_back(aEntry);
if (!sc::NumFmtUtil::isLatinScript(*aEntry.pPattern, rDoc))
......
......@@ -351,9 +351,9 @@ ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
bMulti ( bNewMulti )
{
ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
pApplyPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pNewApply ) ));
pLineOuter = pNewOuter ? const_cast<SvxBoxItem*>(static_cast<const SvxBoxItem*>( &pPool->Put( *pNewOuter ) )) : nullptr;
pLineInner = pNewInner ? const_cast<SvxBoxInfoItem*>(static_cast<const SvxBoxInfoItem*>( &pPool->Put( *pNewInner ) )) : nullptr;
pApplyPattern = const_cast<ScPatternAttr*>(&pPool->Put( *pNewApply ));
pLineOuter = pNewOuter ? const_cast<SvxBoxItem*>( &pPool->Put( *pNewOuter ) ) : nullptr;
pLineInner = pNewInner ? const_cast<SvxBoxInfoItem*>( &pPool->Put( *pNewInner ) ) : nullptr;
aRangeCover = pRangeCover ? *pRangeCover : aRange;
}
......
......@@ -75,9 +75,9 @@ ScUndoCursorAttr::ScUndoCursorAttr( ScDocShell* pNewDocShell,
pNewEditData( static_cast<EditTextObject*>(nullptr) )
{
ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
pNewPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pNewPat ) ));
pOldPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pOldPat ) ));
pApplyPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pApplyPat ) ));
pNewPattern = const_cast<ScPatternAttr*>( &pPool->Put( *pNewPat ) );
pOldPattern = const_cast<ScPatternAttr*>( &pPool->Put( *pOldPat ) );
pApplyPattern = const_cast<ScPatternAttr*>( &pPool->Put( *pApplyPat ) );
}
ScUndoCursorAttr::~ScUndoCursorAttr()
......
......@@ -88,7 +88,7 @@ const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem )
}
else
pNewItem->GetItemSet().Put( *pSetToPut );
const SfxSetItem* pNewPoolItem = static_cast<const SfxSetItem*>(&pPool->Put( *pNewItem ));
const SfxSetItem* pNewPoolItem = &pPool->Put( *pNewItem );
DBG_ASSERT( pNewPoolItem != pNewItem.get(), "Pool: same in and out?" );
pNewItem.reset();
......
......@@ -467,7 +467,7 @@ void SwHistorySetFootnote::SetInDoc( SwDoc* pDoc, bool )
// set the footnote in the TextNode
SwFormatFootnote aTemp( m_bEndNote );
SwFormatFootnote& rNew = const_cast<SwFormatFootnote&>(
static_cast<const SwFormatFootnote&>(pDoc->GetAttrPool().Put(aTemp)) );
pDoc->GetAttrPool().Put(aTemp) );
if ( !m_FootnoteNumber.isEmpty() )
{
rNew.SetNumStr( m_FootnoteNumber );
......
......@@ -420,10 +420,10 @@ void Writer::AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont )
{
SvxFontItem aFont( rFont );
aFont.SetWhich( RES_CHRATR_FONT );
pItem = static_cast<const SvxFontItem*>(&rPool.Put( aFont ));
pItem = &rPool.Put( aFont );
}
else
pItem = static_cast<const SvxFontItem*>(&rPool.Put( rFont ));
pItem = &rPool.Put( rFont );
if( 1 < pItem->GetRefCount() )
rPool.Remove( *pItem );
......
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