diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-03-27 03:51:53 +0100 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-03-27 13:17:40 +0100 |
commit | 32ec7666596b2a0f27c72f9d856e2ec0f0545f6b (patch) | |
tree | 29ed24a59a586644c13ed28a72104d878df65938 /drawinglayer | |
parent | 0bca4ccd54263bdef3722d96fe98760a5966c2f4 (diff) |
fdo#62525: use cow_wrapper for FontAttribute
Change-Id: Ic07da7c7cf225a910e6f0fa4f6d20c4700e7ec7a
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/attribute/fontattribute.cxx | 89 |
2 files changed, 32 insertions, 63 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx index 36686fe1c912..b49ab83b300e 100644 --- a/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FONTATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -44,8 +45,11 @@ namespace drawinglayer */ class DRAWINGLAYER_DLLPUBLIC FontAttribute { + public: + typedef o3tl::cow_wrapper< ImpFontAttribute > ImplType; + private: - ImpFontAttribute* mpFontAttribute; + ImplType mpFontAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/fontattribute.cxx b/drawinglayer/source/attribute/fontattribute.cxx index 627fb6c439db..7f4316f00794 100644 --- a/drawinglayer/source/attribute/fontattribute.cxx +++ b/drawinglayer/source/attribute/fontattribute.cxx @@ -18,6 +18,7 @@ */ #include <drawinglayer/attribute/fontattribute.hxx> +#include <rtl/instance.hxx> #include <tools/string.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -29,9 +30,6 @@ namespace drawinglayer class ImpFontAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - /// core data String maFamilyName; // Font Family Name String maStyleName; // Font Style Name @@ -57,8 +55,7 @@ namespace drawinglayer bool bOutline, bool bRTL, bool bBiDiStrong) - : mnRefCount(0), - maFamilyName(rFamilyName), + : maFamilyName(rFamilyName), maStyleName(rStyleName), mnWeight(nWeight), mbSymbol(bSymbol), @@ -71,6 +68,20 @@ namespace drawinglayer { } + ImpFontAttribute() + : maFamilyName(), + maStyleName(), + mnWeight(0), + mbSymbol(false), + mbVertical(false), + mbItalic(false), + mbOutline(false), + mbRTL(false), + mbBiDiStrong(false), + mbMonospaced(false) + { + } + // data read access const String& getFamilyName() const { return maFamilyName; } const String& getStyleName() const { return maStyleName; } @@ -96,26 +107,14 @@ namespace drawinglayer && getBiDiStrong() == rCompare.getBiDiStrong() && getMonospaced() == rCompare.getMonospaced()); } - - static ImpFontAttribute* get_global_default() - { - static ImpFontAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpFontAttribute( - String(), String(), - 0, - false, false, false, false, false, false, false); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + namespace + { + struct theGlobalDefault : + public rtl::Static< FontAttribute::ImplType, theGlobalDefault > {}; + } + FontAttribute::FontAttribute( const String& rFamilyName, const String& rStyleName, @@ -127,73 +126,39 @@ namespace drawinglayer bool bOutline, bool bRTL, bool bBiDiStrong) - : mpFontAttribute(new ImpFontAttribute( + : mpFontAttribute(ImpFontAttribute( rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong)) { } FontAttribute::FontAttribute() - : mpFontAttribute(ImpFontAttribute::get_global_default()) + : mpFontAttribute(theGlobalDefault::get()) { - mpFontAttribute->mnRefCount++; } FontAttribute::FontAttribute(const FontAttribute& rCandidate) : mpFontAttribute(rCandidate.mpFontAttribute) { - mpFontAttribute->mnRefCount++; } FontAttribute::~FontAttribute() { - if(mpFontAttribute->mnRefCount) - { - mpFontAttribute->mnRefCount--; - } - else - { - delete mpFontAttribute; - } } bool FontAttribute::isDefault() const { - return mpFontAttribute == ImpFontAttribute::get_global_default(); + return mpFontAttribute.same_object(theGlobalDefault::get()); } FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate) { - if(rCandidate.mpFontAttribute != mpFontAttribute) - { - if(mpFontAttribute->mnRefCount) - { - mpFontAttribute->mnRefCount--; - } - else - { - delete mpFontAttribute; - } - - mpFontAttribute = rCandidate.mpFontAttribute; - mpFontAttribute->mnRefCount++; - } - + mpFontAttribute = rCandidate.mpFontAttribute; return *this; } bool FontAttribute::operator==(const FontAttribute& rCandidate) const { - if(rCandidate.mpFontAttribute == mpFontAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpFontAttribute == *mpFontAttribute); + return rCandidate.mpFontAttribute == mpFontAttribute; } const String& FontAttribute::getFamilyName() const |