diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2016-01-14 11:46:24 +1100 |
---|---|---|
committer | Chris Sherlock <chris.sherlock79@gmail.com> | 2016-01-14 11:46:28 +1100 |
commit | 43488d9de74d785445f5f7cbb80163bfb2e36c1b (patch) | |
tree | 4c511b24643c443dc0d33684936651dc6da5dbe2 /vcl | |
parent | 2496c497b6ffe9c69370ccc12bb103099c877165 (diff) |
vcl: FontMetric now has ImplFontMetricPtr objects
ImplFontMetricPtr is a typedef to an intrusive_ptr<ImplFontMetric>.
I have ditched the manual reference counting to use Boost's smart
pointer.
Change-Id: I5e93f45d19d43c8b7253f4342c1b9ef4a4301527
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/impfontmetric.hxx | 22 | ||||
-rw-r--r-- | vcl/source/gdi/metric.cxx | 29 |
2 files changed, 26 insertions, 25 deletions
diff --git a/vcl/inc/impfontmetric.hxx b/vcl/inc/impfontmetric.hxx index 226be2edfac5..7b9413f9fe4f 100644 --- a/vcl/inc/impfontmetric.hxx +++ b/vcl/inc/impfontmetric.hxx @@ -20,8 +20,17 @@ #ifndef INCLUDED_VCL_INC_IMPFONTMETRIC_HXX #define INCLUDED_VCL_INC_IMPFONTMETRIC_HXX +#include <boost/intrusive_ptr.hpp> + +class ImplFontCharMap; +typedef boost::intrusive_ptr< ImplFontCharMap > ImplFontCharMapPtr; + class ImplFontMetric { + friend class FontMetric; + friend void intrusive_ptr_add_ref(ImplFontMetric* pImplFontMetric); + friend void intrusive_ptr_release(ImplFontMetric* pImplFontMetric); + private: long mnAscent; // Ascent long mnDescent; // Descent @@ -41,8 +50,6 @@ public: bool operator==( const ImplFontMetric& ) const; ImplFontMetric(); - void AddReference(); - void DeReference(); long GetAscent() const { return mnAscent; } long GetDescent() const { return mnDescent; } @@ -70,6 +77,17 @@ public: }; +inline void intrusive_ptr_add_ref(ImplFontMetric* pImplFontMetric) +{ + ++pImplFontMetric->mnRefCount; +} + +inline void intrusive_ptr_release(ImplFontMetric* pImplFontMetric) +{ + if (--pImplFontMetric->mnRefCount == 0) + delete pImplFontMetric; +} + #endif // INCLUDED_VCL_INC_IMPFONTMETRIC_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/metric.cxx b/vcl/source/gdi/metric.cxx index eb7271d4a82e..adbb45420af0 100644 --- a/vcl/source/gdi/metric.cxx +++ b/vcl/source/gdi/metric.cxx @@ -26,19 +26,17 @@ #include <cstdio> FontMetric::FontMetric() -: mpImplMetric( new ImplFontMetric ) +: mpImplMetric( new ImplFontMetric() ) {} FontMetric::FontMetric( const FontMetric& rFontMetric ) -: Font( rFontMetric ) -{ - mpImplMetric = rFontMetric.mpImplMetric; - mpImplMetric->AddReference(); -} + : Font( rFontMetric ) + , mpImplMetric( rFontMetric.mpImplMetric ) +{} FontMetric::~FontMetric() { - mpImplMetric->DeReference(); + mpImplMetric = nullptr; } FontMetric& FontMetric::operator=( const FontMetric& rFontMetric ) @@ -47,9 +45,7 @@ FontMetric& FontMetric::operator=( const FontMetric& rFontMetric ) if( mpImplMetric != rFontMetric.mpImplMetric ) { - mpImplMetric->DeReference(); mpImplMetric = rFontMetric.mpImplMetric; - mpImplMetric->AddReference(); } return *this; @@ -181,25 +177,12 @@ ImplFontMetric::ImplFontMetric() mnLineHeight( 0 ), mnSlant( 0 ), mnBulletOffset( 0 ), - mnRefCount( 1 ), + mnRefCount( 0 ), mbScalableFont( false ), mbFullstopCentered( false ), mbDevice( false ) {} -inline void ImplFontMetric::AddReference() -{ - // TODO: disable refcounting on the default maps? - ++mnRefCount; -} - -inline void ImplFontMetric::DeReference() -{ - // TODO: disable refcounting on the default maps? - if( --mnRefCount <= 0 ) - delete this; -} - bool ImplFontMetric::operator==( const ImplFontMetric& r ) const { if( mbScalableFont != r.mbScalableFont |