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

fdo#62525: use cow_wrapper for Sdr3DLightAttribute

Change-Id: I9639746d072642d46c3f0766c473425221b1706a
üst f5cf7f36
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLIGHTATTRIBUTE3D_HXX #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLIGHTATTRIBUTE3D_HXX
#include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/drawinglayerdllapi.h>
#include <o3tl/cow_wrapper.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// predefines // predefines
...@@ -42,8 +43,11 @@ namespace drawinglayer ...@@ -42,8 +43,11 @@ namespace drawinglayer
{ {
class DRAWINGLAYER_DLLPUBLIC Sdr3DLightAttribute class DRAWINGLAYER_DLLPUBLIC Sdr3DLightAttribute
{ {
public:
typedef o3tl::cow_wrapper< ImpSdr3DLightAttribute > ImplType;
private: private:
ImpSdr3DLightAttribute* mpSdr3DLightAttribute; ImplType mpSdr3DLightAttribute;
public: public:
// constructors/destructor // constructors/destructor
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <drawinglayer/attribute/sdrlightattribute3d.hxx> #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
#include <basegfx/color/bcolor.hxx> #include <basegfx/color/bcolor.hxx>
#include <basegfx/vector/b3dvector.hxx> #include <basegfx/vector/b3dvector.hxx>
#include <rtl/instance.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -30,9 +31,6 @@ namespace drawinglayer ...@@ -30,9 +31,6 @@ namespace drawinglayer
class ImpSdr3DLightAttribute class ImpSdr3DLightAttribute
{ {
public: public:
// refcounter
sal_uInt32 mnRefCount;
// 3D light attribute definitions // 3D light attribute definitions
basegfx::BColor maColor; basegfx::BColor maColor;
basegfx::B3DVector maDirection; basegfx::B3DVector maDirection;
...@@ -44,13 +42,19 @@ namespace drawinglayer ...@@ -44,13 +42,19 @@ namespace drawinglayer
const basegfx::BColor& rColor, const basegfx::BColor& rColor,
const basegfx::B3DVector& rDirection, const basegfx::B3DVector& rDirection,
bool bSpecular) bool bSpecular)
: mnRefCount(0), : maColor(rColor),
maColor(rColor),
maDirection(rDirection), maDirection(rDirection),
mbSpecular(bSpecular) mbSpecular(bSpecular)
{ {
} }
ImpSdr3DLightAttribute()
: maColor(basegfx::BColor()),
maDirection(basegfx::B3DVector()),
mbSpecular(false)
{
}
// data read access // data read access
const basegfx::BColor& getColor() const { return maColor; } const basegfx::BColor& getColor() const { return maColor; }
const basegfx::B3DVector& getDirection() const { return maDirection; } const basegfx::B3DVector& getDirection() const { return maDirection; }
...@@ -62,31 +66,19 @@ namespace drawinglayer ...@@ -62,31 +66,19 @@ namespace drawinglayer
&& getDirection() == rCandidate.getDirection() && getDirection() == rCandidate.getDirection()
&& getSpecular() == rCandidate.getSpecular()); && getSpecular() == rCandidate.getSpecular());
} }
static ImpSdr3DLightAttribute* get_global_default()
{
static ImpSdr3DLightAttribute* pDefault = 0;
if(!pDefault)
{
pDefault = new ImpSdr3DLightAttribute(
basegfx::BColor(),
basegfx::B3DVector(),
false);
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
}
return pDefault;
}
}; };
namespace
{
struct theGlobalDefault :
public rtl::Static< Sdr3DLightAttribute::ImplType, theGlobalDefault > {};
}
Sdr3DLightAttribute::Sdr3DLightAttribute( Sdr3DLightAttribute::Sdr3DLightAttribute(
const basegfx::BColor& rColor, const basegfx::BColor& rColor,
const basegfx::B3DVector& rDirection, const basegfx::B3DVector& rDirection,
bool bSpecular) bool bSpecular)
: mpSdr3DLightAttribute(new ImpSdr3DLightAttribute( : mpSdr3DLightAttribute(ImpSdr3DLightAttribute(
rColor, rDirection, bSpecular)) rColor, rDirection, bSpecular))
{ {
} }
...@@ -94,59 +86,26 @@ namespace drawinglayer ...@@ -94,59 +86,26 @@ namespace drawinglayer
Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate) Sdr3DLightAttribute::Sdr3DLightAttribute(const Sdr3DLightAttribute& rCandidate)
: mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute) : mpSdr3DLightAttribute(rCandidate.mpSdr3DLightAttribute)
{ {
mpSdr3DLightAttribute->mnRefCount++;
} }
Sdr3DLightAttribute::~Sdr3DLightAttribute() Sdr3DLightAttribute::~Sdr3DLightAttribute()
{ {
if(mpSdr3DLightAttribute->mnRefCount)
{
mpSdr3DLightAttribute->mnRefCount--;
}
else
{
delete mpSdr3DLightAttribute;
}
} }
bool Sdr3DLightAttribute::isDefault() const bool Sdr3DLightAttribute::isDefault() const
{ {
return mpSdr3DLightAttribute == ImpSdr3DLightAttribute::get_global_default(); return mpSdr3DLightAttribute.same_object(theGlobalDefault::get());
} }
Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate) Sdr3DLightAttribute& Sdr3DLightAttribute::operator=(const Sdr3DLightAttribute& rCandidate)
{ {
if(rCandidate.mpSdr3DLightAttribute != mpSdr3DLightAttribute) mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute;
{
if(mpSdr3DLightAttribute->mnRefCount)
{
mpSdr3DLightAttribute->mnRefCount--;
}
else
{
delete mpSdr3DLightAttribute;
}
mpSdr3DLightAttribute = rCandidate.mpSdr3DLightAttribute;
mpSdr3DLightAttribute->mnRefCount++;
}
return *this; return *this;
} }
bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute& rCandidate) const
{ {
if(rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute) return rCandidate.mpSdr3DLightAttribute == mpSdr3DLightAttribute;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpSdr3DLightAttribute == *mpSdr3DLightAttribute);
} }
const basegfx::BColor& Sdr3DLightAttribute::getColor() const const basegfx::BColor& Sdr3DLightAttribute::getColor() 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