]> git.lyx.org Git - lyx.git/blob - src/TexRow.h
Cmake build: Adapt to compile after 0213e7b5c62f487bdddd95ff0b2de736f64b1dc3
[lyx.git] / src / TexRow.h
1 // -*- C++ -*-
2 /**
3  * \file TexRow.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Matthias Ettrich
8  * \author Lars Gullik Bjønnes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef TEXROW_H
15 #define TEXROW_H
16
17 #include <vector>
18
19
20 namespace lyx {
21
22
23 /// Represents the correspondence between paragraphs and the generated
24 /// LaTeX file
25
26 class TexRow {
27 public:
28         ///
29         TexRow() : lastid(-1), lastpos(-1), started(false) {}
30
31         /// Clears structure
32         void reset();
33
34         /// Define what paragraph and position the next row will represent
35         void start(int id, int pos);
36
37         /// Insert node when line is completed
38         void newline();
39
40         /// Insert multiple nodes when zero or more lines are completed
41         void newlines(int num_lines);
42
43         /**
44          * getIdFromRow - find pid and position for a given row
45          * @param row row number to find
46          * @param id set to id if found
47          * @param pos set to paragraph position if found
48          * @return true if found, false otherwise
49          *
50          * If the row could not be found, pos is set to zero and
51          * id is set to -1
52          */
53         bool getIdFromRow(int row, int & id, int & pos) const;
54
55         /**
56          * getRowFromIdPos - find row containing a given id and pos
57          * @param id of the paragraph
58          * @param pos a given position in that paragraph
59          * @return the row number within the rowlist
60          */
61         int getRowFromIdPos(int id, int pos) const;
62         
63         /// Returns the number of rows contained
64         int rows() const { return rowlist.size(); }
65
66         /// an individual id/pos <=> row mapping
67         class RowItem {
68         public:
69                 RowItem(int id, int pos)
70                         : id_(id), pos_(pos)
71                 {}
72
73                 /// paragraph id
74                 int id() const { return id_; }
75                 /// set paragraph position
76                 void pos(int p) { pos_ = p; }
77                 /// paragraph position
78                 int pos() const { return pos_; }
79         private:
80                 RowItem();
81                 int id_;
82                 int pos_;
83         };
84         ///
85         typedef std::vector<RowItem> RowList;
86 private:
87         /// container of id/pos <=> row mapping
88         RowList rowlist;
89         /// Last paragraph
90         int lastid;
91         /// Last position
92         int lastpos;
93         /// Is id/pos already registered for current row?
94         bool started;
95 };
96
97
98 } // namespace lyx
99
100 #endif // TEXROW_H