diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:21:35 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:49:17 +0200 |
commit | 92261a33c8ebd2d1c4d35b1b526e98abe746955e (patch) | |
tree | 383e6103a74548b753dcba60ef4b91383889f787 /drawinglayer | |
parent | 8ee042bdb5502228fecf9a05da491bbb2cb3efc5 (diff) |
fdo#62525: use cow_wrapper for StrokeAttribute
Change-Id: Icf5daca279902b90da98069338638c3ad432e69a
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/strokeattribute.hxx | 7 | ||||
-rw-r--r-- | drawinglayer/source/attribute/strokeattribute.cxx | 80 |
2 files changed, 24 insertions, 63 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/strokeattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/strokeattribute.hxx index 3759213f1a2a..6d4cea978482 100644 --- a/drawinglayer/inc/drawinglayer/attribute/strokeattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/strokeattribute.hxx @@ -21,7 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_STROKEATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> - +#include <o3tl/cow_wrapper.hxx> #include <vector> ////////////////////////////////////////////////////////////////////////////// @@ -39,8 +39,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC StrokeAttribute { + public: + typedef o3tl::cow_wrapper< ImpStrokeAttribute > ImplType; + private: - ImpStrokeAttribute* mpStrokeAttribute; + ImplType mpStrokeAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/strokeattribute.cxx b/drawinglayer/source/attribute/strokeattribute.cxx index d6da1a2e5f07..c6c5b692c2ff 100644 --- a/drawinglayer/source/attribute/strokeattribute.cxx +++ b/drawinglayer/source/attribute/strokeattribute.cxx @@ -18,6 +18,7 @@ */ #include <drawinglayer/attribute/strokeattribute.hxx> +#include <rtl/instance.hxx> #include <numeric> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpStrokeAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // data definitions ::std::vector< double > maDotDashArray; // array of double which defines the dot-dash pattern double mfFullDotDashLen; // sum of maDotDashArray (for convenience) @@ -39,12 +37,17 @@ namespace drawinglayer ImpStrokeAttribute( const ::std::vector< double >& rDotDashArray, double fFullDotDashLen) - : mnRefCount(0), - maDotDashArray(rDotDashArray), + : maDotDashArray(rDotDashArray), mfFullDotDashLen(fFullDotDashLen) { } + ImpStrokeAttribute() + : maDotDashArray(std::vector< double >()), + mfFullDotDashLen(0.0) + { + } + // data read access const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; } double getFullDotDashLen() const @@ -64,95 +67,50 @@ namespace drawinglayer return (getDotDashArray() == rCandidate.getDotDashArray() && getFullDotDashLen() == rCandidate.getFullDotDashLen()); } - - static ImpStrokeAttribute* get_global_default() - { - static ImpStrokeAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpStrokeAttribute( - std::vector< double >(), - 0.0); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< StrokeAttribute::ImplType, theGlobalDefault > {}; + } + StrokeAttribute::StrokeAttribute( const ::std::vector< double >& rDotDashArray, double fFullDotDashLen) - : mpStrokeAttribute(new ImpStrokeAttribute( + : mpStrokeAttribute(ImpStrokeAttribute( rDotDashArray, fFullDotDashLen)) { } StrokeAttribute::StrokeAttribute() - : mpStrokeAttribute(ImpStrokeAttribute::get_global_default()) + : mpStrokeAttribute(theGlobalDefault::get()) { - mpStrokeAttribute->mnRefCount++; } StrokeAttribute::StrokeAttribute(const StrokeAttribute& rCandidate) : mpStrokeAttribute(rCandidate.mpStrokeAttribute) { - mpStrokeAttribute->mnRefCount++; } StrokeAttribute::~StrokeAttribute() { - if(mpStrokeAttribute->mnRefCount) - { - mpStrokeAttribute->mnRefCount--; - } - else - { - delete mpStrokeAttribute; - } } bool StrokeAttribute::isDefault() const { - return mpStrokeAttribute == ImpStrokeAttribute::get_global_default(); + return mpStrokeAttribute.same_object(theGlobalDefault::get()); } StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute& rCandidate) { - if(rCandidate.mpStrokeAttribute != mpStrokeAttribute) - { - if(mpStrokeAttribute->mnRefCount) - { - mpStrokeAttribute->mnRefCount--; - } - else - { - delete mpStrokeAttribute; - } - - mpStrokeAttribute = rCandidate.mpStrokeAttribute; - mpStrokeAttribute->mnRefCount++; - } - + mpStrokeAttribute = rCandidate.mpStrokeAttribute; return *this; } bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const { - if(rCandidate.mpStrokeAttribute == mpStrokeAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpStrokeAttribute == *mpStrokeAttribute); + return rCandidate.mpStrokeAttribute == mpStrokeAttribute; } const ::std::vector< double >& StrokeAttribute::getDotDashArray() const |