diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:05:40 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:49:16 +0200 |
commit | 4f989f306898db0b9732301b03e2b4d02159869d (patch) | |
tree | 4161243a796f77e9f32f1099aed405e404b2ffb3 /drawinglayer | |
parent | f61b5c3654fc011ab0c6e042f6df010e39536d85 (diff) |
fdo#62525: use cow_wrapper for SdrLightingAttribute
Change-Id: Ibd6bd31ef78f2e853ff668f64202eff89afb1234
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/sdrlightingattribute3d.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/sdrlightingattribute3d.cxx | 80 |
2 files changed, 24 insertions, 62 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrlightingattribute3d.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrlightingattribute3d.hxx index 08b333c319b7..0c3bb96b9f70 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrlightingattribute3d.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrlightingattribute3d.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLIGHTINGATTRIBUTE3D_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> #include <vector> @@ -45,8 +46,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC SdrLightingAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdrLightingAttribute > ImplType; + private: - ImpSdrLightingAttribute* mpSdrLightingAttribute; + ImplType mpSdrLightingAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/sdrlightingattribute3d.cxx b/drawinglayer/source/attribute/sdrlightingattribute3d.cxx index 34028408d2b9..b7ee605424d9 100644 --- a/drawinglayer/source/attribute/sdrlightingattribute3d.cxx +++ b/drawinglayer/source/attribute/sdrlightingattribute3d.cxx @@ -21,6 +21,7 @@ #include <basegfx/color/bcolor.hxx> #include <basegfx/vector/b3dvector.hxx> #include <drawinglayer/attribute/sdrlightattribute3d.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -31,9 +32,6 @@ namespace drawinglayer class ImpSdrLightingAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // 3D light attribute definitions basegfx::BColor maAmbientLight; ::std::vector< Sdr3DLightAttribute > maLightVector; @@ -41,12 +39,17 @@ namespace drawinglayer ImpSdrLightingAttribute( const basegfx::BColor& rAmbientLight, const ::std::vector< Sdr3DLightAttribute >& rLightVector) - : mnRefCount(0), - maAmbientLight(rAmbientLight), + : maAmbientLight(rAmbientLight), maLightVector(rLightVector) { } + ImpSdrLightingAttribute() + : maAmbientLight(basegfx::BColor()), + maLightVector(std::vector< Sdr3DLightAttribute >()) + { + } + // data read access const basegfx::BColor& getAmbientLight() const { return maAmbientLight; } const ::std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; } @@ -56,95 +59,50 @@ namespace drawinglayer return (getAmbientLight() == rCandidate.getAmbientLight() && getLightVector() == rCandidate.getLightVector()); } - - static ImpSdrLightingAttribute* get_global_default() - { - static ImpSdrLightingAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdrLightingAttribute( - basegfx::BColor(), - std::vector< Sdr3DLightAttribute >()); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< SdrLightingAttribute::ImplType, theGlobalDefault > {}; + } + SdrLightingAttribute::SdrLightingAttribute( const basegfx::BColor& rAmbientLight, const ::std::vector< Sdr3DLightAttribute >& rLightVector) - : mpSdrLightingAttribute(new ImpSdrLightingAttribute( + : mpSdrLightingAttribute(ImpSdrLightingAttribute( rAmbientLight, rLightVector)) { } SdrLightingAttribute::SdrLightingAttribute() - : mpSdrLightingAttribute(ImpSdrLightingAttribute::get_global_default()) + : mpSdrLightingAttribute(theGlobalDefault::get()) { - mpSdrLightingAttribute->mnRefCount++; } SdrLightingAttribute::SdrLightingAttribute(const SdrLightingAttribute& rCandidate) : mpSdrLightingAttribute(rCandidate.mpSdrLightingAttribute) { - mpSdrLightingAttribute->mnRefCount++; } SdrLightingAttribute::~SdrLightingAttribute() { - if(mpSdrLightingAttribute->mnRefCount) - { - mpSdrLightingAttribute->mnRefCount--; - } - else - { - delete mpSdrLightingAttribute; - } } bool SdrLightingAttribute::isDefault() const { - return mpSdrLightingAttribute == ImpSdrLightingAttribute::get_global_default(); + return mpSdrLightingAttribute.same_object(theGlobalDefault::get()); } SdrLightingAttribute& SdrLightingAttribute::operator=(const SdrLightingAttribute& rCandidate) { - if(rCandidate.mpSdrLightingAttribute != mpSdrLightingAttribute) - { - if(mpSdrLightingAttribute->mnRefCount) - { - mpSdrLightingAttribute->mnRefCount--; - } - else - { - delete mpSdrLightingAttribute; - } - - mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute; - mpSdrLightingAttribute->mnRefCount++; - } - + mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute; return *this; } bool SdrLightingAttribute::operator==(const SdrLightingAttribute& rCandidate) const { - if(rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdrLightingAttribute == *mpSdrLightingAttribute); + return rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute; } const ::std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() const |