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 @@ ...@@ -21,9 +21,9 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLINEATTRIBUTE_HXX #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLINEATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/drawinglayerdllapi.h>
#include <basegfx/vector/b2enums.hxx> #include <basegfx/vector/b2enums.hxx>
#include <com/sun/star/drawing/LineCap.hpp> #include <com/sun/star/drawing/LineCap.hpp>
#include <o3tl/cow_wrapper.hxx>
#include <vector> #include <vector>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -45,8 +45,11 @@ namespace drawinglayer ...@@ -45,8 +45,11 @@ namespace drawinglayer
{ {
class DRAWINGLAYER_DLLPUBLIC SdrLineAttribute class DRAWINGLAYER_DLLPUBLIC SdrLineAttribute
{ {
public:
typedef o3tl::cow_wrapper< ImpSdrLineAttribute > ImplType;
private: private:
ImpSdrLineAttribute* mpSdrLineAttribute; ImplType mpSdrLineAttribute;
public: public:
/// constructors/assignmentoperator/destructor /// constructors/assignmentoperator/destructor
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <drawinglayer/attribute/sdrlineattribute.hxx> #include <drawinglayer/attribute/sdrlineattribute.hxx>
#include <basegfx/color/bcolor.hxx> #include <basegfx/color/bcolor.hxx>
#include <rtl/instance.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -29,9 +30,6 @@ namespace drawinglayer ...@@ -29,9 +30,6 @@ namespace drawinglayer
class ImpSdrLineAttribute class ImpSdrLineAttribute
{ {
public: public:
// refcounter
sal_uInt32 mnRefCount;
// line definitions // line definitions
basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines
double mfWidth; // 1/100th mm, 0.0==hair double mfWidth; // 1/100th mm, 0.0==hair
...@@ -49,8 +47,7 @@ namespace drawinglayer ...@@ -49,8 +47,7 @@ namespace drawinglayer
com::sun::star::drawing::LineCap eCap, com::sun::star::drawing::LineCap eCap,
const ::std::vector< double >& rDotDashArray, const ::std::vector< double >& rDotDashArray,
double fFullDotDashLen) double fFullDotDashLen)
: mnRefCount(0), : meJoin(eJoin),
meJoin(eJoin),
mfWidth(fWidth), mfWidth(fWidth),
mfTransparence(fTransparence), mfTransparence(fTransparence),
maColor(rColor), maColor(rColor),
...@@ -61,8 +58,7 @@ namespace drawinglayer ...@@ -61,8 +58,7 @@ namespace drawinglayer
} }
explicit ImpSdrLineAttribute(const basegfx::BColor& rColor) explicit ImpSdrLineAttribute(const basegfx::BColor& rColor)
: mnRefCount(0), : meJoin(basegfx::B2DLINEJOIN_NONE),
meJoin(basegfx::B2DLINEJOIN_NONE),
mfWidth(0.0), mfWidth(0.0),
mfTransparence(0.0), mfTransparence(0.0),
maColor(rColor), maColor(rColor),
...@@ -72,6 +68,17 @@ namespace drawinglayer ...@@ -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 // data read access
basegfx::B2DLineJoin getJoin() const { return meJoin; } basegfx::B2DLineJoin getJoin() const { return meJoin; }
double getWidth() const { return mfWidth; } double getWidth() const { return mfWidth; }
...@@ -90,30 +97,14 @@ namespace drawinglayer ...@@ -90,30 +97,14 @@ namespace drawinglayer
&& getCap() == rCandidate.getCap() && getCap() == rCandidate.getCap()
&& getDotDashArray() == rCandidate.getDotDashArray()); && getDotDashArray() == rCandidate.getDotDashArray());
} }
static ImpSdrLineAttribute* get_global_default()
{
static ImpSdrLineAttribute* pDefault = 0;
if(!pDefault)
{
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;
}
}; };
namespace
{
struct theGlobalDefault :
public rtl::Static< SdrLineAttribute::ImplType, theGlobalDefault > {};
}
SdrLineAttribute::SdrLineAttribute( SdrLineAttribute::SdrLineAttribute(
basegfx::B2DLineJoin eJoin, basegfx::B2DLineJoin eJoin,
double fWidth, double fWidth,
...@@ -123,7 +114,7 @@ namespace drawinglayer ...@@ -123,7 +114,7 @@ namespace drawinglayer
const ::std::vector< double >& rDotDashArray, const ::std::vector< double >& rDotDashArray,
double fFullDotDashLen) double fFullDotDashLen)
: mpSdrLineAttribute( : mpSdrLineAttribute(
new ImpSdrLineAttribute( ImpSdrLineAttribute(
eJoin, eJoin,
fWidth, fWidth,
fTransparence, fTransparence,
...@@ -136,67 +127,33 @@ namespace drawinglayer ...@@ -136,67 +127,33 @@ namespace drawinglayer
} }
SdrLineAttribute::SdrLineAttribute() SdrLineAttribute::SdrLineAttribute()
: mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default()) : mpSdrLineAttribute(theGlobalDefault::get())
{ {
mpSdrLineAttribute->mnRefCount++;
} }
SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate) SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate)
: mpSdrLineAttribute(rCandidate.mpSdrLineAttribute) : mpSdrLineAttribute(rCandidate.mpSdrLineAttribute)
{ {
mpSdrLineAttribute->mnRefCount++;
} }
SdrLineAttribute::~SdrLineAttribute() SdrLineAttribute::~SdrLineAttribute()
{ {
if(mpSdrLineAttribute->mnRefCount)
{
mpSdrLineAttribute->mnRefCount--;
}
else
{
delete mpSdrLineAttribute;
}
} }
bool SdrLineAttribute::isDefault() const bool SdrLineAttribute::isDefault() const
{ {
return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default(); return mpSdrLineAttribute.same_object(theGlobalDefault::get());
} }
SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate) SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate)
{ {
if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute) mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
{
if(mpSdrLineAttribute->mnRefCount)
{
mpSdrLineAttribute->mnRefCount--;
}
else
{
delete mpSdrLineAttribute;
}
mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
mpSdrLineAttribute->mnRefCount++;
}
return *this; return *this;
} }
bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const
{ {
if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute) return rCandidate.mpSdrLineAttribute == mpSdrLineAttribute;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute);
} }
basegfx::B2DLineJoin SdrLineAttribute::getJoin() const 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