summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-05-29 21:01:51 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-06-06 07:01:24 +0000
commit4d666f5092d7c4f2ece9702dda4d874e44cdc6f7 (patch)
tree86e78c047c1d4b2b58438855d68f27fc7a24b130 /svl
parent71cf1aefca1ecf10272308d7c75201bd39d3b0f6 (diff)
tdf#89329: use shared_ptr for pImpl in slstitm
Change-Id: Icb9167f8e7612f40992e7146c0dce539c0b0eac7 Reviewed-on: https://gerrit.libreoffice.org/25632 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/items/slstitm.cxx100
1 files changed, 29 insertions, 71 deletions
diff --git a/svl/source/items/slstitm.cxx b/svl/source/items/slstitm.cxx
index ec40ab2b4882..2419a1a25c54 100644
--- a/svl/source/items/slstitm.cxx
+++ b/svl/source/items/slstitm.cxx
@@ -27,58 +27,53 @@
#include <stringio.hxx>
SfxPoolItem* SfxStringListItem::CreateDefault() { return new SfxStringListItem; }
+
class SfxImpStringList
{
public:
- sal_uInt16 nRefCount;
std::vector<OUString> aList;
- SfxImpStringList() { nRefCount = 1; }
- ~SfxImpStringList();
+ SfxImpStringList() {}
+ ~SfxImpStringList();
};
SfxImpStringList::~SfxImpStringList()
{
- DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted");
- nRefCount = 0xffff;
}
-SfxStringListItem::SfxStringListItem() :
- pImp(nullptr)
+SfxStringListItem::SfxStringListItem()
{
}
SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<OUString>* pList ) :
- SfxPoolItem( which ),
- pImp(nullptr)
+ SfxPoolItem( which )
{
// FIXME: Putting an empty list does not work
// Therefore the query after the count is commented out
if( pList /*!!! && pList->Count() */ )
{
- pImp = new SfxImpStringList;
- pImp->aList = *pList;
+ pImpl.reset(new SfxImpStringList);
+ pImpl->aList = *pList;
}
}
SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) :
- SfxPoolItem( which ),
- pImp(nullptr)
+ SfxPoolItem( which )
{
sal_Int32 nEntryCount;
rStream.ReadInt32( nEntryCount );
if( nEntryCount )
- pImp = new SfxImpStringList;
+ pImpl.reset(new SfxImpStringList);
- if (pImp)
+ if (pImpl)
{
for( sal_Int32 i=0; i < nEntryCount; i++ )
{
- pImp->aList.push_back( readByteString(rStream) );
+ pImpl->aList.push_back( readByteString(rStream) );
}
}
}
@@ -86,35 +81,21 @@ SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) :
SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) :
SfxPoolItem( rItem ),
- pImp(rItem.pImp)
+ pImpl(rItem.pImpl.get())
{
- if( pImp )
- {
- DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
- pImp->nRefCount++;
- }
}
SfxStringListItem::~SfxStringListItem()
{
- if( pImp )
- {
- DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
- if( pImp->nRefCount > 1 )
- pImp->nRefCount--;
- else
- delete pImp;
- }
}
std::vector<OUString>& SfxStringListItem::GetList()
{
- if( !pImp )
- pImp = new SfxImpStringList;
- DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
- return pImp->aList;
+ if( !pImpl )
+ pImpl.reset( new SfxImpStringList );
+ return pImpl->aList;
}
const std::vector<OUString>& SfxStringListItem::GetList () const
@@ -129,7 +110,7 @@ bool SfxStringListItem::operator==( const SfxPoolItem& rItem ) const
const SfxStringListItem& rSSLItem = static_cast<const SfxStringListItem&>(rItem);
- return pImp == rSSLItem.pImp;
+ return pImpl == rSSLItem.pImpl;
}
@@ -150,13 +131,6 @@ bool SfxStringListItem::GetPresentation
SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const
{
return new SfxStringListItem( *this );
- /*
- if( pImp )
- return new SfxStringListItem( Which(), &(pImp->aList) );
- else
- return new SfxStringListItem( Which(), NULL );
- */
-
}
@@ -168,19 +142,17 @@ SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, sal_uInt16 ) const
SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const
{
- if( !pImp )
+ if( !pImpl )
{
rStream.WriteInt32( 0 );
return rStream;
}
- DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
-
- sal_uInt32 nCount = pImp->aList.size();
+ sal_uInt32 nCount = pImpl->aList.size();
rStream.WriteUInt32( nCount );
for( sal_uInt32 i=0; i < nCount; i++ )
- writeByteString(rStream, pImp->aList[i]);
+ writeByteString(rStream, pImpl->aList[i]);
return rStream;
}
@@ -188,13 +160,7 @@ SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const
void SfxStringListItem::SetString( const OUString& rStr )
{
- DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
-
- if ( pImp && (pImp->nRefCount == 1) )
- delete pImp;
- else if( pImp )
- pImp->nRefCount--;
- pImp = new SfxImpStringList;
+ pImpl.reset( new SfxImpStringList );
sal_Int32 nStart = 0;
OUString aStr(convertLineEnd(rStr, LINEEND_CR));
@@ -206,12 +172,12 @@ void SfxStringListItem::SetString( const OUString& rStr )
if (nStart<aStr.getLength())
{
// put last string only if not empty
- pImp->aList.push_back(aStr.copy(nStart));
+ pImpl->aList.push_back(aStr.copy(nStart));
}
break;
}
- pImp->aList.push_back(aStr.copy(nStart, nDelimPos-nStart));
+ pImpl->aList.push_back(aStr.copy(nStart, nDelimPos-nStart));
// skip both inserted string and delimiter
nStart = nDelimPos + 1 ;
@@ -222,17 +188,15 @@ void SfxStringListItem::SetString( const OUString& rStr )
OUString SfxStringListItem::GetString()
{
OUString aStr;
- if ( pImp )
+ if ( pImpl )
{
- DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
-
- std::vector<OUString>::const_iterator iter = pImp->aList.begin();
+ std::vector<OUString>::const_iterator iter = pImpl->aList.begin();
for (;;)
{
aStr += *iter;
++iter;
- if (iter == pImp->aList.end())
+ if (iter == pImpl->aList.end())
break;
aStr += "\r";
@@ -244,26 +208,20 @@ OUString SfxStringListItem::GetString()
void SfxStringListItem::SetStringList( const css::uno::Sequence< OUString >& rList )
{
- DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
-
- if ( pImp && (pImp->nRefCount == 1) )
- delete pImp;
- else if( pImp )
- pImp->nRefCount--;
- pImp = new SfxImpStringList;
+ pImpl.reset(new SfxImpStringList);
// String belongs to the list
for ( sal_Int32 n = 0; n < rList.getLength(); n++ )
- pImp->aList.push_back(rList[n]);
+ pImpl->aList.push_back(rList[n]);
}
void SfxStringListItem::GetStringList( css::uno::Sequence< OUString >& rList ) const
{
- long nCount = pImp->aList.size();
+ long nCount = pImpl->aList.size();
rList.realloc( nCount );
for( long i=0; i < nCount; i++ )
- rList[i] = pImp->aList[i];
+ rList[i] = pImpl->aList[i];
}
// virtual