summaryrefslogtreecommitdiff
path: root/svtools
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2017-12-09 23:28:39 +0900
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-12-09 19:42:58 +0100
commit0fa13a403fed6e729e58963479d34694afa7b8d8 (patch)
treeff9aaeec0975972bb1ae3979ca39b4444e1ef2fb /svtools
parentd635da1972f15862bb283e77787243fbff8361a6 (diff)
svtools: Simplify ImageMap with std::unique_ptr
Change-Id: I49b3c21ff4d8177fb75197d6641040be0ace6324 Reviewed-on: https://gerrit.libreoffice.org/46149 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/misc/imap.cxx38
-rw-r--r--svtools/source/misc/imap2.cxx22
2 files changed, 25 insertions, 35 deletions
diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx
index 471399fd40bc..b06fd21042db 100644
--- a/svtools/source/misc/imap.cxx
+++ b/svtools/source/misc/imap.cxx
@@ -570,15 +570,15 @@ ImageMap::ImageMap( const ImageMap& rImageMap )
switch( pCopyObj->GetType() )
{
case IMAP_OBJ_RECTANGLE:
- maList.push_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>( pCopyObj ) ) );
+ maList.emplace_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>( pCopyObj ) ) );
break;
case IMAP_OBJ_CIRCLE:
- maList.push_back( new IMapCircleObject( *static_cast<IMapCircleObject*>( pCopyObj ) ) );
+ maList.emplace_back( new IMapCircleObject( *static_cast<IMapCircleObject*>( pCopyObj ) ) );
break;
case IMAP_OBJ_POLYGON:
- maList.push_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>( pCopyObj ) ) );
+ maList.emplace_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>( pCopyObj ) ) );
break;
default:
@@ -598,8 +598,6 @@ ImageMap::ImageMap( const ImageMap& rImageMap )
ImageMap::~ImageMap()
{
-
- ClearImageMap();
}
@@ -611,8 +609,6 @@ ImageMap::~ImageMap()
void ImageMap::ClearImageMap()
{
- for(IMapObject* i : maList)
- delete i;
maList.clear();
aName.clear();
@@ -638,15 +634,15 @@ ImageMap& ImageMap::operator=( const ImageMap& rImageMap )
switch( pCopyObj->GetType() )
{
case IMAP_OBJ_RECTANGLE:
- maList.push_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>(pCopyObj) ) );
+ maList.emplace_back( new IMapRectangleObject( *static_cast<IMapRectangleObject*>(pCopyObj) ) );
break;
case IMAP_OBJ_CIRCLE:
- maList.push_back( new IMapCircleObject( *static_cast<IMapCircleObject*>(pCopyObj) ) );
+ maList.emplace_back( new IMapCircleObject( *static_cast<IMapCircleObject*>(pCopyObj) ) );
break;
case IMAP_OBJ_POLYGON:
- maList.push_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>(pCopyObj) ) );
+ maList.emplace_back( new IMapPolygonObject( *static_cast<IMapPolygonObject*>(pCopyObj) ) );
break;
default:
@@ -678,7 +674,7 @@ bool ImageMap::operator==( const ImageMap& rImageMap )
for ( size_t i = 0; ( i < nCount ) && !bDifferent; i++ )
{
- IMapObject* pObj = maList[ i ];
+ IMapObject* pObj = maList[ i ].get();
IMapObject* pEqObj = rImageMap.GetIMapObject( i );
if ( pObj->GetType() == pEqObj->GetType() )
@@ -745,15 +741,15 @@ void ImageMap::InsertIMapObject( const IMapObject& rIMapObject )
switch( rIMapObject.GetType() )
{
case IMAP_OBJ_RECTANGLE:
- maList.push_back( new IMapRectangleObject( static_cast<const IMapRectangleObject&>( rIMapObject ) ) );
+ maList.emplace_back( new IMapRectangleObject( static_cast<const IMapRectangleObject&>( rIMapObject ) ) );
break;
case IMAP_OBJ_CIRCLE:
- maList.push_back( new IMapCircleObject( static_cast<const IMapCircleObject&>( rIMapObject ) ) );
+ maList.emplace_back( new IMapCircleObject( static_cast<const IMapCircleObject&>( rIMapObject ) ) );
break;
case IMAP_OBJ_POLYGON:
- maList.push_back( new IMapPolygonObject( static_cast<const IMapPolygonObject&>( rIMapObject ) ) );
+ maList.emplace_back( new IMapPolygonObject( static_cast<const IMapPolygonObject&>( rIMapObject ) ) );
break;
default:
@@ -788,9 +784,9 @@ IMapObject* ImageMap::GetHitIMapObject( const Size& rTotalSize,
// walk over all objects and execute HitTest
IMapObject* pObj = nullptr;
- for(IMapObject* i : maList) {
+ for(auto& i : maList) {
if ( i->IsHit( aRelPoint ) ) {
- pObj = i;
+ pObj = i.get();
break;
}
}
@@ -804,7 +800,7 @@ void ImageMap::Scale( const Fraction& rFracX, const Fraction& rFracY )
for ( size_t i = 0; i < nCount; i++ )
{
- IMapObject* pObj = maList[ i ];
+ IMapObject* pObj = maList[ i ].get();
switch( pObj->GetType() )
{
@@ -839,7 +835,7 @@ void ImageMap::ImpWriteImageMap( SvStream& rOStm ) const
for ( size_t i = 0; i < nCount; i++ )
{
- IMapObject* pObj = maList[ i ];
+ auto& pObj = maList[ i ];
pObj->Write( rOStm );
}
}
@@ -877,7 +873,7 @@ void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount )
{
IMapRectangleObject* pObj = new IMapRectangleObject;
pObj->Read( rIStm );
- maList.push_back( pObj );
+ maList.emplace_back( pObj );
}
break;
@@ -885,7 +881,7 @@ void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount )
{
IMapCircleObject* pObj = new IMapCircleObject;
pObj->Read( rIStm );
- maList.push_back( pObj );
+ maList.emplace_back( pObj );
}
break;
@@ -893,7 +889,7 @@ void ImageMap::ImpReadImageMap( SvStream& rIStm, size_t nCount )
{
IMapPolygonObject* pObj = new IMapPolygonObject;
pObj->Read( rIStm );
- maList.push_back( pObj );
+ maList.emplace_back( pObj );
}
break;
diff --git a/svtools/source/misc/imap2.cxx b/svtools/source/misc/imap2.cxx
index a0b86edef094..a51bce522f27 100644
--- a/svtools/source/misc/imap2.cxx
+++ b/svtools/source/misc/imap2.cxx
@@ -159,7 +159,7 @@ void ImageMap::ImpWriteCERN( SvStream& rOStm ) const
for ( size_t i = 0; i < nCount; i++ )
{
- IMapObject* pObj = maList[ i ];
+ IMapObject* pObj = maList[ i ].get();
switch( pObj->GetType() )
{
@@ -187,7 +187,7 @@ void ImageMap::ImpWriteNCSA( SvStream& rOStm ) const
for ( size_t i = 0; i < nCount; i++ )
{
- IMapObject* pObj = maList[ i ];
+ IMapObject* pObj = maList[ i ].get();
switch( pObj->GetType() )
{
@@ -273,8 +273,7 @@ void ImageMap::ImpReadCERNLine( const OString& rLine )
const OUString aURL( ImpReadCERNURL( &pStr, "" ) );
const tools::Rectangle aRect( aTopLeft, aBottomRight );
- IMapRectangleObject* pObj = new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
else if ( ( aToken == "circle" ) || ( aToken == "circ" ) )
{
@@ -282,8 +281,7 @@ void ImageMap::ImpReadCERNLine( const OString& rLine )
const long nRadius = ImpReadCERNRadius( &pStr );
const OUString aURL( ImpReadCERNURL( &pStr, "" ) );
- IMapCircleObject* pObj = new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
else if ( ( aToken == "polygon" ) || ( aToken == "poly" ) )
{
@@ -296,8 +294,7 @@ void ImageMap::ImpReadCERNLine( const OString& rLine )
aURL = ImpReadCERNURL( &pStr, "" );
- IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
}
@@ -414,8 +411,7 @@ void ImageMap::ImpReadNCSALine( const OString& rLine )
const Point aBottomRight( ImpReadNCSACoords( &pStr ) );
const tools::Rectangle aRect( aTopLeft, aBottomRight );
- IMapRectangleObject* pObj = new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapRectangleObject( aRect, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
else if ( aToken == "circle" )
{
@@ -425,8 +421,7 @@ void ImageMap::ImpReadNCSALine( const OString& rLine )
long nRadius = (long) sqrt( (double) aDX.X() * aDX.X() +
(double) aDX.Y() * aDX.Y() );
- IMapCircleObject* pObj = new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapCircleObject( aCenter, nRadius, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
else if ( aToken == "poly" )
{
@@ -438,8 +433,7 @@ void ImageMap::ImpReadNCSALine( const OString& rLine )
for ( sal_uInt16 i = 0; i < nCount; i++ )
aPoly[ i ] = ImpReadNCSACoords( &pStr );
- IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() );
- maList.push_back( pObj );
+ maList.emplace_back( new IMapPolygonObject( aPoly, aURL, OUString(), OUString(), OUString(), OUString() ) );
}
}