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

loplugin:useuniqueptr in ScHTMLLayoutParser

bitfields and make_unique don't play nice together, so bFirstRow
had to become a regular bool field.

Change-Id: I990a0ddcbbef5e826fbe26736e68ebce55cebb4c
Reviewed-on: https://gerrit.libreoffice.org/57303
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst cdd373e5
...@@ -214,12 +214,12 @@ ScHTMLLayoutParser::ScHTMLLayoutParser( ...@@ -214,12 +214,12 @@ ScHTMLLayoutParser::ScHTMLLayoutParser(
nColOffset(0), nColOffset(0),
nColOffsetStart(0), nColOffsetStart(0),
nOffsetTolerance( SC_HTML_OFFSET_TOLERANCE_SMALL ), nOffsetTolerance( SC_HTML_OFFSET_TOLERANCE_SMALL ),
bTabInTabCell( false ),
bFirstRow( true ), bFirstRow( true ),
bTabInTabCell( false ),
bInCell( false ), bInCell( false ),
bInTitle( false ) bInTitle( false )
{ {
MakeColNoRef( pLocalColOffset, 0, 0, 0, 0 ); MakeColNoRef( pLocalColOffset.get(), 0, 0, 0, 0 );
MakeColNoRef( &maColOffset, 0, 0, 0, 0 ); MakeColNoRef( &maColOffset, 0, 0, 0, 0 );
} }
...@@ -227,18 +227,17 @@ ScHTMLLayoutParser::~ScHTMLLayoutParser() ...@@ -227,18 +227,17 @@ ScHTMLLayoutParser::~ScHTMLLayoutParser()
{ {
while ( !aTableStack.empty() ) while ( !aTableStack.empty() )
{ {
ScHTMLTableStackEntry* pS = aTableStack.top(); ScHTMLTableStackEntry* pS = aTableStack.top().get();
aTableStack.pop(); if ( pS->pLocalColOffset != pLocalColOffset.get() )
if ( pS->pLocalColOffset != pLocalColOffset )
delete pS->pLocalColOffset; delete pS->pLocalColOffset;
delete pS; aTableStack.pop();
} }
delete pLocalColOffset; pLocalColOffset.reset();
if ( pTables ) if ( pTables )
{ {
for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it) for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it)
delete it->second; delete it->second;
delete pTables; pTables.reset();
} }
} }
...@@ -646,7 +645,7 @@ void ScHTMLLayoutParser::SetWidths() ...@@ -646,7 +645,7 @@ void ScHTMLLayoutParser::SetWidths()
pLocalColOffset->clear(); pLocalColOffset->clear();
for ( nCol = 0; nCol <= nColsPerRow; ++nCol, nOff = nOff + nWidth ) for ( nCol = 0; nCol <= nColsPerRow; ++nCol, nOff = nOff + nWidth )
{ {
MakeColNoRef( pLocalColOffset, nOff, 0, 0, 0 ); MakeColNoRef( pLocalColOffset.get(), nOff, 0, 0, 0 );
} }
nTableWidth = static_cast<sal_uInt16>(pLocalColOffset->back() - pLocalColOffset->front()); nTableWidth = static_cast<sal_uInt16>(pLocalColOffset->back() - pLocalColOffset->front());
for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i ) for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i )
...@@ -736,7 +735,7 @@ void ScHTMLLayoutParser::SetWidths() ...@@ -736,7 +735,7 @@ void ScHTMLLayoutParser::SetWidths()
pLocalColOffset->clear(); pLocalColOffset->clear();
for ( nCol = 0; nCol <= nColsPerRow; nCol++ ) for ( nCol = 0; nCol <= nColsPerRow; nCol++ )
{ {
MakeColNoRef( pLocalColOffset, pOffsets[nCol], 0, 0, 0 ); MakeColNoRef( pLocalColOffset.get(), pOffsets[nCol], 0, 0, 0 );
} }
nTableWidth = pOffsets[nColsPerRow] - pOffsets[0]; nTableWidth = pOffsets[nColsPerRow] - pOffsets[0];
...@@ -800,7 +799,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE ) ...@@ -800,7 +799,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE )
} }
pE->nOffset = nColOffset; pE->nOffset = nColOffset;
sal_uInt16 nWidth = GetWidth( pE ); sal_uInt16 nWidth = GetWidth( pE );
MakeCol( pLocalColOffset, pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance ); MakeCol( pLocalColOffset.get(), pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance );
if ( pE->nWidth ) if ( pE->nWidth )
pE->nWidth = nWidth; pE->nWidth = nWidth;
nColOffset = pE->nOffset + nWidth; nColOffset = pE->nOffset + nWidth;
...@@ -1032,8 +1031,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1032,8 +1031,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
{ // Table in Table { // Table in Table
sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize() sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize()
Colonize(mxActEntry.get()); Colonize(mxActEntry.get());
aTableStack.push( new ScHTMLTableStackEntry( aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell, mxActEntry, xLockedList, pLocalColOffset.get(), nFirstTableCell,
nRowCnt, nColCntStart, nMaxCol, nTable, nRowCnt, nColCntStart, nMaxCol, nTable,
nTableWidth, nColOffset, nColOffsetStart, nTableWidth, nColOffset, nColOffsetStart,
bFirstRow ) ); bFirstRow ) );
...@@ -1088,8 +1087,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1088,8 +1087,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
CloseEntry( pInfo ); CloseEntry( pInfo );
NextRow( pInfo ); NextRow( pInfo );
} }
aTableStack.push( new ScHTMLTableStackEntry( aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell, mxActEntry, xLockedList, pLocalColOffset.get(), nFirstTableCell,
nRowCnt, nColCntStart, nMaxCol, nTable, nRowCnt, nColCntStart, nMaxCol, nTable,
nTableWidth, nColOffset, nColOffsetStart, nTableWidth, nColOffset, nColOffsetStart,
bFirstRow ) ); bFirstRow ) );
...@@ -1122,8 +1121,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo ) ...@@ -1122,8 +1121,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
bFirstRow = true; bFirstRow = true;
nFirstTableCell = maList.size(); nFirstTableCell = maList.size();
pLocalColOffset = new ScHTMLColOffset; pLocalColOffset.reset( new ScHTMLColOffset );
MakeColNoRef( pLocalColOffset, nColOffsetStart, 0, 0, 0 ); MakeColNoRef( pLocalColOffset.get(), nColOffsetStart, 0, 0, 0 );
} }
void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
...@@ -1141,7 +1140,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1141,7 +1140,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
{ // Table in Table done { // Table in Table done
if ( !aTableStack.empty() ) if ( !aTableStack.empty() )
{ {
ScHTMLTableStackEntry* pS = aTableStack.top(); std::unique_ptr<ScHTMLTableStackEntry> pS = std::move(aTableStack.top());
aTableStack.pop(); aTableStack.pop();
auto& pE = pS->xCellEntry; auto& pE = pS->xCellEntry;
...@@ -1151,7 +1150,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1151,7 +1150,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
SCROW nRow = pS->nRowCnt; SCROW nRow = pS->nRowCnt;
sal_uInt16 nTab = pS->nTable; sal_uInt16 nTab = pS->nTable;
if ( !pTables ) if ( !pTables )
pTables = new OuterMap; pTables.reset( new OuterMap );
// Height of outer table // Height of outer table
OuterMap::const_iterator it = pTables->find( nTab ); OuterMap::const_iterator it = pTables->find( nTab );
InnerMap* pTab1; InnerMap* pTab1;
...@@ -1258,12 +1257,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1258,12 +1257,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
nColOffsetStart = pS->nColOffsetStart; nColOffsetStart = pS->nColOffsetStart;
bFirstRow = pS->bFirstRow; bFirstRow = pS->bFirstRow;
xLockedList = pS->xLockedList; xLockedList = pS->xLockedList;
delete pLocalColOffset; pLocalColOffset.reset( pS->pLocalColOffset );
pLocalColOffset = pS->pLocalColOffset;
// mxActEntry is kept around if a table is started in the same row // mxActEntry is kept around if a table is started in the same row
// (anything's possible in HTML); will be deleted by CloseEntry // (anything's possible in HTML); will be deleted by CloseEntry
mxActEntry = pE; mxActEntry = pE;
delete pS;
} }
bTabInTabCell = true; bTabInTabCell = true;
bInCell = true; bInCell = true;
...@@ -1275,11 +1272,9 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo ) ...@@ -1275,11 +1272,9 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
nTable = 0; nTable = 0;
if ( !aTableStack.empty() ) if ( !aTableStack.empty() )
{ {
ScHTMLTableStackEntry* pS = aTableStack.top(); std::unique_ptr<ScHTMLTableStackEntry> pS = std::move(aTableStack.top());
aTableStack.pop(); aTableStack.pop();
delete pLocalColOffset; pLocalColOffset.reset( pS->pLocalColOffset );
pLocalColOffset = pS->pLocalColOffset;
delete pS;
} }
} }
} }
...@@ -1385,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo ) ...@@ -1385,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo )
if( rOption.GetToken() == HtmlOptionId::WIDTH ) if( rOption.GetToken() == HtmlOptionId::WIDTH )
{ {
sal_uInt16 nVal = GetWidthPixel( rOption ); sal_uInt16 nVal = GetWidthPixel( rOption );
MakeCol( pLocalColOffset, nColOffset, nVal, 0, 0 ); MakeCol( pLocalColOffset.get(), nColOffset, nVal, 0, 0 );
nColOffset = nColOffset + nVal; nColOffset = nColOffset + nVal;
} }
} }
......
...@@ -152,13 +152,13 @@ class ScHTMLLayoutParser : public ScHTMLParser ...@@ -152,13 +152,13 @@ class ScHTMLLayoutParser : public ScHTMLParser
private: private:
Size aPageSize; Size aPageSize;
OUString aBaseURL; OUString aBaseURL;
::std::stack< ScHTMLTableStackEntry* > ::std::stack< std::unique_ptr<ScHTMLTableStackEntry> >
aTableStack; aTableStack;
OUString aString; OUString aString;
ScRangeListRef xLockedList; // per table ScRangeListRef xLockedList; // per table
OuterMap* pTables; std::unique_ptr<OuterMap> pTables;
ScHTMLColOffset maColOffset; ScHTMLColOffset maColOffset;
ScHTMLColOffset* pLocalColOffset; // per table std::unique_ptr<ScHTMLColOffset> pLocalColOffset; // per table
sal_uLong nFirstTableCell; // per table sal_uLong nFirstTableCell; // per table
short nTableLevel; short nTableLevel;
sal_uInt16 nTable; sal_uInt16 nTable;
...@@ -169,8 +169,8 @@ private: ...@@ -169,8 +169,8 @@ private:
sal_uInt16 nColOffset; // current, pixel sal_uInt16 nColOffset; // current, pixel
sal_uInt16 nColOffsetStart; // start value per table, in pixel sal_uInt16 nColOffsetStart; // start value per table, in pixel
sal_uInt16 nOffsetTolerance; // for use with SeekOffset and related sal_uInt16 nOffsetTolerance; // for use with SeekOffset and related
bool bFirstRow; // per table, whether in first row
bool bTabInTabCell:1; bool bTabInTabCell:1;
bool bFirstRow:1; // per table, whether in first row
bool bInCell:1; bool bInCell:1;
bool bInTitle:1; bool bInTitle:1;
......
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