Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/3073
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/73/3073/1
fdo#62525: use cow_wrapper for FillHatchAttribute
Change-Id: I1581b4bca6f14bd27af12ff40a4f4c0fe08af133
---
M drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
M drawinglayer/source/attribute/fillhatchattribute.cxx
2 files changed, 27 insertions(+), 64 deletions(-)
diff --git a/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
b/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
index dc2665b..7e6244b 100644
--- a/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
+++ b/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FILLHATCHATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h>
+#include <o3tl/cow_wrapper.hxx>
//////////////////////////////////////////////////////////////////////////////
// predefines
@@ -55,8 +56,11 @@
{
class DRAWINGLAYER_DLLPUBLIC FillHatchAttribute
{
+ public:
+ typedef o3tl::cow_wrapper< ImpFillHatchAttribute > ImplType;
+
private:
- ImpFillHatchAttribute* mpFillHatchAttribute;
+ ImplType mpFillHatchAttribute;
public:
/// constructors/assignmentoperator/destructor
diff --git a/drawinglayer/source/attribute/fillhatchattribute.cxx
b/drawinglayer/source/attribute/fillhatchattribute.cxx
index d3d86ee..e89628b 100644
--- a/drawinglayer/source/attribute/fillhatchattribute.cxx
+++ b/drawinglayer/source/attribute/fillhatchattribute.cxx
@@ -19,6 +19,7 @@
#include <drawinglayer/attribute/fillhatchattribute.hxx>
#include <basegfx/color/bcolor.hxx>
+#include <rtl/instance.hxx>
//////////////////////////////////////////////////////////////////////////////
@@ -29,9 +30,6 @@
class ImpFillHatchAttribute
{
public:
- // refcounter
- sal_uInt32 mnRefCount;
-
// data definitions
HatchStyle meStyle;
double mfDistance;
@@ -47,12 +45,20 @@
double fAngle,
const basegfx::BColor& rColor,
bool bFillBackground)
- : mnRefCount(0),
- meStyle(eStyle),
+ : meStyle(eStyle),
mfDistance(fDistance),
mfAngle(fAngle),
maColor(rColor),
mbFillBackground(bFillBackground)
+ {
+ }
+
+ ImpFillHatchAttribute()
+ : meStyle(HATCHSTYLE_SINGLE),
+ mfDistance(0.0),
+ mfAngle(0.0),
+ maColor(basegfx::BColor()),
+ mbFillBackground(false)
{
}
@@ -71,26 +77,13 @@
&& getColor() == rCandidate.getColor()
&& isFillBackground() == rCandidate.isFillBackground());
}
-
- static ImpFillHatchAttribute* get_global_default()
- {
- static ImpFillHatchAttribute* pDefault = 0;
-
- if(!pDefault)
- {
- pDefault = new ImpFillHatchAttribute(
- HATCHSTYLE_SINGLE,
- 0.0, 0.0,
- basegfx::BColor(),
- false);
-
- // never delete; start with RefCount 1, not 0
- pDefault->mnRefCount++;
- }
-
- return pDefault;
- }
};
+
+ namespace
+ {
+ struct theGlobalDefault :
+ public rtl::Static< FillHatchAttribute::ImplType, theGlobalDefault > {};
+ }
FillHatchAttribute::FillHatchAttribute(
HatchStyle eStyle,
@@ -98,73 +91,39 @@
double fAngle,
const basegfx::BColor& rColor,
bool bFillBackground)
- : mpFillHatchAttribute(new ImpFillHatchAttribute(
+ : mpFillHatchAttribute(ImpFillHatchAttribute(
eStyle, fDistance, fAngle, rColor, bFillBackground))
{
}
FillHatchAttribute::FillHatchAttribute()
- : mpFillHatchAttribute(ImpFillHatchAttribute::get_global_default())
+ : mpFillHatchAttribute(theGlobalDefault::get())
{
- mpFillHatchAttribute->mnRefCount++;
}
FillHatchAttribute::FillHatchAttribute(const FillHatchAttribute& rCandidate)
: mpFillHatchAttribute(rCandidate.mpFillHatchAttribute)
{
- mpFillHatchAttribute->mnRefCount++;
}
FillHatchAttribute::~FillHatchAttribute()
{
- if(mpFillHatchAttribute->mnRefCount)
- {
- mpFillHatchAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillHatchAttribute;
- }
}
bool FillHatchAttribute::isDefault() const
{
- return mpFillHatchAttribute == ImpFillHatchAttribute::get_global_default();
+ return mpFillHatchAttribute.same_object(theGlobalDefault::get());
}
FillHatchAttribute& FillHatchAttribute::operator=(const FillHatchAttribute& rCandidate)
{
- if(rCandidate.mpFillHatchAttribute != mpFillHatchAttribute)
- {
- if(mpFillHatchAttribute->mnRefCount)
- {
- mpFillHatchAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillHatchAttribute;
- }
-
- mpFillHatchAttribute = rCandidate.mpFillHatchAttribute;
- mpFillHatchAttribute->mnRefCount++;
- }
-
+ mpFillHatchAttribute = rCandidate.mpFillHatchAttribute;
return *this;
}
bool FillHatchAttribute::operator==(const FillHatchAttribute& rCandidate) const
{
- if(rCandidate.mpFillHatchAttribute == mpFillHatchAttribute)
- {
- return true;
- }
-
- if(rCandidate.isDefault() != isDefault())
- {
- return false;
- }
-
- return (*rCandidate.mpFillHatchAttribute == *mpFillHatchAttribute);
+ return rCandidate.mpFillHatchAttribute == mpFillHatchAttribute;
}
// data read access
--
To view, visit https://gerrit.libreoffice.org/3073
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1581b4bca6f14bd27af12ff40a4f4c0fe08af133
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thomas Arnhold <thomas@arnhold.org>
Context
- [PATCH] fdo#62525: use cow_wrapper for FillHatchAttribute · Thomas Arnhold (via Code Review)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.