Kaydet (Commit) 04c5f27e authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SetGetExpFields

and a couple more utility methods to o3tl::sorted_vector to make this
easier

Change-Id: Iebbbb8899b67fffa1ac98ae46b7fa70a7e35f866
Reviewed-on: https://gerrit.libreoffice.org/61344
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 70b125c6
......@@ -243,6 +243,26 @@ public:
tmp.release();
return ret;
}
/**
* implement upper_bound for sorted_vectors containing std::unique_ptr
*/
typename super_sorted_vector::const_iterator upper_bound( typename Value::element_type const * x ) const
{
Value tmp(const_cast<typename Value::element_type*>(x));
auto ret = super_sorted_vector::upper_bound(tmp);
tmp.release();
return ret;
}
/**
* implement lower_bound for sorted_vectors containing std::unique_ptr
*/
typename super_sorted_vector::const_iterator lower_bound( typename Value::element_type const * x ) const
{
Value tmp(const_cast<typename Value::element_type*>(x));
auto ret = super_sorted_vector::lower_bound(tmp);
tmp.release();
return ret;
}
};
......
......@@ -674,9 +674,9 @@ static void lcl_MakeFieldLst(
if ( pCFrame != nullptr
&& ( bInReadOnly || !pCFrame->IsProtected() ) )
{
SetGetExpField* pNew = new SetGetExpField( SwNodeIndex( rTextNode ), pTextField );
std::unique_ptr<SetGetExpField> pNew(new SetGetExpField( SwNodeIndex( rTextNode ), pTextField ));
pNew->SetBodyPos( *pCFrame );
rLst.insert( pNew );
rLst.insert( std::move(pNew) );
}
}
}
......
......@@ -1446,7 +1446,7 @@ void DocumentFieldsManager::FieldsToCalc( SwCalc& rCalc, const SetGetExpField& r
{
SetGetExpFields::const_iterator const itLast =
mpUpdateFields->GetSortLst()->upper_bound(
const_cast<SetGetExpField*>(&rToThisField));
&rToThisField);
for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
lcl_CalcField( m_rDoc, rCalc, **it, pMgr );
}
......@@ -1496,8 +1496,7 @@ void DocumentFieldsManager::FieldsToExpand( SwHashTable<HashStr> & rHashTable,
rHashTable.resize(nTableSize);
SetGetExpFields::const_iterator const itLast =
mpUpdateFields->GetSortLst()->upper_bound(
const_cast<SetGetExpField*>(&rToThisField));
mpUpdateFields->GetSortLst()->upper_bound(&rToThisField);
for( SetGetExpFields::const_iterator it = mpUpdateFields->GetSortLst()->begin(); it != itLast; ++it )
{
......
......@@ -561,8 +561,8 @@ bool sw_GetPostIts(
if (pSrtLst)
{
SwNodeIndex aIdx( pTextField->GetTextNode() );
PostItField_* pNew = new PostItField_( aIdx, pTextField );
pSrtLst->insert( pNew );
std::unique_ptr<PostItField_> pNew(new PostItField_( aIdx, pTextField ));
pSrtLst->insert( std::move(pNew) );
}
else
break; // we just wanted to check for the existence of postits ...
......
......@@ -791,7 +791,6 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie
for( SetGetExpFields::size_type n = 0; n < pFieldSortLst->size(); ++n )
if( &rField == (*pFieldSortLst)[ n ]->GetPointer() )
{
delete (*pFieldSortLst)[n];
pFieldSortLst->erase(n);
n--; // one field can occur multiple times
}
......@@ -1001,7 +1000,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
const SwContentFrame* pFrame = rTextNd.getLayoutFrame(
rDoc.getIDocumentLayoutAccess().GetCurrentLayout(), nullptr, &tmp);
SetGetExpField* pNew = nullptr;
std::unique_ptr<SetGetExpField> pNew;
bool bIsInBody = false;
if( !pFrame || pFrame->IsInDocBody() )
......@@ -1015,7 +1014,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
// fields in hidden sections. So: In order to be updated, a field 1)
// must have a frame, or 2) it must be in the document body.
if( (pFrame != nullptr) || bIsInBody )
pNew = new SetGetExpField( aIdx, &rTField );
pNew.reset(new SetGetExpField( aIdx, &rTField ));
}
else
{
......@@ -1023,7 +1022,7 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
SwPosition aPos( rDoc.GetNodes().GetEndOfPostIts() );
bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
OSL_ENSURE(bResult, "where is the Field");
pNew = new SetGetExpField( aPos.nNode, &rTField, &aPos.nContent );
pNew.reset(new SetGetExpField( aPos.nNode, &rTField, &aPos.nContent ));
}
// always set the BodyTextFlag in GetExp or DB fields
......@@ -1040,14 +1039,13 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& rTField, SwFieldIds nFiel
}
#endif
if( pNew != nullptr )
if( !pFieldSortLst->insert( pNew ).second )
delete pNew;
pFieldSortLst->insert( std::move(pNew) );
}
void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
{
const SwDoc& rDoc = *rSectNd.GetDoc();
SetGetExpField* pNew = nullptr;
std::unique_ptr<SetGetExpField> pNew;
if( rSectNd.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex() )
{
......@@ -1072,16 +1070,15 @@ void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
OSL_ENSURE(bResult, "where is the Field");
pNew = new SetGetExpField( rSectNd, &aPos );
pNew.reset(new SetGetExpField( rSectNd, &aPos ));
} while( false );
}
if( !pNew )
pNew = new SetGetExpField( rSectNd );
pNew.reset(new SetGetExpField( rSectNd ));
if( !pFieldSortLst->insert( pNew ).second )
delete pNew;
pFieldSortLst->insert( std::move(pNew) );
}
void SwDocUpdateField::InsertFieldType( const SwFieldType& rType )
......
......@@ -2194,7 +2194,7 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
rTextNd.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout(),
nullptr, &tmp);
SetGetExpField* pNew;
std::unique_ptr<SetGetExpField> pNew;
if( !pFrame ||
pFrame->IsInDocBody() ||
......@@ -2204,7 +2204,7 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
{
// create index for determination of the TextNode
SwNodeIndex aIdx( rTextNd );
pNew = new SetGetExpField( aIdx, pTField );
pNew.reset( new SetGetExpField( aIdx, pTField ) );
}
else
{
......@@ -2212,12 +2212,11 @@ bool SwRefPageGetFieldType::MakeSetList( SetGetExpFields& rTmpLst )
SwPosition aPos( m_pDoc->GetNodes().GetEndOfPostIts() );
bool const bResult = GetBodyTextNode( *m_pDoc, aPos, *pFrame );
OSL_ENSURE(bResult, "where is the Field?");
pNew = new SetGetExpField( aPos.nNode, pTField,
&aPos.nContent );
pNew.reset( new SetGetExpField( aPos.nNode, pTField,
&aPos.nContent ) );
}
if( !rTmpLst.insert( pNew ).second)
delete pNew;
rTmpLst.insert( std::move(pNew) );
}
}
......
......@@ -69,8 +69,8 @@ SwInputFieldList::SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst )
else
{
SwNodeIndex aIdx( rTextNode );
SetGetExpField* pNew = new SetGetExpField(aIdx, pTextField );
mpSrtLst->insert( pNew );
std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
mpSrtLst->insert( std::move(pNew) );
}
}
}
......@@ -154,8 +154,8 @@ bool SwInputFieldList::BuildSortLst()
if( maTmpLst.end() == it )
{
SwNodeIndex aIdx( rTextNode );
SetGetExpField* pNew = new SetGetExpField(aIdx, pTextField );
mpSrtLst->insert( pNew );
std::unique_ptr<SetGetExpField> pNew(new SetGetExpField(aIdx, pTextField ));
mpSrtLst->insert( std::move(pNew) );
}
else
maTmpLst.erase( it );
......
......@@ -102,10 +102,8 @@ public:
void SetBodyPos( const SwContentFrame& rFrame );
};
class SetGetExpFields : public o3tl::sorted_vector<SetGetExpField*, o3tl::less_ptr_to<SetGetExpField> >
class SetGetExpFields : public o3tl::sorted_vector<std::unique_ptr<SetGetExpField>, o3tl::less_uniqueptr_to<SetGetExpField> >
{
public:
~SetGetExpFields() { DeleteAndDestroyAll(); }
};
// struct for saving strings from the SetExp's string fields
......
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