diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-03-27 03:41:13 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-03-27 12:12:31 +0000 |
commit | 63da9d632827e7d08450dfd72bdcdfbed9c73cae (patch) | |
tree | 9cb85e1a2aefb4bb0fa59ace570d50ae6e4aebfb /drawinglayer | |
parent | 6db890bfbb4cc86d0963599b70033b4eb32ff154 (diff) |
fdo#62525: use cow_wrapper for FillHatchAttribute
Change-Id: I1581b4bca6f14bd27af12ff40a4f4c0fe08af133
Reviewed-on: https://gerrit.libreoffice.org/3073
Reviewed-by: Thorsten Behrens <tbehrens@suse.com>
Tested-by: Thorsten Behrens <tbehrens@suse.com>
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/fillhatchattribute.cxx | 85 |
2 files changed, 27 insertions, 64 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fillhatchattribute.hxx index dc2665b33a59..7e6244be090b 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 @@ namespace drawinglayer { 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 d3d86ee45723..e89628b43a69 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 @@ namespace drawinglayer class ImpFillHatchAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // data definitions HatchStyle meStyle; double mfDistance; @@ -47,8 +45,7 @@ namespace drawinglayer double fAngle, const basegfx::BColor& rColor, bool bFillBackground) - : mnRefCount(0), - meStyle(eStyle), + : meStyle(eStyle), mfDistance(fDistance), mfAngle(fAngle), maColor(rColor), @@ -56,6 +53,15 @@ namespace drawinglayer { } + ImpFillHatchAttribute() + : meStyle(HATCHSTYLE_SINGLE), + mfDistance(0.0), + mfAngle(0.0), + maColor(basegfx::BColor()), + mbFillBackground(false) + { + } + // data read access HatchStyle getStyle() const { return meStyle; } double getDistance() const { return mfDistance; } @@ -71,100 +77,53 @@ namespace drawinglayer && 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, double fDistance, 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 |