diff options
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/sdrlineattribute.hxx | 7 | ||||
-rw-r--r-- | drawinglayer/source/attribute/sdrlineattribute.cxx | 93 |
2 files changed, 30 insertions, 70 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrlineattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrlineattribute.hxx index f487b4d6d59a..bedbd9f29bb9 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrlineattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrlineattribute.hxx @@ -21,9 +21,9 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLINEATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> - #include <basegfx/vector/b2enums.hxx> #include <com/sun/star/drawing/LineCap.hpp> +#include <o3tl/cow_wrapper.hxx> #include <vector> ////////////////////////////////////////////////////////////////////////////// @@ -45,8 +45,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC SdrLineAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdrLineAttribute > ImplType; + private: - ImpSdrLineAttribute* mpSdrLineAttribute; + ImplType mpSdrLineAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/sdrlineattribute.cxx b/drawinglayer/source/attribute/sdrlineattribute.cxx index 1da5a79780d8..60951d9d94f0 100644 --- a/drawinglayer/source/attribute/sdrlineattribute.cxx +++ b/drawinglayer/source/attribute/sdrlineattribute.cxx @@ -19,6 +19,7 @@ #include <drawinglayer/attribute/sdrlineattribute.hxx> #include <basegfx/color/bcolor.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpSdrLineAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // line definitions basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines double mfWidth; // 1/100th mm, 0.0==hair @@ -49,8 +47,7 @@ namespace drawinglayer com::sun::star::drawing::LineCap eCap, const ::std::vector< double >& rDotDashArray, double fFullDotDashLen) - : mnRefCount(0), - meJoin(eJoin), + : meJoin(eJoin), mfWidth(fWidth), mfTransparence(fTransparence), maColor(rColor), @@ -61,8 +58,7 @@ namespace drawinglayer } explicit ImpSdrLineAttribute(const basegfx::BColor& rColor) - : mnRefCount(0), - meJoin(basegfx::B2DLINEJOIN_NONE), + : meJoin(basegfx::B2DLINEJOIN_NONE), mfWidth(0.0), mfTransparence(0.0), maColor(rColor), @@ -72,6 +68,17 @@ namespace drawinglayer { } + ImpSdrLineAttribute() + : meJoin(basegfx::B2DLINEJOIN_ROUND), + mfWidth(0.0), + mfTransparence(0.0), + maColor(basegfx::BColor()), + meCap(com::sun::star::drawing::LineCap_BUTT), + maDotDashArray(std::vector< double >()), + mfFullDotDashLen(0.0) + { + } + // data read access basegfx::B2DLineJoin getJoin() const { return meJoin; } double getWidth() const { return mfWidth; } @@ -90,30 +97,14 @@ namespace drawinglayer && getCap() == rCandidate.getCap() && getDotDashArray() == rCandidate.getDotDashArray()); } - - static ImpSdrLineAttribute* get_global_default() - { - static ImpSdrLineAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdrLineAttribute( - basegfx::B2DLINEJOIN_ROUND, - 0.0, - 0.0, - basegfx::BColor(), - com::sun::star::drawing::LineCap_BUTT, - std::vector< double >(), - 0.0); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< SdrLineAttribute::ImplType, theGlobalDefault > {}; + } + SdrLineAttribute::SdrLineAttribute( basegfx::B2DLineJoin eJoin, double fWidth, @@ -123,7 +114,7 @@ namespace drawinglayer const ::std::vector< double >& rDotDashArray, double fFullDotDashLen) : mpSdrLineAttribute( - new ImpSdrLineAttribute( + ImpSdrLineAttribute( eJoin, fWidth, fTransparence, @@ -136,67 +127,33 @@ namespace drawinglayer } SdrLineAttribute::SdrLineAttribute() - : mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default()) + : mpSdrLineAttribute(theGlobalDefault::get()) { - mpSdrLineAttribute->mnRefCount++; } SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate) : mpSdrLineAttribute(rCandidate.mpSdrLineAttribute) { - mpSdrLineAttribute->mnRefCount++; } SdrLineAttribute::~SdrLineAttribute() { - if(mpSdrLineAttribute->mnRefCount) - { - mpSdrLineAttribute->mnRefCount--; - } - else - { - delete mpSdrLineAttribute; - } } bool SdrLineAttribute::isDefault() const { - return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default(); + return mpSdrLineAttribute.same_object(theGlobalDefault::get()); } SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate) { - if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute) - { - if(mpSdrLineAttribute->mnRefCount) - { - mpSdrLineAttribute->mnRefCount--; - } - else - { - delete mpSdrLineAttribute; - } - - mpSdrLineAttribute = rCandidate.mpSdrLineAttribute; - mpSdrLineAttribute->mnRefCount++; - } - + mpSdrLineAttribute = rCandidate.mpSdrLineAttribute; return *this; } bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const { - if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute); + return rCandidate.mpSdrLineAttribute == mpSdrLineAttribute; } basegfx::B2DLineJoin SdrLineAttribute::getJoin() const |