* qt_helpers.cpp:
[lyx.git] / src / TexRow.cpp
blobf95602ec3a5e27d7a8ca729cf2fef0e88bd79d3c
1 /**
2 * \file TexRow.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Matthias Ettrich
7 * \author Lars Gullik Bjønnes
8 * \author John Levon
10 * Full author contact details are available in file CREDITS.
13 #include <config.h>
15 #include "TexRow.h"
17 #include "support/debug.h"
19 #include <algorithm>
22 namespace lyx {
25 void TexRow::reset()
27 rowlist.clear();
28 lastid = -1;
29 lastpos = -1;
33 void TexRow::start(int id, int pos)
35 lastid = id;
36 lastpos = pos;
40 void TexRow::newline()
42 int const id = lastid;
43 RowList::value_type tmp(id, lastpos);
44 rowlist.push_back(tmp);
48 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
50 if (row <= 0 || row > int(rowlist.size())) {
51 id = -1;
52 pos = 0;
53 return false;
56 id = rowlist[row - 1].id();
57 pos = rowlist[row - 1].pos();
58 return true;
62 int TexRow::getRowFromIdPos(int id, int pos) const
64 bool foundid = false;
66 // this loop finds the last *nonempty* row with the same id
67 // and position <= pos
68 RowList::const_iterator bestrow = rowlist.begin();
69 RowList::const_iterator it = rowlist.begin();
70 RowList::const_iterator const end = rowlist.end();
71 for (; it != end; ++it) {
72 if (it->id() == id && it->pos() <= pos) {
73 foundid = true;
74 if (bestrow->id() != id || it->pos() > bestrow->pos())
75 bestrow = it;
76 } else if (foundid)
77 break;
79 if (!foundid)
80 return rowlist.size();
81 return distance(rowlist.begin(), bestrow);
85 } // namespace lyx