[Libreoffice-commits] core.git: include/svtools svtools/source

Takeshi Abe tabe at fixedpoint.jp
Sat Dec 9 18:44:58 UTC 2017


 include/svtools/imap.hxx      |    5 +++--
 svtools/source/misc/imap.cxx  |   38 +++++++++++++++++---------------------
 svtools/source/misc/imap2.cxx |   22 ++++++++--------------
 3 files changed, 28 insertions(+), 37 deletions(-)

New commits:
commit 0fa13a403fed6e729e58963479d34694afa7b8d8
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sat Dec 9 23:28:39 2017 +0900

    svtools: Simplify ImageMap with std::unique_ptr
    
    Change-Id: I49b3c21ff4d8177fb75197d6641040be0ace6324
    Reviewed-on: https://gerrit.libreoffice.org/46149
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svtools/imap.hxx b/include/svtools/imap.hxx
index 427d2768b67d..e60efb9990ed 100644
--- a/include/svtools/imap.hxx
+++ b/include/svtools/imap.hxx
@@ -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;
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() ) );
     }
 }
 


More information about the Libreoffice-commits mailing list