]> git.lyx.org Git - lyx.git/blob - src/texrow.C
"Inter-word Space"
[lyx.git] / src / texrow.C
1 /**
2  * \file texrow.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Matthias Ettrich
7  */
8
9 #include <config.h>
10
11 #include "texrow.h"
12 #include "debug.h"
13
14 #include <algorithm>
15
16 using std::find_if;
17 using std::endl;
18
19 namespace {
20
21 /// function object returning true when row number is found
22 class same_rownumber {
23 public:
24         same_rownumber(int row) : row_(row) {}
25         bool operator()(TexRow::RowList::value_type const & vt) const {
26                 return vt.rownumber() == row_;
27         }
28
29 private:
30         int row_;
31 };
32
33 } // namespace anon
34
35
36 void TexRow::reset()
37 {
38         rowlist.clear();
39         count = 0;
40         lastid = -1;
41         lastpos = -1;
42 }
43
44
45 void TexRow::start(int id, int pos)
46 {
47         lastid = id;
48         lastpos = pos;
49 }
50
51
52 void TexRow::newline()
53 {
54         int const id = lastid;
55         RowList::value_type tmp(id, lastpos, ++count);
56         rowlist.push_back(tmp);
57 }
58
59
60 bool TexRow::getIdFromRow(int row, int & id, int & pos) const
61 {
62         RowList::const_iterator cit =
63                 find_if(rowlist.begin(), rowlist.end(),
64                         same_rownumber(row));
65
66         if (cit != rowlist.end()) {
67                 id = cit->id();
68                 pos = cit->pos();
69                 return true;
70         }
71         id = -1;
72         pos = 0;
73         return false;
74 }
75
76
77 TexRow & TexRow::operator+=(TexRow const & tr)
78 {
79         rowlist.insert(rowlist.end(), tr.rowlist.begin(), tr.rowlist.end());
80         return *this;
81 }