diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 01:47:25 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:49:16 +0200 |
commit | f98bee58fbf1e4862477fb6aa014447746f1ef9d (patch) | |
tree | c56118a5cc54324b605148b5a1fd97ac2a60fa3f /drawinglayer | |
parent | ce2991ee863e2e5faef95462242552515e1cf89c (diff) |
fdo#62525: use cow_wrapper for SdrFillAttribute
Change-Id: I827e1edb2c6ec2fc3e16fde6f105063e59d40f66
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/sdrfillattribute.cxx | 86 |
2 files changed, 27 insertions, 65 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx index 038916f7e71b..7fd3d38c224e 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrfillattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRFILLATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -44,8 +45,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC SdrFillAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdrFillAttribute > ImplType; + private: - ImpSdrFillAttribute* mpSdrFillAttribute; + ImplType mpSdrFillAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/sdrfillattribute.cxx b/drawinglayer/source/attribute/sdrfillattribute.cxx index 421e34cfe95b..98c6450a7088 100644 --- a/drawinglayer/source/attribute/sdrfillattribute.cxx +++ b/drawinglayer/source/attribute/sdrfillattribute.cxx @@ -22,6 +22,7 @@ #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx> #include <drawinglayer/attribute/fillhatchattribute.hxx> #include <drawinglayer/attribute/fillgradientattribute.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -32,9 +33,6 @@ namespace drawinglayer class ImpSdrFillAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // fill definitions double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. basegfx::BColor maColor; // fill color @@ -49,8 +47,7 @@ namespace drawinglayer const FillGradientAttribute& rGradient, const FillHatchAttribute& rHatch, const SdrFillBitmapAttribute& rBitmap) - : mnRefCount(0), - mfTransparence(fTransparence), + : mfTransparence(fTransparence), maColor(rColor), maGradient(rGradient), maHatch(rHatch), @@ -58,6 +55,15 @@ namespace drawinglayer { } + ImpSdrFillAttribute() + : mfTransparence(0.0), + maColor(basegfx::BColor()), + maGradient(FillGradientAttribute()), + maHatch(FillHatchAttribute()), + maBitmap(SdrFillBitmapAttribute()) + { + } + // data read access double getTransparence() const { return mfTransparence; } const basegfx::BColor& getColor() const { return maColor; } @@ -74,101 +80,53 @@ namespace drawinglayer && getHatch() == rCandidate.getHatch() && getBitmap() == rCandidate.getBitmap()); } - - static ImpSdrFillAttribute* get_global_default() - { - static ImpSdrFillAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdrFillAttribute( - 0.0, - basegfx::BColor(), - FillGradientAttribute(), - FillHatchAttribute(), - SdrFillBitmapAttribute()); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< SdrFillAttribute::ImplType, theGlobalDefault > {}; + } + SdrFillAttribute::SdrFillAttribute( double fTransparence, const basegfx::BColor& rColor, const FillGradientAttribute& rGradient, const FillHatchAttribute& rHatch, const SdrFillBitmapAttribute& rBitmap) - : mpSdrFillAttribute(new ImpSdrFillAttribute( + : mpSdrFillAttribute(ImpSdrFillAttribute( fTransparence, rColor, rGradient, rHatch, rBitmap)) { } SdrFillAttribute::SdrFillAttribute() - : mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default()) + : mpSdrFillAttribute(theGlobalDefault::get()) { - mpSdrFillAttribute->mnRefCount++; } SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate) : mpSdrFillAttribute(rCandidate.mpSdrFillAttribute) { - mpSdrFillAttribute->mnRefCount++; } SdrFillAttribute::~SdrFillAttribute() { - if(mpSdrFillAttribute->mnRefCount) - { - mpSdrFillAttribute->mnRefCount--; - } - else - { - delete mpSdrFillAttribute; - } } bool SdrFillAttribute::isDefault() const { - return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default(); + return mpSdrFillAttribute.same_object(theGlobalDefault::get()); } SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate) { - if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute) - { - if(mpSdrFillAttribute->mnRefCount) - { - mpSdrFillAttribute->mnRefCount--; - } - else - { - delete mpSdrFillAttribute; - } - - mpSdrFillAttribute = rCandidate.mpSdrFillAttribute; - mpSdrFillAttribute->mnRefCount++; - } - + mpSdrFillAttribute = rCandidate.mpSdrFillAttribute; return *this; } bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const { - if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute); + return rCandidate.mpSdrFillAttribute == mpSdrFillAttribute; } double SdrFillAttribute::getTransparence() const |