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

loplugin:useuniqueptr in hwpfilter

Change-Id: If6e8dfcec2842a329229e5c57417ca3f00ef74b3
Reviewed-on: https://gerrit.libreoffice.org/44763Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 13b89618
......@@ -510,14 +510,10 @@ struct TCell
struct Table
{
Table() : box(nullptr) {};
~Table() {
for (auto const& cell : cells)
delete cell;
};
Columns columns;
Rows rows;
std::vector<TCell*> cells;
std::vector<std::unique_ptr<TCell>> cells;
TxtBox *box;
};
......
......@@ -62,21 +62,6 @@ HWPFile::~HWPFile()
{
delete oledata;
delete hiodev;
for (auto const& column : columnlist)
delete column;
for (auto const& paragraph : plist)
delete paragraph;
for (auto const& table : tables)
delete table;
for (auto const& emb : emblist)
delete emb;
for (auto const& hyperlink : hyperlist)
delete hyperlink;
}
int HWPFile::ReadHwpFile(HStream * stream)
......@@ -323,12 +308,10 @@ void HWPFile::TagsRead()
{
case FILETAG_EMBEDDED_PICTURE:
{
EmPicture *emb = new EmPicture(size);
std::unique_ptr<EmPicture> emb(new EmPicture(size));
if (emb->Read(*this))
emblist.push_back(emb);
else
delete emb;
emblist.push_back(std::move(emb));
}
break;
case FILETAG_OLE_OBJECT:
......@@ -346,14 +329,11 @@ void HWPFile::TagsRead()
const int nRecords = size / nRecordLen;
for (int i = 0 ; i < nRecords; ++i)
{
HyperText *hypert = new HyperText;
std::unique_ptr<HyperText> hypert(new HyperText);
if (hypert->Read(*this))
hyperlist.push_back(hypert);
hyperlist.push_back(std::move(hypert));
else
{
delete hypert;
break;
}
}
}
break;
......@@ -454,7 +434,7 @@ HyperText *HWPFile::GetHyperText()
{
++currenthyper;
if (static_cast<size_t>(currenthyper) <= hyperlist.size())
return hyperlist[currenthyper-1];
return hyperlist[currenthyper-1].get();
else
return nullptr;
}
......@@ -469,7 +449,7 @@ EmPicture *HWPFile::GetEmPicture(Picture * pic)
for (auto const& emb : emblist)
if (strcmp(name, emb->name) == 0)
return emb;
return emb.get();
return nullptr;
}
......@@ -481,7 +461,7 @@ EmPicture *HWPFile::GetEmPictureByName(char * name)
for (auto const& emb : emblist)
if (strcmp(name, emb->name) == 0)
return emb;
return emb.get();
return nullptr;
}
......@@ -536,7 +516,7 @@ Table *HWPFile::getTable(int index)
{
if (index < 0 || static_cast<unsigned int>(index) >= tables.size())
return nullptr;
return tables[index];
return tables[index].get();
}
void HWPFile::AddParaShape(std::shared_ptr<ParaShape> const & pshape)
......@@ -585,14 +565,13 @@ void HWPFile::AddCharShape(std::shared_ptr<CharShape> const & cshape)
void HWPFile::AddColumnInfo()
{
ColumnInfo *cinfo = new ColumnInfo(m_nCurrentPage);
columnlist.push_back(cinfo);
columnlist.emplace_back(new ColumnInfo(m_nCurrentPage));
setMaxSettedPage();
}
void HWPFile::SetColumnDef(ColumnDef *coldef)
{
ColumnInfo *cinfo = columnlist.back();
ColumnInfo *cinfo = columnlist.back().get();
if( cinfo->bIsSet )
return;
cinfo->coldef = coldef;
......@@ -615,9 +594,9 @@ void HWPFile::AddHeaderFooter(HeaderFooter * hbox)
headerfooters.push_back(hbox);
}
void HWPFile::AddTable(Table * hbox)
void HWPFile::AddTable(std::unique_ptr<Table> hbox)
{
tables.push_back(hbox);
tables.push_back(std::move(hbox));
}
void HWPFile::AddFBoxStyle(FBoxStyle * fbstyle)
......
......@@ -27,6 +27,7 @@
#include <algorithm>
#include <list>
#include <memory>
#include <vector>
#include <stdio.h>
#include <string.h>
......@@ -220,7 +221,7 @@ class DLLEXPORT HWPFile
void AddDateFormat(DateCode *);
void AddHeaderFooter(HeaderFooter *);
void AddPageNumber(ShowPageNum *);
void AddTable(Table *);
void AddTable(std::unique_ptr<Table>);
ColumnDef* GetColumnDef(int);
int GetPageMasterNum(int page);
......@@ -229,7 +230,7 @@ class DLLEXPORT HWPFile
HWPInfo& GetHWPInfo(void) { return _hwpInfo; }
HWPFont& GetHWPFont(void) { return _hwpFont; }
HWPStyle& GetHWPStyle(void) { return _hwpStyle; }
HWPPara *GetFirstPara(void) { return plist.front(); }
HWPPara *GetFirstPara(void) { return plist.front().get(); }
EmPicture *GetEmPicture(Picture *pic);
EmPicture *GetEmPictureByName(char * name);
......@@ -284,14 +285,14 @@ class DLLEXPORT HWPFile
HWPInfo _hwpInfo;
HWPFont _hwpFont;
HWPStyle _hwpStyle;
std::vector<ColumnInfo*> columnlist;
std::vector<std::unique_ptr<ColumnInfo>> columnlist;
// paragraph list
std::vector<HWPPara*> plist;
std::vector<std::unique_ptr<HWPPara>> plist;
// floating box list
std::vector<FBox*> blist;
// embedded picture list(tag datas)
std::vector<EmPicture*> emblist;
std::vector<HyperText*> hyperlist;
std::vector<std::unique_ptr<EmPicture>> emblist;
std::vector<std::unique_ptr<HyperText>> hyperlist;
int currenthyper;
std::vector<std::shared_ptr<ParaShape>> pslist;
std::vector<std::shared_ptr<CharShape>> cslist;
......@@ -299,7 +300,7 @@ class DLLEXPORT HWPFile
std::vector<DateCode*> datecodes;
std::vector<HeaderFooter*> headerfooters;
std::vector<ShowPageNum*> pagenumbers;
std::vector<Table*> tables;
std::vector<std::unique_ptr<Table>> tables;
//track the stack of HParas types we're currently importing
std::vector<unsigned char> element_import_stack;
......
......@@ -311,7 +311,7 @@ bool TxtBox::Read(HWPFile & hwpf)
if (!pArr) {
return hwpf.SetState(HWP_InvalidFileFormat);
}
Table *tbl = new Table;
std::unique_ptr<Table> tbl(new Table);
for( ii = 0 ; ii < ncell; ii++)
{
tbl->columns.insert(cell[ii].x);
......@@ -351,11 +351,11 @@ bool TxtBox::Read(HWPFile & hwpf)
}
}
for( ii = 0 ; ii < ncell ; ii++ ){
tbl->cells.push_back(pArr[ii]);
tbl->cells.emplace_back(pArr[ii]);
}
tbl->box = this;
hwpf.AddTable(tbl);
m_pTable = tbl;
m_pTable = tbl.get();
hwpf.AddTable(std::move(tbl));
delete[] pArr;
}
else
......
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