From 121303615054568c204def97872343d2014af4a0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 15 Nov 2017 16:23:52 +0200 Subject: loplugin:useuniqueptr in hwpfilter Change-Id: If6e8dfcec2842a329229e5c57417ca3f00ef74b3 Reviewed-on: https://gerrit.libreoffice.org/44763 Tested-by: Jenkins Reviewed-by: Noel Grandin --- hwpfilter/source/hbox.h | 6 +----- hwpfilter/source/hwpfile.cxx | 45 ++++++++++++-------------------------------- hwpfilter/source/hwpfile.h | 15 ++++++++------- hwpfilter/source/hwpread.cxx | 8 ++++---- 4 files changed, 25 insertions(+), 49 deletions(-) (limited to 'hwpfilter') 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 cells; + std::vector> 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 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 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(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(index) >= tables.size()) return nullptr; - return tables[index]; + return tables[index].get(); } void HWPFile::AddParaShape(std::shared_ptr const & pshape) @@ -585,14 +565,13 @@ void HWPFile::AddCharShape(std::shared_ptr 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 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 #include +#include #include #include #include @@ -220,7 +221,7 @@ class DLLEXPORT HWPFile void AddDateFormat(DateCode *); void AddHeaderFooter(HeaderFooter *); void AddPageNumber(ShowPageNum *); - void AddTable(Table *); + void AddTable(std::unique_ptr
); 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 columnlist; + std::vector> columnlist; // paragraph list - std::vector plist; + std::vector> plist; // floating box list std::vector blist; // embedded picture list(tag datas) - std::vector emblist; - std::vector hyperlist; + std::vector> emblist; + std::vector> hyperlist; int currenthyper; std::vector> pslist; std::vector> cslist; @@ -299,7 +300,7 @@ class DLLEXPORT HWPFile std::vector datecodes; std::vector headerfooters; std::vector pagenumbers; - std::vector tables; + std::vector> tables; //track the stack of HParas types we're currently importing std::vector 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
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 -- cgit