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

loplugin:useuiqueptr in SortedEntryList and EventList

Change-Id: I15e6e29347dfce68e5631337bf2d3754bffdf864
Reviewed-on: https://gerrit.libreoffice.org/53234Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 16632fa9
...@@ -307,13 +307,13 @@ void SortedDynamicResultSet::impl_notify( const ListEvent& Changes ) ...@@ -307,13 +307,13 @@ void SortedDynamicResultSet::impl_notify( const ListEvent& Changes )
aWelcome.Old = mxTwo.get(); aWelcome.Old = mxTwo.get();
aWelcome.New = mxOne.get(); aWelcome.New = mxOne.get();
ListAction *pWelcomeAction = new ListAction; std::unique_ptr<ListAction> pWelcomeAction(new ListAction);
pWelcomeAction->ActionInfo <<= aWelcome; pWelcomeAction->ActionInfo <<= aWelcome;
pWelcomeAction->Position = 0; pWelcomeAction->Position = 0;
pWelcomeAction->Count = 0; pWelcomeAction->Count = 0;
pWelcomeAction->ListActionType = ListActionType::WELCOME; pWelcomeAction->ListActionType = ListActionType::WELCOME;
maActions.Insert( pWelcomeAction ); maActions.Insert( std::move(pWelcomeAction) );
} }
else else
{ {
...@@ -483,22 +483,17 @@ SortedDynamicResultSetFactory::createSortedDynamicResultSet( ...@@ -483,22 +483,17 @@ SortedDynamicResultSetFactory::createSortedDynamicResultSet(
void EventList::Clear() void EventList::Clear()
{ {
for (ListAction* p : maData)
{
delete p;
}
maData.clear(); maData.clear();
} }
void EventList::AddEvent( sal_IntPtr nType, sal_IntPtr nPos ) void EventList::AddEvent( sal_IntPtr nType, sal_IntPtr nPos )
{ {
ListAction *pAction = new ListAction; std::unique_ptr<ListAction> pAction(new ListAction);
pAction->Position = nPos; pAction->Position = nPos;
pAction->Count = 1; pAction->Count = 1;
pAction->ListActionType = nType; pAction->ListActionType = nType;
Insert( pAction ); Insert( std::move(pAction) );
} }
// SortedDynamicResultSetListener // SortedDynamicResultSetListener
......
...@@ -1248,7 +1248,7 @@ void SortedResultSet::CopyData( SortedResultSet *pSource ) ...@@ -1248,7 +1248,7 @@ void SortedResultSet::CopyData( SortedResultSet *pSource )
for ( i=1; i<nCount; i++ ) for ( i=1; i<nCount; i++ )
{ {
maS2O.Insert( new SortListData( rSrcS2O[ i ] ), i ); maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( rSrcS2O[ i ] )), i );
m_O2S.push_back(pSource->m_O2S[i]); m_O2S.push_back(pSource->m_O2S[i]);
} }
...@@ -1269,8 +1269,7 @@ void SortedResultSet::Initialize( ...@@ -1269,8 +1269,7 @@ void SortedResultSet::Initialize(
{ {
BuildSortInfo( mxOriginal, xSortInfo, xCompFactory ); BuildSortInfo( mxOriginal, xSortInfo, xCompFactory );
// Insert dummy at pos 0 // Insert dummy at pos 0
SortListData *pData = new SortListData( 0 ); maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( 0 )), 0 );
maS2O.Insert( pData, 0 );
sal_IntPtr nIndex = 1; sal_IntPtr nIndex = 1;
...@@ -1280,10 +1279,10 @@ void SortedResultSet::Initialize( ...@@ -1280,10 +1279,10 @@ void SortedResultSet::Initialize(
try { try {
while ( mxOriginal->absolute( nIndex ) ) while ( mxOriginal->absolute( nIndex ) )
{ {
pData = new SortListData( nIndex ); std::unique_ptr<SortListData> pData(new SortListData( nIndex ));
sal_IntPtr nPos = FindPos( pData, 1, nIndex-1 ); sal_IntPtr nPos = FindPos( pData.get(), 1, nIndex-1 );
maS2O.Insert( pData, nPos ); maS2O.Insert( std::move(pData), nPos );
nIndex++; nIndex++;
} }
...@@ -1354,13 +1353,12 @@ void SortedResultSet::CheckProperties( sal_IntPtr nOldCount, bool bWasFinal ) ...@@ -1354,13 +1353,12 @@ void SortedResultSet::CheckProperties( sal_IntPtr nOldCount, bool bWasFinal )
void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount ) void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount )
{ {
// for all entries in the msS20-list, which are >= nPos, increase by nCount // for all entries in the msS20-list, which are >= nPos, increase by nCount
SortListData *pData;
sal_IntPtr i, nEnd; sal_IntPtr i, nEnd;
nEnd = maS2O.Count(); nEnd = maS2O.Count();
for ( i=1; i<=nEnd; i++ ) for ( i=1; i<=nEnd; i++ )
{ {
pData = maS2O.GetData( i ); SortListData *pData = maS2O.GetData( i );
if ( pData->mnCurPos >= nPos ) if ( pData->mnCurPos >= nPos )
{ {
pData->mnCurPos += nCount; pData->mnCurPos += nCount;
...@@ -1372,9 +1370,9 @@ void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount ) ...@@ -1372,9 +1370,9 @@ void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount )
for ( i=0; i<nCount; i++ ) for ( i=0; i<nCount; i++ )
{ {
nEnd += 1; nEnd += 1;
pData = new SortListData( nEnd ); std::unique_ptr<SortListData> pData(new SortListData( nEnd ));
maS2O.Insert( pData, nEnd ); // Insert( Value, Position ) maS2O.Insert( std::move(pData), nEnd ); // Insert( Value, Position )
m_O2S.insert(m_O2S.begin() + nPos + i, nEnd); m_O2S.insert(m_O2S.begin() + nPos + i, nEnd);
} }
...@@ -1414,10 +1412,9 @@ void SortedResultSet::Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pEv ...@@ -1414,10 +1412,9 @@ void SortedResultSet::Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pEv
} }
} }
SortListData *pData = maS2O.Remove( nSortPos ); std::unique_ptr<SortListData> pData = maS2O.Remove( nSortPos );
if ( pData->mbModified ) if ( pData->mbModified )
m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData)); m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData.get()));
delete pData;
// generate remove Event, but not for new entries // generate remove Event, but not for new entries
if ( nSortPos <= nOldLastSort ) if ( nSortPos <= nOldLastSort )
...@@ -1586,7 +1583,6 @@ void SortedResultSet::ResortModified( EventList* pList ) ...@@ -1586,7 +1583,6 @@ void SortedResultSet::ResortModified( EventList* pList )
{ {
sal_IntPtr nCompare, nCurPos, nNewPos; sal_IntPtr nCompare, nCurPos, nNewPos;
sal_IntPtr nStart, nEnd, nOffset, nVal; sal_IntPtr nStart, nEnd, nOffset, nVal;
ListAction *pAction;
try { try {
for (size_t i = 0; i < m_ModList.size(); ++i) for (size_t i = 0; i < m_ModList.size(); ++i)
...@@ -1616,8 +1612,7 @@ void SortedResultSet::ResortModified( EventList* pList ) ...@@ -1616,8 +1612,7 @@ void SortedResultSet::ResortModified( EventList* pList )
if ( nNewPos != nCurPos ) if ( nNewPos != nCurPos )
{ {
// correct the lists! // correct the lists!
maS2O.Remove( static_cast<sal_uInt32>(nCurPos) ); maS2O.Move( static_cast<sal_uInt32>(nCurPos), nNewPos );
maS2O.Insert( pData, nNewPos );
for (size_t j = 1; j < m_O2S.size(); ++j) for (size_t j = 1; j < m_O2S.size(); ++j)
{ {
nVal = m_O2S[j]; nVal = m_O2S[j];
...@@ -1630,12 +1625,12 @@ void SortedResultSet::ResortModified( EventList* pList ) ...@@ -1630,12 +1625,12 @@ void SortedResultSet::ResortModified( EventList* pList )
m_O2S[pData->mnCurPos] = nNewPos; m_O2S[pData->mnCurPos] = nNewPos;
pAction = new ListAction; std::unique_ptr<ListAction> pAction(new ListAction);
pAction->Position = nCurPos; pAction->Position = nCurPos;
pAction->Count = 1; pAction->Count = 1;
pAction->ListActionType = ListActionType::MOVED; pAction->ListActionType = ListActionType::MOVED;
pAction->ActionInfo <<= nNewPos-nCurPos; pAction->ActionInfo <<= nNewPos-nCurPos;
pList->Insert( pAction ); pList->Insert( std::move(pAction) );
} }
pList->AddEvent( ListActionType::PROPERTIES_CHANGED, nNewPos ); pList->AddEvent( ListActionType::PROPERTIES_CHANGED, nNewPos );
} }
...@@ -1661,8 +1656,7 @@ void SortedResultSet::ResortNew( EventList* pList ) ...@@ -1661,8 +1656,7 @@ void SortedResultSet::ResortNew( EventList* pList )
nNewPos = FindPos( pData, 1, mnLastSort ); nNewPos = FindPos( pData, 1, mnLastSort );
if ( nNewPos != i ) if ( nNewPos != i )
{ {
maS2O.Remove( static_cast<sal_uInt32>(i) ); maS2O.Move( static_cast<sal_uInt32>(i), nNewPos );
maS2O.Insert( pData, nNewPos );
for (size_t j=1; j< m_O2S.size(); ++j) for (size_t j=1; j< m_O2S.size(); ++j)
{ {
nVal = m_O2S[j]; nVal = m_O2S[j];
...@@ -1692,38 +1686,44 @@ SortListData::SortListData( sal_IntPtr nPos ) ...@@ -1692,38 +1686,44 @@ SortListData::SortListData( sal_IntPtr nPos )
mnOldPos = nPos; mnOldPos = nPos;
}; };
SortedEntryList::SortedEntryList()
{
}
void SortedEntryList::Clear() SortedEntryList::~SortedEntryList()
{ {
for (SortListData* p : maData) }
{
delete p;
}
void SortedEntryList::Clear()
{
maData.clear(); maData.clear();
} }
void SortedEntryList::Insert( SortListData *pEntry, sal_IntPtr nPos ) void SortedEntryList::Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos )
{ {
if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
maData.insert( maData.begin() + nPos, pEntry ); maData.insert( maData.begin() + nPos, std::move(pEntry) );
else else
maData.push_back( pEntry ); maData.push_back( std::move(pEntry) );
} }
void SortedEntryList::Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos )
{
auto p = std::move(maData[nOldPos]);
maData.erase( maData.begin() + nOldPos );
maData.insert(maData.begin() + nNewPos, std::move(p));
}
SortListData* SortedEntryList::Remove( sal_IntPtr nPos ) std::unique_ptr<SortListData> SortedEntryList::Remove( sal_IntPtr nPos )
{ {
SortListData *pData; std::unique_ptr<SortListData> pData;
if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
{ {
pData = maData[ nPos ]; pData = std::move(maData[ nPos ]);
maData.erase( maData.begin() + nPos ); maData.erase( maData.begin() + nPos );
} }
else
pData = nullptr;
return pData; return pData;
} }
...@@ -1734,7 +1734,7 @@ SortListData* SortedEntryList::GetData( sal_IntPtr nPos ) ...@@ -1734,7 +1734,7 @@ SortListData* SortedEntryList::GetData( sal_IntPtr nPos )
SortListData *pData; SortListData *pData;
if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
pData = maData[ nPos ]; pData = maData[ nPos ].get();
else else
pData = nullptr; pData = nullptr;
...@@ -1747,7 +1747,7 @@ sal_IntPtr SortedEntryList::operator [] ( sal_IntPtr nPos ) const ...@@ -1747,7 +1747,7 @@ sal_IntPtr SortedEntryList::operator [] ( sal_IntPtr nPos ) const
SortListData *pData; SortListData *pData;
if ( nPos < static_cast<sal_IntPtr>(maData.size()) ) if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
pData = maData[ nPos ]; pData = maData[ nPos ].get();
else else
pData = nullptr; pData = nullptr;
......
...@@ -52,37 +52,37 @@ class PropertyChangeListeners_Impl; ...@@ -52,37 +52,37 @@ class PropertyChangeListeners_Impl;
class SortedEntryList class SortedEntryList
{ {
std::deque < SortListData* > maData; std::deque < std::unique_ptr<SortListData> > maData;
public: public:
SortedEntryList(){} SortedEntryList();
~SortedEntryList(){ Clear(); } ~SortedEntryList();
sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); } sal_uInt32 Count() const { return static_cast<sal_uInt32>(maData.size()); }
void Clear(); void Clear();
void Insert( SortListData *pEntry, sal_IntPtr nPos ); void Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos );
SortListData* Remove( sal_IntPtr nPos ); std::unique_ptr<SortListData> Remove( sal_IntPtr nPos );
SortListData* GetData( sal_IntPtr nPos ); SortListData* GetData( sal_IntPtr nPos );
void Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos );
sal_IntPtr operator [] ( sal_IntPtr nPos ) const; sal_IntPtr operator [] ( sal_IntPtr nPos ) const;
}; };
class EventList class EventList
{ {
std::deque < css::ucb::ListAction* > maData; std::deque < std::unique_ptr<css::ucb::ListAction> > maData;
public: public:
EventList(){} EventList(){}
~EventList(){ Clear(); }
sal_uInt32 Count() { return static_cast<sal_uInt32>(maData.size()); } sal_uInt32 Count() { return static_cast<sal_uInt32>(maData.size()); }
void AddEvent( sal_IntPtr nType, sal_IntPtr nPos ); void AddEvent( sal_IntPtr nType, sal_IntPtr nPos );
void Insert( css::ucb::ListAction *pAction ) { maData.push_back( pAction ); } void Insert( std::unique_ptr<css::ucb::ListAction> pAction ) { maData.push_back( std::move(pAction) ); }
void Clear(); void Clear();
css::ucb::ListAction* GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ]; } css::ucb::ListAction* GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ].get(); }
}; };
......
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