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

loplugin:useuniqueptr in SvxNumRule

Change-Id: I778f62edbddfa2ca10eefa396272e7b011025513
Reviewed-on: https://gerrit.libreoffice.org/49172Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 6b786b43
...@@ -559,7 +559,7 @@ SvxNumRule::SvxNumRule( SvxNumRuleFlags nFeatures, ...@@ -559,7 +559,7 @@ SvxNumRule::SvxNumRule( SvxNumRuleFlags nFeatures,
{ {
if(i < nLevels) if(i < nLevels)
{ {
aFmts[i] = new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER); aFmts[i].reset( new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER) );
// It is a distinction between writer and draw // It is a distinction between writer and draw
if(nFeatures & SvxNumRuleFlags::CONTINUOUS) if(nFeatures & SvxNumRuleFlags::CONTINUOUS)
{ {
...@@ -607,9 +607,9 @@ SvxNumRule::SvxNumRule(const SvxNumRule& rCopy) ...@@ -607,9 +607,9 @@ SvxNumRule::SvxNumRule(const SvxNumRule& rCopy)
for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
{ {
if(rCopy.aFmts[i]) if(rCopy.aFmts[i])
aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]); aFmts[i].reset( new SvxNumberFormat(*rCopy.aFmts[i]) );
else else
aFmts[i] = nullptr; aFmts[i].reset();
aFmtsSet[i] = rCopy.aFmtsSet[i]; aFmtsSet[i] = rCopy.aFmtsSet[i];
} }
} }
...@@ -632,11 +632,11 @@ SvxNumRule::SvxNumRule( SvStream &rStream ) ...@@ -632,11 +632,11 @@ SvxNumRule::SvxNumRule( SvStream &rStream )
bool hasNumberingFormat = nTmp16 & 1; bool hasNumberingFormat = nTmp16 & 1;
aFmtsSet[i] = nTmp16 & 2; // fdo#68648 reset flag aFmtsSet[i] = nTmp16 & 2; // fdo#68648 reset flag
if ( hasNumberingFormat ){ if ( hasNumberingFormat ){
aFmts[i] = new SvxNumberFormat( rStream ); aFmts[i].reset( new SvxNumberFormat( rStream ) );
} }
else else
{ {
aFmts[i] = nullptr; aFmts[i].reset();
aFmtsSet[i] = false; // actually only false is valid aFmtsSet[i] = false; // actually only false is valid
} }
} }
...@@ -690,7 +690,7 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const ...@@ -690,7 +690,7 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const
{ {
xmlTextWriterStartElement(pWriter, BAD_CAST("aFmts")); xmlTextWriterStartElement(pWriter, BAD_CAST("aFmts"));
xmlTextWriterWriteAttribute(pWriter, BAD_CAST("i"), BAD_CAST(OUString::number(i).getStr())); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("i"), BAD_CAST(OUString::number(i).getStr()));
xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", aFmts[i]); xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", aFmts[i].get());
xmlTextWriterEndElement(pWriter); xmlTextWriterEndElement(pWriter);
} }
} }
...@@ -700,8 +700,6 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const ...@@ -700,8 +700,6 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const
SvxNumRule::~SvxNumRule() SvxNumRule::~SvxNumRule()
{ {
for(SvxNumberFormat* aFmt : aFmts)
delete aFmt;
if(!--nRefCount) if(!--nRefCount)
{ {
DELETEZ(pStdNumFmt); DELETEZ(pStdNumFmt);
...@@ -717,11 +715,10 @@ SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy ) ...@@ -717,11 +715,10 @@ SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy )
eNumberingType = rCopy.eNumberingType; eNumberingType = rCopy.eNumberingType;
for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
{ {
delete aFmts[i];
if(rCopy.aFmts[i]) if(rCopy.aFmts[i])
aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]); aFmts[i].reset( new SvxNumberFormat(*rCopy.aFmts[i]) );
else else
aFmts[i] = nullptr; aFmts[i].reset();
aFmtsSet[i] = rCopy.aFmtsSet[i]; aFmtsSet[i] = rCopy.aFmtsSet[i];
} }
return *this; return *this;
...@@ -753,7 +750,7 @@ const SvxNumberFormat* SvxNumRule::Get(sal_uInt16 nLevel)const ...@@ -753,7 +750,7 @@ const SvxNumberFormat* SvxNumRule::Get(sal_uInt16 nLevel)const
{ {
DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" ); DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" );
if( nLevel < SVX_MAX_NUM ) if( nLevel < SVX_MAX_NUM )
return aFmtsSet[nLevel] ? aFmts[nLevel] : nullptr; return aFmtsSet[nLevel] ? aFmts[nLevel].get() : nullptr;
else else
return nullptr; return nullptr;
} }
...@@ -788,8 +785,7 @@ void SvxNumRule::SetLevel( sal_uInt16 i, const SvxNumberFormat& rNumFmt, bool bI ...@@ -788,8 +785,7 @@ void SvxNumRule::SetLevel( sal_uInt16 i, const SvxNumberFormat& rNumFmt, bool bI
if (bReplace) if (bReplace)
{ {
delete aFmts[i]; aFmts[i].reset( new SvxNumberFormat(rNumFmt) );
aFmts[i] = new SvxNumberFormat(rNumFmt);
aFmtsSet[i] = bIsValid; aFmtsSet[i] = bIsValid;
} }
} }
...@@ -806,8 +802,7 @@ void SvxNumRule::SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt) ...@@ -806,8 +802,7 @@ void SvxNumRule::SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt)
SetLevel(nLevel, *pFmt); SetLevel(nLevel, *pFmt);
else else
{ {
delete aFmts[nLevel]; aFmts[nLevel].reset();
aFmts[nLevel] = nullptr;
} }
} }
} }
......
...@@ -245,7 +245,7 @@ class EDITENG_DLLPUBLIC SvxNumRule final ...@@ -245,7 +245,7 @@ class EDITENG_DLLPUBLIC SvxNumRule final
SvxNumRuleType eNumberingType; // Type of numbering SvxNumRuleType eNumberingType; // Type of numbering
bool bContinuousNumbering; // sequential numbering bool bContinuousNumbering; // sequential numbering
SvxNumberFormat* aFmts[SVX_MAX_NUM]; std::unique_ptr<SvxNumberFormat> aFmts[SVX_MAX_NUM];
bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels
static sal_Int32 nRefCount; static sal_Int32 nRefCount;
......
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