2002-05-30 03:37:24 +00:00
|
|
|
/**
|
|
|
|
* \file texrow.C
|
|
|
|
* Copyright 1995-2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-05-30 03:37:24 +00:00
|
|
|
* \author Matthias Ettrich
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "texrow.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-05-07 21:27:29 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
using std::find_if;
|
2000-08-07 20:58:24 +00:00
|
|
|
using std::endl;
|
1999-11-22 16:19:48 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
namespace {
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/// 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_;
|
|
|
|
}
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
private:
|
|
|
|
int row_;
|
|
|
|
};
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void TexRow::reset()
|
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
count = 0;
|
2003-05-07 21:27:29 +00:00
|
|
|
lastid = -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
lastpos = -1;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
2003-05-07 21:27:29 +00:00
|
|
|
void TexRow::start(int id, int pos)
|
1999-11-22 16:19:48 +00:00
|
|
|
{
|
2003-05-07 21:27:29 +00:00
|
|
|
lastid = id;
|
1999-09-27 18:44:28 +00:00
|
|
|
lastpos = pos;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void TexRow::newline()
|
|
|
|
{
|
2003-05-07 21:27:29 +00:00
|
|
|
int const id = lastid;
|
2002-05-30 03:37:24 +00:00
|
|
|
RowList::value_type tmp(id, lastpos, ++count);
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.push_back(tmp);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
|
|
|
|
{
|
|
|
|
RowList::const_iterator cit =
|
2002-12-01 22:59:25 +00:00
|
|
|
find_if(rowlist.begin(), rowlist.end(),
|
2002-05-30 03:37:24 +00:00
|
|
|
same_rownumber(row));
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
if (cit != rowlist.end()) {
|
2001-07-12 11:11:10 +00:00
|
|
|
id = cit->id();
|
|
|
|
pos = cit->pos();
|
2000-08-05 05:17:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
id = -1;
|
|
|
|
pos = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
TexRow & TexRow::operator+=(TexRow const & tr)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
|
1999-09-27 18:44:28 +00:00
|
|
|
return *this;
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|