[Libreoffice-commits] core.git: vcl/headless vcl/inc vcl/ios vcl/osx vcl/qt5 vcl/source vcl/unx vcl/win

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 31 06:30:32 UTC 2018


 vcl/headless/svpprn.cxx             |    9 ++-------
 vcl/inc/headless/svpinst.hxx        |    1 -
 vcl/inc/osx/salinst.h               |    1 -
 vcl/inc/print.h                     |   22 +++++++++++++++++-----
 vcl/inc/qt5/Qt5Instance.hxx         |    1 -
 vcl/inc/salinst.hxx                 |    1 -
 vcl/inc/unx/geninst.h               |    1 -
 vcl/inc/win/salinst.h               |    1 -
 vcl/ios/dummies.cxx                 |   10 ----------
 vcl/osx/salinst.cxx                 |    9 ++-------
 vcl/qt5/Qt5Instance_Print.cxx       |    2 --
 vcl/source/gdi/print.cxx            |   36 ++++++++++++++----------------------
 vcl/unx/generic/print/genprnpsp.cxx |    9 ++-------
 vcl/win/gdi/salprn.cxx              |    9 ++-------
 14 files changed, 39 insertions(+), 73 deletions(-)

New commits:
commit 9078b0b8f48b161ad5b880c31a4413f9e706f01b
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Oct 26 10:01:08 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 31 07:30:07 2018 +0100

    loplugin:useuniqueptr in DeletePrinterQueueInfo
    
    Change-Id: Ia124a4af642e449dc05f5bae2d5ca766bd67bd68
    Reviewed-on: https://gerrit.libreoffice.org/62388
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/headless/svpprn.cxx b/vcl/headless/svpprn.cxx
index 590d04be03db..0bc0ad3dbcbe 100644
--- a/vcl/headless/svpprn.cxx
+++ b/vcl/headless/svpprn.cxx
@@ -213,7 +213,7 @@ void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
     {
         const PrinterInfo& rInfo( rManager.getPrinterInfo(printer) );
         // create new entry
-        SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
+        std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
         pInfo->maPrinterName    = printer;
         pInfo->maDriver         = rInfo.m_aDriverName;
         pInfo->maLocation       = rInfo.m_aLocation;
@@ -230,15 +230,10 @@ void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
             }
         }
 
-        pList->Add( pInfo );
+        pList->Add( std::move(pInfo) );
     }
 }
 
-void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
 {
 }
diff --git a/vcl/inc/headless/svpinst.hxx b/vcl/inc/headless/svpinst.hxx
index 4793d8e463d5..b331c5cbcbad 100644
--- a/vcl/inc/headless/svpinst.hxx
+++ b/vcl/inc/headless/svpinst.hxx
@@ -157,7 +157,6 @@ public:
 
     virtual void            GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
     virtual void            GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
-    virtual void            DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) override;
     virtual OUString        GetDefaultPrinter() override;
     virtual void            PostPrintersChanged() override;
 
diff --git a/vcl/inc/osx/salinst.h b/vcl/inc/osx/salinst.h
index afb1d2b34aa3..18b8de8cfc7f 100644
--- a/vcl/inc/osx/salinst.h
+++ b/vcl/inc/osx/salinst.h
@@ -109,7 +109,6 @@ public:
     virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
     virtual void            GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
     virtual void            GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
-    virtual void            DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) override;
     virtual OUString        GetDefaultPrinter() override;
     virtual SalTimer*       CreateSalTimer() override;
     virtual SalSystem*      CreateSalSystem() override;
diff --git a/vcl/inc/print.h b/vcl/inc/print.h
index 3ea53ec2bdd9..13650ceef34f 100644
--- a/vcl/inc/print.h
+++ b/vcl/inc/print.h
@@ -22,12 +22,12 @@
 
 #include <rtl/ustring.hxx>
 #include <vcl/dllapi.h>
+#include <vcl/print.hxx>
+#include "salprn.hxx"
 
 #include <vector>
 #include <unordered_map>
 
-struct SalPrinterQueueInfo;
-class QueueInfo;
 class JobSetup;
 
 namespace vcl
