summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorThomas Arnhold <thomas@arnhold.org>2013-04-02 14:46:32 +0200
committerThomas Arnhold <thomas@arnhold.org>2013-04-02 14:56:43 +0200
commit4e188ae252322485c54b4c3a6c081bde2f966a9f (patch)
treeffe119482514ddfeb1f108c79a5fad27145dffd6 /drawinglayer
parent44e7cb139d921d6c003d4367a8064bc653342541 (diff)
fdo#62525: use cow_wrapper for LineStartEndAttribute
Change-Id: Id8803574245298c6d15b3c59bbfd3b7c812b5794
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx6
-rw-r--r--drawinglayer/source/attribute/linestartendattribute.cxx82
2 files changed, 25 insertions, 63 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/linestartendattribute.hxx
index 563991915cae..e02d3565aaf7 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 e1208ff7a73e..0e3936157c08 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