[PATCH] fdo#62525: use cow_wrapper for FillGradientAttribute
Thomas Arnhold (via Code Review)
gerrit at gerrit.libreoffice.org
Sat Mar 23 14:10:05 PDT 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/2954
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/54/2954/1
fdo#62525: use cow_wrapper for FillGradientAttribute
a xmlsecurity/workben/signaturetest.cxx.wo
Change-Id: I13aa9817d7abd3753579f6825c166191a836eef3
---
M drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx
M drawinglayer/source/attribute/fillgradientattribute.cxx
2 files changed, 30 insertions(+), 65 deletions(-)
diff --git a/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx
index 6d01c86..e791193 100644
--- a/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx
+++ b/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FILLGRADIENTATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h>
+#include <o3tl/cow_wrapper.hxx>
//////////////////////////////////////////////////////////////////////////////
// predefines
@@ -58,8 +59,11 @@
{
class DRAWINGLAYER_DLLPUBLIC FillGradientAttribute
{
+ public:
+ typedef o3tl::cow_wrapper< ImpFillGradientAttribute > ImplType;
+
private:
- ImpFillGradientAttribute* mpFillGradientAttribute;
+ ImplType mpFillGradientAttribute;
public:
/// constructors/assignmentoperator/destructor
diff --git a/drawinglayer/source/attribute/fillgradientattribute.cxx b/drawinglayer/source/attribute/fillgradientattribute.cxx
index 987082c..6664791 100644
--- a/drawinglayer/source/attribute/fillgradientattribute.cxx
+++ b/drawinglayer/source/attribute/fillgradientattribute.cxx
@@ -19,6 +19,7 @@
#include <drawinglayer/attribute/fillgradientattribute.hxx>
#include <basegfx/color/bcolor.hxx>
+#include <rtl/instance.hxx>
//////////////////////////////////////////////////////////////////////////////
@@ -29,9 +30,6 @@
class ImpFillGradientAttribute
{
public:
- // refcounter
- sal_uInt32 mnRefCount;
-
// data definitions
GradientStyle meStyle;
double mfBorder;
@@ -51,8 +49,7 @@
const basegfx::BColor& rStartColor,
const basegfx::BColor& rEndColor,
sal_uInt16 nSteps)
- : mnRefCount(0),
- meStyle(eStyle),
+ : meStyle(eStyle),
mfBorder(fBorder),
mfOffsetX(fOffsetX),
mfOffsetY(fOffsetY),
@@ -60,6 +57,18 @@
maStartColor(rStartColor),
maEndColor(rEndColor),
mnSteps(nSteps)
+ {
+ }
+
+ ImpFillGradientAttribute()
+ : meStyle(GRADIENTSTYLE_LINEAR),
+ mfBorder(0.0),
+ mfOffsetX(0.0),
+ mfOffsetY(0.0),
+ mfAngle(0.0),
+ maStartColor(basegfx::BColor()),
+ maEndColor(basegfx::BColor()),
+ mnSteps(0)
{
}
@@ -84,27 +93,13 @@
&& getEndColor() == rCandidate.getEndColor()
&& getSteps() == rCandidate.getSteps());
}
-
- static ImpFillGradientAttribute* get_global_default()
- {
- static ImpFillGradientAttribute* pDefault = 0;
-
- if(!pDefault)
- {
- pDefault = new ImpFillGradientAttribute(
- GRADIENTSTYLE_LINEAR,
- 0.0, 0.0, 0.0, 0.0,
- basegfx::BColor(),
- basegfx::BColor(),
- 0);
-
- // never delete; start with RefCount 1, not 0
- pDefault->mnRefCount++;
- }
-
- return pDefault;
- }
};
+
+ namespace
+ {
+ struct theGlobalDefault :
+ public rtl::Static< FillGradientAttribute::ImplType, theGlobalDefault > {};
+ }
FillGradientAttribute::FillGradientAttribute(
GradientStyle eStyle,
@@ -115,73 +110,39 @@
const basegfx::BColor& rStartColor,
const basegfx::BColor& rEndColor,
sal_uInt16 nSteps)
- : mpFillGradientAttribute(new ImpFillGradientAttribute(
+ : mpFillGradientAttribute(ImpFillGradientAttribute(
eStyle, fBorder, fOffsetX, fOffsetY, fAngle, rStartColor, rEndColor, nSteps))
{
}
FillGradientAttribute::FillGradientAttribute()
- : mpFillGradientAttribute(ImpFillGradientAttribute::get_global_default())
+ : mpFillGradientAttribute(theGlobalDefault::get())
{
- mpFillGradientAttribute->mnRefCount++;
}
FillGradientAttribute::FillGradientAttribute(const FillGradientAttribute& rCandidate)
: mpFillGradientAttribute(rCandidate.mpFillGradientAttribute)
{
- mpFillGradientAttribute->mnRefCount++;
}
FillGradientAttribute::~FillGradientAttribute()
{
- if(mpFillGradientAttribute->mnRefCount)
- {
- mpFillGradientAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillGradientAttribute;
- }
}
bool FillGradientAttribute::isDefault() const
{
- return mpFillGradientAttribute == ImpFillGradientAttribute::get_global_default();
+ return mpFillGradientAttribute.same_object(theGlobalDefault::get());
}
FillGradientAttribute& FillGradientAttribute::operator=(const FillGradientAttribute& rCandidate)
{
- if(rCandidate.mpFillGradientAttribute != mpFillGradientAttribute)
- {
- if(mpFillGradientAttribute->mnRefCount)
- {
- mpFillGradientAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillGradientAttribute;
- }
-
- mpFillGradientAttribute = rCandidate.mpFillGradientAttribute;
- mpFillGradientAttribute->mnRefCount++;
- }
-
+ mpFillGradientAttribute = rCandidate.mpFillGradientAttribute;
return *this;
}
bool FillGradientAttribute::operator==(const FillGradientAttribute& rCandidate) const
{
- if(rCandidate.mpFillGradientAttribute == mpFillGradientAttribute)
- {
- return true;
- }
-
- if(rCandidate.isDefault() != isDefault())
- {
- return false;
- }
-
- return (*rCandidate.mpFillGradientAttribute == *mpFillGradientAttribute);
+ return rCandidate.mpFillGradientAttribute == mpFillGradientAttribute;
}
const basegfx::BColor& FillGradientAttribute::getStartColor() const
--
To view, visit https://gerrit.libreoffice.org/2954
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I13aa9817d7abd3753579f6825c166191a836eef3
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thomas Arnhold <thomas at arnhold.org>
More information about the LibreOffice
mailing list