@@ -35,8 +35,17 @@ namespace vcl
 
 struct ImplPrnQueueData
 {
-    QueueInfo*              mpQueueInfo;
-    SalPrinterQueueInfo*    mpSalQueueInfo;
+    std::unique_ptr<QueueInfo>           mpQueueInfo;
+    std::unique_ptr<SalPrinterQueueInfo> mpSalQueueInfo;
+
+// unlike other similar places, we need to ifdef this to keep old GCC baseline happy
+#ifdef _MSC_VER
+    ImplPrnQueueData() {}
+    ImplPrnQueueData(ImplPrnQueueData&&) = default;
+  
+    ImplPrnQueueData& operator=( ImplPrnQueueData const & ) = delete; // MSVC2017 workaround
+    ImplPrnQueueData( ImplPrnQueueData const & ) = delete; // MSVC2017 workaround
+#endif
 };
 
 class VCL_PLUGIN_PUBLIC ImplPrnQueueList
@@ -49,7 +58,10 @@ public:
     ImplPrnQueueList() {}
     ~ImplPrnQueueList();
 
-    void                    Add( SalPrinterQueueInfo* pData );
+    ImplPrnQueueList& operator=( ImplPrnQueueList const & ) = delete; // MSVC2017 workaround
+    ImplPrnQueueList( ImplPrnQueueList const & ) = delete; // MSVC2017 workaround
+
+void                    Add( std::unique_ptr<SalPrinterQueueInfo> pData );
     ImplPrnQueueData*       Get( const OUString& rPrinter );
 };
 
diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx
index 8f5a2670b238..473f26c58b13 100644
--- a/vcl/inc/qt5/Qt5Instance.hxx
+++ b/vcl/inc/qt5/Qt5Instance.hxx
@@ -76,7 +76,6 @@ public:
     virtual std::unique_ptr<SalPrinter> CreatePrinter(SalInfoPrinter* pInfoPrinter) override;
     virtual void GetPrinterQueueInfo(ImplPrnQueueList* pList) override;
     virtual void GetPrinterQueueState(SalPrinterQueueInfo* pInfo) override;
-    virtual void DeletePrinterQueueInfo(SalPrinterQueueInfo* pInfo) override;
     virtual OUString GetDefaultPrinter() override;
     virtual void PostPrintersChanged() override;
 
diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx
index b365fe6545ca..1d400e5f9bae 100644
--- a/vcl/inc/salinst.hxx
+++ b/vcl/inc/salinst.hxx
@@ -122,7 +122,6 @@ public:
 
     virtual void            GetPrinterQueueInfo( ImplPrnQueueList* pList ) = 0;
     virtual void            GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) = 0;
-    virtual void            DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) = 0;
     virtual OUString        GetDefaultPrinter() = 0;
 
     // SalTimer
diff --git a/vcl/inc/unx/geninst.h b/vcl/inc/unx/geninst.h
index 17688b8772db..ba795485fff6 100644
--- a/vcl/inc/unx/geninst.h
+++ b/vcl/inc/unx/geninst.h
@@ -58,7 +58,6 @@ public:
     virtual std::unique_ptr<SalPrinter> CreatePrinter  ( SalInfoPrinter* pInfoPrinter ) override;
     virtual void                GetPrinterQueueInfo    ( ImplPrnQueueList* pList ) override;
     virtual void                GetPrinterQueueState   ( SalPrinterQueueInfo* pInfo ) override;
-    virtual void                DeletePrinterQueueInfo ( SalPrinterQueueInfo* pInfo ) override;
     virtual OUString            GetDefaultPrinter() override;
     virtual void                PostPrintersChanged() = 0;
     virtual void                updatePrinterUpdate() override;
diff --git a/vcl/inc/win/salinst.h b/vcl/inc/win/salinst.h
index 88f31fd548cf..bcd3540ad8a9 100644
--- a/vcl/inc/win/salinst.h
+++ b/vcl/inc/win/salinst.h
@@ -58,7 +58,6 @@ public:
     virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
     virtual void            GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
     virtual void            GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
-    virtual void            DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) override;
     virtual OUString            GetDefaultPrinter() override;
     virtual SalTimer*           CreateSalTimer() override;
     virtual SalSystem*          CreateSalSystem() override;
diff --git a/vcl/ios/dummies.cxx b/vcl/ios/dummies.cxx
index 94e2a86204ee..efb2d251078d 100644
--- a/vcl/ios/dummies.cxx
+++ b/vcl/ios/dummies.cxx
@@ -65,11 +65,6 @@ void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* /* pInfo */ )
 {
 }
 
