]> git.lyx.org Git - lyx.git/blob - src/texrow.C
unify toclevel for articles and reports/books; proper numbering of Paragraph/SubParag...
[lyx.git] / src / texrow.C
1 /**
2  * \file texrow.C
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 using std::find_if;
21
22
23 namespace {
24
25 /// function object returning true when row number is found
26 class same_rownumber {
27 public:
28         same_rownumber(int row) : row_(row) {}
29         bool operator()(TexRow::RowList::value_type const & vt) const {
30                 return vt.rownumber() == row_;
31         }
32
33 private:
34         int row_;
35 };
36
37 } // namespace anon
38
39
40 void TexRow::reset()
41 {
42         rowlist.clear();
43         count = 0;
44         lastid = -1;
45         lastpos = -1;
46 }
47
48
49 void TexRow::start(int id, int pos)
50 {
51         lastid = id;
52         lastpos = pos;
53 }
54
55
56 void TexRow::newline()
57 {
58         int const id = lastid;
59         RowList::value_type tmp(id, lastpos, ++count);
60         rowlist.push_back(tmp);
61 }
62
63
64 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
65 {
66         RowList::const_iterator cit =
67                 find_if(rowlist.begin(), rowlist.end(),
68                         same_rownumber(row));
69
70         if (cit != rowlist.end()) {
71                 id = cit->id();
72                 pos = cit->pos();
73                 return true;
74         }
75         id = -1;
76         pos = 0;
77         return false;
78 }
79
80
81 TexRow & TexRow::operator+=(TexRow const & tr)
82 {
83         rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
84         return *this;
85 }