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

loplugin:useuniqueptr in ScConsData

Change-Id: I0f9392d95ec2887ee62d1486f63600693a8b4dca
Reviewed-on: https://gerrit.libreoffice.org/56497
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 4fc072bf
...@@ -53,16 +53,16 @@ private: ...@@ -53,16 +53,16 @@ private:
bool bRowByName; bool bRowByName;
SCSIZE nColCount; SCSIZE nColCount;
SCSIZE nRowCount; SCSIZE nRowCount;
bool** ppUsed; std::unique_ptr<std::unique_ptr<bool[]>[]> ppUsed;
double** ppSum; std::unique_ptr<std::unique_ptr<double[]>[]> ppSum;
double** ppCount; std::unique_ptr<std::unique_ptr<double[]>[]> ppCount;
double** ppSumSqr; std::unique_ptr<std::unique_ptr<double[]>[]> ppSumSqr;
ScReferenceList** ppRefs; std::unique_ptr<std::unique_ptr<ScReferenceList[]>[]> ppRefs;
::std::vector<OUString> maColHeaders; ::std::vector<OUString> maColHeaders;
::std::vector<OUString> maRowHeaders; ::std::vector<OUString> maRowHeaders;
::std::vector<OUString> maTitles; ::std::vector<OUString> maTitles;
SCSIZE nDataCount; SCSIZE nDataCount;
SCSIZE** ppTitlePos; std::unique_ptr<std::unique_ptr<SCSIZE[]>[]> ppTitlePos;
bool bCornerUsed; bool bCornerUsed;
OUString aCornerText; // only for bColByName && bRowByName OUString aCornerText; // only for bColByName && bRowByName
......
...@@ -61,49 +61,23 @@ ScConsData::ScConsData() : ...@@ -61,49 +61,23 @@ ScConsData::ScConsData() :
bRowByName(false), bRowByName(false),
nColCount(0), nColCount(0),
nRowCount(0), nRowCount(0),
ppUsed(nullptr),
ppSum(nullptr),
ppCount(nullptr),
ppSumSqr(nullptr),
ppRefs(nullptr),
nDataCount(0), nDataCount(0),
ppTitlePos(nullptr),
bCornerUsed(false) bCornerUsed(false)
{ {
} }
ScConsData::~ScConsData() ScConsData::~ScConsData()
{ {
DeleteData();
}
#define DELETEARR(ppArray,nCount) \
{ \
sal_uLong i; \
if (ppArray) \
for(i=0; i<nCount; i++) \
delete[] ppArray[i]; \
delete[] ppArray; \
ppArray = nullptr; \
} }
void ScConsData::DeleteData() void ScConsData::DeleteData()
{ {
if (ppRefs) ppRefs.reset();
{ ppCount.reset();
for (SCSIZE i=0; i<nColCount; i++) ppSum.reset();
{ ppSumSqr.reset();
delete[] ppRefs[i]; ppUsed.reset();
} ppTitlePos.reset();
delete[] ppRefs;
ppRefs = nullptr;
}
DELETEARR( ppCount, nColCount );
DELETEARR( ppSum, nColCount );
DELETEARR( ppSumSqr,nColCount );
DELETEARR( ppUsed, nColCount );
DELETEARR( ppTitlePos, nRowCount );
::std::vector<OUString>().swap( maColHeaders); ::std::vector<OUString>().swap( maColHeaders);
::std::vector<OUString>().swap( maRowHeaders); ::std::vector<OUString>().swap( maRowHeaders);
::std::vector<OUString>().swap( maTitles); ::std::vector<OUString>().swap( maTitles);
...@@ -123,40 +97,40 @@ void ScConsData::InitData() ...@@ -123,40 +97,40 @@ void ScConsData::InitData()
{ {
if (bReference && nColCount && !ppRefs) if (bReference && nColCount && !ppRefs)
{ {
ppRefs = new ScReferenceList*[nColCount]; ppRefs.reset(new std::unique_ptr<ScReferenceList[]>[nColCount]);
for (SCSIZE i=0; i<nColCount; i++) for (SCSIZE i=0; i<nColCount; i++)
ppRefs[i] = new ScReferenceList[nRowCount]; ppRefs[i].reset(new ScReferenceList[nRowCount]);
} }
else if (nColCount && !ppCount) else if (nColCount && !ppCount)
{ {
ppCount = new double*[nColCount]; ppCount.reset( new std::unique_ptr<double[]>[nColCount] );
ppSum = new double*[nColCount]; ppSum.reset( new std::unique_ptr<double[]>[nColCount] );
ppSumSqr = new double*[nColCount]; ppSumSqr.reset( new std::unique_ptr<double[]>[nColCount] );
for (SCSIZE i=0; i<nColCount; i++) for (SCSIZE i=0; i<nColCount; i++)
{ {
ppCount[i] = new double[nRowCount]; ppCount[i].reset( new double[nRowCount] );
ppSum[i] = new double[nRowCount]; ppSum[i].reset( new double[nRowCount] );
ppSumSqr[i] = new double[nRowCount]; ppSumSqr[i].reset( new double[nRowCount] );
} }
} }
if (nColCount && !ppUsed) if (nColCount && !ppUsed)
{ {
ppUsed = new bool*[nColCount]; ppUsed.reset( new std::unique_ptr<bool[]>[nColCount] );
for (SCSIZE i=0; i<nColCount; i++) for (SCSIZE i=0; i<nColCount; i++)
{ {
ppUsed[i] = new bool[nRowCount]; ppUsed[i].reset( new bool[nRowCount] );
memset( ppUsed[i], 0, nRowCount * sizeof(bool) ); memset( ppUsed[i].get(), 0, nRowCount * sizeof(bool) );
} }
} }
if (nRowCount && nDataCount && !ppTitlePos) if (nRowCount && nDataCount && !ppTitlePos)
{ {
ppTitlePos = new SCSIZE*[nRowCount]; ppTitlePos.reset( new std::unique_ptr<SCSIZE[]>[nRowCount] );
for (SCSIZE i=0; i<nRowCount; i++) for (SCSIZE i=0; i<nRowCount; i++)
{ {
ppTitlePos[i] = new SCSIZE[nDataCount]; ppTitlePos[i].reset( new SCSIZE[nDataCount] );
memset( ppTitlePos[i], 0, nDataCount * sizeof(SCSIZE) ); //TODO: not necessary ? memset( ppTitlePos[i].get(), 0, nDataCount * sizeof(SCSIZE) ); //TODO: not necessary ?
} }
} }
......
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