diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:43:01 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 02:49:17 +0200 |
commit | 7470c93a7b70eec967a52ddbf8a3c9430d3b6f2f (patch) | |
tree | b7e728fb6b1b78cecbb96c27b95f9bc3439c8208 /drawinglayer | |
parent | fdo#62525: use cow_wrapper for SdrSceneAttribute (diff) | |
download | core-7470c93a7b70eec967a52ddbf8a3c9430d3b6f2f.tar.gz core-7470c93a7b70eec967a52ddbf8a3c9430d3b6f2f.zip |
fdo#62525: use cow_wrapper for Sdr3DObjectAttribute
Change-Id: I80e378f6a88068f5d3b36c6187b41ab8d968a0c3
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/sdrobjectattribute3d.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/sdrobjectattribute3d.cxx | 95 |
2 files changed, 32 insertions, 69 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrobjectattribute3d.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrobjectattribute3d.hxx index 809efa5a22f0..860093a67666 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrobjectattribute3d.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrobjectattribute3d.hxx @@ -26,6 +26,7 @@ #include <com/sun/star/drawing/TextureProjectionMode.hpp> #include <com/sun/star/drawing/TextureKind2.hpp> #include <com/sun/star/drawing/TextureMode.hpp> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -43,8 +44,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC Sdr3DObjectAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdr3DObjectAttribute > ImplType; + private: - ImpSdr3DObjectAttribute* mpSdr3DObjectAttribute; + ImplType mpSdr3DObjectAttribute; public: // constructors/destructor diff --git a/drawinglayer/source/attribute/sdrobjectattribute3d.cxx b/drawinglayer/source/attribute/sdrobjectattribute3d.cxx index a0b1e453d950..77926c507484 100644 --- a/drawinglayer/source/attribute/sdrobjectattribute3d.cxx +++ b/drawinglayer/source/attribute/sdrobjectattribute3d.cxx @@ -19,6 +19,7 @@ #include <drawinglayer/attribute/sdrobjectattribute3d.hxx> #include <drawinglayer/attribute/materialattribute3d.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpSdr3DObjectAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // 3D object attribute definitions ::com::sun::star::drawing::NormalsKind maNormalsKind; // normals type (0..2) ::com::sun::star::drawing::TextureProjectionMode maTextureProjectionX; // texture projection type X (0..2) @@ -59,8 +57,7 @@ namespace drawinglayer bool bShadow3D, bool bTextureFilter, bool bReducedLineGeometry) - : mnRefCount(0), - maNormalsKind(aNormalsKind), + : maNormalsKind(aNormalsKind), maTextureProjectionX(aTextureProjectionX), maTextureProjectionY(aTextureProjectionY), maTextureKind(aTextureKind), @@ -74,6 +71,21 @@ namespace drawinglayer { } + ImpSdr3DObjectAttribute() + : maNormalsKind(::com::sun::star::drawing::NormalsKind_SPECIFIC), + maTextureProjectionX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC), + maTextureProjectionY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC), + maTextureKind(::com::sun::star::drawing::TextureKind2_LUMINANCE), + maTextureMode(::com::sun::star::drawing::TextureMode_REPLACE), + maMaterial(MaterialAttribute3D()), + mbNormalsInvert(false), + mbDoubleSided(false), + mbShadow3D(false), + mbTextureFilter(false), + mbReducedLineGeometry(false) + { + } + // data read access ::com::sun::star::drawing::NormalsKind getNormalsKind() const { return maNormalsKind; } ::com::sun::star::drawing::TextureProjectionMode getTextureProjectionX() const { return maTextureProjectionX; } @@ -101,34 +113,14 @@ namespace drawinglayer && getTextureFilter() == rCandidate.getTextureFilter() && getReducedLineGeometry() == rCandidate.getReducedLineGeometry()); } - - static ImpSdr3DObjectAttribute* get_global_default() - { - static ImpSdr3DObjectAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdr3DObjectAttribute( - ::com::sun::star::drawing::NormalsKind_SPECIFIC, - ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC, - ::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC, - ::com::sun::star::drawing::TextureKind2_LUMINANCE, - ::com::sun::star::drawing::TextureMode_REPLACE, - MaterialAttribute3D(), - false, - false, - false, - false, - false); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< Sdr3DObjectAttribute::ImplType, theGlobalDefault > {}; + } + Sdr3DObjectAttribute::Sdr3DObjectAttribute( ::com::sun::star::drawing::NormalsKind aNormalsKind, ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX, @@ -141,7 +133,7 @@ namespace drawinglayer bool bShadow3D, bool bTextureFilter, bool bReducedLineGeometry) - : mpSdr3DObjectAttribute(new ImpSdr3DObjectAttribute( + : mpSdr3DObjectAttribute(ImpSdr3DObjectAttribute( aNormalsKind, aTextureProjectionX, aTextureProjectionY, aTextureKind, aTextureMode, rMaterial, bNormalsInvert, bDoubleSided, bShadow3D, bTextureFilter, bReducedLineGeometry)) { @@ -150,59 +142,26 @@ namespace drawinglayer Sdr3DObjectAttribute::Sdr3DObjectAttribute(const Sdr3DObjectAttribute& rCandidate) : mpSdr3DObjectAttribute(rCandidate.mpSdr3DObjectAttribute) { - mpSdr3DObjectAttribute->mnRefCount++; } Sdr3DObjectAttribute::~Sdr3DObjectAttribute() { - if(mpSdr3DObjectAttribute->mnRefCount) - { - mpSdr3DObjectAttribute->mnRefCount--; - } - else - { - delete mpSdr3DObjectAttribute; - } } bool Sdr3DObjectAttribute::isDefault() const { - return mpSdr3DObjectAttribute == ImpSdr3DObjectAttribute::get_global_default(); + return mpSdr3DObjectAttribute.same_object(theGlobalDefault::get()); } Sdr3DObjectAttribute& Sdr3DObjectAttribute::operator=(const Sdr3DObjectAttribute& rCandidate) { - if(rCandidate.mpSdr3DObjectAttribute != mpSdr3DObjectAttribute) - { - if(mpSdr3DObjectAttribute->mnRefCount) - { - mpSdr3DObjectAttribute->mnRefCount--; - } - else - { - delete mpSdr3DObjectAttribute; - } - - mpSdr3DObjectAttribute = rCandidate.mpSdr3DObjectAttribute; - mpSdr3DObjectAttribute->mnRefCount++; - } - + mpSdr3DObjectAttribute = rCandidate.mpSdr3DObjectAttribute; return *this; } bool Sdr3DObjectAttribute::operator==(const Sdr3DObjectAttribute& rCandidate) const { - if(rCandidate.mpSdr3DObjectAttribute == mpSdr3DObjectAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdr3DObjectAttribute == *mpSdr3DObjectAttribute); + return rCandidate.mpSdr3DObjectAttribute == mpSdr3DObjectAttribute; } ::com::sun::star::drawing::NormalsKind Sdr3DObjectAttribute::getNormalsKind() const |