Kaydet (Commit) 0fa13a40 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Noel Grandin

svtools: Simplify ImageMap with std::unique_ptr

Change-Id: I49b3c21ff4d8177fb75197d6641040be0ace6324
Reviewed-on: https://gerrit.libreoffice.org/46149Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst d635da19
......@@ -23,6 +23,7 @@
#include <svtools/imapobj.hxx>
#include <svtools/svtdllapi.h>
#include <tools/stream.hxx>
#include <memory>
#include <vector>
class Point;
......@@ -35,7 +36,7 @@ class SVT_DLLPUBLIC ImageMap final
{
private:
::std::vector< IMapObject* > maList;
std::vector<std::unique_ptr<IMapObject>> maList;
OUString aName;
// binary saving/loading
......@@ -81,7 +82,7 @@ public:
// not be destroyed from outside
IMapObject* GetIMapObject( size_t nPos ) const
{
return ( nPos < maList.size() ) ? maList[ nPos ] : nullptr;
return ( nPos < maList.size() ) ? maList[ nPos ].get() : nullptr;
}
// returns the object which was hit first or NULL;
......
......@@ -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;
......
......@@ -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() ) );
}
}
......
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