mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
* TexRow.{h,cpp} switch from std::list to std::vector
(operator+=): remove unused method (getRowFromIdPos) new method to get the texrow from id,pos git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19502 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
484dd46b35
commit
6b87801d09
@ -20,30 +20,10 @@
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using std::find_if;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
/// function object returning true when row number is found
|
||||
class same_rownumber {
|
||||
public:
|
||||
same_rownumber(int row) : row_(row) {}
|
||||
bool operator()(TexRow::RowList::value_type const & vt) const {
|
||||
return vt.rownumber() == row_;
|
||||
}
|
||||
|
||||
private:
|
||||
int row_;
|
||||
};
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void TexRow::reset()
|
||||
{
|
||||
rowlist.clear();
|
||||
count = 0;
|
||||
lastid = -1;
|
||||
lastpos = -1;
|
||||
}
|
||||
@ -59,32 +39,41 @@ void TexRow::start(int id, int pos)
|
||||
void TexRow::newline()
|
||||
{
|
||||
int const id = lastid;
|
||||
RowList::value_type tmp(id, lastpos, ++count);
|
||||
RowList::value_type tmp(id, lastpos);
|
||||
rowlist.push_back(tmp);
|
||||
}
|
||||
|
||||
|
||||
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
|
||||
{
|
||||
RowList::const_iterator cit =
|
||||
find_if(rowlist.begin(), rowlist.end(),
|
||||
same_rownumber(row));
|
||||
|
||||
if (cit != rowlist.end()) {
|
||||
id = cit->id();
|
||||
pos = cit->pos();
|
||||
return true;
|
||||
if (row <= 0 || row > rowlist.size()) {
|
||||
id = -1;
|
||||
pos = 0;
|
||||
return false;
|
||||
}
|
||||
id = -1;
|
||||
pos = 0;
|
||||
return false;
|
||||
|
||||
id = rowlist[row - 1].id();
|
||||
pos = rowlist[row - 1].pos();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TexRow & TexRow::operator+=(TexRow const & tr)
|
||||
int TexRow::getRowFromIdPos(int id, int pos) const
|
||||
{
|
||||
rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
|
||||
return *this;
|
||||
int bestrow = 0;
|
||||
bool foundid = false;
|
||||
|
||||
// this loop finds the last *nonempty* row whith the same id
|
||||
// and position <= pos
|
||||
for (unsigned r = 0, n = rowlist.size(); r != n; ++r) {
|
||||
if (rowlist[r].id() == id && rowlist[r].pos() <= pos) {
|
||||
foundid = true;
|
||||
if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos())
|
||||
bestrow = r;
|
||||
} else if (foundid)
|
||||
break;
|
||||
}
|
||||
return bestrow;
|
||||
}
|
||||
|
||||
|
||||
|
27
src/TexRow.h
27
src/TexRow.h
@ -14,7 +14,7 @@
|
||||
#ifndef TEXROW_H
|
||||
#define TEXROW_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -26,9 +26,7 @@ namespace lyx {
|
||||
class TexRow {
|
||||
public:
|
||||
///
|
||||
TexRow() : count(0), lastid(-1), lastpos(-1) {}
|
||||
|
||||
TexRow & operator+= (TexRow const &);
|
||||
TexRow() : lastid(-1), lastpos(-1) {}
|
||||
|
||||
/// Clears structure
|
||||
void reset();
|
||||
@ -51,14 +49,22 @@ public:
|
||||
*/
|
||||
bool getIdFromRow(int row, int & id, int & pos) const;
|
||||
|
||||
/**
|
||||
* getRowFromIdPos - find row containing a given id and pos
|
||||
* @param id of the paragraph
|
||||
* @param pos a given position in that paragraph
|
||||
* @return the row number within the rowlist
|
||||
*/
|
||||
int getRowFromIdPos(int id, int pos) const;
|
||||
|
||||
/// Returns the number of rows contained
|
||||
int rows() const { return count; }
|
||||
int rows() const { return rowlist.size(); }
|
||||
|
||||
/// an individual id/pos <=> row mapping
|
||||
class RowItem {
|
||||
public:
|
||||
RowItem(int id, int pos, int row)
|
||||
: id_(id), pos_(pos), rownumber_(row)
|
||||
RowItem(int id, int pos)
|
||||
: id_(id), pos_(pos)
|
||||
{}
|
||||
|
||||
/// paragraph id
|
||||
@ -67,19 +73,14 @@ public:
|
||||
void pos(int p) { pos_ = p; }
|
||||
/// paragraph position
|
||||
int pos() const { return pos_; }
|
||||
/// row number
|
||||
int rownumber() const { return rownumber_; }
|
||||
private:
|
||||
RowItem();
|
||||
int id_;
|
||||
int pos_;
|
||||
int rownumber_;
|
||||
};
|
||||
///
|
||||
typedef std::list<RowItem> RowList;
|
||||
typedef std::vector<RowItem> RowList;
|
||||
private:
|
||||
/// number of lines
|
||||
unsigned int count;
|
||||
/// container of id/pos <=> row mapping
|
||||
RowList rowlist;
|
||||
/// Last paragraph
|
||||
|
Loading…
Reference in New Issue
Block a user