diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-02 14:54:29 +0200 |
---|---|---|
committer | Thomas Arnhold <thomas@arnhold.org> | 2013-04-02 14:56:44 +0200 |
commit | c42bdb023725016af22d7cee8cf81c8975234d94 (patch) | |
tree | e2140f8f261108ffd27b2994ff585b951c8683ec /drawinglayer | |
parent | 4e188ae252322485c54b4c3a6c081bde2f966a9f (diff) |
fdo#62525: use cow_wrapper for MaterialAttribute3D
Change-Id: I7ee65afe8065525e6af198a4d1b75e1035644983
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/materialattribute3d.cxx | 89 |
2 files changed, 28 insertions, 67 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx b/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx index cb64b0f9e330..9c4d34dce155 100644 --- a/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_MATERIALATTRIBUTE3D_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -41,8 +42,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC MaterialAttribute3D { + public: + typedef o3tl::cow_wrapper< ImpMaterialAttribute3D > ImplType; + private: - ImpMaterialAttribute3D* mpMaterialAttribute3D; + ImplType mpMaterialAttribute3D; public: // constructors/destructor diff --git a/drawinglayer/source/attribute/materialattribute3d.cxx b/drawinglayer/source/attribute/materialattribute3d.cxx index 72ab55d7f631..e0a920a28309 100644 --- a/drawinglayer/source/attribute/materialattribute3d.cxx +++ b/drawinglayer/source/attribute/materialattribute3d.cxx @@ -19,6 +19,7 @@ #include <drawinglayer/attribute/materialattribute3d.hxx> #include <basegfx/color/bcolor.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpMaterialAttribute3D { public: - // refcounter - sal_uInt32 mnRefCount; - // materialAttribute3D definitions basegfx::BColor maColor; // object color basegfx::BColor maSpecular; // material specular color @@ -39,8 +37,7 @@ namespace drawinglayer sal_uInt16 mnSpecularIntensity; // material specular intensity [0..128] ImpMaterialAttribute3D(const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) - : mnRefCount(0), - maColor(rColor), + : maColor(rColor), maSpecular(rSpecular), maEmission(rEmission), mnSpecularIntensity(nSpecularIntensity) @@ -48,14 +45,21 @@ namespace drawinglayer } ImpMaterialAttribute3D(const basegfx::BColor& rColor) - : mnRefCount(0), - maColor(rColor), + : maColor(rColor), maSpecular(1.0, 1.0, 1.0), maEmission(), mnSpecularIntensity(15) { } + ImpMaterialAttribute3D() + : maColor(basegfx::BColor()), + maSpecular(basegfx::BColor()), + maEmission(basegfx::BColor()), + mnSpecularIntensity(0) + { + } + // data read access const basegfx::BColor& getColor() const { return maColor; } const basegfx::BColor& getSpecular() const { return maSpecular; } @@ -69,105 +73,58 @@ namespace drawinglayer && getEmission() == rCandidate.getEmission() && getSpecularIntensity() == rCandidate.getSpecularIntensity()); } - - static ImpMaterialAttribute3D* get_global_default() - { - static ImpMaterialAttribute3D* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpMaterialAttribute3D( - basegfx::BColor(), - basegfx::BColor(), - basegfx::BColor(), - 0); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< MaterialAttribute3D::ImplType, theGlobalDefault > {}; + } + MaterialAttribute3D::MaterialAttribute3D( const basegfx::BColor& rColor, const basegfx::BColor& rSpecular, const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) - : mpMaterialAttribute3D(new ImpMaterialAttribute3D( + : mpMaterialAttribute3D(ImpMaterialAttribute3D( rColor, rSpecular, rEmission, nSpecularIntensity)) { } MaterialAttribute3D::MaterialAttribute3D( const basegfx::BColor& rColor) - : mpMaterialAttribute3D(new ImpMaterialAttribute3D(rColor)) + : mpMaterialAttribute3D(ImpMaterialAttribute3D(rColor)) { } MaterialAttribute3D::MaterialAttribute3D() - : mpMaterialAttribute3D(ImpMaterialAttribute3D::get_global_default()) + : mpMaterialAttribute3D(theGlobalDefault::get()) { - mpMaterialAttribute3D->mnRefCount++; } MaterialAttribute3D::MaterialAttribute3D(const MaterialAttribute3D& rCandidate) : mpMaterialAttribute3D(rCandidate.mpMaterialAttribute3D) { - mpMaterialAttribute3D->mnRefCount++; } MaterialAttribute3D::~MaterialAttribute3D() { - if(mpMaterialAttribute3D->mnRefCount) - { - mpMaterialAttribute3D->mnRefCount--; - } - else - { - delete mpMaterialAttribute3D; - } } bool MaterialAttribute3D::isDefault() const { - return mpMaterialAttribute3D == ImpMaterialAttribute3D::get_global_default(); + return mpMaterialAttribute3D.same_object(theGlobalDefault::get()); } MaterialAttribute3D& MaterialAttribute3D::operator=(const MaterialAttribute3D& rCandidate) { - if(rCandidate.mpMaterialAttribute3D != mpMaterialAttribute3D) - { - if(mpMaterialAttribute3D->mnRefCount) - { - mpMaterialAttribute3D->mnRefCount--; - } - else - { - delete mpMaterialAttribute3D; - } - - mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D; - mpMaterialAttribute3D->mnRefCount++; - } - + mpMaterialAttribute3D = rCandidate.mpMaterialAttribute3D; return *this; } bool MaterialAttribute3D::operator==(const MaterialAttribute3D& rCandidate) const { - if(rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpMaterialAttribute3D == *mpMaterialAttribute3D); + return rCandidate.mpMaterialAttribute3D == mpMaterialAttribute3D; } const basegfx::BColor& MaterialAttribute3D::getColor() const |