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

loplugin:useuniqueptr in LwpFormulaInfo

Change-Id: Iac1f025f1311ef05fd48581d5bee9875163f4f2b
Reviewed-on: https://gerrit.libreoffice.org/60972
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst fd84276c
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include <osl/thread.h> #include <osl/thread.h>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <o3tl/make_unique.hxx>
#include <memory> #include <memory>
LwpFormulaArg::~LwpFormulaArg() LwpFormulaArg::~LwpFormulaArg()
...@@ -81,19 +82,13 @@ LwpFormulaArg::~LwpFormulaArg() ...@@ -81,19 +82,13 @@ LwpFormulaArg::~LwpFormulaArg()
LwpFormulaInfo::~LwpFormulaInfo() LwpFormulaInfo::~LwpFormulaInfo()
{ {
while(m_aStack.size()>0)
{
LwpFormulaArg* pArg=m_aStack.back();
m_aStack.pop_back();
delete pArg; pArg=nullptr;
}
} }
void LwpFormulaInfo::ReadConst() void LwpFormulaInfo::ReadConst()
{ {
double Constant = m_pObjStrm->QuickReadDouble(); double Constant = m_pObjStrm->QuickReadDouble();
m_aStack.push_back( new LwpFormulaConst(Constant) ); m_aStack.push_back( o3tl::make_unique<LwpFormulaConst>(Constant) );
} }
/** /**
...@@ -112,7 +107,7 @@ void LwpFormulaInfo::ReadText() ...@@ -112,7 +107,7 @@ void LwpFormulaInfo::ReadText()
aText += OUString(pBuf.get(), nStrLen, osl_getThreadTextEncoding()); aText += OUString(pBuf.get(), nStrLen, osl_getThreadTextEncoding());
aText += "\""; aText += "\"";
m_aStack.push_back(new LwpFormulaText(aText)); m_aStack.push_back(o3tl::make_unique<LwpFormulaText>(aText));
} }
void LwpFormulaInfo::ReadCellID() void LwpFormulaInfo::ReadCellID()
...@@ -123,26 +118,24 @@ void LwpFormulaInfo::ReadCellID() ...@@ -123,26 +118,24 @@ void LwpFormulaInfo::ReadCellID()
RowSpecifier.QuickRead(m_pObjStrm.get()); RowSpecifier.QuickRead(m_pObjStrm.get());
ColumnSpecifier.QuickRead(m_pObjStrm.get()); ColumnSpecifier.QuickRead(m_pObjStrm.get());
m_aStack.push_back( new LwpFormulaCellAddr(ColumnSpecifier.ColumnID(cColumn), m_aStack.push_back( o3tl::make_unique<LwpFormulaCellAddr>(ColumnSpecifier.ColumnID(cColumn),
RowSpecifier.RowID(m_nFormulaRow)) ); RowSpecifier.RowID(m_nFormulaRow)) );
} }
void LwpFormulaInfo::ReadCellRange() void LwpFormulaInfo::ReadCellRange()
{ {
ReadCellID( ); // start ReadCellID( ); // start
LwpFormulaCellAddr* pStartCellAddr = static_cast<LwpFormulaCellAddr*>(m_aStack.back()); std::unique_ptr<LwpFormulaCellAddr> pStartCellAddr( static_cast<LwpFormulaCellAddr*>(m_aStack.back().release()));
m_aStack.pop_back(); m_aStack.pop_back();
ReadCellID(); // end ReadCellID(); // end
LwpFormulaCellAddr* pEndCellAddr = static_cast<LwpFormulaCellAddr*>(m_aStack.back()); std::unique_ptr<LwpFormulaCellAddr> pEndCellAddr(static_cast<LwpFormulaCellAddr*>(m_aStack.back().release()));
m_aStack.pop_back(); m_aStack.pop_back();
m_aStack.push_back( new LwpFormulaCellRangeAddr(pStartCellAddr->GetCol(), m_aStack.push_back( o3tl::make_unique<LwpFormulaCellRangeAddr>(pStartCellAddr->GetCol(),
pStartCellAddr->GetRow(), pStartCellAddr->GetRow(),
pEndCellAddr->GetCol(), pEndCellAddr->GetCol(),
pEndCellAddr->GetRow()) ); pEndCellAddr->GetRow()) );
delete pStartCellAddr;
delete pEndCellAddr;
} }
/** /**
...@@ -190,7 +183,7 @@ void LwpFormulaInfo::ReadExpression() ...@@ -190,7 +183,7 @@ void LwpFormulaInfo::ReadExpression()
{ {
std::unique_ptr<LwpFormulaFunc> xFunc(new LwpFormulaFunc(TokenType)); std::unique_ptr<LwpFormulaFunc> xFunc(new LwpFormulaFunc(TokenType));
ReadArguments(*xFunc); ReadArguments(*xFunc);
m_aStack.push_back(xFunc.release()); m_aStack.push_back(std::move(xFunc));
} }
break; break;
...@@ -211,18 +204,18 @@ void LwpFormulaInfo::ReadExpression() ...@@ -211,18 +204,18 @@ void LwpFormulaInfo::ReadExpression()
if (m_aStack.size() >= 2) if (m_aStack.size() >= 2)
{//binary operator {//binary operator
LwpFormulaOp* pOp = new LwpFormulaOp(TokenType); std::unique_ptr<LwpFormulaOp> pOp(new LwpFormulaOp(TokenType));
pOp->AddArg(std::unique_ptr<LwpFormulaArg>(m_aStack.back())); m_aStack.pop_back(); pOp->AddArg(std::move(m_aStack.back())); m_aStack.pop_back();
pOp->AddArg(std::unique_ptr<LwpFormulaArg>(m_aStack.back())); m_aStack.pop_back(); pOp->AddArg(std::move(m_aStack.back())); m_aStack.pop_back();
m_aStack.push_back(pOp); m_aStack.push_back(std::move(pOp));
} }
break; break;
case TK_UNARY_MINUS: case TK_UNARY_MINUS:
if (!m_aStack.empty()) if (!m_aStack.empty())
{ {
LwpFormulaUnaryOp* pOp = new LwpFormulaUnaryOp(TokenType); std::unique_ptr<LwpFormulaUnaryOp> pOp(new LwpFormulaUnaryOp(TokenType));
pOp->AddArg(std::unique_ptr<LwpFormulaArg>(m_aStack.back())); m_aStack.pop_back(); pOp->AddArg(std::move(m_aStack.back())); m_aStack.pop_back();
m_aStack.push_back(pOp); m_aStack.push_back(std::move(pOp));
} }
break; break;
default: default:
...@@ -293,7 +286,7 @@ void LwpFormulaInfo::ReadArguments(LwpFormulaFunc& aFunc) ...@@ -293,7 +286,7 @@ void LwpFormulaInfo::ReadArguments(LwpFormulaFunc& aFunc)
if (bArgument && !m_aStack.empty()) if (bArgument && !m_aStack.empty())
{ {
aFunc.AddArg(std::unique_ptr<LwpFormulaArg>(m_aStack.back())); aFunc.AddArg(std::move(m_aStack.back()));
m_aStack.pop_back(); m_aStack.pop_back();
} }
} }
...@@ -333,8 +326,7 @@ OUString LwpFormulaInfo::Convert(LwpTableLayout* pCellsMap) ...@@ -333,8 +326,7 @@ OUString LwpFormulaInfo::Convert(LwpTableLayout* pCellsMap)
{ {
if(1==m_aStack.size()) if(1==m_aStack.size())
{ {
LwpFormulaArg* pFormula = m_aStack.back(); aFormula = m_aStack[0]->ToString(pCellsMap);
aFormula = pFormula->ToString(pCellsMap);
} }
else else
{ {
......
...@@ -209,7 +209,7 @@ private: ...@@ -209,7 +209,7 @@ private:
void ReadConst(); void ReadConst();
void MarkUnsupported(sal_uInt16 TokenType); void MarkUnsupported(sal_uInt16 TokenType);
std::vector<LwpFormulaArg*> m_aStack; std::vector<std::unique_ptr<LwpFormulaArg>> m_aStack;
sal_uInt16 m_nFormulaRow; sal_uInt16 m_nFormulaRow;
}; };
......
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