diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-03-23 06:28:11 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-03-23 21:56:02 +0100 |
commit | 75ad992d1801334a2bb39e1b0bdf3ca5f3714625 (patch) | |
tree | 489f62a6f58d4e40152c15dae383a1188f95ee22 /drawinglayer | |
parent | Start slideshow with the next visible slide, part2 (diff) | |
download | core-75ad992d1801334a2bb39e1b0bdf3ca5f3714625.tar.gz core-75ad992d1801334a2bb39e1b0bdf3ca5f3714625.zip |
fdo#62525: use cow_wrapper for FillGradientAttribute
Change-Id: I85a9864820f49da8ebcc4a7d2c80a3c9d0c13b27
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/fillgradientattribute.cxx | 89 |
2 files changed, 30 insertions, 65 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fillgradientattribute.hxx index 6d01c86b84f5..e791193651a0 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 @@ namespace drawinglayer { 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 987082c5011f..66647917d0c6 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 @@ namespace drawinglayer class ImpFillGradientAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // data definitions GradientStyle meStyle; double mfBorder; @@ -51,8 +49,7 @@ namespace drawinglayer const basegfx::BColor& rStartColor, const basegfx::BColor& rEndColor, sal_uInt16 nSteps) - : mnRefCount(0), - meStyle(eStyle), + : meStyle(eStyle), mfBorder(fBorder), mfOffsetX(fOffsetX), mfOffsetY(fOffsetY), @@ -63,6 +60,18 @@ namespace drawinglayer { } + ImpFillGradientAttribute() + : meStyle(GRADIENTSTYLE_LINEAR), + mfBorder(0.0), + mfOffsetX(0.0), + mfOffsetY(0.0), + mfAngle(0.0), + maStartColor(basegfx::BColor()), + maEndColor(basegfx::BColor()), + mnSteps(0) + { + } + // data read access GradientStyle getStyle() const { return meStyle; } double getBorder() const { return mfBorder; } @@ -84,28 +93,14 @@ namespace drawinglayer && 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, double fBorder, @@ -115,73 +110,39 @@ namespace drawinglayer 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 |