From b462fa972e27d9c1510ee547e95f3e9062e4579d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 18 Oct 2017 15:53:53 +0200 Subject: use std::unique_ptr in hwpfilter Change-Id: I3aa6e1342f975420b19e9e21058a0331ed2d71e0 Reviewed-on: https://gerrit.libreoffice.org/43525 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- hwpfilter/source/hbox.cxx | 29 ----------------------------- hwpfilter/source/hbox.h | 12 ++++++------ hwpfilter/source/hwpfile.cxx | 35 +++++++++++++++++++++++++++++++++++ hwpfilter/source/hwpfile.h | 1 + hwpfilter/source/hwpreader.cxx | 36 ++++++++++++++++++------------------ 5 files changed, 60 insertions(+), 53 deletions(-) (limited to 'hwpfilter') diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx index ec042a86dbfe..87f3ef0c9db6 100644 --- a/hwpfilter/source/hbox.cxx +++ b/hwpfilter/source/hbox.cxx @@ -347,18 +347,6 @@ TxtBox::TxtBox() TxtBox::~TxtBox() { - for (auto& entry : plists) - { - for (auto const& para : entry) - { - delete para; - } - } - - for (auto const& para : caption) - { - delete para; - } } // picture(11) @@ -382,11 +370,6 @@ Picture::~Picture() { if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo ) delete static_cast(picinfo.picdraw.hdo); - - for (auto const& para : caption) - { - delete para; - } } @@ -394,30 +377,18 @@ Picture::~Picture() // hidden(15) Hidden::~Hidden() { - for (auto const& para : plist) - { - delete para; - } } // header/footer(16) HeaderFooter::~HeaderFooter() { - for (auto const& para : plist) - { - delete para; - } } // footnote(17) Footnote::~Footnote() { - for (auto const& para : plist) - { - delete para; - } } diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h index e95698943f8c..d934c9bf6622 100644 --- a/hwpfilter/source/hbox.h +++ b/hwpfilter/source/hbox.h @@ -363,12 +363,12 @@ struct TxtBox: public FBox /** * Paragraph list */ - std::vector> plists; + std::vector>> plists; /** * Caption */ - std::vector caption; + std::vector> caption; TxtBox(); virtual ~TxtBox() override; @@ -625,7 +625,7 @@ struct Picture: public FBox PicDef picinfo; char reserved3[9]; - std::vector caption; + std::vector> caption; /** * It's for the Drawing object */ @@ -668,7 +668,7 @@ struct Hidden: public HBox hchar dummy; unsigned char info[8]; // h, next, dummy - std::vector plist; + std::vector> plist; Hidden(); virtual ~Hidden() override; @@ -697,7 +697,7 @@ struct HeaderFooter: public HBox /** * Paragraph list of header or footer */ - std::vector plist; + std::vector> plist; HeaderFooter(); virtual ~HeaderFooter() override; @@ -730,7 +730,7 @@ struct Footnote: public HBox /** * Paragraph list of Footnote objects */ - std::vector plist; + std::vector> plist; Footnote(); virtual ~Footnote() override; diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx index 2bb3350fc4a5..a93e03f3023a 100644 --- a/hwpfilter/source/hwpfile.cxx +++ b/hwpfilter/source/hwpfile.cxx @@ -267,6 +267,41 @@ bool HWPFile::ReadParaList(std::vector < HWPPara* > &aplist, unsigned char flag) return true; } +bool HWPFile::ReadParaList(std::vector< std::unique_ptr > &aplist, unsigned char flag) +{ + std::unique_ptr spNode( new HWPPara ); + unsigned char tmp_etcflag; + unsigned char prev_etcflag = 0; + while (spNode->Read(*this, flag)) + { + if( !(spNode->etcflag & 0x04) ){ + tmp_etcflag = spNode->etcflag; + spNode->etcflag = prev_etcflag; + prev_etcflag = tmp_etcflag; + } + if (spNode->nch && spNode->reuse_shape) + { + if (!aplist.empty()){ + spNode->pshape = aplist.back()->pshape; + } + else{ + spNode->nch = 0; + spNode->reuse_shape = 0; + } + } + spNode->pshape->pagebreak = spNode->etcflag; + if (spNode->nch) + AddParaShape(spNode->pshape); + + if (!aplist.empty()) + aplist.back()->SetNext(spNode.get()); + aplist.push_back(std::move(spNode)); + spNode.reset( new HWPPara ); + } + + return true; +} + void HWPFile::TagsRead() { while (true) diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h index fee55b75a91c..cb6074c4f869 100644 --- a/hwpfilter/source/hwpfile.h +++ b/hwpfilter/source/hwpfile.h @@ -160,6 +160,7 @@ class DLLEXPORT HWPFile /** * Reads main paragraph list */ + bool ReadParaList(std::vector> &aplist, unsigned char flag = 0); bool ReadParaList(std::vector &aplist, unsigned char flag = 0); /** * Sets if the stream is compressed diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index 06cef295d392..c18fad632ff2 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -1125,7 +1125,7 @@ void HwpReader::makeMasterStyles() d->bInHeader = true; d->pPn = pPage->pagenumber; } - parsePara(pPage->header->plist.front()); + parsePara(pPage->header->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; rendEl("style:header"); @@ -1140,7 +1140,7 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 3; } - parsePara(pPage->header_even->plist.front()); + parsePara(pPage->header_even->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; @@ -1175,7 +1175,7 @@ void HwpReader::makeMasterStyles() d->nPnPos = 1; d->pPn = pPage->pagenumber; } - parsePara(pPage->header_odd->plist.front()); + parsePara(pPage->header_odd->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; @@ -1226,7 +1226,7 @@ void HwpReader::makeMasterStyles() d->bInHeader = true; d->pPn = pPage->pagenumber; } - parsePara(pPage->footer->plist.front()); + parsePara(pPage->footer->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; rendEl("style:footer"); @@ -1241,7 +1241,7 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 3; } - parsePara(pPage->footer_even->plist.front()); + parsePara(pPage->footer_even->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; @@ -1276,7 +1276,7 @@ void HwpReader::makeMasterStyles() d->pPn = pPage->pagenumber; d->nPnPos = 1; } - parsePara(pPage->footer_odd->plist.front()); + parsePara(pPage->footer_odd->plist.front().get()); d->bInHeader = false; d->pPn = nullptr; d->nPnPos = 0; @@ -3504,7 +3504,7 @@ void HwpReader::makeTable(TxtBox * hbox) padd("table:protected", sXML_CDATA,"true"); rstartEl("table:table-cell", mxList.get()); mxList->clear(); - parsePara(hbox->plists[tcell->pCell->key].front()); + parsePara(hbox->plists[tcell->pCell->key].front().get()); rendEl("table:table-cell"); } rendEl("table:table-row"); @@ -3560,7 +3560,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) mxList->clear(); if( hbox->cap_pos % 2 ) /* The caption is on the top */ { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } padd( "text:style-name", sXML_CDATA, "Standard"); rstartEl("text:p", mxList.get()); @@ -3628,7 +3628,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) /* If captions are present and it is on the top */ if( hbox->style.cap_len > 0 && (hbox->cap_pos % 2) && hbox->type == TBL_TYPE ) { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } if( hbox->type == TBL_TYPE) // Is Table { @@ -3636,12 +3636,12 @@ void HwpReader::makeTextBox(TxtBox * hbox) } else // Is TextBox { - parsePara(hbox->plists[0].front()); + parsePara(hbox->plists[0].front().get()); } /* If captions are present and it is on the bottom */ if( hbox->style.cap_len > 0 && !(hbox->cap_pos % 2) && hbox->type == TBL_TYPE) { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } rendEl("draw:text-box"); // Caption exist and it is text-box @@ -3650,7 +3650,7 @@ void HwpReader::makeTextBox(TxtBox * hbox) rendEl( "text:p"); if( !(hbox->cap_pos % 2)) { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } rendEl( "draw:text-box"); } @@ -3678,7 +3678,7 @@ void HwpReader::makeFormula(TxtBox * hbox) hchar dest[3]; size_t l = 0; - pPar = hbox->plists[0].front(); + pPar = hbox->plists[0].front().get(); while( pPar ) { for( n = 0; n < pPar->nch && pPar->hhstr[n]->hh; @@ -3814,7 +3814,7 @@ void HwpReader::makePicture(Picture * hbox) mxList->clear(); if( hbox->cap_pos % 2 ) /* Caption is on the top */ { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } padd( "text:style-name", sXML_CDATA, "Standard"); rstartEl("text:p", mxList.get()); @@ -3959,7 +3959,7 @@ void HwpReader::makePicture(Picture * hbox) rendEl( "text:p"); if( !(hbox->cap_pos % 2)) /* Caption is at the bottom, */ { - parsePara(hbox->caption.front()); + parsePara(hbox->caption.front().get()); } rendEl( "draw:text-box"); } @@ -4601,7 +4601,7 @@ void HwpReader::makeHidden(Hidden * hbox) padd("text:string-value", sXML_CDATA, ""); rstartEl("text:hidden-text", mxList.get()); mxList->clear(); - HWPPara *para = hbox->plist.front(); + HWPPara *para = hbox->plist.front().get(); while (para) { @@ -4639,7 +4639,7 @@ void HwpReader::makeFootnote(Footnote * hbox) rchars(ascii(Int2Str(hbox->number, "%d", buf))); rendEl("text:endnote-citation"); rstartEl("text:endnote-body", mxList.get()); - parsePara(hbox->plist.front()); + parsePara(hbox->plist.front().get()); rendEl("text:endnote-body"); rendEl("text:endnote"); } @@ -4656,7 +4656,7 @@ void HwpReader::makeFootnote(Footnote * hbox) rchars(ascii(Int2Str(hbox->number, "%d", buf))); rendEl("text:footnote-citation"); rstartEl("text:footnote-body", mxList.get()); - parsePara(hbox->plist.front()); + parsePara(hbox->plist.front().get()); rendEl("text:footnote-body"); rendEl("text:footnote"); } -- cgit