Kaydet (Commit) a05bb7bf authored tarafından Julien Nabet's avatar Julien Nabet Kaydeden (comit) Noel Grandin

Replace some lists by vectors in hwpfilter

+ simplify some parts

Change-Id: I340d6b6d17f591a58c405965367c15be674103d0
Reviewed-on: https://gerrit.libreoffice.org/43439Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ebfdb9a1
...@@ -628,7 +628,7 @@ static HWPPara *LoadParaList() ...@@ -628,7 +628,7 @@ static HWPPara *LoadParaList()
HWPFile *hwpf = GetCurrentDoc(); HWPFile *hwpf = GetCurrentDoc();
HIODev *hio = hwpf->SetIODevice(hmem); HIODev *hio = hwpf->SetIODevice(hmem);
std::list < HWPPara* > plist; std::vector< HWPPara* > plist;
hwpf->ReadParaList(plist); hwpf->ReadParaList(plist);
hwpf->SetIODevice(hio); hwpf->SetIODevice(hio);
......
...@@ -349,19 +349,15 @@ TxtBox::~TxtBox() ...@@ -349,19 +349,15 @@ TxtBox::~TxtBox()
{ {
for (auto& entry : plists) for (auto& entry : plists)
{ {
std::list < HWPPara* >::iterator it = entry.begin(); for (auto const& para : entry)
for (; it != entry.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
std::list < HWPPara* >::iterator it = caption.begin(); for (auto const& para : caption)
for (; it != caption.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
...@@ -387,11 +383,9 @@ Picture::~Picture() ...@@ -387,11 +383,9 @@ Picture::~Picture()
if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo ) if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo); delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo);
std::list < HWPPara* >::iterator it = caption.begin(); for (auto const& para : caption)
for (; it != caption.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
...@@ -400,11 +394,9 @@ Picture::~Picture() ...@@ -400,11 +394,9 @@ Picture::~Picture()
// hidden(15) // hidden(15)
Hidden::~Hidden() Hidden::~Hidden()
{ {
std::list < HWPPara* >::iterator it = plist.begin(); for (auto const& para : plist)
for (; it != plist.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
...@@ -412,11 +404,9 @@ Hidden::~Hidden() ...@@ -412,11 +404,9 @@ Hidden::~Hidden()
// header/footer(16) // header/footer(16)
HeaderFooter::~HeaderFooter() HeaderFooter::~HeaderFooter()
{ {
std::list < HWPPara* >::iterator it = plist.begin(); for (auto const& para : plist)
for (; it != plist.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
...@@ -424,11 +414,9 @@ HeaderFooter::~HeaderFooter() ...@@ -424,11 +414,9 @@ HeaderFooter::~HeaderFooter()
// footnote(17) // footnote(17)
Footnote::~Footnote() Footnote::~Footnote()
{ {
std::list < HWPPara* >::iterator it = plist.begin(); for (auto const& para : plist)
for (; it != plist.end(); ++it)
{ {
HWPPara* pPara = *it; delete para;
delete pPara;
} }
} }
......
...@@ -363,12 +363,12 @@ struct TxtBox: public FBox ...@@ -363,12 +363,12 @@ struct TxtBox: public FBox
/** /**
* Paragraph list * Paragraph list
*/ */
std::vector<std::list<HWPPara*>> plists; std::vector<std::vector<HWPPara*>> plists;
/** /**
* Caption * Caption
*/ */
std::list<HWPPara*> caption; std::vector<HWPPara*> caption;
TxtBox(); TxtBox();
virtual ~TxtBox() override; virtual ~TxtBox() override;
...@@ -511,14 +511,13 @@ struct Table ...@@ -511,14 +511,13 @@ struct Table
{ {
Table() : box(nullptr) {}; Table() : box(nullptr) {};
~Table() { ~Table() {
std::list<TCell*>::iterator it = cells.begin(); for (auto const& cell : cells)
for( ; it != cells.end(); ++it) delete cell;
delete *it;
}; };
Columns columns; Columns columns;
Rows rows; Rows rows;
std::list<TCell*> cells; std::vector<TCell*> cells;
TxtBox *box; TxtBox *box;
}; };
...@@ -626,7 +625,7 @@ struct Picture: public FBox ...@@ -626,7 +625,7 @@ struct Picture: public FBox
PicDef picinfo; PicDef picinfo;
char reserved3[9]; char reserved3[9];
std::list<HWPPara*> caption; std::vector<HWPPara*> caption;
/** /**
* It's for the Drawing object * It's for the Drawing object
*/ */
...@@ -669,7 +668,7 @@ struct Hidden: public HBox ...@@ -669,7 +668,7 @@ struct Hidden: public HBox
hchar dummy; hchar dummy;
unsigned char info[8]; // h, next, dummy unsigned char info[8]; // h, next, dummy
std::list<HWPPara*> plist; std::vector<HWPPara*> plist;
Hidden(); Hidden();
virtual ~Hidden() override; virtual ~Hidden() override;
...@@ -698,7 +697,7 @@ struct HeaderFooter: public HBox ...@@ -698,7 +697,7 @@ struct HeaderFooter: public HBox
/** /**
* Paragraph list of header or footer * Paragraph list of header or footer
*/ */
std::list<HWPPara*> plist; std::vector<HWPPara*> plist;
HeaderFooter(); HeaderFooter();
virtual ~HeaderFooter() override; virtual ~HeaderFooter() override;
...@@ -731,7 +730,7 @@ struct Footnote: public HBox ...@@ -731,7 +730,7 @@ struct Footnote: public HBox
/** /**
* Paragraph list of Footnote objects * Paragraph list of Footnote objects
*/ */
std::list<HWPPara*> plist; std::vector<HWPPara*> plist;
Footnote(); Footnote();
virtual ~Footnote() override; virtual ~Footnote() override;
......
...@@ -63,25 +63,20 @@ HWPFile::~HWPFile() ...@@ -63,25 +63,20 @@ HWPFile::~HWPFile()
delete oledata; delete oledata;
delete hiodev; delete hiodev;
std::list < ColumnInfo* >::iterator it_column = columnlist.begin(); for (auto const& column : columnlist)
for (; it_column != columnlist.end(); ++it_column) delete column;
delete *it_column;
std::list < HWPPara* >::iterator it = plist.begin(); for (auto const& paragraph : plist)
for (; it != plist.end(); ++it) delete paragraph;
delete *it;
std::vector< Table* >::iterator tbl = tables.begin(); for (auto const& table : tables)
for (; tbl != tables.end(); ++tbl) delete table;
delete *tbl;
std::list<EmPicture*>::iterator emb = emblist.begin(); for (auto const& emb : emblist)
for (; emb != emblist.end(); ++emb) delete emb;
delete *emb;
std::list<HyperText*>::iterator hyp = hyperlist.begin(); for (auto const& hyperlink : hyperlist)
for (; hyp != hyperlist.end(); ++hyp) delete hyperlink;
delete *hyp;
} }
int HWPFile::ReadHwpFile(HStream * stream) int HWPFile::ReadHwpFile(HStream * stream)
...@@ -237,7 +232,7 @@ void HWPFile::ParaListRead() ...@@ -237,7 +232,7 @@ void HWPFile::ParaListRead()
ReadParaList(plist); ReadParaList(plist);
} }
bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag) bool HWPFile::ReadParaList(std::vector < HWPPara* > &aplist, unsigned char flag)
{ {
std::unique_ptr<HWPPara> spNode( new HWPPara ); std::unique_ptr<HWPPara> spNode( new HWPPara );
unsigned char tmp_etcflag; unsigned char tmp_etcflag;
...@@ -401,43 +396,32 @@ void HWPFile::TagsRead() ...@@ -401,43 +396,32 @@ void HWPFile::TagsRead()
ColumnDef *HWPFile::GetColumnDef(int num) ColumnDef *HWPFile::GetColumnDef(int num)
{ {
std::list<ColumnInfo*>::iterator it = columnlist.begin(); if (static_cast<size_t>(num) < columnlist.size())
return columnlist[num]->coldef;
for(int i = 0; it != columnlist.end() ; ++it, i++){
if( i == num )
break;
}
if( it != columnlist.end() )
return (*it)->coldef;
else else
return nullptr; return nullptr;
} }
/* Index of @return starts from 1 */ /* Index of @return starts from 1 */
int HWPFile::GetPageMasterNum(int page) int HWPFile::GetPageMasterNum(int page)
{ {
std::list<ColumnInfo*>::iterator it = columnlist.begin(); int i = 0;
int i; for (auto const& column : columnlist)
{
for( i = 1 ; it != columnlist.end() ; ++it, i++){ if( page < column->start_page )
ColumnInfo *now = *it; return i;
if( page < now->start_page ) ++i;
return i-1;
} }
return i-1; return i;
} }
HyperText *HWPFile::GetHyperText() HyperText *HWPFile::GetHyperText()
{ {
std::list<HyperText*>::iterator it = hyperlist.begin(); ++currenthyper;
if (static_cast<size_t>(currenthyper) <= hyperlist.size())
for( int i = 0; it != hyperlist.end(); ++it, i++ ){ return hyperlist[currenthyper-1];
if( i == currenthyper ) else
break; return nullptr;
}
currenthyper++;
return it != hyperlist.end() ? *it : nullptr;
} }
EmPicture *HWPFile::GetEmPicture(Picture * pic) EmPicture *HWPFile::GetEmPicture(Picture * pic)
...@@ -448,10 +432,9 @@ EmPicture *HWPFile::GetEmPicture(Picture * pic) ...@@ -448,10 +432,9 @@ EmPicture *HWPFile::GetEmPicture(Picture * pic)
name[1] = 'W'; name[1] = 'W';
name[2] = 'P'; name[2] = 'P';
std::list < EmPicture* >::iterator it = emblist.begin(); for (auto const& emb : emblist)
for (; it != emblist.end(); ++it) if (strcmp(name, emb->name) == 0)
if (strcmp(name, (*it)->name) == 0) return emb;
return *it;
return nullptr; return nullptr;
} }
...@@ -461,10 +444,9 @@ EmPicture *HWPFile::GetEmPictureByName(char * name) ...@@ -461,10 +444,9 @@ EmPicture *HWPFile::GetEmPictureByName(char * name)
name[1] = 'W'; name[1] = 'W';
name[2] = 'P'; name[2] = 'P';
std::list < EmPicture* >::iterator it = emblist.begin(); for (auto const& emb : emblist)
for (; it != emblist.end(); ++it) if (strcmp(name, emb->name) == 0)
if (strcmp(name, (*it)->name) == 0) return emb;
return *it;
return nullptr; return nullptr;
} }
......
...@@ -160,7 +160,7 @@ class DLLEXPORT HWPFile ...@@ -160,7 +160,7 @@ class DLLEXPORT HWPFile
/** /**
* Reads main paragraph list * Reads main paragraph list
*/ */
bool ReadParaList(std::list<HWPPara*> &aplist, unsigned char flag = 0); bool ReadParaList(std::vector<HWPPara*> &aplist, unsigned char flag = 0);
/** /**
* Sets if the stream is compressed * Sets if the stream is compressed
*/ */
...@@ -282,14 +282,14 @@ class DLLEXPORT HWPFile ...@@ -282,14 +282,14 @@ class DLLEXPORT HWPFile
HWPInfo _hwpInfo; HWPInfo _hwpInfo;
HWPFont _hwpFont; HWPFont _hwpFont;
HWPStyle _hwpStyle; HWPStyle _hwpStyle;
std::list<ColumnInfo*> columnlist; std::vector<ColumnInfo*> columnlist;
// paragraph linked list // paragraph list
std::list<HWPPara*> plist; std::vector<HWPPara*> plist;
// floating box linked list // floating box list
std::list<FBox*> blist; std::vector<FBox*> blist;
// embedded picture list(tag datas) // embedded picture list(tag datas)
std::list<EmPicture*> emblist; std::vector<EmPicture*> emblist;
std::list<HyperText*> hyperlist; std::vector<HyperText*> hyperlist;
int currenthyper; int currenthyper;
std::vector<std::shared_ptr<ParaShape>> pslist; std::vector<std::shared_ptr<ParaShape>> pslist;
std::vector<std::shared_ptr<CharShape>> cslist; std::vector<std::shared_ptr<CharShape>> cslist;
......
...@@ -1921,9 +1921,8 @@ void HwpReader::makeTableStyle(Table *tbl) ...@@ -1921,9 +1921,8 @@ void HwpReader::makeTableStyle(Table *tbl)
} }
// cell // cell
for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it) for (auto const& tcell : tbl->cells)
{ {
TCell *tcell = *it;
sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1); sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
padd("style:name", sXML_CDATA, ascii( buf )); padd("style:name", sXML_CDATA, ascii( buf ));
padd("style:family", sXML_CDATA,"table-cell"); padd("style:family", sXML_CDATA,"table-cell");
...@@ -3475,9 +3474,8 @@ void HwpReader::makeTable(TxtBox * hbox) ...@@ -3475,9 +3474,8 @@ void HwpReader::makeTable(TxtBox * hbox)
// cell // cell
int j = -1, k = -1; int j = -1, k = -1;
for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it) for (auto const& tcell : tbl->cells)
{ {
TCell *tcell = *it;
if( tcell->nRowIndex > j ) if( tcell->nRowIndex > j )
{ {
if( j > k ) if( j > k )
......
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