Hello libreoffice devs,
this is my first patch series to the lo project. It replaces the use
of the tools Stack class and corresponding macros with the std::stack
as suggested in in bug #39445 [1] (an easy hack).
I would like to continue with cleaning up the tools module. I've seen
that there are other containers in tools like a Table which probably
could be replaced in most places with a std::table or a std::vector and
the List that could be replaced with std::vector. Should I set up a new
Bug for that or can I just hack on if there aren't any objections on
these changes?
[1] https://bugs.freedesktop.org/show_bug.cgi?id=39445#c1
---
sc/inc/chgtrack.hxx | 10 +---
sc/source/core/tool/chgtrack.cxx | 69
+++++++++++++++------------
sc/source/filter/inc/XclExpChangeTrack.hxx | 1 +
3 files changed, 42 insertions(+), 38 deletions(-)
diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index 11159ed..5dc02d8 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -30,11 +30,11 @@
#define SC_CHGTRACK_HXX
#include <deque>
+#include <stack>
#include <tools/string.hxx>
#include <tools/datetime.hxx>
#include <tools/table.hxx>
-#include <tools/stack.hxx>
#include <tools/mempool.hxx>
#include <tools/link.hxx>
#include <unotools/options.hxx>
@@ -689,8 +689,6 @@ enum ScChangeActionContentCellType
SC_CACCT_MATREF
};
-class Stack;
-
class ScChangeActionContent : public ScChangeAction
{
friend class ScChangeTrack;
@@ -779,7 +777,7 @@ class ScChangeActionContent : public ScChangeAction
// pRejectActions!=NULL: reject actions get
// stacked, no SetNewValue, no Append
sal_Bool Select( ScDocument*, ScChangeTrack*,
- sal_Bool bOldest, Stack* pRejectActions );
+ sal_Bool bOldest, ::std::stack<ScChangeActionContent*>*
pRejectActions );
void PutValueToDoc( ScBaseCell*, const String&,
ScDocument*, SCsCOL nDx, SCsROW nDy ) const;
@@ -901,8 +899,6 @@ public:
// --- ScChangeActionReject -------------------------------------------------
-class Stack;
-
class ScChangeActionReject : public ScChangeAction
{
friend class ScChangeTrack;
@@ -955,7 +951,7 @@ struct ScChangeTrackMsgInfo
// MsgQueue for notification via ModifiedLink
typedef std::deque<ScChangeTrackMsgInfo*> ScChangeTrackMsgQueue;
-DECLARE_STACK( ScChangeTrackMsgStack, ScChangeTrackMsgInfo* )
+typedef std::stack<ScChangeTrackMsgInfo*> ScChangeTrackMsgStack;
enum ScChangeTrackMergeState
{
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index b63e5c6..8063cc9 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -29,7 +29,6 @@
#include <tools/shl.hxx> // SHL_CALC
-#include <tools/stack.hxx>
#include <tools/rtti.hxx>
#include <svl/zforlist.hxx>
#include <svl/itemset.hxx>
@@ -53,13 +52,9 @@
#include "globstr.hrc"
-#include <stack>
-
#define SC_CHGTRACK_CXX
#include "chgtrack.hxx"
-DECLARE_STACK( ScChangeActionStack, ScChangeAction* )
-
const sal_uInt16 nMemPoolChangeActionCellListEntry = (0x2000 - 64) /
sizeof(ScChangeActionCellListEntry);
IMPL_FIXEDMEMPOOL_NEWDEL( ScChangeActionCellListEntry, nMemPoolChangeActionCellListEntry,
nMemPoolChangeActionCellListEntry )
@@ -1518,7 +1513,7 @@ sal_Bool ScChangeActionContent::Reject( ScDocument* pDoc )
sal_Bool ScChangeActionContent::Select( ScDocument* pDoc, ScChangeTrack* pTrack,
- sal_Bool bOldest, Stack* pRejectActions )
+ sal_Bool bOldest, ::std::stack<ScChangeActionContent*>* pRejectActions )
{
if ( !aBigRange.IsValid( pDoc ) )
return false;
@@ -1563,7 +1558,7 @@ sal_Bool ScChangeActionContent::Select( ScDocument* pDoc, ScChangeTrack*
pTrack,
pNew->SetRejectAction( bOldest ? GetActionNumber() : pEnd->GetActionNumber() );
pNew->SetState( SC_CAS_ACCEPTED );
if ( pRejectActions )
- pRejectActions->Push( pNew );
+ pRejectActions->push( pNew );
else
{
pNew->SetNewValue( pDoc->GetCell( rPos ), pDoc );
@@ -2143,11 +2138,16 @@ void ScChangeTrack::ClearMsgQueue()
delete pBlockModifyMsg;
pBlockModifyMsg = NULL;
}
- ScChangeTrackMsgInfo* pMsgInfo;
- while ( ( pMsgInfo = aMsgStackTmp.Pop() ) != NULL )
- delete pMsgInfo;
- while ( ( pMsgInfo = aMsgStackFinal.Pop() ) != NULL )
- delete pMsgInfo;
+ while ( !aMsgStackTmp.empty() )
+ {
+ delete aMsgStackTmp.top();
+ aMsgStackTmp.pop();
+ }
+ while ( !aMsgStackFinal.empty() );
+ {
+ delete aMsgStackFinal.top();
+ aMsgStackFinal.pop();
+ }
ScChangeTrackMsgQueue::iterator itQueue;
for ( itQueue = aMsgQueue.begin(); itQueue != aMsgQueue.end(); ++itQueue)
@@ -2214,7 +2214,7 @@ void ScChangeTrack::StartBlockModify( ScChangeTrackMsgType eMsgType,
if ( aModifiedLink.IsSet() )
{
if ( pBlockModifyMsg )
- aMsgStackTmp.Push( pBlockModifyMsg ); // Block im Block
+ aMsgStackTmp.push( pBlockModifyMsg ); // Block im Block
pBlockModifyMsg = new ScChangeTrackMsgInfo;
pBlockModifyMsg->eMsgType = eMsgType;
pBlockModifyMsg->nStartAction = nStartAction;
@@ -2232,19 +2232,20 @@ void ScChangeTrack::EndBlockModify( sal_uLong nEndAction )
{
pBlockModifyMsg->nEndAction = nEndAction;
// Blocks in Blocks aufgeloest
- aMsgStackFinal.Push( pBlockModifyMsg );
+ aMsgStackFinal.push( pBlockModifyMsg );
}
else
delete pBlockModifyMsg;
- pBlockModifyMsg = aMsgStackTmp.Pop(); // evtl. Block im Block
+ pBlockModifyMsg = aMsgStackTmp.top(); // evtl. Block im Block
+ aMsgStackTmp.pop();
}
if ( !pBlockModifyMsg )
{
sal_Bool bNew = false;
- ScChangeTrackMsgInfo* pMsg;
- while ( ( pMsg = aMsgStackFinal.Pop() ) != NULL )
+ while ( !aMsgStackFinal.empty() )
{
- aMsgQueue.push_back( pMsg );
+ aMsgQueue.push_back( aMsgStackFinal.top() );
+ aMsgStackFinal.pop();
bNew = sal_True;
}
if ( bNew )
@@ -3846,10 +3847,15 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
sal_Bool bIsDelete = pAct->IsDeleteType();
sal_Bool bIsMasterDelete = ( bListMasterDelete && pAct->IsMasterDelete() );
- const ScChangeAction* pCur = pAct;
- ScChangeActionStack* pStack = new ScChangeActionStack;
- do
+ const ScChangeAction* pCur = NULL;
+ ::std::stack<ScChangeAction*> cStack;
+ cStack.push(pAct);
+
+ while ( !cStack.empty() )
{
+ pCur = cStack.top();
+ cStack.pop();
+
if ( pCur->IsInsertType() )
{
const ScChangeActionLinkEntry* pL = pCur->GetFirstDependentEntry();
@@ -3863,7 +3869,7 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
sal_uLong n = p->GetActionNumber();
if ( !IsGenerated( n ) && rTable.Insert( n, p ) )
if ( p->HasDependent() )
- pStack->Push( p );
+ cStack.push( p );
}
else
{
@@ -3911,7 +3917,7 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
if ( !IsGenerated( n ) && rTable.Insert( n, p ) )
if ( p->HasDeleted() ||
p->GetType() == SC_CAT_CONTENT )
- pStack->Push( p );
+ cStack.push( p );
}
else
{
@@ -3942,7 +3948,7 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
// nur ein TopContent einer Kette ist in LinkDeleted
if ( bAllFlat && (p->HasDeleted() ||
p->GetType() == SC_CAT_CONTENT) )
- pStack->Push( p );
+ cStack.push( p );
}
pL = pL->GetNext();
}
@@ -3959,7 +3965,7 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
sal_uLong n = p->GetActionNumber();
if ( !IsGenerated( n ) && rTable.Insert( n, p ) )
if ( p->HasDependent() || p->HasDeleted() )
- pStack->Push( p );
+ cStack.push( p );
}
else
{
@@ -4003,7 +4009,7 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
sal_uLong n = p->GetActionNumber();
if ( !IsGenerated( n ) && rTable.Insert( n, p ) )
if ( p->HasDependent() )
- pStack->Push( p );
+ cStack.push( p );
}
else
rTable.Insert( p->GetActionNumber(), p );
@@ -4018,11 +4024,10 @@ void ScChangeTrack::GetDependents( ScChangeAction* pAct,
ScChangeAction* p = GetAction(
((ScChangeActionReject*)pCur)->GetRejectAction() );
if ( p != pAct && !rTable.Get( p->GetActionNumber() ) )
- pStack->Push( p );
+ cStack.push( p );
}
}
- } while ( ( pCur = pStack->Pop() ) != NULL );
- delete pStack;
+ }
}
@@ -4067,7 +4072,7 @@ sal_Bool ScChangeTrack::SelectContent( ScChangeAction* pAct, sal_Bool bOldest
)
if ( pContent->HasDependent() )
{
sal_Bool bOk = sal_True;
- Stack aRejectActions;
+ ::std::stack<ScChangeActionContent*> aRejectActions;
const ScChangeActionLinkEntry* pL = pContent->GetFirstDependentEntry();
while ( pL )
{
@@ -4092,8 +4097,10 @@ sal_Bool ScChangeTrack::SelectContent( ScChangeAction* pAct, sal_Bool
bOldest )
// now the matrix is inserted and new content values are ready
ScChangeActionContent* pNew;
- while ( ( pNew = (ScChangeActionContent*) aRejectActions.Pop() ) != NULL )
+ while ( !aRejectActions.empty() )
{
+ pNew = aRejectActions.top();
+ aRejectActions.pop();
ScAddress aPos( pNew->GetBigRange().aStart.MakeAddress() );
pNew->SetNewValue( pDoc->GetCell( aPos ), pDoc );
Append( pNew );
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx b/sc/source/filter/inc/XclExpChangeTrack.hxx
index 3fb4883..b3e8009 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -30,6 +30,7 @@
#define SC_XCLEXPCHANGETRACK_HXX
#include <tools/datetime.hxx>
+#include <tools/stack.hxx>
#include <rtl/uuid.h>
#include "bigrange.hxx"
#include "chgtrack.hxx"
Context
- [Libreoffice] [PATCH 01/11] Replace ScChangeTrackMsgStack with std::stack< ScChangeTrackMsgInfo* > · Marcel Metz
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.