summaryrefslogtreecommitdiff
path: root/svl/source/items
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-01-10 14:54:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-01-11 14:50:11 +0100
commitccf986a77a4b218964033e70601ae220eb2c9b13 (patch)
tree08dc4cfd477a6723e8e389046fef9af67ca753a9 /svl/source/items
parent9d6b6fc96718389d7bf5f84a9e00fc5bb275c265 (diff)
loplugin:useuniqueptr in svl
Change-Id: I2fdb63517349474d90cb17ad2bd667f30840e83d Reviewed-on: https://gerrit.libreoffice.org/47727 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl/source/items')
-rw-r--r--svl/source/items/itemiter.cxx4
-rw-r--r--svl/source/items/itemset.cxx85
-rw-r--r--svl/source/items/stylepool.cxx46
3 files changed, 59 insertions, 76 deletions
diff --git a/svl/source/items/itemiter.cxx b/svl/source/items/itemiter.cxx
index a42a90bc2358..2cc6ae36212d 100644
--- a/svl/source/items/itemiter.cxx
+++ b/svl/source/items/itemiter.cxx
@@ -32,7 +32,7 @@ SfxItemIter::SfxItemIter( const SfxItemSet& rItemSet )
}
else
{
- SfxItemArray ppFnd = m_rSet.m_pItems;
+ SfxPoolItem const** ppFnd = m_rSet.m_pItems.get();
// Find the first Item that is set
for (m_nStart = 0; !*(ppFnd + m_nStart ); ++m_nStart)
@@ -53,7 +53,7 @@ SfxItemIter::~SfxItemIter()
const SfxPoolItem* SfxItemIter::NextItem()
{
- SfxItemArray ppFnd = m_rSet.m_pItems;
+ SfxPoolItem const** ppFnd = m_rSet.m_pItems.get();
if (m_nCurrent < m_nEnd)
{
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 7e99dfa098fb..3c0bfa79aec3 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -98,7 +98,7 @@ SfxItemSet::SfxItemSet(SfxItemPool& rPool)
m_pPool->FillItemIdRanges_Impl( m_pWhichRanges );
const sal_uInt16 nSize = TotalCount();
- m_pItems = new const SfxPoolItem*[nSize]{};
+ m_pItems.reset(new const SfxPoolItem*[nSize]{});
}
void SfxItemSet::InitRanges_Impl(const sal_uInt16 *pWhichPairTable)
@@ -111,7 +111,7 @@ void SfxItemSet::InitRanges_Impl(const sal_uInt16 *pWhichPairTable)
pPtr += 2;
}
- m_pItems = new const SfxPoolItem*[nCnt]{};
+ m_pItems.reset( new const SfxPoolItem*[nCnt]{} );
std::ptrdiff_t cnt = pPtr - pWhichPairTable +1;
m_pWhichRanges = new sal_uInt16[ cnt ];
@@ -161,7 +161,7 @@ SfxItemSet::SfxItemSet(
#endif
}
m_pWhichRanges[i] = 0;
- m_pItems = new SfxPoolItem const *[size]{};
+ m_pItems.reset( new SfxPoolItem const *[size]{} );
}
SfxItemSet::SfxItemSet( SfxItemPool& rPool, const sal_uInt16* pWhichPairTable )
@@ -190,10 +190,11 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rASet )
pPtr += 2;
}
- m_pItems = new const SfxPoolItem* [ nCnt ];
+ m_pItems.reset( new const SfxPoolItem* [ nCnt ] );
// Copy attributes
- SfxItemArray ppDst = m_pItems, ppSrc = rASet.m_pItems;
+ SfxPoolItem const** ppDst = m_pItems.get();
+ SfxPoolItem const** ppSrc = rASet.m_pItems.get();
for( sal_uInt16 n = nCnt; n; --n, ++ppDst, ++ppSrc )
if ( nullptr == *ppSrc || // Current Default?
IsInvalidItem(*ppSrc) || // DontCare?
@@ -223,7 +224,7 @@ SfxItemSet::~SfxItemSet()
sal_uInt16 nCount = TotalCount();
if( Count() )
{
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
for( sal_uInt16 nCnt = nCount; nCnt; --nCnt, ++ppFnd )
if( *ppFnd && !IsInvalidItem(*ppFnd) )
{
@@ -241,7 +242,7 @@ SfxItemSet::~SfxItemSet()
}
}
- delete[] m_pItems;
+ m_pItems.reset();
if (m_pWhichRanges != m_pPool->GetFrozenIdRanges())
delete[] m_pWhichRanges;
m_pWhichRanges = nullptr; // for invariant-testing
@@ -256,7 +257,7 @@ sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich )
return 0;
sal_uInt16 nDel = 0;
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
if( nWhich )
{
@@ -347,7 +348,7 @@ sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich )
void SfxItemSet::ClearInvalidItems()
{
sal_uInt16* pPtr = m_pWhichRanges;
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
while( *pPtr )
{
for( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd )
@@ -364,7 +365,7 @@ void SfxItemSet::InvalidateAllItems()
{
assert( !m_nCount && "There are still Items set" );
m_nCount = TotalCount();
- memset(static_cast<void*>(m_pItems), -1, m_nCount * sizeof(SfxPoolItem*));
+ memset(static_cast<void*>(m_pItems.get()), -1, m_nCount * sizeof(SfxPoolItem*));
}
SfxItemState SfxItemSet::GetItemState( sal_uInt16 nWhich,
@@ -376,7 +377,7 @@ SfxItemState SfxItemSet::GetItemState( sal_uInt16 nWhich,
SfxItemState eRet = SfxItemState::UNKNOWN;
do
{
- SfxItemArray ppFnd = pAktSet->m_pItems;
+ SfxPoolItem const** ppFnd = pAktSet->m_pItems.get();
const sal_uInt16* pPtr = pAktSet->m_pWhichRanges;
if (pPtr)
{
@@ -428,7 +429,7 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
if ( !nWhich )
return nullptr; //FIXME: Only because of Outliner bug
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
const sal_uInt16* pPtr = m_pWhichRanges;
while( *pPtr )
{
@@ -511,7 +512,7 @@ bool SfxItemSet::Put( const SfxItemSet& rSet, bool bInvalidAsDefault )
bool bRet = false;
if( rSet.Count() )
{
- SfxItemArray ppFnd = rSet.m_pItems;
+ SfxPoolItem const** ppFnd = rSet.m_pItems.get();
const sal_uInt16* pPtr = rSet.m_pWhichRanges;
while ( *pPtr )
{
@@ -559,7 +560,7 @@ void SfxItemSet::PutExtended
)
{
// don't "optimize" with "if( rSet.Count()" because of dont-care + defaults
- SfxItemArray ppFnd = rSet.m_pItems;
+ SfxPoolItem const** ppFnd = rSet.m_pItems.get();
const sal_uInt16* pPtr = rSet.m_pWhichRanges;
while ( *pPtr )
{
@@ -709,7 +710,7 @@ void SfxItemSet::SetRanges( const sal_uInt16 *pNewRanges )
// create new item-array (by iterating through all new ranges)
sal_uInt16 nSize = Capacity_Impl(pNewRanges);
- SfxItemArray aNewItems = new const SfxPoolItem* [ nSize ];
+ SfxPoolItem const** aNewItems = new const SfxPoolItem* [ nSize ];
sal_uInt16 nNewCount = 0;
if (m_nCount == 0)
memset( aNewItems, 0, nSize * sizeof( SfxPoolItem* ) );
@@ -758,8 +759,7 @@ void SfxItemSet::SetRanges( const sal_uInt16 *pNewRanges )
}
// replace old items-array and ranges
- delete[] m_pItems;
- m_pItems = aNewItems;
+ m_pItems.reset( aNewItems );
m_nCount = nNewCount;
if( pNewRanges == GetPool()->GetFrozenIdRanges() )
@@ -857,7 +857,7 @@ const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, bool bSrchInParent) const
{
if( pAktSet->Count() )
{
- SfxItemArray ppFnd = pAktSet->m_pItems;
+ SfxPoolItem const** ppFnd = pAktSet->m_pItems.get();
const sal_uInt16* pPtr = pAktSet->m_pWhichRanges;
while( *pPtr )
{
@@ -953,8 +953,8 @@ void SfxItemSet::Intersect( const SfxItemSet& rSet )
// If the Ranges are identical, we can easily process it
if( bEqual )
{
- SfxItemArray ppFnd1 = m_pItems;
- SfxItemArray ppFnd2 = rSet.m_pItems;
+ SfxPoolItem const** ppFnd1 = m_pItems.get();
+ SfxPoolItem const** ppFnd2 = rSet.m_pItems.get();
for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
if( *ppFnd1 && !*ppFnd2 )
@@ -1019,8 +1019,8 @@ void SfxItemSet::Differentiate( const SfxItemSet& rSet )
// If the Ranges are identical, we can easily process it
if( bEqual )
{
- SfxItemArray ppFnd1 = m_pItems;
- SfxItemArray ppFnd2 = rSet.m_pItems;
+ SfxPoolItem const** ppFnd1 = m_pItems.get();
+ SfxPoolItem const** ppFnd2 = rSet.m_pItems.get();
for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
if( *ppFnd1 && *ppFnd2 )
@@ -1229,8 +1229,8 @@ void SfxItemSet::MergeValues( const SfxItemSet& rSet )
// If the Ranges match, they are easier to process!
if( bEqual )
{
- SfxItemArray ppFnd1 = m_pItems;
- SfxItemArray ppFnd2 = rSet.m_pItems;
+ SfxPoolItem const** ppFnd1 = m_pItems.get();
+ SfxPoolItem const** ppFnd2 = rSet.m_pItems.get();
for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 )
MergeItem_Impl(m_pPool, m_nCount, ppFnd1, *ppFnd2, false/*bIgnoreDefaults*/);
@@ -1259,7 +1259,7 @@ void SfxItemSet::MergeValues( const SfxItemSet& rSet )
void SfxItemSet::MergeValue( const SfxPoolItem& rAttr, bool bIgnoreDefaults )
{
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
const sal_uInt16* pPtr = m_pWhichRanges;
const sal_uInt16 nWhich = rAttr.Which();
while( *pPtr )
@@ -1278,7 +1278,7 @@ void SfxItemSet::MergeValue( const SfxPoolItem& rAttr, bool bIgnoreDefaults )
void SfxItemSet::InvalidateItem( sal_uInt16 nWhich )
{
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
const sal_uInt16* pPtr = m_pWhichRanges;
while( *pPtr )
{
@@ -1374,12 +1374,12 @@ bool SfxItemSet::Equals(const SfxItemSet &rCmp, bool bComparePool) const
}
// Are all pointers the same?
- if (0 == memcmp( m_pItems, rCmp.m_pItems, nCount1 * sizeof(m_pItems[0]) ))
+ if (0 == memcmp( m_pItems.get(), rCmp.m_pItems.get(), nCount1 * sizeof(m_pItems[0]) ))
return true;
// We need to compare each one separately then
- const SfxPoolItem **ppItem1 = m_pItems;
- const SfxPoolItem **ppItem2 = rCmp.m_pItems;
+ const SfxPoolItem **ppItem1 = m_pItems.get();
+ const SfxPoolItem **ppItem2 = rCmp.m_pItems.get();
for ( sal_uInt16 nPos = 0; nPos < nCount1; ++nPos )
{
// If the pointers of the poolable Items are not the same, the Items
@@ -1425,7 +1425,7 @@ SfxItemSet *SfxItemSet::Clone(bool bItems, SfxItemPool *pToPool ) const
void SfxItemSet::PutDirect(const SfxPoolItem &rItem)
{
- SfxItemArray ppFnd = m_pItems;
+ SfxPoolItem const** ppFnd = m_pItems.get();
const sal_uInt16* pPtr = m_pWhichRanges;
const sal_uInt16 nWhich = rItem.Which();
#ifdef DBG_UTIL
@@ -1537,31 +1537,28 @@ static sal_uInt16 *AddRanges_Impl(
*
* @returns the new ItemArray (the old 'pItems' is freed)
*/
-static SfxItemArray AddItem_Impl(SfxItemArray pItems, sal_uInt16 nOldSize, sal_uInt16 nPos)
+static void AddItem_Impl(std::unique_ptr<SfxPoolItem const*[]> & rpItems, sal_uInt16 nOldSize, sal_uInt16 nPos)
{
// Create new ItemArray
- SfxItemArray pNew = new const SfxPoolItem*[nOldSize+1];
+ SfxPoolItem const** pNew = new const SfxPoolItem*[nOldSize+1];
// Was there one before?
- if ( pItems )
+ if ( rpItems )
{
// Copy all Items before nPos
if ( nPos )
- memcpy( static_cast<void*>(pNew), pItems, nPos * sizeof(SfxPoolItem *) );
+ memcpy( static_cast<void*>(pNew), rpItems.get(), nPos * sizeof(SfxPoolItem *) );
// Copy all Items after nPos
if ( nPos < nOldSize )
- memcpy( static_cast<void*>(pNew + nPos + 1), pItems + nPos,
+ memcpy( static_cast<void*>(pNew + nPos + 1), rpItems.get() + nPos,
(nOldSize-nPos) * sizeof(SfxPoolItem *) );
}
// Initialize new Item
*(pNew + nPos) = nullptr;
- // Free old ItemArray
- delete[] pItems;
-
- return pNew;
+ rpItems.reset(pNew);
}
/**
@@ -1606,7 +1603,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
(*pPtr)--;
// Make room before first Item of this Range
- m_pItems = AddItem_Impl(m_pItems, nItemCount, nPos);
+ AddItem_Impl(m_pItems, nItemCount, nPos);
break;
}
@@ -1618,7 +1615,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
// Make room after last Item of this Range
nPos += nWhich - *pPtr;
- m_pItems = AddItem_Impl(m_pItems, nItemCount, nPos);
+ AddItem_Impl(m_pItems, nItemCount, nPos);
break;
}
@@ -1649,7 +1646,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
// Expand ItemArray
nPos = nItemCount;
- m_pItems = AddItem_Impl(m_pItems, nItemCount, nPos);
+ AddItem_Impl(m_pItems, nItemCount, nPos);
}
// Add new Item to Pool
@@ -1657,7 +1654,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
// Remember old Item
bool bIncrementCount = false;
- const SfxPoolItem* pOld = *( m_pItems + nPos );
+ const SfxPoolItem* pOld = m_pItems[nPos];
if ( IsInvalidItem(pOld) ) // state "dontcare"
pOld = nullptr;
if ( !pOld )
@@ -1671,7 +1668,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
}
// Add new Item to ItemSet
- *(m_pItems + nPos) = &rNew;
+ m_pItems[nPos] = &rNew;
// Send Changed Notification
if ( pOld )
diff --git a/svl/source/items/stylepool.cxx b/svl/source/items/stylepool.cxx
index 04d801c3ac5b..6e52248eb82a 100644
--- a/svl/source/items/stylepool.cxx
+++ b/svl/source/items/stylepool.cxx
@@ -33,11 +33,11 @@ namespace {
*/
class Node
{
- std::vector<Node*> mChildren; // child nodes, create by findChildNode(..)
+ std::vector<std::unique_ptr<Node>> mChildren; // child nodes, create by findChildNode(..)
// container of shared pointers of inserted item sets; for non-poolable
// items more than one item set is needed
std::vector< std::shared_ptr<SfxItemSet> > maItemSet;
- const SfxPoolItem *mpItem; // my pool item
+ std::unique_ptr<const SfxPoolItem> mpItem; // my pool item
Node *mpUpper; // if I'm a child node that's my parent node
// #i86923#
const bool mbIsItemIgnorable;
@@ -57,7 +57,6 @@ namespace {
mpUpper( pParent ),
mbIsItemIgnorable( bIgnorable )
{}
- ~Node();
// #i86923#
bool hasItemSet( const bool bCheckUsage ) const;
// #i87808#
@@ -127,18 +126,15 @@ namespace {
Node* Node::findChildNode( const SfxPoolItem& rItem,
const bool bIsItemIgnorable )
{
- Node* pNextNode = this;
- std::vector<Node*>::const_iterator aIter = mChildren.begin();
- while( aIter != mChildren.end() )
+ for( auto const & rChild : mChildren )
{
- if( rItem.Which() == (*aIter)->mpItem->Which() &&
- rItem == *(*aIter)->mpItem )
- return *aIter;
- ++aIter;
+ if( rItem.Which() == rChild->mpItem->Which() &&
+ rItem == *rChild->mpItem )
+ return rChild.get();
}
// #i86923#
- pNextNode = new Node( rItem, pNextNode, bIsItemIgnorable );
- mChildren.push_back( pNextNode );
+ auto pNextNode = new Node( rItem, this, bIsItemIgnorable );
+ mChildren.emplace_back( pNextNode );
return pNextNode;
}
@@ -164,12 +160,13 @@ namespace {
const bool bSkipIgnorable )
{
// Searching downstairs
- std::vector<Node*>::const_iterator aIter = mChildren.begin();
+ auto aIter = mChildren.begin();
// For pLast == 0 and pLast == this all children are of interest
// for another pLast the search starts behind pLast...
if( pLast && pLast != this )
{
- aIter = std::find( mChildren.begin(), mChildren.end(), pLast );
+ aIter = std::find_if( mChildren.begin(), mChildren.end(),
+ [&] (std::unique_ptr<Node> const &p) { return p.get() == pLast; });
if( aIter != mChildren.end() )
++aIter;
}
@@ -182,7 +179,7 @@ namespace {
++aIter;
continue;
}
- pNext = *aIter;
+ pNext = aIter->get();
// #i86923#
if ( pNext->hasItemSet( bSkipUnusedItemSets ) )
{
@@ -212,10 +209,10 @@ namespace {
{
bool bHasIgnorableChildren( false );
- std::vector<Node*>::const_iterator aIter = mChildren.begin();
+ auto aIter = mChildren.begin();
while( aIter != mChildren.end() && !bHasIgnorableChildren )
{
- Node* pChild = *aIter;
+ Node* pChild = aIter->get();
if ( pChild->mbIsItemIgnorable )
{
bHasIgnorableChildren =
@@ -235,10 +232,10 @@ namespace {
DBG_ASSERT( hasIgnorableChildren( bSkipUnusedItemSets ),
"<Node::getItemSetOfIgnorableChild> - node has no ignorable children" );
- std::vector<Node*>::const_iterator aIter = mChildren.begin();
+ auto aIter = mChildren.begin();
while( aIter != mChildren.end() )
{
- Node* pChild = *aIter;
+ Node* pChild = aIter->get();
if ( pChild->mbIsItemIgnorable )
{
if ( pChild->hasItemSet( bSkipUnusedItemSets ) )
@@ -261,17 +258,6 @@ namespace {
return pReturn;
}
- Node::~Node()
- {
- std::vector<Node*>::const_iterator aIter = mChildren.begin();
- while( aIter != mChildren.end() )
- {
- delete *aIter;
- ++aIter;
- }
- delete mpItem;
- }
-
class Iterator : public IStylePoolIteratorAccess
{
std::map< const SfxItemSet*, Node >& mrRoot;