summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drawinglayer/inc/drawinglayer/attribute/sdrlinestartendattribute.hxx6
-rw-r--r--drawinglayer/source/attribute/sdrlinestartendattribute.cxx92
2 files changed, 30 insertions, 68 deletions
diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrlinestartendattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrlinestartendattribute.hxx
index 2715bb78ae6c..19c1a5147db0 100644
--- a/drawinglayer/inc/drawinglayer/attribute/sdrlinestartendattribute.hxx
+++ b/drawinglayer/inc/drawinglayer/attribute/sdrlinestartendattribute.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLINESTARTENDATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h>
+#include <o3tl/cow_wrapper.hxx>
//////////////////////////////////////////////////////////////////////////////
// predefines
@@ -41,8 +42,11 @@ namespace drawinglayer
{
class DRAWINGLAYER_DLLPUBLIC SdrLineStartEndAttribute
{
+ public:
+ typedef o3tl::cow_wrapper< ImpSdrLineStartEndAttribute > ImplType;
+
private:
- ImpSdrLineStartEndAttribute* mpSdrLineStartEndAttribute;
+ ImplType mpSdrLineStartEndAttribute;
public:
/// constructors/assignmentoperator/destructor
diff --git a/drawinglayer/source/attribute/sdrlinestartendattribute.cxx b/drawinglayer/source/attribute/sdrlinestartendattribute.cxx
index 1fe894d31f85..c4851da75dd9 100644
--- a/drawinglayer/source/attribute/sdrlinestartendattribute.cxx
+++ b/drawinglayer/source/attribute/sdrlinestartendattribute.cxx
@@ -19,6 +19,7 @@
#include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <rtl/instance.hxx>
//////////////////////////////////////////////////////////////////////////////
@@ -29,9 +30,6 @@ namespace drawinglayer
class ImpSdrLineStartEndAttribute
{
public:
- // refcounter
- sal_uInt32 mnRefCount;
-
// line arrow definitions
basegfx::B2DPolyPolygon maStartPolyPolygon; // start Line PolyPolygon
basegfx::B2DPolyPolygon maEndPolyPolygon; // end Line PolyPolygon
@@ -53,8 +51,7 @@ namespace drawinglayer
bool bEndActive,
bool bStartCentered,
bool bEndCentered)
- : mnRefCount(0),
- maStartPolyPolygon(rStartPolyPolygon),
+ : maStartPolyPolygon(rStartPolyPolygon),
maEndPolyPolygon(rEndPolyPolygon),
mfStartWidth(fStartWidth),
mfEndWidth(fEndWidth),
@@ -65,6 +62,18 @@ namespace drawinglayer
{
}
+ ImpSdrLineStartEndAttribute()
+ : maStartPolyPolygon(basegfx::B2DPolyPolygon()),
+ maEndPolyPolygon(basegfx::B2DPolyPolygon()),
+ mfStartWidth(0.0),
+ mfEndWidth(0.0),
+ mbStartActive(false),
+ mbEndActive(false),
+ mbStartCentered(false),
+ mbEndCentered(false)
+ {
+ }
+
// data read access
const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; }
const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; }
@@ -86,31 +95,14 @@ namespace drawinglayer
&& isStartCentered() == rCandidate.isStartCentered()
&& isEndCentered() == rCandidate.isEndCentered());
}
-
- static ImpSdrLineStartEndAttribute* get_global_default()
- {
- static ImpSdrLineStartEndAttribute* pDefault = 0;
-
- if(!pDefault)
- {
- pDefault = new ImpSdrLineStartEndAttribute(
- basegfx::B2DPolyPolygon(),
- basegfx::B2DPolyPolygon(),
- 0.0,
- 0.0,
- false,
- false,
- false,
- false);
-
- // never delete; start with RefCount 1, not 0
- pDefault->mnRefCount++;
- }
-
- return pDefault;
- }
};
+ namespace
+ {
+ struct theGlobalDefault :
+ public rtl::Static< SdrLineStartEndAttribute::ImplType, theGlobalDefault > {};
+ }
+
SdrLineStartEndAttribute::SdrLineStartEndAttribute(
const basegfx::B2DPolyPolygon& rStartPolyPolygon,
const basegfx::B2DPolyPolygon& rEndPolyPolygon,
@@ -120,73 +112,39 @@ namespace drawinglayer
bool bEndActive,
bool bStartCentered,
bool bEndCentered)
- : mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute(
+ : mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute(
rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered))
{
}
SdrLineStartEndAttribute::SdrLineStartEndAttribute()
- : mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default())
+ : mpSdrLineStartEndAttribute(theGlobalDefault::get())
{
- mpSdrLineStartEndAttribute->mnRefCount++;
}
SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate)
: mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute)
{
- mpSdrLineStartEndAttribute->mnRefCount++;
}
SdrLineStartEndAttribute::~SdrLineStartEndAttribute()
{
- if(mpSdrLineStartEndAttribute->mnRefCount)
- {
- mpSdrLineStartEndAttribute->mnRefCount--;
- }
- else
- {
- delete mpSdrLineStartEndAttribute;
- }
}
bool SdrLineStartEndAttribute::isDefault() const
{
- return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default();
+ return mpSdrLineStartEndAttribute.same_object(theGlobalDefault::get());
}
SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate)
{
- if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute)
- {
- if(mpSdrLineStartEndAttribute->mnRefCount)
- {
- mpSdrLineStartEndAttribute->mnRefCount--;
- }
- else
- {
- delete mpSdrLineStartEndAttribute;
- }
-
- mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
- mpSdrLineStartEndAttribute->mnRefCount++;
- }
-
+ mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
return *this;
}
bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const
{
- if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute)
- {
- return true;
- }
-
- if(rCandidate.isDefault() != isDefault())
- {
- return false;
- }
-
- return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute);
+ return rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute;
}
const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const