summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-08-16 11:00:46 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-17 10:30:23 +0200
commitd94ec445b7377062a5b6503c2dc4a3182612cd0e (patch)
tree1cef39c1646cb4f49481206cc080f2678431137e /sc
parent070254c2a129d8e35bbdb37d38f90fec03490182 (diff)
loplugin:useuniqueptr in ScFormatRangeStyles
no need to store a ref-counted thing like OUString on the heap, just put it directly inside a std::vector. And no need to store a dynamic container like std::list on the heap either, just put it directly inside a std::vector. Change-Id: If14a620916caab543d799ca868ee94129a51c672 Reviewed-on: https://gerrit.libreoffice.org/59224 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/xml/XMLStylesExportHelper.cxx85
-rw-r--r--sc/source/filter/xml/XMLStylesExportHelper.hxx10
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx30
3 files changed, 43 insertions, 82 deletions
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index dba0fee848f6..3ee8db545ea9 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -703,27 +703,6 @@ ScFormatRangeStyles::ScFormatRangeStyles()
ScFormatRangeStyles::~ScFormatRangeStyles()
{
- auto i(aStyleNames.begin());
- auto endi(aStyleNames.end());
- while (i != endi)
- {
- delete *i;
- ++i;
- }
- i = aAutoStyleNames.begin();
- endi = aAutoStyleNames.end();
- while (i != endi)
- {
- delete *i;
- ++i;
- }
- ScMyFormatRangeListVec::iterator j(aTables.begin());
- ScMyFormatRangeListVec::iterator endj(aTables.end());
- while (j != endj)
- {
- delete *j;
- ++j;
- }
}
void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
@@ -732,16 +711,15 @@ void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
if (nTable > nSize)
for (sal_Int32 i = nSize; i < nTable; ++i)
{
- ScMyFormatRangeAddresses* aRangeAddresses(new ScMyFormatRangeAddresses);
- aTables.push_back(aRangeAddresses);
+ aTables.emplace_back();
}
}
-bool ScFormatRangeStyles::AddStyleName(OUString* rpString, sal_Int32& rIndex, const bool bIsAutoStyle)
+bool ScFormatRangeStyles::AddStyleName(OUString const & rString, sal_Int32& rIndex, const bool bIsAutoStyle)
{
if (bIsAutoStyle)
{
- aAutoStyleNames.push_back(rpString);
+ aAutoStyleNames.push_back(rString);
rIndex = aAutoStyleNames.size() - 1;
return true;
}
@@ -752,7 +730,7 @@ bool ScFormatRangeStyles::AddStyleName(OUString* rpString, sal_Int32& rIndex, co
sal_Int32 i(nCount - 1);
while ((i >= 0) && (!bFound))
{
- if (*aStyleNames.at(i) == *rpString)
+ if (aStyleNames.at(i) == rString)
bFound = true;
else
i--;
@@ -764,7 +742,7 @@ bool ScFormatRangeStyles::AddStyleName(OUString* rpString, sal_Int32& rIndex, co
}
else
{
- aStyleNames.push_back(rpString);
+ aStyleNames.push_back(rString);
rIndex = aStyleNames.size() - 1;
return true;
}
@@ -776,7 +754,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
sal_Int32 nPrefixLength(rPrefix.getLength());
OUString sTemp(rString.copy(nPrefixLength));
sal_Int32 nIndex(sTemp.toInt32());
- if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && *aAutoStyleNames.at(nIndex - 1) == rString)
+ if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1) == rString)
{
bIsAutoStyle = true;
return nIndex - 1;
@@ -787,7 +765,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
bool bFound(false);
while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
{
- if (*aStyleNames[i] == rString)
+ if (aStyleNames[i] == rString)
bFound = true;
else
++i;
@@ -802,7 +780,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
i = 0;
while (!bFound && static_cast<size_t>(i) < aAutoStyleNames.size())
{
- if (*aAutoStyleNames[i] == rString)
+ if (aAutoStyleNames[i] == rString)
bFound = true;
else
++i;
@@ -824,21 +802,16 @@ sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
if (static_cast<size_t>(nTable) >= aTables.size())
return -1;
- ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
- ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
- ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
- while (aItr != aEndItr)
+ for (const ScMyFormatRange & rFormatRange : aTables[nTable])
{
- if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
- ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
- ((*aItr).aRangeAddress.StartRow <= nRow) &&
- ((*aItr).aRangeAddress.EndRow >= nRow))
+ if ((rFormatRange.aRangeAddress.StartColumn <= nColumn) &&
+ (rFormatRange.aRangeAddress.EndColumn >= nColumn) &&
+ (rFormatRange.aRangeAddress.StartRow <= nRow) &&
+ (rFormatRange.aRangeAddress.EndRow >= nRow))
{
- bIsAutoStyle = aItr->bIsAutoStyle;
- return (*aItr).nStyleNameIndex;
+ bIsAutoStyle = rFormatRange.bIsAutoStyle;
+ return rFormatRange.nStyleNameIndex;
}
- else
- ++aItr;
}
return -1;
}
@@ -849,9 +822,9 @@ sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const s
OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
if (static_cast<size_t>(nTable) >= aTables.size())
return -1;
- ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
- ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
- ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
+ ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
+ ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
+ ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
while (aItr != aEndItr)
{
if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
@@ -874,7 +847,7 @@ sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const s
else
{
if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
- aItr = pFormatRanges->erase(aItr);
+ aItr = rFormatRanges.erase(aItr);
else
++aItr;
}
@@ -887,9 +860,9 @@ void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sa
{
sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
- ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
- ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
+ ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
+ ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
+ ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
sal_Int32 nColumns = 0;
while (aItr != aEndItr && nColumns < nTotalColumns)
{
@@ -937,7 +910,7 @@ void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sa
}
else
if(aItr->aRangeAddress.EndRow < nRow)
- aItr = pFormatRanges->erase(aItr);
+ aItr = rFormatRanges.erase(aItr);
else
++aItr;
}
@@ -955,11 +928,11 @@ void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress& rCell
aFormatRange.nNumberFormat = nNumberFormat;
aFormatRange.bIsAutoStyle = bIsAutoStyle;
OSL_ENSURE(static_cast<size_t>(rCellRangeAddress.Sheet) < aTables.size(), "wrong table");
- ScMyFormatRangeAddresses* pFormatRanges(aTables[rCellRangeAddress.Sheet]);
- pFormatRanges->push_back(aFormatRange);
+ ScMyFormatRangeAddresses& rFormatRanges(aTables[rCellRangeAddress.Sheet]);
+ rFormatRanges.push_back(aFormatRange);
}
-OUString* ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
+OUString & ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
{
if (bIsAutoStyle)
return aAutoStyleNames[nIndex];
@@ -969,10 +942,8 @@ OUString* ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const
void ScFormatRangeStyles::Sort()
{
- sal_Int32 nTables = aTables.size();
- for (sal_Int32 i = 0; i < nTables; ++i)
- if (!aTables[i]->empty())
- aTables[i]->sort();
+ for (auto & rTable : aTables)
+ rTable.sort();
}
ScColumnRowStylesBase::ScColumnRowStylesBase()
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.hxx b/sc/source/filter/xml/XMLStylesExportHelper.hxx
index 478e94d75f7f..3fa54f49919e 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.hxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.hxx
@@ -174,11 +174,11 @@ struct ScMyFormatRange
class ScFormatRangeStyles
{
typedef std::list<ScMyFormatRange> ScMyFormatRangeAddresses;
- typedef std::vector<ScMyFormatRangeAddresses*> ScMyFormatRangeListVec;
+ typedef std::vector<ScMyFormatRangeAddresses> ScMyFormatRangeListVec;
ScMyFormatRangeListVec aTables;
- std::vector<OUString*> aStyleNames;
- std::vector<OUString*> aAutoStyleNames;
+ std::vector<OUString> aStyleNames;
+ std::vector<OUString> aAutoStyleNames;
const ScMyDefaultStyleList* pColDefaults;
public:
@@ -187,7 +187,7 @@ public:
void SetColDefaults(const ScMyDefaultStyleList* pDefaults) { pColDefaults = pDefaults; }
void AddNewTable(const sal_Int32 nTable);
- bool AddStyleName(OUString* pString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
+ bool AddStyleName(const OUString& rString, sal_Int32& rIndex, const bool bIsAutoStyle = true);
sal_Int32 GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle);
// does not delete ranges
sal_Int32 GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
@@ -199,7 +199,7 @@ public:
const sal_Int32 nTable, ScRowFormatRanges* pFormatRanges);
void AddRangeStyleName(const css::table::CellRangeAddress& rCellRangeAddress, const sal_Int32 nStringIndex,
const bool bIsAutoStyle, const sal_Int32 nValidationIndex, const sal_Int32 nNumberFormat);
- OUString* GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
+ OUString& GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle);
void Sort();
};
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 9fffd6a4c637..8d48be539110 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -756,7 +756,7 @@ void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_In
AddAttribute(sAttrColumnsRepeated, sOUEndCol);
}
if (nIndex != -1)
- AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
+ AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
SvXMLElementExport aElemC(*this, sElemCol, true, true);
}
@@ -922,9 +922,7 @@ void ScXMLExport::ExportExternalRefCacheStyles()
sal_Int32 nIndex;
if (GetAutoStylePool()->Add(aName, XML_STYLE_FAMILY_TABLE_CELL, aDefaultStyle, aProps))
{
- OUString* pTemp(new OUString(aName));
- if (!pCellStyles->AddStyleName(pTemp, nIndex))
- delete pTemp;
+ pCellStyles->AddStyleName(aName, nIndex);
}
else
{
@@ -1329,7 +1327,7 @@ void ScXMLExport::WriteRowContent()
else
{
if (nIndex != -1)
- AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
+ AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
if (nPrevValidationIndex > -1)
AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
if (nCols > 1)
@@ -1350,7 +1348,7 @@ void ScXMLExport::WriteRowContent()
if (!bIsFirst)
{
if (nIndex != -1)
- AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
+ AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
if (nPrevValidationIndex > -1)
AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
if (nCols > 1)
@@ -2104,9 +2102,7 @@ void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& x
{
GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TABLE_CELL, *pOldName);
// add to pCellStyles, so the name is found for normal sheets
- OUString* pTemp(new OUString(*pOldName));
- if (!pCellStyles->AddStyleName(pTemp, nIndex))
- delete pTemp;
+ pCellStyles->AddStyleName(*pOldName, nIndex);
}
}
else
@@ -2129,9 +2125,7 @@ void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& x
bool bIsAutoStyle(true);
if (bAdded || GetAutoStylePool()->Add(sName, XML_STYLE_FAMILY_TABLE_CELL, sStyleName, aPropStates))
{
- OUString* pTemp(new OUString(sName));
- if (!pCellStyles->AddStyleName(pTemp, nIndex))
- delete pTemp;
+ pCellStyles->AddStyleName(sName, nIndex);
}
else
nIndex = pCellStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX, bIsAutoStyle);
@@ -2150,13 +2144,9 @@ void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& x
}
else
{
- OUString* pTemp(new OUString(EncodeStyleName(sStyleName)));
+ OUString sEncodedStyleName(EncodeStyleName(sStyleName));
sal_Int32 nIndex(0);
- if (!pCellStyles->AddStyleName(pTemp, nIndex, false))
- {
- delete pTemp;
- pTemp = nullptr;
- }
+ pCellStyles->AddStyleName(sEncodedStyleName, nIndex, false);
if ( !pOldName )
{
uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
@@ -3187,7 +3177,7 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
SetRepeatAttribute(nEqualCellCount, (aCell.nType != table::CellContentType_EMPTY));
if (aCell.nStyleIndex != -1)
- AddAttribute(sAttrStyleName, *pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
+ AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
if (aCell.nValidationIndex > -1)
AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(aCell.nValidationIndex));
bool bIsMatrix(aCell.bIsMatrixBase || aCell.bIsMatrixCovered);
@@ -5058,7 +5048,7 @@ void ScXMLExport::WriteExternalRefCaches()
sal_Int32 nIndex = GetNumberFormatStyleIndex(nNumFmt);
if (nIndex >= 0)
{
- const OUString aStyleName = *pCellStyles->GetStyleNameByIndex(nIndex, true);
+ const OUString & aStyleName = pCellStyles->GetStyleNameByIndex(nIndex, true);
AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, aStyleName);
}