diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-03-23 05:40:32 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-03-23 20:06:16 +0000 |
commit | 62fca307fc0fc775234572c79a1237494c2d72a7 (patch) | |
tree | 04ec86229d94c08b18a72b84001581f0ef159f6a /drawinglayer | |
parent | fb8dd00d597495e8622a54dfd724ccc99d1fe999 (diff) |
fdo#62525: use cow_wrapper for SdrShadowAttribute
Thanks to Thorsten.
Change-Id: I9b5435d2326e9ebf340e88025eeea25ff6388ea2
Reviewed-on: https://gerrit.libreoffice.org/2946
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/sdrshadowattribute.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/sdrshadowattribute.cxx | 81 |
2 files changed, 25 insertions, 62 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx index 91657cde8829..ee1f36292505 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRSHADOWATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -42,8 +43,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC SdrShadowAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdrShadowAttribute > ImplType; + private: - ImpSdrShadowAttribute* mpSdrShadowAttribute; + ImplType mpSdrShadowAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/sdrshadowattribute.cxx b/drawinglayer/source/attribute/sdrshadowattribute.cxx index f6b5e4916ee9..9705f6af617f 100644 --- a/drawinglayer/source/attribute/sdrshadowattribute.cxx +++ b/drawinglayer/source/attribute/sdrshadowattribute.cxx @@ -20,6 +20,7 @@ #include <drawinglayer/attribute/sdrshadowattribute.hxx> #include <basegfx/vector/b2dvector.hxx> #include <basegfx/color/bcolor.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -30,9 +31,6 @@ namespace drawinglayer class ImpSdrShadowAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // shadow definitions basegfx::B2DVector maOffset; // shadow offset 1/100th mm double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. @@ -42,13 +40,19 @@ namespace drawinglayer const basegfx::B2DVector& rOffset, double fTransparence, const basegfx::BColor& rColor) - : mnRefCount(0), - maOffset(rOffset), + : maOffset(rOffset), mfTransparence(fTransparence), maColor(rColor) { } + ImpSdrShadowAttribute() + : maOffset(basegfx::B2DVector()), + mfTransparence(0.0), + maColor(basegfx::BColor()) + { + } + // data read access const basegfx::B2DVector& getOffset() const { return maOffset; } double getTransparence() const { return mfTransparence; } @@ -60,97 +64,52 @@ namespace drawinglayer && getTransparence() == rCandidate.getTransparence() && getColor() == rCandidate.getColor()); } + }; - static ImpSdrShadowAttribute* get_global_default() - { - static ImpSdrShadowAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdrShadowAttribute( - basegfx::B2DVector(), - 0.0, - basegfx::BColor()); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } + namespace + { + struct theGlobalDefault : + public rtl::Static< SdrShadowAttribute::ImplType, theGlobalDefault > {}; + } - return pDefault; - } - }; SdrShadowAttribute::SdrShadowAttribute( const basegfx::B2DVector& rOffset, double fTransparence, const basegfx::BColor& rColor) - : mpSdrShadowAttribute(new ImpSdrShadowAttribute( + : mpSdrShadowAttribute(ImpSdrShadowAttribute( rOffset, fTransparence, rColor)) { } SdrShadowAttribute::SdrShadowAttribute() - : mpSdrShadowAttribute(ImpSdrShadowAttribute::get_global_default()) + : mpSdrShadowAttribute(theGlobalDefault::get()) { - mpSdrShadowAttribute->mnRefCount++; } SdrShadowAttribute::SdrShadowAttribute(const SdrShadowAttribute& rCandidate) : mpSdrShadowAttribute(rCandidate.mpSdrShadowAttribute) { - mpSdrShadowAttribute->mnRefCount++; } SdrShadowAttribute::~SdrShadowAttribute() { - if(mpSdrShadowAttribute->mnRefCount) - { - mpSdrShadowAttribute->mnRefCount--; - } - else - { - delete mpSdrShadowAttribute; - } } bool SdrShadowAttribute::isDefault() const { - return mpSdrShadowAttribute == ImpSdrShadowAttribute::get_global_default(); + return mpSdrShadowAttribute.same_object(theGlobalDefault::get()); } SdrShadowAttribute& SdrShadowAttribute::operator=(const SdrShadowAttribute& rCandidate) { - if(rCandidate.mpSdrShadowAttribute != mpSdrShadowAttribute) - { - if(mpSdrShadowAttribute->mnRefCount) - { - mpSdrShadowAttribute->mnRefCount--; - } - else - { - delete mpSdrShadowAttribute; - } - - mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute; - mpSdrShadowAttribute->mnRefCount++; - } - + mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute; return *this; } bool SdrShadowAttribute::operator==(const SdrShadowAttribute& rCandidate) const { - if(rCandidate.mpSdrShadowAttribute == mpSdrShadowAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdrShadowAttribute == *mpSdrShadowAttribute); + return mpSdrShadowAttribute == rCandidate.mpSdrShadowAttribute; } const basegfx::B2DVector& SdrShadowAttribute::getOffset() const |