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

fdo#62525: use cow_wrapper for SdrLightingAttribute

Change-Id: Ibd6bd31ef78f2e853ff668f64202eff89afb1234
üst f61b5c36
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLIGHTINGATTRIBUTE3D_HXX #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRLIGHTINGATTRIBUTE3D_HXX
#include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/drawinglayerdllapi.h>
#include <o3tl/cow_wrapper.hxx>
#include <vector> #include <vector>
...@@ -45,8 +46,11 @@ namespace drawinglayer ...@@ -45,8 +46,11 @@ namespace drawinglayer
{ {
class DRAWINGLAYER_DLLPUBLIC SdrLightingAttribute class DRAWINGLAYER_DLLPUBLIC SdrLightingAttribute
{ {
public:
typedef o3tl::cow_wrapper< ImpSdrLightingAttribute > ImplType;
private: private:
ImpSdrLightingAttribute* mpSdrLightingAttribute; ImplType mpSdrLightingAttribute;
public: public:
/// constructors/assignmentoperator/destructor /// constructors/assignmentoperator/destructor
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <basegfx/color/bcolor.hxx> #include <basegfx/color/bcolor.hxx>
#include <basegfx/vector/b3dvector.hxx> #include <basegfx/vector/b3dvector.hxx>
#include <drawinglayer/attribute/sdrlightattribute3d.hxx> #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
#include <rtl/instance.hxx>
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -31,9 +32,6 @@ namespace drawinglayer ...@@ -31,9 +32,6 @@ namespace drawinglayer
class ImpSdrLightingAttribute class ImpSdrLightingAttribute
{ {
public: public:
// refcounter
sal_uInt32 mnRefCount;
// 3D light attribute definitions // 3D light attribute definitions
basegfx::BColor maAmbientLight; basegfx::BColor maAmbientLight;
::std::vector< Sdr3DLightAttribute > maLightVector; ::std::vector< Sdr3DLightAttribute > maLightVector;
...@@ -41,12 +39,17 @@ namespace drawinglayer ...@@ -41,12 +39,17 @@ namespace drawinglayer
ImpSdrLightingAttribute( ImpSdrLightingAttribute(
const basegfx::BColor& rAmbientLight, const basegfx::BColor& rAmbientLight,
const ::std::vector< Sdr3DLightAttribute >& rLightVector) const ::std::vector< Sdr3DLightAttribute >& rLightVector)
: mnRefCount(0), : maAmbientLight(rAmbientLight),
maAmbientLight(rAmbientLight),
maLightVector(rLightVector) maLightVector(rLightVector)
{ {
} }
ImpSdrLightingAttribute()
: maAmbientLight(basegfx::BColor()),
maLightVector(std::vector< Sdr3DLightAttribute >())
{
}
// data read access // data read access
const basegfx::BColor& getAmbientLight() const { return maAmbientLight; } const basegfx::BColor& getAmbientLight() const { return maAmbientLight; }
const ::std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; } const ::std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; }
...@@ -56,95 +59,50 @@ namespace drawinglayer ...@@ -56,95 +59,50 @@ namespace drawinglayer
return (getAmbientLight() == rCandidate.getAmbientLight() return (getAmbientLight() == rCandidate.getAmbientLight()
&& getLightVector() == rCandidate.getLightVector()); && getLightVector() == rCandidate.getLightVector());
} }
};
static ImpSdrLightingAttribute* get_global_default() namespace
{
static ImpSdrLightingAttribute* pDefault = 0;
if(!pDefault)
{ {
pDefault = new ImpSdrLightingAttribute( struct theGlobalDefault :
basegfx::BColor(), public rtl::Static< SdrLightingAttribute::ImplType, theGlobalDefault > {};
std::vector< Sdr3DLightAttribute >());
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
} }
return pDefault;
}
};
SdrLightingAttribute::SdrLightingAttribute( SdrLightingAttribute::SdrLightingAttribute(
const basegfx::BColor& rAmbientLight, const basegfx::BColor& rAmbientLight,
const ::std::vector< Sdr3DLightAttribute >& rLightVector) const ::std::vector< Sdr3DLightAttribute >& rLightVector)
: mpSdrLightingAttribute(new ImpSdrLightingAttribute( : mpSdrLightingAttribute(ImpSdrLightingAttribute(
rAmbientLight, rLightVector)) rAmbientLight, rLightVector))
{ {
} }
SdrLightingAttribute::SdrLightingAttribute() SdrLightingAttribute::SdrLightingAttribute()
: mpSdrLightingAttribute(ImpSdrLightingAttribute::get_global_default()) : mpSdrLightingAttribute(theGlobalDefault::get())
{ {
mpSdrLightingAttribute->mnRefCount++;
} }
SdrLightingAttribute::SdrLightingAttribute(const SdrLightingAttribute& rCandidate) SdrLightingAttribute::SdrLightingAttribute(const SdrLightingAttribute& rCandidate)
: mpSdrLightingAttribute(rCandidate.mpSdrLightingAttribute) : mpSdrLightingAttribute(rCandidate.mpSdrLightingAttribute)
{ {
mpSdrLightingAttribute->mnRefCount++;
} }
SdrLightingAttribute::~SdrLightingAttribute() SdrLightingAttribute::~SdrLightingAttribute()
{ {
if(mpSdrLightingAttribute->mnRefCount)
{
mpSdrLightingAttribute->mnRefCount--;
}
else
{
delete mpSdrLightingAttribute;
}
} }
bool SdrLightingAttribute::isDefault() const bool SdrLightingAttribute::isDefault() const
{ {
return mpSdrLightingAttribute == ImpSdrLightingAttribute::get_global_default(); return mpSdrLightingAttribute.same_object(theGlobalDefault::get());
} }
SdrLightingAttribute& SdrLightingAttribute::operator=(const SdrLightingAttribute& rCandidate) SdrLightingAttribute& SdrLightingAttribute::operator=(const SdrLightingAttribute& rCandidate)
{ {
if(rCandidate.mpSdrLightingAttribute != mpSdrLightingAttribute)
{
if(mpSdrLightingAttribute->mnRefCount)
{
mpSdrLightingAttribute->mnRefCount--;
}
else
{
delete mpSdrLightingAttribute;
}
mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute; mpSdrLightingAttribute = rCandidate.mpSdrLightingAttribute;
mpSdrLightingAttribute->mnRefCount++;
}
return *this; return *this;
} }
bool SdrLightingAttribute::operator==(const SdrLightingAttribute& rCandidate) const bool SdrLightingAttribute::operator==(const SdrLightingAttribute& rCandidate) const
{ {
if(rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute) return rCandidate.mpSdrLightingAttribute == mpSdrLightingAttribute;
{
return true;
}
if(rCandidate.isDefault() != isDefault())
{
return false;
}
return (*rCandidate.mpSdrLightingAttribute == *mpSdrLightingAttribute);
} }
const ::std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() const const ::std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() 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