summaryrefslogtreecommitdiff
path: root/hwpfilter
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-15 16:23:52 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-16 07:55:00 +0100
commit121303615054568c204def97872343d2014af4a0 (patch)
tree233ba5de1ddb4d890310d0648c31b13a1c561f00 /hwpfilter
parent13b89618c49adfd77d184f22e23420a7b6d4678b (diff)
loplugin:useuniqueptr in hwpfilter
Change-Id: If6e8dfcec2842a329229e5c57417ca3f00ef74b3 Reviewed-on: https://gerrit.libreoffice.org/44763 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'hwpfilter')
-rw-r--r--hwpfilter/source/hbox.h6
-rw-r--r--hwpfilter/source/hwpfile.cxx45
-rw-r--r--hwpfilter/source/hwpfile.h15
-rw-r--r--hwpfilter/source/hwpread.cxx8
4 files changed, 25 insertions, 49 deletions
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
index d934c9bf6622..8592e7d4cd8d 100644
--- a/hwpfilter/source/hbox.h
+++ b/hwpfilter/source/hbox.h
@@ -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;
};
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 62006be23a34..69653f162f6d 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -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)
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 817173d24707..83bf28860f9b 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -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;
diff --git a/hwpfilter/source/hwpread.cxx b/hwpfilter/source/hwpread.cxx
index 46f278574da9..149c4f239301 100644
--- a/hwpfilter/source/hwpread.cxx
+++ b/hwpfilter/source/hwpread.cxx
@@ -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