summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hwpfilter/source/hpara.cxx87
-rw-r--r--hwpfilter/source/hpara.h5
-rw-r--r--hwpfilter/source/hwpreader.cxx26
3 files changed, 52 insertions, 66 deletions
diff --git a/hwpfilter/source/hpara.cxx b/hwpfilter/source/hpara.cxx
index 96b2729c8698..5b9ac75c87bd 100644
--- a/hwpfilter/source/hpara.cxx
+++ b/hwpfilter/source/hpara.cxx
@@ -77,7 +77,6 @@ HWPPara::HWPPara()
, pstyno(0)
, linfo(nullptr)
, cshapep(nullptr)
- , hhstr(nullptr)
{
memset(&cshape, 0, sizeof(cshape));
memset(&pshape, 0, sizeof(pshape));
@@ -87,19 +86,8 @@ HWPPara::~HWPPara()
{
delete[] linfo;
delete[] cshapep;
- if (hhstr)
- {
-// virtual destructor
-/* C++은 null에 대해서도 동작한다. */
- for (int ii = 0; ii < nch; ++ii)
- delete hhstr[ii];
-
- delete[]hhstr;
- }
-
}
-
bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
{
unsigned char same_cshape;
@@ -180,14 +168,12 @@ bool HWPPara::Read(HWPFile & hwpf, unsigned char flag)
}
}
// read string
- hhstr = ::comphelper::newArray_null<HBox *>(nch);
- if (!hhstr) { return false; }
- for (ii = 0; ii < nch; ii++)
- hhstr[ii] = nullptr;
+ hhstr.resize(nch);
ii = 0;
while (ii < nch)
{
- if (nullptr == (hhstr[ii] = readHBox(hwpf)))
+ hhstr[ii] = readHBox(hwpf);
+ if (!hhstr[ii])
return false;
if (hhstr[ii]->hh == CH_END_PARA)
break;
@@ -207,93 +193,93 @@ CharShape *HWPPara::GetCharShape(int pos)
}
-HBox *HWPPara::readHBox(HWPFile & hwpf)
+std::unique_ptr<HBox> HWPPara::readHBox(HWPFile & hwpf)
{
+ std::unique_ptr<HBox> hbox;
+
hchar hh;
if (!hwpf.Read2b(hh))
- return nullptr;
-
- HBox *hbox = nullptr;
+ return hbox;
if (hwpf.State() != HWP_NoError)
- return nullptr;
+ return hbox;
if (hh > 31 || hh == CH_END_PARA)
- hbox = new HBox(hh);
+ hbox.reset(new HBox(hh));
else if (IS_SP_SKIP_BLOCK(hh))
- hbox = new SkipData(hh);
+ hbox.reset(new SkipData(hh));
else
{
switch (hh)
{
case CH_FIELD: // 5
- hbox = new FieldCode;
+ hbox.reset(new FieldCode);
break;
case CH_BOOKMARK: // 6
- hbox = new Bookmark;
+ hbox.reset(new Bookmark);
break;
case CH_DATE_FORM: // 7
- hbox = new DateFormat;
+ hbox.reset(new DateFormat);
break;
case CH_DATE_CODE: // 8
- hbox = new DateCode;
+ hbox.reset(new DateCode);
break;
case CH_TAB: // 9
- hbox = new Tab;
+ hbox.reset(new Tab);
break;
case CH_TEXT_BOX: // 10
- hbox = new TxtBox;
+ hbox.reset(new TxtBox);
break;
case CH_PICTURE: // 11
- hbox = new Picture;
+ hbox.reset(new Picture);
break;
case CH_LINE: // 14
- hbox = new Line;
+ hbox.reset(new Line);
break;
case CH_HIDDEN: // 15
- hbox = new Hidden;
+ hbox.reset(new Hidden);
break;
case CH_HEADER_FOOTER: // 16
- hbox = new HeaderFooter;
+ hbox.reset(new HeaderFooter);
break;
case CH_FOOTNOTE: // 17
- hbox = new Footnote;
+ hbox.reset(new Footnote);
break;
case CH_AUTO_NUM: // 18
- hbox = new AutoNum;
+ hbox.reset(new AutoNum);
break;
case CH_NEW_NUM: // 19
- hbox = new NewNum;
+ hbox.reset(new NewNum);
break;
case CH_SHOW_PAGE_NUM: // 20
- hbox = new ShowPageNum;
+ hbox.reset(new ShowPageNum);
break;
case CH_PAGE_NUM_CTRL: // 21
- hbox = new PageNumCtrl;
+ hbox.reset(new PageNumCtrl);
break;
case CH_MAIL_MERGE: // 22
- hbox = new MailMerge;
+ hbox.reset(new MailMerge);
break;
case CH_COMPOSE: // 23
- hbox = new Compose;
+ hbox.reset(new Compose);
break;
case CH_HYPHEN: // 24
- hbox = new Hyphen;
+ hbox.reset(new Hyphen);
break;
case CH_TOC_MARK: // 25
- hbox = new TocMark;
+ hbox.reset(new TocMark);
break;
case CH_INDEX_MARK: // 26
- hbox = new IndexMark;
+ hbox.reset(new IndexMark);
break;
case CH_OUTLINE: // 28
- hbox = new Outline;
+ hbox.reset(new Outline);
break;
case CH_KEEP_SPACE: // 30
- hbox = new KeepSpace;
+ hbox.reset(new KeepSpace);
break;
case CH_FIXED_SPACE: // 31
- hbox = new FixedSpace;
+ hbox.reset(new FixedSpace);
break;
default:
break;
@@ -301,13 +287,12 @@ HBox *HWPPara::readHBox(HWPFile & hwpf)
}
if (!hbox || !hbox->Read(hwpf))
{
- delete hbox;
-
- return nullptr;
+ hbox.reset();
+ return hbox;
}
if( hh == CH_TEXT_BOX || hh == CH_PICTURE || hh == CH_LINE )
{
- FBox *fbox = static_cast<FBox *>(hbox);
+ FBox *fbox = static_cast<FBox *>(hbox.get());
if( ( fbox->style.anchor_type == 1) && ( fbox->pgy >= begin_ypos) )
{
//strange construct to compile without warning
diff --git a/hwpfilter/source/hpara.h b/hwpfilter/source/hpara.h
index afb9f5a50b91..6496eae80f70 100644
--- a/hwpfilter/source/hpara.h
+++ b/hwpfilter/source/hpara.h
@@ -23,6 +23,7 @@
#include <hwplib.h>
#include <hwpfile.h>
#include <hinfo.h>
+#include <memory>
struct HBox;
@@ -110,7 +111,7 @@ class DLLEXPORT HWPPara
/**
* Box object list
*/
- HBox **hhstr;
+ std::vector<std::unique_ptr<HBox>> hhstr;
HWPPara(void);
~HWPPara(void);
@@ -135,7 +136,7 @@ class DLLEXPORT HWPPara
HWPPara *Next(void) { return _next;}
private:
- HBox *readHBox(HWPFile &);
+ std::unique_ptr<HBox> readHBox(HWPFile &);
};
#endif // INCLUDED_HWPFILTER_SOURCE_HPARA_H
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 5e499e7fd471..cf1dbd452d16 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -2945,7 +2945,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
}
else if (para->hhstr[n]->hh == CH_FIELD)
{
- FieldCode *hbox = static_cast<FieldCode *>(para->hhstr[n]);
+ FieldCode *hbox = static_cast<FieldCode*>(para->hhstr[n].get());
if( hbox->location_info == 1)
{
if( !pstart ) {STARTP;}
@@ -2981,7 +2981,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeBookmark(static_cast<Bookmark *>(para->hhstr[n]));
+ makeBookmark(static_cast<Bookmark*>(para->hhstr[n].get()));
break;
case CH_DATE_FORM: // 7
break;
@@ -2989,7 +2989,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeDateCode(static_cast<DateCode *>(para->hhstr[n]));
+ makeDateCode(static_cast<DateCode*>(para->hhstr[n].get()));
break;
case CH_TAB: // 9
if( !pstart ) {STARTP;}
@@ -2998,12 +2998,12 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !tstart ) {STARTT;}
makeChars(str);
}
- makeTab(static_cast<Tab *>(para->hhstr[n]));
+ makeTab(static_cast<Tab*>(para->hhstr[n].get()));
break;
case CH_TEXT_BOX: /* 10 - ordered by Table/text box/formula/button/hypertext */
{
-/* produce tables first, and treat formula as being in text:p. */
- TxtBox *hbox = static_cast<TxtBox *>(para->hhstr[n]);
+ /* produce tables first, and treat formula as being in text:p. */
+ TxtBox *hbox = static_cast<TxtBox*>(para->hhstr[n].get());
if( hbox->style.anchor_type == 0 )
{
@@ -3037,7 +3037,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
}
case CH_PICTURE: // 11
{
- Picture *hbox = static_cast<Picture *>(para->hhstr[n]);
+ Picture *hbox = static_cast<Picture*>(para->hhstr[n].get());
if( hbox->style.anchor_type == 0 )
{
if( !pstart ) {STARTP;}
@@ -3059,7 +3059,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
}
case CH_LINE: // 14
{
- Line *hbox = static_cast<Line *>(para->hhstr[n]);
+ Line *hbox = static_cast<Line*>(para->hhstr[n].get());
if (str.size() > 0)
{
if( !pstart ) {STARTP;}
@@ -3076,19 +3076,19 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeHidden(static_cast<Hidden *>(para->hhstr[n]));
+ makeHidden(static_cast<Hidden*>(para->hhstr[n].get()));
break;
case CH_FOOTNOTE: // 17
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeFootnote(static_cast<Footnote *>(para->hhstr[n]));
+ makeFootnote(static_cast<Footnote*>(para->hhstr[n].get()));
break;
case CH_AUTO_NUM: // 18
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeAutoNum(static_cast<AutoNum *>(para->hhstr[n]));
+ makeAutoNum(static_cast<AutoNum*>(para->hhstr[n].get()));
break;
case CH_NEW_NUM: // 19 -skip
break;
@@ -3098,7 +3098,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeMailMerge(static_cast<MailMerge *>(para->hhstr[n]));
+ makeMailMerge(static_cast<MailMerge*>(para->hhstr[n].get()));
break;
case CH_COMPOSE: /* 23 - overlapping letters */
break;
@@ -3118,7 +3118,7 @@ void HwpReader::make_text_p3(HWPPara * para,bool bParaStart)
if( !pstart ) {STARTP;}
if( !tstart ) {STARTT;}
makeChars(str);
- makeOutline(static_cast<Outline *>(para->hhstr[n]));
+ makeOutline(static_cast<Outline *>(para->hhstr[n].get()));
break;
case CH_FIXED_SPACE:
case CH_KEEP_SPACE: