drawinglayer/inc/drawinglayer/attribute/lineattribute.hxx | 6 drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx | 6 drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx | 6 drawinglayer/source/attribute/lineattribute.cxx | 84 ++------- drawinglayer/source/attribute/linestartendattribute.cxx | 82 ++------- drawinglayer/source/attribute/materialattribute3d.cxx | 89 ++-------- 6 files changed, 79 insertions(+), 194 deletions(-)
New commits: commit c42bdb023725016af22d7cee8cf81c8975234d94 Author: Thomas Arnhold <tho...@arnhold.org> Date: Tue Apr 2 14:54:29 2013 +0200 fdo#62525: use cow_wrapper for MaterialAttribute3D Change-Id: I7ee65afe8065525e6af198a4d1b75e1035644983 diff --git a/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx b/drawinglayer/inc/drawinglayer/attribute/materialattribute3d.hxx index cb64b0f..9c4d34d 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 72ab55d..e0a920a 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 commit 4e188ae252322485c54b4c3a6c081bde2f966a9f Author: Thomas Arnhold <tho...@arnhold.org> Date: Tue Apr 2 14:46:32 2013 +0200 fdo#62525: use cow_wrapper for LineStartEndAttribute Change-Id: Id8803574245298c6d15b3c59bbfd3b7c812b5794 diff --git a/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx index 5639919..e02d356 100644 --- a/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_LINESTARTENDATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -41,8 +42,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC LineStartEndAttribute { + public: + typedef o3tl::cow_wrapper< ImpLineStartEndAttribute > ImplType; + private: - ImpLineStartEndAttribute* mpLineStartEndAttribute; + ImplType mpLineStartEndAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/linestartendattribute.cxx b/drawinglayer/source/attribute/linestartendattribute.cxx index e1208ff..0e39361 100644 --- a/drawinglayer/source/attribute/linestartendattribute.cxx +++ b/drawinglayer/source/attribute/linestartendattribute.cxx @@ -20,6 +20,7 @@ #include <drawinglayer/attribute/linestartendattribute.hxx> #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolypolygon.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -30,9 +31,6 @@ namespace drawinglayer class ImpLineStartEndAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // data definitions double mfWidth; // absolute line StartEndGeometry base width basegfx::B2DPolyPolygon maPolyPolygon; // the StartEndGeometry PolyPolygon @@ -44,13 +42,19 @@ namespace drawinglayer double fWidth, const basegfx::B2DPolyPolygon& rPolyPolygon, bool bCentered) - : mnRefCount(0), - mfWidth(fWidth), + : mfWidth(fWidth), maPolyPolygon(rPolyPolygon), mbCentered(bCentered) { } + ImpLineStartEndAttribute() + : mfWidth(0.0), + maPolyPolygon(basegfx::B2DPolyPolygon()), + mbCentered(false) + { + } + // data read access double getWidth() const { return mfWidth; } const basegfx::B2DPolyPolygon& getB2DPolyPolygon() const { return maPolyPolygon; } @@ -62,97 +66,51 @@ namespace drawinglayer && getB2DPolyPolygon() == rCandidate.getB2DPolyPolygon() && isCentered() == rCandidate.isCentered()); } - - static ImpLineStartEndAttribute* get_global_default() - { - static ImpLineStartEndAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpLineStartEndAttribute( - 0.0, - basegfx::B2DPolyPolygon(), - false); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< LineStartEndAttribute::ImplType, theGlobalDefault > {}; + } + LineStartEndAttribute::LineStartEndAttribute( double fWidth, const basegfx::B2DPolyPolygon& rPolyPolygon, bool bCentered) - : mpLineStartEndAttribute(new ImpLineStartEndAttribute( + : mpLineStartEndAttribute(ImpLineStartEndAttribute( fWidth, rPolyPolygon, bCentered)) { } LineStartEndAttribute::LineStartEndAttribute() - : mpLineStartEndAttribute(ImpLineStartEndAttribute::get_global_default()) + : mpLineStartEndAttribute(theGlobalDefault::get()) { - mpLineStartEndAttribute->mnRefCount++; } LineStartEndAttribute::LineStartEndAttribute(const LineStartEndAttribute& rCandidate) : mpLineStartEndAttribute(rCandidate.mpLineStartEndAttribute) { - mpLineStartEndAttribute->mnRefCount++; } LineStartEndAttribute::~LineStartEndAttribute() { - if(mpLineStartEndAttribute->mnRefCount) - { - mpLineStartEndAttribute->mnRefCount--; - } - else - { - delete mpLineStartEndAttribute; - } } bool LineStartEndAttribute::isDefault() const { - return mpLineStartEndAttribute == ImpLineStartEndAttribute::get_global_default(); + return mpLineStartEndAttribute.same_object(theGlobalDefault::get()); } LineStartEndAttribute& LineStartEndAttribute::operator=(const LineStartEndAttribute& rCandidate) { - if(rCandidate.mpLineStartEndAttribute != mpLineStartEndAttribute) - { - if(mpLineStartEndAttribute->mnRefCount) - { - mpLineStartEndAttribute->mnRefCount--; - } - else - { - delete mpLineStartEndAttribute; - } - - mpLineStartEndAttribute = rCandidate.mpLineStartEndAttribute; - mpLineStartEndAttribute->mnRefCount++; - } - + mpLineStartEndAttribute = rCandidate.mpLineStartEndAttribute; return *this; } bool LineStartEndAttribute::operator==(const LineStartEndAttribute& rCandidate) const { - if(rCandidate.mpLineStartEndAttribute == mpLineStartEndAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpLineStartEndAttribute == *mpLineStartEndAttribute); + return rCandidate.mpLineStartEndAttribute == mpLineStartEndAttribute; } double LineStartEndAttribute::getWidth() const commit 44e7cb139d921d6c003d4367a8064bc653342541 Author: Thomas Arnhold <tho...@arnhold.org> Date: Tue Apr 2 14:39:54 2013 +0200 fdo#62525: use cow_wrapper for LineAttribute Change-Id: I8934156790051d52dd317b6654b1cc2e1bc381a4 diff --git a/drawinglayer/inc/drawinglayer/attribute/lineattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/lineattribute.hxx index 4984a12..58eb987 100644 --- a/drawinglayer/inc/drawinglayer/attribute/lineattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/lineattribute.hxx @@ -24,6 +24,7 @@ #include <basegfx/vector/b2enums.hxx> #include <com/sun/star/drawing/LineCap.hpp> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -44,8 +45,11 @@ namespace drawinglayer { class DRAWINGLAYER_DLLPUBLIC LineAttribute { + public: + typedef o3tl::cow_wrapper< ImpLineAttribute > ImplType; + private: - ImpLineAttribute* mpLineAttribute; + ImplType mpLineAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/lineattribute.cxx b/drawinglayer/source/attribute/lineattribute.cxx index 6d506c01..e7859bf4 100644 --- a/drawinglayer/source/attribute/lineattribute.cxx +++ b/drawinglayer/source/attribute/lineattribute.cxx @@ -19,6 +19,7 @@ #include <drawinglayer/attribute/lineattribute.hxx> #include <basegfx/color/bcolor.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpLineAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // data definitions basegfx::BColor maColor; // color double mfWidth; // absolute line width @@ -43,14 +41,21 @@ namespace drawinglayer double fWidth, basegfx::B2DLineJoin aB2DLineJoin, com::sun::star::drawing::LineCap aLineCap) - : mnRefCount(0), - maColor(rColor), + : maColor(rColor), mfWidth(fWidth), meLineJoin(aB2DLineJoin), meLineCap(aLineCap) { } + ImpLineAttribute() + : maColor(basegfx::BColor()), + mfWidth(0.0), + meLineJoin(basegfx::B2DLINEJOIN_ROUND), + meLineCap(com::sun::star::drawing::LineCap_BUTT) + { + } + // data read access const basegfx::BColor& getColor() const { return maColor; } double getWidth() const { return mfWidth; } @@ -64,34 +69,21 @@ namespace drawinglayer && getLineJoin() == rCandidate.getLineJoin() && getLineCap() == rCandidate.getLineCap()); } - - static ImpLineAttribute* get_global_default() - { - static ImpLineAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpLineAttribute( - basegfx::BColor(), - 0.0, - basegfx::B2DLINEJOIN_ROUND, - com::sun::star::drawing::LineCap_BUTT); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< LineAttribute::ImplType, theGlobalDefault > {}; + } + LineAttribute::LineAttribute( const basegfx::BColor& rColor, double fWidth, basegfx::B2DLineJoin aB2DLineJoin, com::sun::star::drawing::LineCap aLineCap) : mpLineAttribute( - new ImpLineAttribute( + ImpLineAttribute( rColor, fWidth, aB2DLineJoin, @@ -100,67 +92,33 @@ namespace drawinglayer } LineAttribute::LineAttribute() - : mpLineAttribute(ImpLineAttribute::get_global_default()) + : mpLineAttribute(theGlobalDefault::get()) { - mpLineAttribute->mnRefCount++; } LineAttribute::LineAttribute(const LineAttribute& rCandidate) : mpLineAttribute(rCandidate.mpLineAttribute) { - mpLineAttribute->mnRefCount++; } LineAttribute::~LineAttribute() { - if(mpLineAttribute->mnRefCount) - { - mpLineAttribute->mnRefCount--; - } - else - { - delete mpLineAttribute; - } } bool LineAttribute::isDefault() const { - return mpLineAttribute == ImpLineAttribute::get_global_default(); + return mpLineAttribute.same_object(theGlobalDefault::get()); } LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate) { - if(rCandidate.mpLineAttribute != mpLineAttribute) - { - if(mpLineAttribute->mnRefCount) - { - mpLineAttribute->mnRefCount--; - } - else - { - delete mpLineAttribute; - } - - mpLineAttribute = rCandidate.mpLineAttribute; - mpLineAttribute->mnRefCount++; - } - + mpLineAttribute = rCandidate.mpLineAttribute; return *this; } bool LineAttribute::operator==(const LineAttribute& rCandidate) const { - if(rCandidate.mpLineAttribute == mpLineAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpLineAttribute == *mpLineAttribute); + return rCandidate.mpLineAttribute == mpLineAttribute; } const basegfx::BColor& LineAttribute::getColor() const _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits