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

Stephan Bergmann sbergman at redhat.com
Tue Jun 13 10:32:29 UTC 2017


 include/svx/sdr/properties/defaultproperties.hxx  |    6 +++++-
 svx/source/sdr/properties/attributeproperties.cxx |   20 +++++++++-----------
 svx/source/sdr/properties/defaultproperties.cxx   |   13 +++----------
 svx/source/sdr/properties/groupproperties.cxx     |    3 +--
 4 files changed, 18 insertions(+), 24 deletions(-)

New commits:
commit 96c4aeb797bef23e42190a0c44aeb43047c936c7
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jun 13 12:32:02 2017 +0200

    Use unique_ptr for DefaultProperties::mpItemSet
    
    Change-Id: Ia5272aac6825a9f571ae0ed144475eb291426894

diff --git a/include/svx/sdr/properties/defaultproperties.hxx b/include/svx/sdr/properties/defaultproperties.hxx
index 5864f0e75f00..8d2b90009353 100644
--- a/include/svx/sdr/properties/defaultproperties.hxx
+++ b/include/svx/sdr/properties/defaultproperties.hxx
@@ -20,6 +20,10 @@
 #ifndef INCLUDED_SVX_SDR_PROPERTIES_DEFAULTPROPERTIES_HXX
 #define INCLUDED_SVX_SDR_PROPERTIES_DEFAULTPROPERTIES_HXX
 
+#include <sal/config.h>
+
+#include <memory>
+
 #include <svx/sdr/properties/properties.hxx>
 #include <svx/svxdllapi.h>
 
@@ -33,7 +37,7 @@ namespace sdr
         {
         protected:
             // the to be used ItemSet
-            SfxItemSet*                                     mpItemSet;
+            std::unique_ptr<SfxItemSet> mpItemSet;
 
             // create a new itemset
             virtual SfxItemSet* CreateObjectSpecificItemSet(SfxItemPool& rPool) override;
diff --git a/svx/source/sdr/properties/attributeproperties.cxx b/svx/source/sdr/properties/attributeproperties.cxx
index d18959eb4ca1..369c6bd3cd77 100644
--- a/svx/source/sdr/properties/attributeproperties.cxx
+++ b/svx/source/sdr/properties/attributeproperties.cxx
@@ -17,6 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <utility>
+
 #include <sdr/properties/attributeproperties.hxx>
 #include <sdr/properties/itemsettools.hxx>
 #include <tools/debug.hxx>
@@ -253,7 +257,6 @@ namespace sdr
                     // because this functionality is used by UNDO only. Thus
                     // objects and ItemSets would be moved back to their original
                     // pool before usage.
-                    SfxItemSet* pOldSet = mpItemSet;
                     SfxStyleSheet* pStySheet = GetStyleSheet();
 
                     if(pStySheet)
@@ -261,8 +264,9 @@ namespace sdr
                         ImpRemoveStyleSheet();
                     }
 
-                    mpItemSet = mpItemSet->Clone(false, pDestPool);
-                    SdrModel::MigrateItemSet(pOldSet, mpItemSet, pNewModel);
+                    auto pOldSet = std::move(mpItemSet);
+                    mpItemSet.reset(pOldSet->Clone(false, pDestPool));
+                    SdrModel::MigrateItemSet(pOldSet.get(), mpItemSet.get(), pNewModel);
 
                     // set stylesheet (if used)
                     if(pStySheet)
@@ -297,8 +301,6 @@ namespace sdr
                             ImpAddStyleSheet(pNewStyleSheet, true);
                         }
                     }
-
-                    delete pOldSet;
                 }
             }
         }
@@ -451,12 +453,9 @@ namespace sdr
                                 {
                                     ImpRemoveStyleSheet();
                                 }
-
-                                delete mpItemSet;
-                                mpItemSet = nullptr;
                             }
 
-                            mpItemSet = pNewSet;
+                            mpItemSet.reset(pNewSet);
                         }
                     }
                 }
@@ -503,8 +502,7 @@ namespace sdr
                 }
 
                 // replace itemsets
-                delete mpItemSet;
-                mpItemSet = pDestItemSet;
+                mpItemSet.reset(pDestItemSet);
 
                 // set necessary changes like in RemoveStyleSheet()
                 GetSdrObject().SetBoundRectDirty();
diff --git a/svx/source/sdr/properties/defaultproperties.cxx b/svx/source/sdr/properties/defaultproperties.cxx
index 3904ef5c6f20..3d53ddec61fe 100644
--- a/svx/source/sdr/properties/defaultproperties.cxx
+++ b/svx/source/sdr/properties/defaultproperties.cxx
@@ -53,7 +53,7 @@ namespace sdr
         {
             if(rProps.mpItemSet)
             {
-                mpItemSet = rProps.mpItemSet->Clone();
+                mpItemSet.reset(rProps.mpItemSet->Clone());
 
                 // do not keep parent info, this may be changed by later constructors.
                 // This class just copies the ItemSet, ignore parent.
@@ -69,20 +69,13 @@ namespace sdr
             return *(new DefaultProperties(*this, rObj));
         }
 
-        DefaultProperties::~DefaultProperties()
-        {
-            if(mpItemSet)
-            {
-                delete mpItemSet;
-                mpItemSet = nullptr;
-            }
-        }
+        DefaultProperties::~DefaultProperties() {}
 
         const SfxItemSet& DefaultProperties::GetObjectItemSet() const
         {
             if(!mpItemSet)
             {
-                const_cast<DefaultProperties*>(this)->mpItemSet = const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool());
+                const_cast<DefaultProperties*>(this)->mpItemSet.reset(const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool()));
                 const_cast<DefaultProperties*>(this)->ForceDefaultAttributes();
             }
 
diff --git a/svx/source/sdr/properties/groupproperties.cxx b/svx/source/sdr/properties/groupproperties.cxx
index 00932e8eca82..4dfc770e0888 100644
--- a/svx/source/sdr/properties/groupproperties.cxx
+++ b/svx/source/sdr/properties/groupproperties.cxx
@@ -263,8 +263,7 @@ namespace sdr
                     // The ItemSet for merge is constructed on demand, so it's enough here to
                     // just delete it and set to 0L.
                     // mpItemSet->ClearItem();
-                    delete mpItemSet;
-                    mpItemSet = nullptr;
+                    mpItemSet.reset();
                 }
             }
         }


More information about the Libreoffice-commits mailing list