Kaydet (Commit) 8ee042bd authored tarafından Thomas Arnhold's avatar Thomas Arnhold

fdo#62525: use cow_wrapper for SdrLineAttribute

Change-Id: I62b897bd49ef05a3862cb2cd91c3aa13f621e9fd
üst 4f989f30
......@@ -21,9 +21,9 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLINEATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h>
#include <basegfx/vector/b2enums.hxx>
#include <com/sun/star/drawing/LineCap.hpp>
#include <o3tl/cow_wrapper.hxx>
#include <vector>
//////////////////////////////////////////////////////////////////////////////
......@@ -45,8 +45,11 @@ namespace drawinglayer
{
class DRAWINGLAYER_DLLPUBLIC SdrLineAttribute
{
public:
typedef o3tl::cow_wrapper< ImpSdrLineAttribute > ImplType;
private:
ImpSdrLineAttribute* mpSdrLineAttribute;
ImplType mpSdrLineAttribute;
public:
/// constructors/assignmentoperator/destructor
......
......@@ -19,6 +19,7 @@
#include <drawinglayer/attribute/sdrlineattribute.hxx>
#include <basegfx/color/bcolor.hxx>
#include <rtl/instance.hxx>
//////////////////////////////////////////////////////////////////////////////
......@@ -29,9 +30,6 @@ namespace drawinglayer
class ImpSdrLineAttribute
{
public:
// refcounter
sal_uInt32 mnRefCount;
// line definitions
basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines
double mfWidth; // 1/100th mm, 0.0==hair
......@@ -49,8 +47,7 @@ namespace drawinglayer
com::sun::star::drawing::LineCap eCap,
const ::std::vector< double >& rDotDashArray,
double fFullDotDashLen)
: mnRefCount(0),
meJoin(eJoin),
: meJoin(eJoin),
mfWidth(fWidth),
mfTransparence(fTransparence),
maColor(rColor),
......@@ -61,8 +58,7 @@ namespace drawinglayer
}
explicit ImpSdrLineAttribute(const basegfx::BColor& rColor)
: mnRefCount(0),
meJoin(basegfx::B2DLINEJOIN_NONE),
: meJoin(basegfx::B2DLINEJOIN_NONE),
mfWidth(0.0),
mfTransparence(0.0),
maColor(rColor),
......@@ -72,6 +68,17 @@ namespace drawinglayer
{
}
ImpSdrLineAttribute()
: meJoin(basegfx::B2DLINEJOIN_ROUND),
mfWidth(0.0),
mfTransparence(0.0),
maColor(basegfx::BColor()),
meCap(com::sun::star::drawing::LineCap_BUTT),
maDotDashArray(std::vector< double >()),
mfFullDotDashLen(0.0)
{
}
// data read access
basegfx::B2DLineJoin getJoin() const { return meJoin; }
double getWidth() const { return mfWidth; }
......@@ -90,29 +97,13 @@ namespace drawinglayer
&& getCap() == rCandidate.getCap()
&& getDotDashArray() == rCandidate.getDotDashArray());
}
};
static ImpSdrLineAttribute* get_global_default()
{
static ImpSdrLineAttribute* pDefault = 0;
if(!pDefault)
namespace
{
pDefault = new ImpSdrLineAttribute(
basegfx::B2DLINEJOIN_ROUND,
0.0,
0.0,
basegfx::BColor(),
com::sun::star::drawing::LineCap_BUTT,
std::vector< double >(),
0.0);
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
}
return pDefault;
struct theGlobalDefault :
public rtl::Static< SdrLineAttribute::ImplType, theGlobalDefault > {};
}
};
SdrLineAttribute::SdrLineAttribute(
basegfx::B2DLineJoin eJoin,
......@@ -123,7 +114,7 @@ namespace drawinglayer
const ::std::vector< double >& rDotDashArray,
double fFullDotDashLen)
: mpSdrLineAttribute(
new ImpSdrLineAttribute(
ImpSdrLineAttribute(
eJoin,
fWidth,
fTransparence,
......@@ -136,67 +127,33 @@ namespace drawinglayer
}
SdrLineAttribute::SdrLineAttribute()
: mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default())
: mpSdrLineAttribute(theGlobalDefault::get())
{
mpSdrLineAttribute->mnRefCount++;
}
SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate)
: mpSdrLineAttribute(rCandidate.mpSdrLineAttribute)
{
mpSdrLineAttribute->mnRefCount++;
}
SdrLineAttribute::~SdrLineAttribute()
{
if(mpSdrLineAttribute->mnRefCount)
{
mpSdrLineAttribute->mnRefCount--;
}
else
{
delete mpSdrLineAttribute;
}
}
bool SdrLineAttribute::isDefault() const
{
return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default();
return mpSdrLineAttribute.same_object(theGlobalDefault::get());
}
SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate)
{
if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute)
{
if(mpSdrLineAttribute->mnRefCount)
{
mpSdrLineAttribute->mnRefCount--;
}
else
{
delete mpSdrLineAttribute;
}
mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
mpSdrLineAttribute->mnRefCount++;
}
return *this;
}
bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const
{
if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute)
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute);
return rCandidate.mpSdrLineAttribute == mpSdrLineAttribute;
}
basegfx::B2DLineJoin SdrLineAttribute::getJoin() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment