summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/inc/docary.hxx14
-rw-r--r--sw/source/core/doc/docbasic.cxx8
-rw-r--r--sw/source/core/doc/docfmt.cxx11
-rw-r--r--sw/source/core/frmedt/fefly1.cxx2
-rw-r--r--sw/source/core/undo/rolbck.cxx12
-rw-r--r--sw/source/core/undo/unattr.cxx3
-rw-r--r--sw/source/core/undo/undobj1.cxx4
7 files changed, 31 insertions, 23 deletions
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 6d25e85dcc74..10e41d68f901 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -225,7 +225,7 @@ public:
// Get the iterator of the exact object (includes pointer!),
// e.g for position with std::distance.
- // There is also Contains, if you don't need the position.
+ // There is also ContainsFormat, if you don't need the position.
const_iterator find( const value_type& x ) const;
// As this array is non-unique related to type and name,
@@ -253,8 +253,11 @@ public:
virtual size_t GetFormatCount() const override { return m_Array.size(); }
virtual SwFormat* GetFormat(size_t idx) const override { return operator[]( idx ); }
- bool Contains( const value_type& x ) const;
- inline bool Contains( const SwFormat* p ) const;
+ /// fast check if given format is contained here
+ /// @precond pFormat must not have been deleted
+ bool ContainsFormat(SwFrameFormat const* pFormat) const;
+ /// not so fast check that given format is still alive (i.e. contained here)
+ bool IsAlive(SwFrameFormat const*) const;
void DeleteAndDestroyAll( bool keepDefault = false );
@@ -262,11 +265,6 @@ public:
void newDefault( const_iterator const& position );
};
-inline bool SwFrameFormats::Contains( const SwFormat* p ) const
-{
- value_type p2 = dynamic_cast<value_type>(const_cast<SwFormat*>( p ));
- return p2 != nullptr && this->Contains( p2 );
-}
/// Unsorted, undeleting SwFrameFormat vector
class SwFrameFormatsV : public SwFormatsModifyBase<SwFrameFormat*>
diff --git a/sw/source/core/doc/docbasic.cxx b/sw/source/core/doc/docbasic.cxx
index dd27799b79f2..8b4ee3a007fd 100644
--- a/sw/source/core/doc/docbasic.cxx
+++ b/sw/source/core/doc/docbasic.cxx
@@ -164,8 +164,12 @@ sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEve
const SwFrameFormat* pFormat = rCallEvent.PTR.pFormat;
if( bCheckPtr )
{
- if ( GetSpzFrameFormats()->Contains( pFormat ) )
+ if (GetSpzFrameFormats()->IsAlive(pFormat))
bCheckPtr = false; // misuse as a flag
+ else
+ // this shouldn't be possible now that SwCallMouseEvent
+ // listens for dying format?
+ assert(false);
}
if( !bCheckPtr )
pTable = &pFormat->GetMacro().GetMacroTable();
@@ -179,7 +183,7 @@ sal_uInt16 SwDoc::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEve
{
const SwFrameFormat* pFormat = rCallEvent.PTR.IMAP.pFormat;
const ImageMap* pIMap;
- if( GetSpzFrameFormats()->Contains( pFormat ) &&
+ if (GetSpzFrameFormats()->IsAlive(pFormat) &&
nullptr != (pIMap = pFormat->GetURL().GetMap()) )
{
for( size_t nPos = pIMap->GetIMapObjectCount(); nPos; )
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 5dff133d929f..544c30eaad55 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -711,7 +711,7 @@ void SwDoc::DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast )
else
{
// The format has to be in the one or the other, we'll see in which one.
- if ( mpFrameFormatTable->Contains( pFormat ) )
+ if (mpFrameFormatTable->ContainsFormat(pFormat))
{
if (bBroadcast)
BroadcastStyleOperation(pFormat->GetName(),
@@ -730,7 +730,7 @@ void SwDoc::DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast )
}
else
{
- bool contains = GetSpzFrameFormats()->Contains( pFormat );
+ bool contains = GetSpzFrameFormats()->ContainsFormat(pFormat);
OSL_ENSURE( contains, "FrameFormat not found." );
if( contains )
{
@@ -2116,11 +2116,16 @@ void SwFrameFormats::erase( const_iterator const& position )
m_PosIndex.erase( begin() + (position - begin()) );
}
-bool SwFrameFormats::Contains( const SwFrameFormats::value_type& x ) const
+bool SwFrameFormats::ContainsFormat(const SwFrameFormat *const x) const
{
return (x->m_ffList == this);
}
+bool SwFrameFormats::IsAlive(SwFrameFormat const*const p) const
+{
+ return find(const_cast<SwFrameFormat*>(p)) != end();
+}
+
bool SwFrameFormats::newDefault( const value_type& x )
{
std::pair<iterator,bool> res = m_PosIndex.push_front( x );
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 4a103aef478f..66fbcfcee252 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -947,7 +947,7 @@ void SwFEShell::SetPageObjsNewPage( std::vector<SwFrameFormat*>& rFillArr )
bool bTmpAssert = false;
for( auto pFormat : rFillArr )
{
- if( mpDoc->GetSpzFrameFormats()->Contains( pFormat ))
+ if (mpDoc->GetSpzFrameFormats()->IsAlive(pFormat))
{
// FlyFormat is still valid, therefore process
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index 9c6116a5e568..4b3ce11653f4 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -786,7 +786,7 @@ void SwHistoryChangeFlyAnchor::SetInDoc( SwDoc* pDoc, bool )
{
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
- if ( pDoc->GetSpzFrameFormats()->Contains( &m_rFormat ) ) // Format does still exist
+ if (pDoc->GetSpzFrameFormats()->IsAlive(&m_rFormat)) // Format does still exist
{
SwFormatAnchor aTmp( m_rFormat.GetAnchor() );
@@ -824,12 +824,12 @@ SwHistoryChangeFlyChain::SwHistoryChangeFlyChain( SwFlyFrameFormat& rFormat,
void SwHistoryChangeFlyChain::SetInDoc( SwDoc* pDoc, bool )
{
- if (pDoc->GetSpzFrameFormats()->Contains( m_pFlyFormat ) )
+ if (pDoc->GetSpzFrameFormats()->IsAlive(m_pFlyFormat))
{
SwFormatChain aChain;
- if ( m_pPrevFormat &&
- pDoc->GetSpzFrameFormats()->Contains( m_pPrevFormat ) )
+ if (m_pPrevFormat &&
+ pDoc->GetSpzFrameFormats()->IsAlive(m_pPrevFormat))
{
aChain.SetPrev( m_pPrevFormat );
SwFormatChain aTmp( m_pPrevFormat->GetChain() );
@@ -837,8 +837,8 @@ void SwHistoryChangeFlyChain::SetInDoc( SwDoc* pDoc, bool )
m_pPrevFormat->SetFormatAttr( aTmp );
}
- if ( m_pNextFormat &&
- pDoc->GetSpzFrameFormats()->Contains( m_pNextFormat ) )
+ if (m_pNextFormat &&
+ pDoc->GetSpzFrameFormats()->IsAlive(m_pNextFormat))
{
aChain.SetNext( m_pNextFormat );
SwFormatChain aTmp( m_pNextFormat->GetChain() );
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index 9805ed309dd9..f631dc00706b 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -133,7 +133,8 @@ void SwUndoFormatAttr::Init()
SaveFlyAnchor( m_bSaveDrawPt );
} else if ( RES_FRMFMT == m_nFormatWhich ) {
SwDoc* pDoc = m_pFormat->GetDoc();
- if ( pDoc->GetTableFrameFormats()->Contains( m_pFormat )) {
+ if (pDoc->GetTableFrameFormats()->ContainsFormat(dynamic_cast<SwFrameFormat*>(m_pFormat)))
+ {
// Table Format: save table position, table formats are volatile!
SwTable * pTable = SwIterator<SwTable,SwFormat>( *m_pFormat ).First();
if ( pTable ) {
diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx
index 94d05c0386a0..b5f27ce5b33f 100644
--- a/sw/source/core/undo/undobj1.cxx
+++ b/sw/source/core/undo/undobj1.cxx
@@ -519,7 +519,7 @@ void SwUndoSetFlyFormat::UndoImpl(::sw::UndoRedoContext & rContext)
SwDoc & rDoc = rContext.GetDoc();
// Is the new Format still existent?
- if( rDoc.GetFrameFormats()->Contains( pOldFormat ) )
+ if (rDoc.GetFrameFormats()->IsAlive(pOldFormat))
{
if( bAnchorChgd )
pFrameFormat->DelFrames();
@@ -592,7 +592,7 @@ void SwUndoSetFlyFormat::RedoImpl(::sw::UndoRedoContext & rContext)
SwDoc & rDoc = rContext.GetDoc();
// Is the new Format still existent?
- if( rDoc.GetFrameFormats()->Contains( pNewFormat ) )
+ if (rDoc.GetFrameFormats()->IsAlive(pNewFormat))
{
if( bAnchorChgd )