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