[Libreoffice-commits] core.git: sc/inc sc/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Aug 24 06:55:01 UTC 2018
sc/inc/chgtrack.hxx | 10 +-
sc/source/core/tool/chgtrack.cxx | 3
sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx | 76 +++++++----------
sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx | 14 +--
4 files changed, 47 insertions(+), 56 deletions(-)
New commits:
commit a5e733aa1d7a6e4905062dae85376fcad2c92c67
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Aug 22 15:51:30 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Aug 24 08:54:37 2018 +0200
pass ScChangeAction around by std::unique_ptr
Change-Id: I34dbed97f01a14dbdcdaaec90233a4a1641cee0e
Reviewed-on: https://gerrit.libreoffice.org/59454
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index eb7c63d3174c..e39920bfe5c0 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -215,8 +215,6 @@ protected:
// only to be used in the XML import
ScChangeAction( ScChangeActionType, const ScBigRange&, const sal_uLong nAction);
- virtual ~ScChangeAction();
-
OUString GetRefString(
const ScBigRange& rRange, const ScDocument* pDoc, bool bFlag3D = false) const;
@@ -277,6 +275,8 @@ protected:
virtual const ScChangeTrack* GetChangeTrack() const = 0;
public:
+ virtual ~ScChangeAction();
+
bool IsInsertType() const;
bool IsDeleteType() const;
bool IsVirgin() const;
@@ -367,7 +367,6 @@ class ScChangeActionIns : public ScChangeAction
bool mbEndOfList; /// whether or not a row was auto-inserted at the bottom.
ScChangeActionIns( const ScRange& rRange, bool bEndOfList = false );
- virtual ~ScChangeActionIns() override;
virtual void AddContent( ScChangeActionContent* ) override {}
virtual void DeleteCellEntries() override {}
@@ -377,6 +376,7 @@ class ScChangeActionIns : public ScChangeAction
virtual const ScChangeTrack* GetChangeTrack() const override { return nullptr; }
public:
+ virtual ~ScChangeActionIns() override;
ScChangeActionIns(
const sal_uLong nActionNumber,
const ScChangeActionState eState,
@@ -437,7 +437,6 @@ class ScChangeActionDel : public ScChangeAction
SCROW nDy;
ScChangeActionDel( const ScRange& rRange, SCCOL nDx, SCROW nDy, ScChangeTrack* );
- virtual ~ScChangeActionDel() override;
virtual void AddContent( ScChangeActionContent* ) override;
virtual void DeleteCellEntries() override;
@@ -461,6 +460,7 @@ public:
const OUString &sComment, const ScChangeActionType eType,
const SCCOLROW nD, ScChangeTrack* pTrack); // only to use in the XML import
// which of nDx and nDy is set is dependent on the type
+ virtual ~ScChangeActionDel() override;
// is the last in a row (or single)
bool IsBaseDelete() const;
@@ -1123,7 +1123,7 @@ public:
sal_uLong AddLoadedGenerated( const ScCellValue& rNewCell,
const ScBigRange& aBigRange, const OUString& sNewValue ); // only to use in the XML import
- void AppendLoaded( ScChangeAction* pAppend ); // this is only for the XML import public, it should be protected
+ void AppendLoaded( std::unique_ptr<ScChangeAction> pAppend ); // this is only for the XML import public, it should be protected
void SetActionMax(sal_uLong nTempActionMax)
{ nActionMax = nTempActionMax; } // only to use in the XML import
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 840e5905af9a..149a7f016c7a 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -2379,8 +2379,9 @@ void ScChangeTrack::MasterLinks( ScChangeAction* pAppend )
}
}
-void ScChangeTrack::AppendLoaded( ScChangeAction* pAppend )
+void ScChangeTrack::AppendLoaded( std::unique_ptr<ScChangeAction> pActionParam )
{
+ ScChangeAction* pAppend = pActionParam.release();
aMap.insert( ::std::make_pair( pAppend->GetActionNumber(), pAppend ) );
if ( !pLast )
pFirst = pLast = pAppend;
diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
index 8d0c4ce6c9b7..e440861e43f6 100644
--- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
+++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx
@@ -26,6 +26,7 @@
#include <tools/datetime.hxx>
#include <osl/diagnose.h>
#include <svl/zforlist.hxx>
+#include <o3tl/make_unique.hxx>
#include <sax/tools/converter.hxx>
#define SC_CHANGE_ID_PREFIX "ct"
@@ -168,29 +169,29 @@ void ScXMLChangeTrackingImportHelper::StartChangeAction(const ScChangeActionType
case SC_CAT_INSERT_ROWS:
case SC_CAT_INSERT_TABS:
{
- pCurrentAction = new ScMyInsAction(nActionType);
+ pCurrentAction = o3tl::make_unique<ScMyInsAction>(nActionType);
}
break;
case SC_CAT_DELETE_COLS:
case SC_CAT_DELETE_ROWS:
case SC_CAT_DELETE_TABS:
{
- pCurrentAction = new ScMyDelAction(nActionType);
+ pCurrentAction = o3tl::make_unique<ScMyDelAction>(nActionType);
}
break;
case SC_CAT_MOVE:
{
- pCurrentAction = new ScMyMoveAction();
+ pCurrentAction = o3tl::make_unique<ScMyMoveAction>();
}
break;
case SC_CAT_CONTENT:
{
- pCurrentAction = new ScMyContentAction();
+ pCurrentAction = o3tl::make_unique<ScMyContentAction>();
}
break;
case SC_CAT_REJECT:
{
- pCurrentAction = new ScMyRejAction();
+ pCurrentAction = o3tl::make_unique<ScMyRejAction>();
}
break;
default:
@@ -231,7 +232,7 @@ void ScXMLChangeTrackingImportHelper::SetPreviousChange(const sal_uInt32 nPrevio
ScMyCellInfo* pCellInfo)
{
OSL_ENSURE(pCurrentAction->nActionType == SC_CAT_CONTENT, "wrong action type");
- ScMyContentAction* pAction = static_cast<ScMyContentAction*>(pCurrentAction);
+ ScMyContentAction* pAction = static_cast<ScMyContentAction*>(pCurrentAction.get());
pAction->nPreviousAction = nPreviousAction;
pAction->pCellInfo.reset( pCellInfo );
}
@@ -298,7 +299,7 @@ void ScXMLChangeTrackingImportHelper::SetInsertionCutOff(const sal_uInt32 nID, c
if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
(pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
{
- static_cast<ScMyDelAction*>(pCurrentAction)->pInsCutOff.reset( new ScMyInsertionCutOff(nID, nPosition) );
+ static_cast<ScMyDelAction*>(pCurrentAction.get())->pInsCutOff.reset( new ScMyInsertionCutOff(nID, nPosition) );
}
else
{
@@ -311,7 +312,7 @@ void ScXMLChangeTrackingImportHelper::AddMoveCutOff(const sal_uInt32 nID, const
if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
(pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
{
- static_cast<ScMyDelAction*>(pCurrentAction)->aMoveCutOffs.push_front(ScMyMoveCutOff(nID, nStartPosition, nEndPosition));
+ static_cast<ScMyDelAction*>(pCurrentAction.get())->aMoveCutOffs.push_front(ScMyMoveCutOff(nID, nStartPosition, nEndPosition));
}
else
{
@@ -323,7 +324,7 @@ void ScXMLChangeTrackingImportHelper::SetMoveRanges(const ScBigRange& aSourceRan
{
if (pCurrentAction->nActionType == SC_CAT_MOVE)
{
- static_cast<ScMyMoveAction*>(pCurrentAction)->pMoveRanges.reset( new ScMyMoveRanges(aSourceRange, aTargetRange) );
+ static_cast<ScMyMoveAction*>(pCurrentAction.get())->pMoveRanges.reset( new ScMyMoveRanges(aSourceRange, aTargetRange) );
}
else
{
@@ -338,7 +339,7 @@ void ScXMLChangeTrackingImportHelper::GetMultiSpannedRange()
{
if (nMultiSpannedSlaveCount)
{
- static_cast<ScMyDelAction*>(pCurrentAction)->nD = nMultiSpannedSlaveCount;
+ static_cast<ScMyDelAction*>(pCurrentAction.get())->nD = nMultiSpannedSlaveCount;
}
++nMultiSpannedSlaveCount;
if (nMultiSpannedSlaveCount >= nMultiSpanned)
@@ -358,12 +359,12 @@ void ScXMLChangeTrackingImportHelper::AddGenerated(std::unique_ptr<ScMyCellInfo>
ScMyGenerated aGenerated { aBigRange, 0, std::move(pCellInfo) };
if (pCurrentAction->nActionType == SC_CAT_MOVE)
{
- static_cast<ScMyMoveAction*>(pCurrentAction)->aGeneratedList.push_back(std::move(aGenerated));
+ static_cast<ScMyMoveAction*>(pCurrentAction.get())->aGeneratedList.push_back(std::move(aGenerated));
}
else if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) ||
(pCurrentAction->nActionType == SC_CAT_DELETE_ROWS))
{
- static_cast<ScMyDelAction*>(pCurrentAction)->aGeneratedList.push_back(std::move(aGenerated));
+ static_cast<ScMyDelAction*>(pCurrentAction.get())->aGeneratedList.push_back(std::move(aGenerated));
}
else
{
@@ -384,7 +385,7 @@ void ScXMLChangeTrackingImportHelper::EndChangeAction()
GetMultiSpannedRange();
if (pCurrentAction->nActionNumber > 0)
- aActions.push_back(pCurrentAction);
+ aActions.push_back(std::move(pCurrentAction));
else
{
OSL_FAIL("no current action");
@@ -412,7 +413,7 @@ void ScXMLChangeTrackingImportHelper::ConvertInfo(const ScMyActionInfo& aInfo, O
rUser = aInfo.sUser; // shouldn't happen
}
-ScChangeAction* ScXMLChangeTrackingImportHelper::CreateInsertAction(const ScMyInsAction* pAction)
+std::unique_ptr<ScChangeAction> ScXMLChangeTrackingImportHelper::CreateInsertAction(const ScMyInsAction* pAction)
{
DateTime aDateTime( Date(0), tools::Time(0) );
OUString aUser;
@@ -420,12 +421,11 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateInsertAction(const ScMyIn
OUString sComment (pAction->aInfo.sComment);
- ScChangeAction* pNewAction = new ScChangeActionIns(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
+ return o3tl::make_unique<ScChangeActionIns>(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType);
- return pNewAction;
}
-ScChangeAction* ScXMLChangeTrackingImportHelper::CreateDeleteAction(const ScMyDelAction* pAction)
+std::unique_ptr<ScChangeAction> ScXMLChangeTrackingImportHelper::CreateDeleteAction(const ScMyDelAction* pAction)
{
DateTime aDateTime( Date(0), tools::Time(0) );
OUString aUser;
@@ -433,12 +433,11 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateDeleteAction(const ScMyDe
OUString sComment (pAction->aInfo.sComment);
- ScChangeAction* pNewAction = new ScChangeActionDel(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
+ return o3tl::make_unique<ScChangeActionDel>(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
pAction->aBigRange, aUser, aDateTime, sComment, pAction->nActionType, pAction->nD, pTrack);
- return pNewAction;
}
-ScChangeAction* ScXMLChangeTrackingImportHelper::CreateMoveAction(const ScMyMoveAction* pAction)
+std::unique_ptr<ScChangeAction> ScXMLChangeTrackingImportHelper::CreateMoveAction(const ScMyMoveAction* pAction)
{
OSL_ENSURE(pAction->pMoveRanges, "no move ranges");
if (pAction->pMoveRanges)
@@ -449,14 +448,13 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateMoveAction(const ScMyMove
OUString sComment (pAction->aInfo.sComment);
- ScChangeAction* pNewAction = new ScChangeActionMove(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
+ return o3tl::make_unique<ScChangeActionMove>(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
pAction->pMoveRanges->aTargetRange, aUser, aDateTime, sComment, pAction->pMoveRanges->aSourceRange , pTrack);
- return pNewAction;
}
return nullptr;
}
-ScChangeAction* ScXMLChangeTrackingImportHelper::CreateRejectionAction(const ScMyRejAction* pAction)
+std::unique_ptr<ScChangeAction> ScXMLChangeTrackingImportHelper::CreateRejectionAction(const ScMyRejAction* pAction)
{
DateTime aDateTime( Date(0), tools::Time(0) );
OUString aUser;
@@ -464,12 +462,11 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateRejectionAction(const ScM
OUString sComment (pAction->aInfo.sComment);
- ScChangeAction* pNewAction = new ScChangeActionReject(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
+ return o3tl::make_unique<ScChangeActionReject>(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
pAction->aBigRange, aUser, aDateTime, sComment);
- return pNewAction;
}
-ScChangeAction* ScXMLChangeTrackingImportHelper::CreateContentAction(const ScMyContentAction* pAction)
+std::unique_ptr<ScChangeAction> ScXMLChangeTrackingImportHelper::CreateContentAction(const ScMyContentAction* pAction)
{
ScCellValue aCell;
OUString sInputString;
@@ -485,9 +482,8 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateContentAction(const ScMyC
OUString sComment (pAction->aInfo.sComment);
- ScChangeAction* pNewAction = new ScChangeActionContent(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
+ return o3tl::make_unique<ScChangeActionContent>(pAction->nActionNumber, pAction->nActionState, pAction->nRejectingNumber,
pAction->aBigRange, aUser, aDateTime, sComment, aCell, pDoc, sInputString);
- return pNewAction;
}
void ScXMLChangeTrackingImportHelper::CreateGeneratedActions(std::deque<ScMyGenerated>& rList)
@@ -752,7 +748,7 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
auto aEndItr(aActions.end());
while (aItr != aEndItr)
{
- ScChangeAction* pAction = nullptr;
+ std::unique_ptr<ScChangeAction> pAction;
switch ((*aItr)->nActionType)
{
@@ -760,33 +756,33 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
case SC_CAT_INSERT_ROWS:
case SC_CAT_INSERT_TABS:
{
- pAction = CreateInsertAction(static_cast<ScMyInsAction*>(*aItr));
+ pAction = CreateInsertAction(static_cast<ScMyInsAction*>(aItr->get()));
}
break;
case SC_CAT_DELETE_COLS:
case SC_CAT_DELETE_ROWS:
case SC_CAT_DELETE_TABS:
{
- ScMyDelAction* pDelAct = static_cast<ScMyDelAction*>(*aItr);
+ ScMyDelAction* pDelAct = static_cast<ScMyDelAction*>(aItr->get());
pAction = CreateDeleteAction(pDelAct);
CreateGeneratedActions(pDelAct->aGeneratedList);
}
break;
case SC_CAT_MOVE:
{
- ScMyMoveAction* pMovAct = static_cast<ScMyMoveAction*>(*aItr);
+ ScMyMoveAction* pMovAct = static_cast<ScMyMoveAction*>(aItr->get());
pAction = CreateMoveAction(pMovAct);
CreateGeneratedActions(pMovAct->aGeneratedList);
}
break;
case SC_CAT_CONTENT:
{
- pAction = CreateContentAction(static_cast<ScMyContentAction*>(*aItr));
+ pAction = CreateContentAction(static_cast<ScMyContentAction*>(aItr->get()));
}
break;
case SC_CAT_REJECT:
{
- pAction = CreateRejectionAction(static_cast<ScMyRejAction*>(*aItr));
+ pAction = CreateRejectionAction(static_cast<ScMyRejAction*>(aItr->get()));
}
break;
default:
@@ -796,7 +792,7 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
}
if (pAction)
- pTrack->AppendLoaded(pAction);
+ pTrack->AppendLoaded(std::move(pAction));
else
{
OSL_FAIL("no action");
@@ -811,16 +807,12 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
aEndItr = aActions.end();
while (aItr != aEndItr)
{
- SetDependencies(*aItr);
+ SetDependencies(aItr->get());
if ((*aItr)->nActionType == SC_CAT_CONTENT)
++aItr;
else
- {
- if (*aItr)
- delete *aItr;
aItr = aActions.erase(aItr);
- }
}
aItr = aActions.begin();
@@ -828,9 +820,7 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc)
while (aItr != aEndItr)
{
OSL_ENSURE((*aItr)->nActionType == SC_CAT_CONTENT, "wrong action type");
- SetNewCell(static_cast<ScMyContentAction*>(*aItr));
- if (*aItr)
- delete *aItr;
+ SetNewCell(static_cast<ScMyContentAction*>(aItr->get()));
aItr = aActions.erase(aItr);
}
if (aProtect.getLength())
diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx
index deeb12a6674d..587cf654d2d8 100644
--- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx
+++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx
@@ -164,21 +164,21 @@ struct ScMyRejAction : public ScMyBaseAction
class ScXMLChangeTrackingImportHelper
{
std::set<OUString> aUsers;
- std::deque<ScMyBaseAction*> aActions;
+ std::deque<std::unique_ptr<ScMyBaseAction>> aActions;
css::uno::Sequence<sal_Int8> aProtect;
ScDocument* pDoc;
ScChangeTrack* pTrack;
- ScMyBaseAction* pCurrentAction;
+ std::unique_ptr<ScMyBaseAction> pCurrentAction;
sal_Int16 nMultiSpanned;
sal_Int16 nMultiSpannedSlaveCount;
private:
void ConvertInfo(const ScMyActionInfo& aInfo, OUString& rUser, DateTime& aDateTime);
- ScChangeAction* CreateInsertAction(const ScMyInsAction* pAction);
- ScChangeAction* CreateDeleteAction(const ScMyDelAction* pAction);
- ScChangeAction* CreateMoveAction(const ScMyMoveAction* pAction);
- ScChangeAction* CreateRejectionAction(const ScMyRejAction* pAction);
- ScChangeAction* CreateContentAction(const ScMyContentAction* pAction);
+ std::unique_ptr<ScChangeAction> CreateInsertAction(const ScMyInsAction* pAction);
+ std::unique_ptr<ScChangeAction> CreateDeleteAction(const ScMyDelAction* pAction);
+ std::unique_ptr<ScChangeAction> CreateMoveAction(const ScMyMoveAction* pAction);
+ std::unique_ptr<ScChangeAction> CreateRejectionAction(const ScMyRejAction* pAction);
+ std::unique_ptr<ScChangeAction> CreateContentAction(const ScMyContentAction* pAction);
void CreateGeneratedActions(std::deque<ScMyGenerated>& rList);
More information about the Libreoffice-commits
mailing list