Kaydet (Commit) 25fbd841 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Replace TSdrObjectPtr with unique_ptr with custom deleter

Change-Id: If15e1bab07ee5e9c70a6a0f1961ec2db0c946eb5
üst 0ada00bd
...@@ -146,41 +146,11 @@ using ::com::sun::star::table::CellRangeAddress; ...@@ -146,41 +146,11 @@ using ::com::sun::star::table::CellRangeAddress;
namespace { namespace {
/** Helper class which mimics the auto_ptr< SdrObject > semantics, but calls struct SdrObjectFree {
SdrObject::Free instead of deleting the SdrObject directly. */ void operator ()(SdrObject * obj) { SdrObject::Free(obj); }
template< typename SdrObjType >
class TSdrObjectPtr
{
public:
inline explicit TSdrObjectPtr( SdrObjType* pObj = 0 ) : mpObj( pObj ) {}
inline ~TSdrObjectPtr() { free(); }
inline const SdrObjType* operator->() const { return mpObj; }
inline SdrObjType* operator->() { return mpObj; }
inline const SdrObjType* get() const { return mpObj; }
inline SdrObjType* get() { return mpObj; }
inline const SdrObjType& operator*() const { return *mpObj; }
inline SdrObjType& operator*() { return *mpObj; }
inline bool is() const { return mpObj != 0; }
inline bool operator!() const { return mpObj == 0; }
inline void reset( SdrObjType* pObj = 0 ) { free(); mpObj = pObj; }
inline SdrObjType* release() { SdrObjType* pObj = mpObj; mpObj = 0; return pObj; }
private:
TSdrObjectPtr( const TSdrObjectPtr& ); // not implemented
TSdrObjectPtr& operator=( TSdrObjectPtr& rxObj ); // not implemented
inline void free() { SdrObject* pObj = mpObj; mpObj = 0; SdrObject::Free( pObj ); }
private:
SdrObjType* mpObj;
}; };
typedef TSdrObjectPtr< SdrObject > SdrObjectPtr; typedef std::unique_ptr<SdrObject, SdrObjectFree> SdrObjectPtr;
} // namespace } // namespace
...@@ -457,7 +427,7 @@ SdrObject* XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, con ...@@ -457,7 +427,7 @@ SdrObject* XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, con
else else
{ {
xSdrObj.reset( DoCreateSdrObj( rDffConv, rAnchorRect ) ); xSdrObj.reset( DoCreateSdrObj( rDffConv, rAnchorRect ) );
if( xSdrObj.is() ) if( xSdrObj )
xSdrObj->SetModel( rDffConv.GetModel() ); xSdrObj->SetModel( rDffConv.GetModel() );
//added for exporting OCX control //added for exporting OCX control
/* mnObjType value set should be as below table: /* mnObjType value set should be as below table:
...@@ -477,7 +447,7 @@ SdrObject* XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, con ...@@ -477,7 +447,7 @@ SdrObject* XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, con
+-----------------------------------------------------+ +-----------------------------------------------------+
0x0019 Note 0x001E OfficeArt object 0x0019 Note 0x001E OfficeArt object
*/ */
if( xSdrObj.is() && xSdrObj->IsUnoObj() && if( xSdrObj && xSdrObj->IsUnoObj() &&
( (mnObjType < 25 && mnObjType > 10) || mnObjType == 7 || mnObjType == 8 ) ) ( (mnObjType < 25 && mnObjType > 10) || mnObjType == 7 || mnObjType == 8 ) )
{ {
SdrUnoObj* pSdrUnoObj = dynamic_cast< SdrUnoObj* >( xSdrObj.get() ); SdrUnoObj* pSdrUnoObj = dynamic_cast< SdrUnoObj* >( xSdrObj.get() );
...@@ -1033,7 +1003,7 @@ sal_Size XclImpGroupObj::DoGetProgressSize() const ...@@ -1033,7 +1003,7 @@ sal_Size XclImpGroupObj::DoGetProgressSize() const
SdrObject* XclImpGroupObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& /*rAnchorRect*/ ) const SdrObject* XclImpGroupObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& /*rAnchorRect*/ ) const
{ {
TSdrObjectPtr< SdrObjGroup > xSdrObj( new SdrObjGroup ); std::unique_ptr<SdrObjGroup, SdrObjectFree> xSdrObj( new SdrObjGroup );
// child objects in BIFF2-BIFF5 have absolute size, not needed to pass own anchor rectangle // child objects in BIFF2-BIFF5 have absolute size, not needed to pass own anchor rectangle
SdrObjList& rObjList = *xSdrObj->GetSubList(); // SdrObjGroup always returns existing sublist SdrObjList& rObjList = *xSdrObj->GetSubList(); // SdrObjGroup always returns existing sublist
for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end(); aIt != aEnd; ++aIt ) for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end(); aIt != aEnd; ++aIt )
...@@ -1430,7 +1400,7 @@ void XclImpTextObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uI ...@@ -1430,7 +1400,7 @@ void XclImpTextObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uI
SdrObject* XclImpTextObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const SdrObject* XclImpTextObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const Rectangle& rAnchorRect ) const
{ {
TSdrObjectPtr< SdrObjCustomShape > xSdrObj( new SdrObjCustomShape ); std::unique_ptr<SdrObjCustomShape, SdrObjectFree> xSdrObj( new SdrObjCustomShape );
xSdrObj->NbcSetSnapRect( rAnchorRect ); xSdrObj->NbcSetSnapRect( rAnchorRect );
OUString aRectType = "rectangle"; OUString aRectType = "rectangle";
xSdrObj->MergeDefaultAttributes( &aRectType ); xSdrObj->MergeDefaultAttributes( &aRectType );
...@@ -1826,7 +1796,7 @@ SdrObject* XclImpControlHelper::CreateSdrObjectFromShape( ...@@ -1826,7 +1796,7 @@ SdrObject* XclImpControlHelper::CreateSdrObjectFromShape(
{ {
mxShape = rxShape; mxShape = rxShape;
SdrObjectPtr xSdrObj( SdrObject::getSdrObjectFromXShape( rxShape ) ); SdrObjectPtr xSdrObj( SdrObject::getSdrObjectFromXShape( rxShape ) );
if( xSdrObj.is() ) if( xSdrObj )
{ {
xSdrObj->NbcSetSnapRect( rAnchorRect ); xSdrObj->NbcSetSnapRect( rAnchorRect );
// #i30543# insert into control layer // #i30543# insert into control layer
...@@ -3288,7 +3258,7 @@ void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, const XclImpDrawOb ...@@ -3288,7 +3258,7 @@ void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, const XclImpDrawOb
{ {
// CreateSdrObject() recursively creates embedded child objects // CreateSdrObject() recursively creates embedded child objects
SdrObjectPtr xSdrObj( rDrawObj.CreateSdrObject( *this, aAnchorRect, false ) ); SdrObjectPtr xSdrObj( rDrawObj.CreateSdrObject( *this, aAnchorRect, false ) );
if( xSdrObj.is() ) if( xSdrObj )
rDrawObj.PreProcessSdrObject( *this, *xSdrObj ); rDrawObj.PreProcessSdrObject( *this, *xSdrObj );
// call InsertSdrObject() also, if SdrObject is missing // call InsertSdrObject() also, if SdrObject is missing
InsertSdrObject( rObjList, rDrawObj, xSdrObj.release() ); InsertSdrObject( rObjList, rDrawObj, xSdrObj.release() );
...@@ -3518,11 +3488,11 @@ SdrObject* XclImpDffConverter::ProcessObj( SvStream& rDffStrm, DffObjData& rDffO ...@@ -3518,11 +3488,11 @@ SdrObject* XclImpDffConverter::ProcessObj( SvStream& rDffStrm, DffObjData& rDffO
// try to create a custom SdrObject that overwrites the passed object // try to create a custom SdrObject that overwrites the passed object
SdrObjectPtr xNewSdrObj( xDrawObj->CreateSdrObject( *this, rAnchorRect, true ) ); SdrObjectPtr xNewSdrObj( xDrawObj->CreateSdrObject( *this, rAnchorRect, true ) );
if( xNewSdrObj.is() ) if( xNewSdrObj )
xSdrObj.reset( xNewSdrObj.release() ); xSdrObj.reset( xNewSdrObj.release() );
// process the SdrObject // process the SdrObject
if( xSdrObj.is() ) if( xSdrObj )
{ {
// cell anchoring // cell anchoring
if ( !rDffObjData.bPageAnchor ) if ( !rDffObjData.bPageAnchor )
...@@ -3543,7 +3513,7 @@ SdrObject* XclImpDffConverter::ProcessObj( SvStream& rDffStrm, DffObjData& rDffO ...@@ -3543,7 +3513,7 @@ SdrObject* XclImpDffConverter::ProcessObj( SvStream& rDffStrm, DffObjData& rDffO
xSdrObj.reset(); xSdrObj.reset();
} }
if( xSdrObj.is() ) if( xSdrObj )
{ {
/* Store the relation between shape ID and SdrObject for connectors. /* Store the relation between shape ID and SdrObject for connectors.
Must be done here (and not in InsertSdrObject() function), Must be done here (and not in InsertSdrObject() function),
...@@ -3719,7 +3689,7 @@ void XclImpDffConverter::ProcessShContainer( SvStream& rDffStrm, const DffRecord ...@@ -3719,7 +3689,7 @@ void XclImpDffConverter::ProcessShContainer( SvStream& rDffStrm, const DffRecord
virtual functions ProcessClientAnchor2() and ProcessObj() and writes virtual functions ProcessClientAnchor2() and ProcessObj() and writes
the pointer to the related draw object data (OBJ record) into pDrawObj. */ the pointer to the related draw object data (OBJ record) into pDrawObj. */
SdrObjectPtr xSdrObj( ImportObj( rDffStrm, &pDrawObj, aDummy, aDummy, 0, 0 ) ); SdrObjectPtr xSdrObj( ImportObj( rDffStrm, &pDrawObj, aDummy, aDummy, 0, 0 ) );
if( pDrawObj && xSdrObj.is() ) if( pDrawObj && xSdrObj )
InsertSdrObject( GetConvData().mrSdrPage, *pDrawObj, xSdrObj.release() ); InsertSdrObject( GetConvData().mrSdrPage, *pDrawObj, xSdrObj.release() );
rShHeader.SeekToEndOfRecord( rDffStrm ); rShHeader.SeekToEndOfRecord( rDffStrm );
} }
...@@ -3730,7 +3700,7 @@ void XclImpDffConverter::InsertSdrObject( SdrObjList& rObjList, const XclImpDraw ...@@ -3730,7 +3700,7 @@ void XclImpDffConverter::InsertSdrObject( SdrObjList& rObjList, const XclImpDraw
/* Take ownership of the passed object. If insertion fails (e.g. rDrawObj /* Take ownership of the passed object. If insertion fails (e.g. rDrawObj
states to skip insertion), the object is automatically deleted. */ states to skip insertion), the object is automatically deleted. */
SdrObjectPtr xSdrObj( pSdrObj ); SdrObjectPtr xSdrObj( pSdrObj );
if( xSdrObj.is() && rDrawObj.IsInsertSdrObj() ) if( xSdrObj && rDrawObj.IsInsertSdrObj() )
{ {
rObjList.NbcInsertObject( xSdrObj.release() ); rObjList.NbcInsertObject( xSdrObj.release() );
// callback to drawing manager for e.g. tracking of used sheet area // callback to drawing manager for e.g. tracking of used sheet area
...@@ -3740,7 +3710,7 @@ void XclImpDffConverter::InsertSdrObject( SdrObjList& rObjList, const XclImpDraw ...@@ -3740,7 +3710,7 @@ void XclImpDffConverter::InsertSdrObject( SdrObjList& rObjList, const XclImpDraw
} }
/* SdrObject still here? Insertion failed, remove data from shape ID map. /* SdrObject still here? Insertion failed, remove data from shape ID map.
The SdrObject will be destructed then. */ The SdrObject will be destructed then. */
if( xSdrObj.is() ) if( xSdrObj )
rConvData.maSolverCont.RemoveSdrObjectInfo( *xSdrObj ); rConvData.maSolverCont.RemoveSdrObjectInfo( *xSdrObj );
} }
......
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