-void SvpSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 std::unique_ptr<SalPrinter> SalGenericInstance::CreatePrinter( SalInfoPrinter* /* pInfoPrinter */ )
 {
     return nullptr;
@@ -103,11 +98,6 @@ void SalGenericInstance::GetPrinterQueueState( SalPrinterQueueInfo* /* pInfo */
 {
 }
 
-void SalGenericInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 void SalGenericInstance::updatePrinterUpdate()
 {
 }
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 46a52bd9b213..7886f8efa129 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -726,14 +726,14 @@ void AquaSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
         NSString* pType = i < nTypeCount ? [pTypes objectAtIndex: i] : nil;
         if( pName )
         {
-            SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
+            std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
             pInfo->maPrinterName    = GetOUString( pName );
             if( pType )
                 pInfo->maDriver     = GetOUString( pType );
             pInfo->mnStatus         = PrintQueueFlags::NONE;
             pInfo->mnJobs           = 0;
 
-            pList->Add( pInfo );
+            pList->Add( std::move(pInfo) );
         }
     }
 }
@@ -742,11 +742,6 @@ void AquaSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
 {
 }
 
-void AquaSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 OUString AquaSalInstance::GetDefaultPrinter()
 {
     // #i113170# may not be the main thread if called from UNO API
diff --git a/vcl/qt5/Qt5Instance_Print.cxx b/vcl/qt5/Qt5Instance_Print.cxx
index 501db07e7362..7ce19a2b97d6 100644
--- a/vcl/qt5/Qt5Instance_Print.cxx
+++ b/vcl/qt5/Qt5Instance_Print.cxx
@@ -114,8 +114,6 @@ void Qt5Instance::GetPrinterQueueInfo(ImplPrnQueueList* pList)
     }
 }
 
-void Qt5Instance::DeletePrinterQueueInfo(SalPrinterQueueInfo* pInfo) { delete pInfo; }
-
 void Qt5Instance::GetPrinterQueueState(SalPrinterQueueInfo*) {}
 
 OUString Qt5Instance::GetDefaultPrinter()
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 06774a99cbcf..cff0450231f7 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -345,33 +345,25 @@ SalPrinterQueueInfo::~SalPrinterQueueInfo()
 
 ImplPrnQueueList::~ImplPrnQueueList()
 {
-    ImplSVData*         pSVData = ImplGetSVData();
-    for(ImplPrnQueueData & rQueueInfo : m_aQueueInfos)
-    {
-        delete rQueueInfo.mpQueueInfo;
-        pSVData->mpDefInst->DeletePrinterQueueInfo( rQueueInfo.mpSalQueueInfo );
-    }
 }
 
-void ImplPrnQueueList::Add( SalPrinterQueueInfo* pData )
+void ImplPrnQueueList::Add( std::unique_ptr<SalPrinterQueueInfo> pData )
 {
     std::unordered_map< OUString, sal_Int32 >::iterator it =
         m_aNameToIndex.find( pData->maPrinterName );
     if( it == m_aNameToIndex.end() )
     {
         m_aNameToIndex[ pData->maPrinterName ] = m_aQueueInfos.size();
-        m_aQueueInfos.emplace_back( );
-        m_aQueueInfos.back().mpQueueInfo = nullptr;
-        m_aQueueInfos.back().mpSalQueueInfo = pData;
         m_aPrinterList.push_back( pData->maPrinterName );
+        m_aQueueInfos.push_back( ImplPrnQueueData() );
+        m_aQueueInfos.back().mpQueueInfo = nullptr;
+        m_aQueueInfos.back().mpSalQueueInfo = std::move(pData);
     }
     else // this should not happen, but ...
     {
         ImplPrnQueueData& rData = m_aQueueInfos[ it->second ];
-        delete rData.mpQueueInfo;
-        rData.mpQueueInfo = nullptr;
-        ImplGetSVData()->mpDefInst->DeletePrinterQueueInfo( rData.mpSalQueueInfo );
-        rData.mpSalQueueInfo = pData;
+        rData.mpQueueInfo.reset();
+        rData.mpSalQueueInfo = std::move(pData);
     }
 }
 
@@ -430,10 +422,10 @@ const QueueInfo* Printer::GetQueueInfo( const OUString& rPrinterName, bool bStat
     if( pInfo )
     {
         if( !pInfo->mpQueueInfo || bStatusUpdate )
-            pSVData->mpDefInst->GetPrinterQueueState( pInfo->mpSalQueueInfo );
+            pSVData->mpDefInst->GetPrinterQueueState( pInfo->mpSalQueueInfo.get() );
 
         if ( !pInfo->mpQueueInfo )
-            pInfo->mpQueueInfo = new QueueInfo;
+            pInfo->mpQueueInfo.reset(new QueueInfo);
 
         pInfo->mpQueueInfo->maPrinterName   = pInfo->mpSalQueueInfo->maPrinterName;
         pInfo->mpQueueInfo->maDriver        = pInfo->mpSalQueueInfo->maDriver;
@@ -441,7 +433,7 @@ const QueueInfo* Printer::GetQueueInfo( const OUString& rPrinterName, bool bStat
         pInfo->mpQueueInfo->maComment       = pInfo->mpSalQueueInfo->maComment;
         pInfo->mpQueueInfo->mnStatus        = pInfo->mpSalQueueInfo->mnStatus;
         pInfo->mpQueueInfo->mnJobs          = pInfo->mpSalQueueInfo->mnJobs;
-        return pInfo->mpQueueInfo;
+        return pInfo->mpQueueInfo.get();
     }
     return nullptr;
 }
@@ -795,13 +787,13 @@ SalPrinterQueueInfo* Printer::ImplGetQueueInfo( const OUString& rPrinterName,
         // first search for the printer name directly
         ImplPrnQueueData* pInfo = pPrnList->Get( rPrinterName );
         if( pInfo )
-            return pInfo->mpSalQueueInfo;
+            return pInfo->mpSalQueueInfo.get();
 
         // then search case insensitive
         for(ImplPrnQueueData & rQueueInfo : pPrnList->m_aQueueInfos)
         {
             if( rQueueInfo.mpSalQueueInfo->maPrinterName.equalsIgnoreAsciiCase( rPrinterName ) )
-                return rQueueInfo.mpSalQueueInfo;
+                return rQueueInfo.mpSalQueueInfo.get();
         }
 
         // then search for driver name
@@ -810,17 +802,17 @@ SalPrinterQueueInfo* Printer::ImplGetQueueInfo( const OUString& rPrinterName,
             for(ImplPrnQueueData & rQueueInfo : pPrnList->m_aQueueInfos)
             {
                 if( rQueueInfo.mpSalQueueInfo->maDriver == *pDriver )
-                    return rQueueInfo.mpSalQueueInfo;
+                    return rQueueInfo.mpSalQueueInfo.get();
             }
         }
 
         // then the default printer
         pInfo = pPrnList->Get( GetDefaultPrinterName() );
         if( pInfo )
-            return pInfo->mpSalQueueInfo;
+            return pInfo->mpSalQueueInfo.get();
 
         // last chance: the first available printer
-        return pPrnList->m_aQueueInfos[0].mpSalQueueInfo;
+        return pPrnList->m_aQueueInfos[0].mpSalQueueInfo.get();
     }
 
     return nullptr;
diff --git a/vcl/unx/generic/print/genprnpsp.cxx b/vcl/unx/generic/print/genprnpsp.cxx
index 873abc28575f..376da8fcf51f 100644
--- a/vcl/unx/generic/print/genprnpsp.cxx
+++ b/vcl/unx/generic/print/genprnpsp.cxx
@@ -420,7 +420,7 @@ void SalGenericInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
     {
         const PrinterInfo& rInfo( rManager.getPrinterInfo(printer) );
         // create new entry
-        SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
+        std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
         pInfo->maPrinterName    = printer;
         pInfo->maDriver         = rInfo.m_aDriverName;
         pInfo->maLocation       = rInfo.m_aLocation;
@@ -437,15 +437,10 @@ void SalGenericInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
             }
         }
 
-        pList->Add( pInfo );
+        pList->Add( std::move(pInfo) );
     }
 }
 
-void SalGenericInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 void SalGenericInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
 {
     mbPrinterInit = true;
diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx
index 92ca44f6af3d..51eb8f9bb602 100644
--- a/vcl/win/gdi/salprn.cxx
+++ b/vcl/win/gdi/salprn.cxx
@@ -163,11 +163,11 @@ void WinSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
         {
             for ( i = 0; i < nInfoPrn4; i++ )
             {
-                SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
+                std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
                 pInfo->maPrinterName = o3tl::toU(pWinInfo4[i].pPrinterName);
                 pInfo->mnStatus      = PrintQueueFlags::NONE;
                 pInfo->mnJobs        = 0;
-                pList->Add( pInfo );
+                pList->Add( std::move(pInfo) );
             }
         }
         std::free( pWinInfo4 );
@@ -211,11 +211,6 @@ void WinSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo )
     }
 }
 
-void WinSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
-{
-    delete pInfo;
-}
-
 OUString WinSalInstance::GetDefaultPrinter()
 {
     DWORD   nChars = 0;


More information about the Libreoffice-commits mailing list