Use boost::intrusive_ptr in lieu of manual ref-counting.
Change-Id: I0a29a1e490f5aa52a9057be71164573e403affe9
This commit is contained in:
parent
af246f9455
commit
aa3babb42f
1 changed files with 57 additions and 69 deletions
|
@ -32,24 +32,25 @@
|
||||||
#include <vcl/bitmap.hxx>
|
#include <vcl/bitmap.hxx>
|
||||||
#include <tools/stream.hxx>
|
#include <tools/stream.hxx>
|
||||||
|
|
||||||
|
#include <boost/intrusive_ptr.hpp>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the guts of OutlinerParaObject, refcounted and shared among
|
* This is the guts of OutlinerParaObject, refcounted and shared among
|
||||||
* multiple instances of OutlinerParaObject.
|
* multiple instances of OutlinerParaObject.
|
||||||
*/
|
*/
|
||||||
class OutlinerParaObjData
|
struct OutlinerParaObjData
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
// data members
|
// data members
|
||||||
EditTextObject* mpEditTextObject;
|
EditTextObject* mpEditTextObject;
|
||||||
ParagraphDataVector maParagraphDataVector;
|
ParagraphDataVector maParagraphDataVector;
|
||||||
bool mbIsEditDoc;
|
bool mbIsEditDoc;
|
||||||
|
|
||||||
// refcounter
|
// refcounter
|
||||||
sal_uInt32 mnRefCount;
|
mutable size_t mnRefCount;
|
||||||
|
|
||||||
// constuctor
|
// constuctor
|
||||||
OutlinerParaObjData(EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc)
|
OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
|
||||||
: mpEditTextObject(pEditTextObject),
|
mpEditTextObject(pEditTextObject),
|
||||||
maParagraphDataVector(rParagraphDataVector),
|
maParagraphDataVector(rParagraphDataVector),
|
||||||
mbIsEditDoc(bIsEditDoc),
|
mbIsEditDoc(bIsEditDoc),
|
||||||
mnRefCount(0)
|
mnRefCount(0)
|
||||||
|
@ -58,6 +59,11 @@ public:
|
||||||
maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
|
maParagraphDataVector.resize(pEditTextObject->GetParagraphCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OutlinerParaObjData( const OutlinerParaObjData& r ) :
|
||||||
|
mpEditTextObject(r.mpEditTextObject->Clone()),
|
||||||
|
maParagraphDataVector(r.maParagraphDataVector),
|
||||||
|
mbIsEditDoc(r.mbIsEditDoc) {}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
~OutlinerParaObjData()
|
~OutlinerParaObjData()
|
||||||
{
|
{
|
||||||
|
@ -78,41 +84,37 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void intrusive_ptr_add_ref(const OutlinerParaObjData* p)
|
||||||
|
{
|
||||||
|
++p->mnRefCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void intrusive_ptr_release(const OutlinerParaObjData* p)
|
||||||
|
{
|
||||||
|
--p->mnRefCount;
|
||||||
|
if (!p->mnRefCount)
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
|
||||||
struct OutlinerParaObject::Impl
|
struct OutlinerParaObject::Impl
|
||||||
{
|
{
|
||||||
OutlinerParaObjData* mpData;
|
typedef boost::intrusive_ptr<OutlinerParaObjData> DataRef;
|
||||||
|
DataRef mxData;
|
||||||
|
|
||||||
Impl( const EditTextObject& rTextObj, const ParagraphDataVector& rParaData, bool bIsEditDoc ) :
|
Impl( const EditTextObject& rTextObj, const ParagraphDataVector& rParaData, bool bIsEditDoc ) :
|
||||||
mpData(new OutlinerParaObjData(rTextObj.Clone(), rParaData, bIsEditDoc)) {}
|
mxData(new OutlinerParaObjData(rTextObj.Clone(), rParaData, bIsEditDoc)) {}
|
||||||
|
|
||||||
Impl( const EditTextObject& rTextObj ) :
|
Impl( const EditTextObject& rTextObj ) :
|
||||||
mpData(new OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) {}
|
mxData(new OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) {}
|
||||||
|
|
||||||
Impl( const Impl& r ) : mpData(r.mpData)
|
Impl( const Impl& r ) : mxData(r.mxData) {}
|
||||||
{
|
|
||||||
mpData->mnRefCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
~Impl()
|
~Impl() {}
|
||||||
{
|
|
||||||
if (mpData->mnRefCount)
|
|
||||||
mpData->mnRefCount--;
|
|
||||||
else
|
|
||||||
delete mpData;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void OutlinerParaObject::ImplMakeUnique()
|
void OutlinerParaObject::ImplMakeUnique()
|
||||||
{
|
{
|
||||||
if (mpImpl->mpData->mnRefCount)
|
mpImpl->mxData.reset(new OutlinerParaObjData(*mpImpl->mxData));
|
||||||
{
|
|
||||||
OutlinerParaObjData* pNew = new OutlinerParaObjData(
|
|
||||||
mpImpl->mpData->mpEditTextObject->Clone(),
|
|
||||||
mpImpl->mpData->maParagraphDataVector,
|
|
||||||
mpImpl->mpData->mbIsEditDoc);
|
|
||||||
mpImpl->mpData->mnRefCount--;
|
|
||||||
mpImpl->mpData = pNew;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinerParaObject::OutlinerParaObject(
|
OutlinerParaObject::OutlinerParaObject(
|
||||||
|
@ -124,86 +126,72 @@ OutlinerParaObject::OutlinerParaObject( const EditTextObject& rTextObj ) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinerParaObject::OutlinerParaObject(const OutlinerParaObject& rCandidate) :
|
OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
|
||||||
mpImpl(new Impl(*rCandidate.mpImpl)) {}
|
mpImpl(new Impl(*r.mpImpl)) {}
|
||||||
|
|
||||||
OutlinerParaObject::~OutlinerParaObject()
|
OutlinerParaObject::~OutlinerParaObject()
|
||||||
{
|
{
|
||||||
delete mpImpl;
|
delete mpImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinerParaObject& OutlinerParaObject::operator=(const OutlinerParaObject& rCandidate)
|
OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
|
||||||
{
|
{
|
||||||
if(rCandidate.mpImpl->mpData != mpImpl->mpData)
|
mpImpl->mxData = r.mpImpl->mxData;
|
||||||
{
|
|
||||||
if (mpImpl->mpData->mnRefCount)
|
|
||||||
{
|
|
||||||
mpImpl->mpData->mnRefCount--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete mpImpl->mpData;
|
|
||||||
}
|
|
||||||
|
|
||||||
mpImpl->mpData = rCandidate.mpImpl->mpData;
|
|
||||||
mpImpl->mpData->mnRefCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutlinerParaObject::operator==(const OutlinerParaObject& rCandidate) const
|
bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
|
||||||
{
|
{
|
||||||
if (rCandidate.mpImpl->mpData == mpImpl->mpData)
|
if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*rCandidate.mpImpl->mpData == *mpImpl->mpData);
|
return (*r.mpImpl->mxData == *mpImpl->mxData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #i102062#
|
// #i102062#
|
||||||
bool OutlinerParaObject::isWrongListEqual(const OutlinerParaObject& rCompare) const
|
bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
|
||||||
{
|
{
|
||||||
if (rCompare.mpImpl->mpData == mpImpl->mpData)
|
if (r.mpImpl->mxData.get() == mpImpl->mxData.get())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mpImpl->mpData->isWrongListEqual(*rCompare.mpImpl->mpData);
|
return mpImpl->mxData->isWrongListEqual(*r.mpImpl->mxData);
|
||||||
}
|
}
|
||||||
|
|
||||||
sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
|
sal_uInt16 OutlinerParaObject::GetOutlinerMode() const
|
||||||
{
|
{
|
||||||
return mpImpl->mpData->mpEditTextObject->GetUserType();
|
return mpImpl->mxData->mpEditTextObject->GetUserType();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
|
void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew)
|
||||||
{
|
{
|
||||||
if (mpImpl->mpData->mpEditTextObject->GetUserType() != nNew)
|
if (mpImpl->mxData->mpEditTextObject->GetUserType() != nNew)
|
||||||
{
|
{
|
||||||
ImplMakeUnique();
|
ImplMakeUnique();
|
||||||
mpImpl->mpData->mpEditTextObject->SetUserType(nNew);
|
mpImpl->mxData->mpEditTextObject->SetUserType(nNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutlinerParaObject::IsVertical() const
|
bool OutlinerParaObject::IsVertical() const
|
||||||
{
|
{
|
||||||
return mpImpl->mpData->mpEditTextObject->IsVertical();
|
return mpImpl->mxData->mpEditTextObject->IsVertical();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutlinerParaObject::SetVertical(bool bNew)
|
void OutlinerParaObject::SetVertical(bool bNew)
|
||||||
{
|
{
|
||||||
if((bool)mpImpl->mpData->mpEditTextObject->IsVertical() != bNew)
|
if (mpImpl->mxData->mpEditTextObject->IsVertical() != bNew)
|
||||||
{
|
{
|
||||||
ImplMakeUnique();
|
ImplMakeUnique();
|
||||||
mpImpl->mpData->mpEditTextObject->SetVertical(bNew);
|
mpImpl->mxData->mpEditTextObject->SetVertical(bNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sal_Int32 OutlinerParaObject::Count() const
|
sal_Int32 OutlinerParaObject::Count() const
|
||||||
{
|
{
|
||||||
size_t nSize = mpImpl->mpData->maParagraphDataVector.size();
|
size_t nSize = mpImpl->mxData->maParagraphDataVector.size();
|
||||||
if (nSize > EE_PARA_MAX_COUNT)
|
if (nSize > EE_PARA_MAX_COUNT)
|
||||||
{
|
{
|
||||||
SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
|
SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
|
||||||
|
@ -214,9 +202,9 @@ sal_Int32 OutlinerParaObject::Count() const
|
||||||
|
|
||||||
sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
|
sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
|
||||||
{
|
{
|
||||||
if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->mpData->maParagraphDataVector.size())
|
if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->mxData->maParagraphDataVector.size())
|
||||||
{
|
{
|
||||||
return mpImpl->mpData->maParagraphDataVector[nPara].getDepth();
|
return mpImpl->mxData->maParagraphDataVector[nPara].getDepth();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -226,19 +214,19 @@ sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
|
||||||
|
|
||||||
const EditTextObject& OutlinerParaObject::GetTextObject() const
|
const EditTextObject& OutlinerParaObject::GetTextObject() const
|
||||||
{
|
{
|
||||||
return *mpImpl->mpData->mpEditTextObject;
|
return *mpImpl->mxData->mpEditTextObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutlinerParaObject::IsEditDoc() const
|
bool OutlinerParaObject::IsEditDoc() const
|
||||||
{
|
{
|
||||||
return mpImpl->mpData->mbIsEditDoc;
|
return mpImpl->mxData->mbIsEditDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
|
const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
|
||||||
{
|
{
|
||||||
if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->mpData->maParagraphDataVector.size())
|
if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->mxData->maParagraphDataVector.size())
|
||||||
{
|
{
|
||||||
return mpImpl->mpData->maParagraphDataVector[nIndex];
|
return mpImpl->mxData->maParagraphDataVector[nIndex];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -251,21 +239,21 @@ const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) cons
|
||||||
void OutlinerParaObject::ClearPortionInfo()
|
void OutlinerParaObject::ClearPortionInfo()
|
||||||
{
|
{
|
||||||
ImplMakeUnique();
|
ImplMakeUnique();
|
||||||
mpImpl->mpData->mpEditTextObject->ClearPortionInfo();
|
mpImpl->mxData->mpEditTextObject->ClearPortionInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName,
|
bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName,
|
||||||
SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
|
SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
|
||||||
{
|
{
|
||||||
ImplMakeUnique();
|
ImplMakeUnique();
|
||||||
return mpImpl->mpData->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
|
return mpImpl->mxData->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
|
void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
|
||||||
const OUString& rOldName, const OUString& rNewName)
|
const OUString& rOldName, const OUString& rNewName)
|
||||||
{
|
{
|
||||||
ImplMakeUnique();
|
ImplMakeUnique();
|
||||||
mpImpl->mpData->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
|
mpImpl->mxData->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
|
void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
|
||||||
|
@ -282,7 +270,7 @@ void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewN
|
||||||
{
|
{
|
||||||
if(GetDepth(--nDecrementer) == nLevel)
|
if(GetDepth(--nDecrementer) == nLevel)
|
||||||
{
|
{
|
||||||
mpImpl->mpData->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
|
mpImpl->mxData->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue