]> git.lyx.org Git - lyx.git/blob - src/TexRow.cpp
use FileName::isDirectory()
[lyx.git] / src / TexRow.cpp
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.
5  *
6  * \author Matthias Ettrich
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "TexRow.h"
16 #include "debug.h"
17
18 #include <algorithm>
19
20
21 namespace lyx {
22
23
24 void TexRow::reset()
25 {
26         rowlist.clear();
27         lastid = -1;
28         lastpos = -1;
29 }
30
31
32 void TexRow::start(int id, int pos)
33 {
34         lastid = id;
35         lastpos = pos;
36 }
37
38
39 void TexRow::newline()
40 {
41         int const id = lastid;
42         RowList::value_type tmp(id, lastpos);
43         rowlist.push_back(tmp);
44 }
45
46
47 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
48 {
49         if (row <= 0 || row > int(rowlist.size())) {
50                 id = -1;
51                 pos = 0;
52                 return false;
53         }
54
55         id = rowlist[row - 1].id();
56         pos = rowlist[row - 1].pos();
57         return true;
58 }
59
60
61 int TexRow::getRowFromIdPos(int id, int pos) const
62 {
63         int bestrow = 0;
64         bool foundid = false;
65
66         // this loop finds the last *nonempty* row whith the same id
67         // and position <= pos
68         for (unsigned r = 0, n = rowlist.size(); r != n; ++r) {
69                 if (rowlist[r].id() == id && rowlist[r].pos() <= pos) {
70                         foundid = true;
71                         if (rowlist[bestrow].id() != id || rowlist[r].pos() > rowlist[bestrow].pos())
72                                 bestrow = r;
73                 } else if (foundid)
74                         break;
75         }
76         if (!foundid)
77                 return rowlist.size();
78         return bestrow;
79 }
80
81
82 } // namespace lyx